xxxxxxxxxx
42
let squares = [];
let ystart = 0;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
let xoff = 0;
for (let i = squares.length - 1; i >= 0; i--) {
let s = squares[i];
s.show();
if (s.update()) {
squares.splice(i, 1);
}
}
if (random(1) < 0.5) {
let s = new Square();
squares.push(s);
}
}
class Square {
constructor(x, y) {
this.x = x || random(width);
this.y = y || random(height, height * 2);
this.speed = random(1, 10);
}
show() {
fill(255);
square(this.x, this.y, 5);
}
update() {
this.y -= this.speed;
return this.y < 0;
}
}