xxxxxxxxxx
66
function setup() {
createCanvas(400, 400);
}
function draw() {
background("skyblue");
noStroke();
fill("white");
ellipse(100, 25, 150, 50);
ellipse(300, 25, 125, 30);
mountains(map(mouseX, 0, 400, 175, 225));
hills(map(mouseX, 0, 400, 200, 300));
trees(mouseX);
car(map(mouseX, 0, 400, -200, 600));
}
function mountains(x) {
noStroke();
fill("grey");
for (let i = 1; i<20; i++) {
let my_x = (x - 400) + 50 * i;
// Make the height of the mountains modulate
let my_y = 50 + (25 * (i % 2));
triangle(my_x, my_y, my_x - 50, 150, my_x + 50, 150);
}
}
function hills(x) {
noStroke();
fill("darkgreen");
for (let i = 1; i<10; i++) {
let my_x = (x - 400) + 100 * i;
let my_y = 250 - (25 * (i % 2));
ellipse(my_x, my_y, 200, my_y);
}
}
function trees(x) {
for (let i = 1; i<20; i++) {
let my_x = (x - 600) + 75 * i;
let my_y = 200 - (10 * (i % 3));
stroke("brown");
strokeWeight(10);
line(my_x, my_y, my_x, 300);
noStroke();
fill("maroon");
ellipse(my_x, my_y, 50, 50);
}
}
function car(x) {
noStroke();
fill("lightgray");
rect(0, 300, 400, 100);
strokeWeight(10);
fill("gray")
stroke("black");
circle(x - 75, 350, 50);
circle(x + 75, 350, 50);
noStroke();
fill("blue");
quad(x - 75, 300, x + 75, 300, x + 50, 250, x - 50, 250);
rect(x - 125, 300, 250, 50);
}