xxxxxxxxxx
50
let raindrops = [];
let num_raindrops = 200;
function setup() {
createCanvas(600, 600);
for (let i=0; i < num_raindrops; i++) {
let r = new Raindrop(random(width), random(height));
raindrops.push(r);
//raindrops.push(new Raindrop(random(width), random(height)));
}
}
function draw() {
background(0, 0, 255);
fill(0, 127, 0);
rect(0, 300, width, height / 2);
for (let i=0; i < num_raindrops; i++) {
raindrops[i].update();
raindrops[i].display();
}
}
class Raindrop {
constructor(x, y) {
this.x = x;
this.y = y;
this.scale = random(1, 3);
this.speedY = random(5, 15);
}
update() {
this.y = this.y + this.speedY;
if (this.y > height) {
this.y = 0;
}
}
display() {
push();
translate(this.x, this.y);
scale(this.scale);
fill(255);
noStroke();
ellipse(0, 0, 10, 10);
triangle(-5, 0, 5, 0, 0, -10);
pop();
}
}