xxxxxxxxxx
59
var Particles = new Array();
var NbOfParticles = 50;
function setup() {
createCanvas(400, 400);
colorMode(RGB, 255, 255, 255, 1);
}
function draw() {
background(220);
if (Particles.length >= NbOfParticles){
Particles.shift();
}
if(mouseX == 0 && mouseY==0){
posinitX = 200;
posinitY = 300;
}else{
posinitX = mouseX;
posinitY = mouseY;
}
Particles.push(new Particle(posinitX + random(5), posinitY+random(5)));
Particles.forEach(function(item, index, array) {
item.show();
item.move();
});
}
class Particle{
constructor(posx, posy){
this.x = posx;
this.y = posy;
this.alpha = 1
this.size = 20;
this.col = color(255, 204, 0,1);
}
move(){
this.x += random(-5, 5);
this.y += -5;
}
show(){
fill(this.col);
noStroke();
circle(this.x, this.y, this.size);
this.size -= 0.2
this.alpha -= 0.02;
this.col = color(255, 204, 0,this.alpha);
}
}