xxxxxxxxxx
43
class Particle {
constructor() {
this.x = width / 2;
this.y = height / 2;
this.vx = random(-1.0, 1.0);
this.vy = random(0.1, 1.0);
this.life = 0;
}
update() {
this.life--;
if (this.life <= 0) {
this.vx = random(-1.0, 1.0);
this.vy = random(-1.0, 1.0);
this.x = width / 2;
this.y = height / 2;
this.life = random(500);
}
this.x = this.x + this.vx;
this.y = this.y + this.vy;
}
draw() {
stroke(0,0,0, this.life);
noFill();
circle(this.x, this.y, 10);
}
}
let particle = [];
function setup() {
createCanvas(400, 400);
for( let i = 0; i < 100; i++ ){
particle[i] = new Particle();
}
}
function draw() {
background(220);
for( let i = 0; i < particle.length; i++ ){
particle[i].update();
particle[i].draw();
}
}