xxxxxxxxxx
57
let drops = [];
let img;
function preload()
{
img = loadImage("bench.jpg");
}
function setup() {
createCanvas(400, 400);
frameRate(50);
for (let i = 0; i < 150; i++)
{
drops[i] = new Drop();
}
img.resize(400,400);
}
function draw() {
// background(230, 230, 250);
image(img, 0, 0);
for (let i = 0; i < drops.length; i++) {
drops[i].fall();
drops[i].show();
}
}
class Drop {
constructor() {
this.x = random(width);
this.y = random(-500, -50);
this.z = random(0, 20);
this.len = map(this.z, 0, 20, 10, 20);
this.yspeed = map(this.z, 0, 20, 1, 20);
}
fall() {
this.y = this.y + this.yspeed;
let grav = map(this.z, 0, 20, 0, 0.2);
this.yspeed = this.yspeed + grav;
if (this.y > height) {
this.y = random(-200, -100);
this.yspeed = map(this.z, 0, 20, 4, 10);
}
}
show() {
let thick = map(this.z, 0, 20, 1, 3);
strokeWeight(thick);
stroke(200, 200, 0);
line(this.x, this.y, this.x, this.y + this.len);
//circle(this.x, this.y, this.len/2)
}
}