xxxxxxxxxx
120
function setup() {
createCanvas(600, 400);
}
function draw() {
// background & text
if (mouseIsPressed == false) {
background(204, 233, 255);
fill(0);
noStroke();
textSize(15);
text("Click to cut down a tree", 320, 80);
} else {
background(37, 35, 61);
fill(255);
noStroke();
textSize(15);
text("Got apple, but the tree is dead", 320, 80);
}
// tree & apple
if (mouseIsPressed == false) {
// tree
fill(153, 222, 66);
rect(125, 30, 50, 50, 25);
rect(100, 55, 100, 50, 25);
rect(75, 95, 150, 60, 30);
rect(50, 135, 200, 70, 35);
// apple
fill(255, 0, 0);
rect(120, 84, 30, 30, 15);
rect(170, 125, 30, 30, 15);
rect(100, 150, 30, 30, 15);
strokeWeight(2);
stroke(95, 72, 52);
line(128, 90, 142, 90);
line(178, 131, 192, 131);
line(108, 156, 122, 156);
line(135, 80, 135, 90);
line(185, 121, 185, 131);
line(115, 146, 115, 156);
} else {
// tree(dead)
fill(255);
noStroke();
circle(150, 80, 60);
triangle(123, 93, 150, 133, 177, 93);
strokeWeight(3);
stroke(157, 103, 52);
line(133, 68, 143, 78);
line(143, 68, 133, 78);
line(157, 68, 167, 78);
line(167, 68, 157, 78);
// apple
fill(255, 0, 0);
noStroke();
rect(430, 226, 30, 30, 15);
rect(465, 226, 30, 30, 15);
rect(500, 226, 30, 30, 15);
strokeWeight(2);
stroke(95, 72, 52);
line(438, 232, 452, 232);
line(473, 232, 487, 232);
line(508, 232, 522, 232);
line(445, 222, 445, 232);
line(480, 222, 480, 232);
line(515, 222, 515, 232);
}
// ground
noStroke();
fill(159, 202, 138);
rect(0, 320, 600, 80);
// tree trunk
noStroke();
fill(117, 93, 71);
rect(110, 205, 80, 115);
strokeWeight(5);
stroke(95, 72, 52);
line(130, 208, 130, 317);
line(150, 208, 150, 317);
line(170, 208, 170, 317);
// basket
noStroke();
fill(200, 147, 98);
rect(430, 260, 100, 60, 0, 0, 30, 30);
noStroke();
fill(157, 103, 52);
rect(425, 250, 110, 10, 5);
strokeWeight(5);
stroke(157, 103, 52);
line(433, 270, 527, 270);
line(433, 280, 527, 280);
line(433, 290, 527, 290);
line(465, 260, 465, 317);
line(480, 260, 480, 317);
line(495, 260, 495, 317);
// ax
if (mouseIsPressed == false) {
noStroke();
fill(191);
rect(mouseX - 45, mouseY - 50, 35, 40);
fill(132);
rect(mouseX - 45, mouseY - 50, 10, 40);
fill(95, 72, 52);
rect(mouseX - 10, mouseY - 55, 10, 90, 5);
} else {
noStroke();
fill(191);
rect(130, 170, 40, 35);
fill(132);
rect(130, 195, 40, 10);
fill(95, 72, 52);
rect(125, 160, 90, 10, 5);
}
}