xxxxxxxxxx
class Particle { //properties of object
constructor(posX, posY, size, col){
this.posX = posX;
this.posY = posY;
this.speed = 2;
this.size = random(-2, 4);
this.lifespan = 70;
this.col = col;
}
fall(){
this.speed =2; //speed of fall
this.posX+=(0); // direction of fall
this.posY+=(1); // direction of fall
//this.col = lerpColor(this.col, color(250,200,0), map(this.lifespan,90,100,50,2)); // color of stars
this.col = (this.col, color(250)); // color of stars
if (this.lifespan>0){
this.lifespan+=20; //length until disappearance
}
}
draw(){
noStroke(); // the stars
fill(this.col);
ellipse(this.posX,this.posY,this.size);
line(30,this.posY, this.posX, this.posY);
}
}
var balls=[];
function setup(){
createCanvas(windowWidth,windowHeight);
}
function draw(){
background(0, 0, 25); //background of sky
for (var i=0;i<500;i+=30){ // number of stars
balls.push(new Particle(random(-100,windowWidth), random(0,windowHeight), random(10,4), color(255, 30, 60)));
} //location of stars
for(var i=0; i<balls.length; i++){
var ball = balls[i];
if(ball.lifespan<=0 || balls.length >=2000){ //lifespan of stars
balls.splice(i, 4);
}
else{
ball.fall();
ball.draw();
}
}
}