xxxxxxxxxx
38
class Drop {
constructor() {
this.pos = createVector(random(-130, width), random(-500, -50), random(0, 20));
this.yspeed = map(this.pos.z, 0, 20, 1, 20);
this.xspeed = map(this.pos.z, 0, 20, 1, 5);
this.len = map(this.pos.z, 0, 20, 10, 20);
this.thickness = map(this.pos.z, 0, 20, 1, 3);
}
update() {
if (this.pos.y > height || this.pos.x > width) {
// Make a splash effect
if (this.pos.y > height) {
strokeWeight(10);
point(this.pos.x, height);
}
// Restart the journey of our dear drop
this.pos.y = random(-500, -50);
this.pos.x = random(-130, width);
this.yspeed = map(this.pos.z, 0, 20, 1, 20);
this.len = map(this.pos.z, 0, 20, 10, 20);
this.thickness = map(this.pos.z, 0, 20, 1, 3);
}
// Add a speed to our drop 🚀
let gravity = map(this.pos.z, 0, 20, 0, 0.2);
this.yspeed += gravity;
this.pos.y += this.yspeed;
this.pos.x += this.xspeed;
}
show() {
stroke(138, 43, 226);
strokeWeight(this.thickness);
line(this.pos.x, this.pos.y, this.pos.x + 4, this.pos.y + this.len);
}
}