xxxxxxxxxx
54
function drawClouds() {
stroke(255);
fill(255);
let d = 100;
for (let c = 0; c < 7; c += 1) {
let xPos = 20 + c * 66;
let yPos = 45 - (c % 3) * 20;
ellipse(xPos, yPos, d, d);
}
}
let xPos = [];
let yPos = [];
let yVel = 4;
let cDiam = 20;
let numDrops = 10;
function setup() {
createCanvas(400, 400);
for (let d = 0; d < numDrops; d += 1) {
xPos.push(random(width));
yPos.push(random(-50, 50));
}
}
function draw() {
background(120);
fill(255);
stroke(0);
// for each drop:
for (let d = 0; d < xPos.length; d += 1) {
// draw
ellipse(xPos[d], yPos[d], cDiam, cDiam);
// update
yPos[d] = yPos[d] + yVel;
// check
if (yPos[d] > height) {
xPos[d] = random(width);
yPos[d] = random(-50, 50);
}
}
// draw some clouds
drawClouds();
}