xxxxxxxxxx
43
let particles = []
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(0);
particles.push(new Particle());
for (let i = particles.length - 1; i >= 0; i--) {
particles[i].show();
particles[i].update();
if (particles[i].alpha < 0) {
particles.splice(i, 1);
}
}
}
class Particle {
constructor() {
this.x = width / 2;
this.y = height;
this.r = random(200, 255);
this.g = random(100, 255);
this.b = random(0, 100);
this.alpha = 230;
this.size = random(25, 40);
this.changeX = random(-1, 1);
this.changeY = random(-5, -1);
}
show() {
noStroke();
fill(this.r, this.g, this.b, this.alpha);
ellipse(this.x, this.y, this.size);
}
update() {
this.x += this.changeX;
this.y += this.changeY;
this.alpha -= 1;
}
}