xxxxxxxxxx
61
/*
Can you make the eyes change color based on the x position of the mouse?
Can you make a nose appear if you press a key?
Can you make one kind of nose appear if you press the a key and another kind of nose if you press the k key?
Can you make the face one color if the Y position of the mouse is less than 200 and another color if the Y position is greater than 200?
Can you make the size of the eyes bigger if the mouse is pressed? (Without drawing a new ellipse, hint: use a variable!)
*/
function setup() {
createCanvas(400, 400);
}
let eye_size = 20;
function draw() {
background(230, 230, 255);
noStroke();
// face
if (mouseY > 200) { // checking the Y position of the mouse
fill(255, 255, 0);
} else {
fill(0, 255, 0);
} // end if
ellipse(200, 200, 300, 300);
if (keyIsPressed == true) { //checking if key is pressed
if (key == 'a') { // checking which key is pressed
fill(255, 0, 0);
ellipse(200, 200, 20, 20);
} else if (key == 'k') {
fill(0, 0, 255);
ellipse(200, 220, 40, 20);
} // if a or k key is being pressed
} // key is pressed
//eyes
fill(mouseX, 0, 0);
ellipse(100, 200, eye_size, eye_size); // left
ellipse(300, 200, 20, 20); // right
// mouth
fill(0, 0, 0);
if (mouseIsPressed == true) { // if the mouse is pressed
rect(100, 250, 200, 10); // draw this rectangle
eye_size = 40;
} else { // otherwise...
rect(150, 250, 100, 20); // draw this rectangle
eye_size = 20;
}
}