Jessica - G

By Jessica Thornburgh
//respond with a yes or no answer then hit enter or return PFont font; String question = "Do your feet hurt?"; String answer=""; int back = 102; void setup() { size(400, 400); font = loadFont("Eureka-24.vlw"); textFont(font); textAlign(CENTER); smooth(); } void draw() { background(back); text(question, 100, 75,200,300); text(answer, 200,300); } void keyPressed() { if ((key == ENTER) || (key == RETURN)) { textSize(36); answer = answer.toLowerCase(); println(answer); // Print to console to see input if (answer.equals("yes")) { back = 255; stroke(0); fill(0); question = "I thought so. You've been running through my mind all day!"; } else if (answer.equals("no")) { back = 0; stroke(255); fill(255); question = "Oh, no? My mistake. I must have you confused with someone else."; } answer = ""; // Clear the variable }else if (key==BACKSPACE) { if(answer.length()>0) { answer = answer.substring(0,answer.length()-1); } }else if ((key > 31) && (key != CODED)) { // If the key is alphanumeric, add it to the String answer = answer + key; } }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*