xxxxxxxxxx
49
const particles = [];
function setup() {
createCanvas(600, 400);
}
function draw() {
background("black");
for (let i = 0; i < 30; 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);
}
}
}
class Particle {
constructor() {
this.x = 300;
this.y = 400;
this.vx = random(-50, 50);
this.vy = random(-5, -5);
this.alpha = 50;
this.color = color(random(100, 255), random(100, 255), random(100, 255));
}
finished() {
return this.alpha < 0;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.alpha -= .5;
}
show() {
noStroke();
fill(this.color, this.alpha);
ellipse(this.x, this.y, 16);
}
}