xxxxxxxxxx
60
var mood = 50; // use "mood" variable to control drawn face
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
if (mood < 30) {
// if mood is less than 30
drawAngryFace(mouseX, mouseY);
} else if (mood < 70) {
// else if mood is less than 70
drawNeutralFace(mouseX, mouseY);
} else {
// else, for all other conditions
drawHappyFace(mouseX, mouseY);
}
}
function drawHappyFace(x, y) {
push();
translate(x, y);
fill(255, 255, 0);
strokeWeight(15);
stroke(0);
circle(0, 0, 200);
line(-30, -30, -30, -10);
line(30, -30, 30, -10);
arc(0, 20, 60, 60, 0, PI);
pop();
}
function drawNeutralFace(x, y) {
push();
translate(x, y);
fill(255, 200, 150);
strokeWeight(15);
stroke(0);
circle(0, 0, 200);
line(-30, -30, -30, -10);
line(30, -30, 30, -10);
line(-30, 30, 30, 30);
pop();
}
function drawAngryFace(x, y) {
push();
translate(x, y);
fill(255, 80, 0);
strokeWeight(15);
stroke(0);
circle(0, 0, 200);
line(-40, -30, -20, -20);
line(40, -30, 20, -20);
arc(0, 40, 60, 60, PI, 0);
pop();
}