Survey creation

Hi all,
I have started a new project in which I want to make a survey using processing. My idea was to insert shapes as multiple choice selection tools and text as the question itself. I’ve been struggling to formulate this, however, so I came here to ask a rough example of a survey with like an example question?
Thanks,
Doge

1 Like

Also I am relatively experienced in Java programming but not so much in Processing.



// list of questions
ArrayList<Question> questions = new ArrayList();

// current
int questionNumber=0;

void setup() {
  size (900, 400);
  textSize(14);

  // make list 
  String[] a1={"wee", "wwddx", "sdf", "sdf", "sdf", "YES", "no."};
  String[] a2={"awwwwee", "aaawwddx", "asdf", "asdf", "sdf", "YES", "no."};
  String[] a3={"bbbbbawwwwee", "bbbbbbaaawwddx", "bbbbasdf", "asdf", "sdf", "YES", "no."};

  questions.add ( new Question("Does it rain?", a1, 40, 40));
  questions.add ( new Question("Did it?", a2, 40, 40));
  questions.add ( new Question("Ask?", a3, 40, 40));
}

void draw() {
  background(0);

  if (questionNumber<questions.size()) {
    Question q1 = questions.get(questionNumber); 
    q1.display();
  } else {
    text("Test is over", 
      333, 333);
  }
}

// -------------------------------------------------------------------

void mousePressed() {

  // end ? 
  if (questionNumber>=questions.size()) {
    return;
  }

  //submit 
  if (mouseX>width/2) {
    questionNumber++;
    return;
  }

  // check input
  Question q1 = questions.get(questionNumber) ; 
  q1.checkMouse();
}

// =========================================================================

class Question {
  //
  String text1;

  float x;
  float y;

  ArrayList<Button> buttons = new ArrayList();

  //constr 
  Question (String t1_, 
    String[] a1, 
    float x_, float y_ ) {

    text1 = t1_;

    x=x_;
    y=y_;

    for (int i = 0; i < 6; i++) {
      buttons.add ( new  Button( a1[i], 66, 32*i+66 ));
    }
  }//constr 

  void display() {
    fill(255);
    text (text1, x-10, y-10);

    for (Button b1 : buttons) {
      b1.display();
    }

    textSize(89); 
    text ("SUBMIT", 
      width/2, height-222);
    textSize(14);
  }

  void checkMouse() {
    Button b2=null;
    boolean foundOne = false; 
    for (Button b1 : buttons) {
      if (b1.checkMouse()) {
        b1.isOn=true;
        b2=b1; 
        foundOne=true;
      }//if
    }//for
    if (foundOne) {
      for (Button b1 : buttons) {
        b1.isOn=false;
      }
      b2.isOn=true;
    } // if
  }// func
}

// ====================================================================

class Button {
  //

  String possibleAnswer; 

  float x;
  float y;
  float sizeButton = 10; 
  boolean isOn = false;  

  //constr 
  Button ( String t1_, 
    float x_, float y_ ) {

    possibleAnswer = t1_; 

    x=x_;
    y=y_;
  }//constr 

  void display() {
    if (isOn) {
      fill(255);
    } else {
      fill(0);
      stroke(255);
    }
    rect(x, y, sizeButton, sizeButton);
    fill(255);
    text(possibleAnswer, x+22, y+11);
  }

  boolean checkMouse() {
    if (dist(mouseX, mouseY, 
      x+sizeButton/2, y+sizeButton/2) < 20)
      return true;
    else
      return false;
  }
}//class
//

Hello @coderdoge,

Welcome to the forum.

Processing in Java < Has a section called Processing is Java

One of the best tools in a programmers tool chest is knowing the resources available to you and learning to navigate and use them.

I encourage you to review the resources available here:

Have fun!

:)

That’s only the beginning of course

You need to record the answers (for example in the first class)

And make submit a real button

Give a result screen maybe

And a start screen with Headline and Explanation

thank you so much, this really helps me out! Also, is there a possible way for a survey like this one to be opened up via something like a discord link or an email link? Thanks again

yeah sure, you need to put it on a website then.