xxxxxxxxxx
59
var drops = [];
function preload() {
img = loadImage("background.jpg");
}
function setup() {
createCanvas(500, 500);
img.resize(500, 500);
}
function draw() {
background(0);
//image(img, 0, 0);
for (let i = 0; i < drops.length; i++) {
drops[i].update();
}
}
class Drop {
constructor(x, y, r, k = 0) {
this.p = createVector(x, y);
this.vel = createVector(0, 0);
this.g = createVector(0, 0.08);
this.f = createVector(0, -0.05);
this.r = r;
this.t = frameCount;
this.k = k;
this.seed = random();
}
update() {
this.f = this.f.mult(createVector(0, 1));
this.vel.add(this.g);
this.vel.add(this.f);
if (this.k == 1) {
this.vel = createVector(0, noise(frameCount*0.05+this.seed));
}
this.p.add(this.vel);
push();
noStroke();
fill(255, 50);
let j = 1;
for (let i = this.r; i > 0; i -= 3) {
circle(this.p.x, this.p.y + j, i);
j += 0.6;
}
pop();
if (frameCount - this.t > 20 && this.r > 10) {
drops.push(new Drop(this.p.x, this.p.y, 10, 1));
this.t = frameCount;
}
}
}
function mousePressed() {
drops.push(new Drop(mouseX, mouseY, 25));
}