xxxxxxxxxx
51
particles = [];
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0);
for (let i = 0; i < 5; i++) {
let p = new Particle();
particles.push(p);
}
for (let i = particles.length - 1; i >= 0; i--) {
particles[i].update();
particles[i].show();
if (particles[i].finished()) {
particles.splice(i, 1);
}
}
fill(40, 25, 2);
rect(230, 390, 135, 20);
}
class Particle {
constructor() {
this.x = random(260, 340);
this.y = 400;
this.vx = random(-1, 1);
this.vy = random(-5, -1);
this.alpha = 255;
this.d = 16;
}
finished() {
return this.alpha < 0;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.alpha -= 3;
this.d -= random(1,0.1);
}
show() {
noStroke();
fill(255, 255, 255, this.alpha);
ellipse(this.x, this.y, this.d);
}
}