xxxxxxxxxx
76
let particles = [];
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(0,0,30,25);
//amount of particles comes out
for(let i=0; i<15; i++){
p = new Particle();
particles.push(p);
}
//burst
for(let i = particles.length-1; i>=0; i--){
particles[i].update();
particles[i].show();
//make the alpha = 0 ones disappear
if(particles[i].gone()){
particles.splice(i,1);
}
}
}
class Particle {
constructor(){
this.x = width/2;
this.y = height/2;
this.movex = random(-0.01,0.01);
this.movey = random(-0.01,0.01);
this.thin = 255;
this.size = 10;
this.sizee = 0.5;
this.color = 250;
}
update(){
this.x += this.movex*mouseX;
this.y += this.movey*mouseY;
this.thin -= 0.8;
this.size -= mouseX*this.sizee;
this.color -=2;
}
gone(){
return this.thin <0;
}
show(){
rectMode(CENTER);
noStroke();
fill(250,250,this.color,this.thin);
circle(this.x,this.y,4);
}
}