xxxxxxxxxx
49
let cloudX;
let cloudY;
let cloudOffsets = [];
function setup() {
createCanvas(400, 600);
cloudY = 100;
cloudX = -150;
// Store random offsets for clouds
for (let i = 0; i < 5; i++) {
let offsetX = random(50, 300);
let offsetY = random(50, 200);
cloudOffsets.push({x: offsetX, y: offsetY});
}
}
function draw() {
if (mouseIsPressed) {
background('#082736BA');
fill('rgb(192,192,192)');
} else {
background('#D0DCE2BA');
fill(255);
}
noStroke();
// Use a for loop to draw multiple clouds
for (let i = 0; i < cloudOffsets.length; i++) {
let offsetX = cloudOffsets[i].x;
let offsetY = cloudOffsets[i].y;
// Draw a cloud
ellipse(cloudX + offsetX, cloudY - 25 + offsetY, 100, 80);
ellipse(cloudX - 40 + offsetX, cloudY - 40 + offsetY, 80, 60);
ellipse(cloudX + 40 + offsetX, 70 + offsetY, cloudY - 40, 50);
ellipse(cloudX - 20 + offsetX, 70 + offsetY, cloudY - 20, 60);
}
// Move clouds
cloudX += 5;
// Reset clouds when they move off-screen
if (cloudX > width + 200) {
cloudX = -200;
}
}