xxxxxxxxxx
62
function setup() {
createCanvas(400, 400);
}
// body variables
let head, body, hat, apple, face;
function draw() {
// background
background(220);
// body
body =
color(36, 50, 71)
fill(body)
strokeWeight(1)
stroke(0, 0, 0)
rect(100, 280, 200, 150, 20, 20, 20, 20);
// head
head =
color(231, 219, 209)
fill(head)
strokeWeight(1)
stroke(0, 0, 0)
// centers the ellipse
translate(width / 2, height / 2)
ellipse(0, 0, 180, 220);
// apple
apple =
strokeWeight(1)
stroke(0, 0, 0)
// toggle face on screen click
if (mouseIsPressed == true) {
if (mouseButton == LEFT) {
strokeWeight(0)
fill(0);
circle(-40, -20, 20) // left eye
circle(40, -20, 20) // right eye
rect(-30, 40, 60, 20); // mouth
}
}
else {
fill(140, 174, 152); // apple
ellipse(1, 10, 150, 140);
}
// hat
hat =
color(36, 50, 71)
fill(hat)
strokeWeight(2)
stroke(0)
square(-45, -180, 90, 80, 55, 10, 10);
rect(-70, -100, 140, 20);
}