p5((s) => {
let drops = [];
s.setup = function () {
s.createCanvas(width, 400);
};
s.draw = function () {
s.background(0);
s.stroke(255);
for (let i = 0; i < drops.length; i++) {
drops[i].fall();
drops[i].show();
if (drops[i].y > s.height) {
drops.splice(i, 1);
}
}
if (s.frameCount % 20 === 0) {
let drop = new Drop(s.random(s.width), -100, s.random(10, 20));
drops.push(drop);
}
};
class Drop {
constructor(x, y, speed) {
this.x = x;
this.y = y;
this.speed = speed;
}
fall() {
this.y += this.speed;
this.x += this.speed / 2
}
show() {
s.line(this.x, this.y, this.x + 5, this.y + s.random(2,10));
}
}
})