var snow = {
_snow:[],
vx: 10,
vy: 10,
gravity: 1,
maxNum:2000,
reset:function(){
this._snow=[];
},
draw:function(){
for (var i = 0, len = this._snow.length; i <len; i++){
var p = this._snow[i];
ctx.fillStyle = "rgba(255,255,255,1)";
ctx.fillRect(p.x, p.y, p.size, p.size);
}
},
update:function(){
if(this._snow.length < this.maxNum)
{
this._snow.push({
x: Math.random() * 500 ,
y:0 ,
size: Math.floor(Math.random()*5),
life:0,
maxLife: 1000,
});
}
for (var i = 0, len = this._snow.length; i <len; i++){
var p = this._snow[i];
p.x -= Math.random() * 2 - 1;
p.y += Math.random() * 1 ;
p.life++; // Age the particle
// If Particle is old, remove it
if (p.life >= p.maxLife) {
//delete p;
this._snow.splice(i,1);
len--;
i--;
}//if
}//for
},
};
I’m still basically doing the same thing but now all the important bits are inside an object that is pushed to an array so each array item knows things like size, color, and location.
the first few I posted, like the embers and snow I thought looked really cool. I had finally gotten the array working but I hadn’t hammered out the logic yet so they just spit out particles with wild abandon forever. no max number. no particle life. just make stuff all the time always then it would get real slow, and die.
I’ve since fixed that, it makes my browsers much happier, but I’m still experiencing some lag with the mouse circle