/*
CINDY CHI
OCT. 15, 2008
DMA 28: INTERACTIVITY
EXCERCISE G
This program takes input from the user and responds to
what is typed by changing aspects of the text as well as
giving direct feedback.
Possible input:
Question #1:
yes = sets backround a certain color dependin on time of day
no = insists on yes
Question #2:
further = shrinks word
closer = magnifies word
Question #3:
fly = word rises
jump = word falls
Question #4:
yell = all caps
calm = unchanged
Question #5:
friend = duplicates user input for a friend
loner = unchanged
*/
PFont original;
PFont question;
//Set color variables
int h = 210;
int s = 0;
int b = 99;
int q_num = 1;
//Time
int day_time = hour();
float scale_num = 1;
int y_coord = 200;
String user_input = "";
void setup()
{
size(400, 400);
colorMode(HSB, 359, 100, 100);
background(0);
original = loadFont("Cambria-80.vlw");
question = loadFont("PrestigeEliteStd-Bd-14.vlw");
}
void draw()
{
background(h, s, b);
textFont(question);
fill(216, 1, 75);
//Questions
if(q_num == 1)
{
if(user_input.equals("no"))
{
text("Why not? It'll be easier to see. Yes?", 5, 20);
}
else
{
text("Wanna set your environment to the time of day?", 5, 20);
}
}
else if(q_num == 2)
{
text("Great now the window looks lovely. I know people", 5, 20);
text("need personal space. Do you want me closer or", 5, 35);
text("further?", 5, 50);
}
else if(q_num == 3)
{
text("Now it's time to have some fun. Do you want to ", 5, 20);
text("jump or fly?", 5, 35);
}
else if(q_num == 4)
{
text("See, wasn't that exciting?!", 5, 20);
text("Say 'yell' if you were excited or 'calm' if not.", 5, 35);
}
else if(q_num == 5)
{
text("Alright, well it's time to leave but you've", 5, 20);
text("gained a friend if you want. Friend or loner?", 5, 35);
}
else if(q_num == 6)
{
if(user_input.equals("Friends :)"))
{
textFont(original);
text(user_input, 5, y_coord + 60);
textFont(question);
text("Goodbye now. May we meet again!", 5, 20);
}
else if(user_input.equals("lonely :("))
{
text("I guess we must leave on sad terms.", 5, 20);
}
}
//User Input
textFont(original);
scale(scale_num, scale_num);
text(user_input, 5, y_coord);
}
void keyPressed()
{
if((key == ENTER) || (key == RETURN))
{
user_input = user_input.toLowerCase();
println(user_input);
//Question #1: Background color changes according to what hour on clock.
if(user_input.equals("yes"))
{
if(day_time <= 7 && day_time >= 4)
{
h = 216;
s = 99;
b = 95;
q_num = 2;
}
else if(day_time <= 4 && day_time >= 20)
{
h = 216;
s = 99;
b = 24;
q_num = 2;
}
else if(day_time <= 11 && day_time >= 7)
{
h = 216;
s = 99;
b = 82;
q_num = 2;
}
else if(day_time <= 17 && day_time >= 11)
{
h = 216;
s = 99;
b = 65;
q_num = 2;
}
else //if(day_time <= 20 && day_time >= 17)
{
h = 216;
s = 99;
b = 51;
q_num = 2;
}
}
else if(user_input.equals("no"))
{
q_num = 1;
}
//Question #2: text becomes bigger if closer and smaller if further
else if(user_input.equals("closer"))
{
y_coord = 170;
scale_num = 1.3;
user_input = "Oh, cozy.";
q_num = 3;
}
else if(user_input.equals("further"))
{
y_coord = 400;
scale_num = 0.5;
user_input = "Not touchy, I see.";
q_num = 3;
}
//Question #3: text rises if fly and falls if jump
else if(user_input.equals("fly"))
{
if(scale_num == 1.3)
{
y_coord = 90;
user_input = "Weee!!";
}
else
{
y_coord = 130;
}
q_num = 4;
}
else if(user_input.equals("jump"))
{
if(scale_num == 1.3)
{
y_coord = 290;
user_input = "Wahhh!!";
}
else
{
y_coord = 780;
}
q_num = 4;
}
//Question #4: text goes to allcaps of yell and unchanged if calm.
else if(user_input.equals("yell"))
{
user_input = user_input.toUpperCase();
user_input = "WOOO!!!!";
q_num = 5;
}
else if(user_input.equals("calm"))
{
user_input = "Eh.";
q_num = 5;
}
//Question #5: Returns to original size/placement and copies text to give
//user a "friend" if user wants
else if(user_input.equals("friend"))
{
scale_num = 1.0;
y_coord = 200;
user_input = "Friends :)";
q_num = 6;
}
else if(user_input.equals("loner"))
{
scale_num = 1.0;
y_coord = 200;
user_input = "lonely :(";
q_num = 6;
}
}
else if(key == BACKSPACE)
{
if(user_input.length() > 0)
{
user_input = user_input.substring(0, user_input.length()-1);
}
}
else if(textWidth(user_input + key) < width)
{
user_input = user_input + key;
}
}Cindy - G
on Tuesday, Oct 21, 2008 – 10:17 pm