xxxxxxxxxx
43
class Circle {
constructor() {
this.x = random(width);
this.y = -30;
this.diam = random(15, 30);
this.yVel = random(2, 5);
this.color = 255;
}
}
let circles = [];
let numCircles = 20;
function setup() {
createCanvas(400, 400);
for (let d = 0; d < numCircles; d += 1) {
let aCircle = new Circle();
circles.push(aCircle);
}
}
function draw() {
background(120);
// for each circle:
for (let d = 0; d < circles.length; d += 1) {
let aCircle = circles[d];
// draw
fill(aCircle.color);
ellipse(aCircle.x, aCircle.y, aCircle.diam, aCircle.diam);
// update
aCircle.y += aCircle.yVel;
// check
if (aCircle.y > height) {
aCircle.y = -30;
}
}
}