I am trying to create an animation in canvas. The first time it worked fine but when a new element was added through setTimeout, all the elements speed is increased. Can anyone tell me why this speed is increasing. Fiddle Link
var canvas = $("#canvas")[0],
context = canvas.getContext("2d"),
bloons = {},
bloonIndex = 0;
var c_wdh = 360,
c_hgt = 540;
function createBloon(x, y) {
this.x = x;
this.y = y;
this.vx = 1,
this.vy = 3;
bloonIndex++;
bloons[bloonIndex] = this;
this.id = bloonIndex;
}
createBloon.prototype.drawImage = function() {
this.y -= this.vy;
context.fillStyle = "#FF0000";
context.fillRect(this.x, this.y, 50, 50);
if(this.y <= -120){
delete bloons[this.id];
}
};
var nob = 0;
var i = 1;
var rendorBloon = setInterval(function(){
bloons[i] = new createBloon(Math.random() * c_wdh, c_hgt);
var animate = setInterval(function () {
context.clearRect(0, 0, c_wdh, c_hgt);
for (var i in bloons){
bloons[i].drawImage();
}
}, 30);
i++;
nob++;
if(nob >= 10){
clearInterval(rendorBloon);
}
}, 1000);