raf(animate);
};
var Boom = function(x,r,boomArea){
this.booms = [];
this.x = x;
this.y = (canvas.height+r);
this.r = r;
this.boomArea = boomArea;
this.theta = 0;
this.dead = false;
this.ba = parseInt(getRandom(10, 20));
this.alphaStart = 0.3;
this.arcArray = [];
};
Boom.prototype = {
_paint:function(){
ctx.save();
var ap = 1, l = this.arcArray.length;
var x, y, apl;
apl = this.alphaStart;
for (var i = l - 1; i >= 0; i--) {
x = this.arcArray[i].x;
y = this.arcArray[i].y;
apl = apl * 0.9;
if (apl > 0.01) {
ctx.fillStyle = "rgba(244,190,32,"+apl+")";
ctx.beginPath();
ctx.arc(x , y , this.r + 1 * Math.random(), 0 , 2 * Math.PI);
ctx.fill();
ctx.fill();
};
};
ctx.restore();
},
_move:function(){
var dx = this.boomArea.x - this.x , dy = this.boomArea.y - this.y;
this.x = this.x + dx * 0.02;
this.y = this.y + dy * 0.02;
this.arcArray.push({
x:this.x,
y:this.y
});
if(Math.abs(dx) <= this.ba && Math.abs(dy) <= this.ba){
this._boom();
this.dead = true;
}else {
this._paint();
};
},
_boom:function(){
var fragNum = getRandom(50, 100);
var color;
var fanwei = parseInt(getRandom(50, 60));
for(var i = 0; i < fragNum; i++){
color = {
a:parseInt(getRandom(120,255)),
b:parseInt(getRandom(120,255)),
c:parseInt(getRandom(120,200))
};
var a = getRandom(-Math.PI, Math.PI);
var x = getRandom(0, fanwei) * Math.cos(a) + this.x;
var y = getRandom(0, fanwei) * Math.sin(a) + this.y;
var radius = getRandom(0 , 2);
var frag = new Frag(this.x , this.y , radius , color , x , y);
this.booms.push(frag);
};
}
};
var Frag = function(centerX , centerY , radius , color ,tx , ty){
this.tx = tx;
this.ty = ty;
this.x = centerX;
this.y = centerY;
this.dead = false;
this.centerX = centerX;
this.centerY = centerY;
this.radius = radius;
this.color = color;
this.alphaStart = 1;
this.arcArray = [];
};
Frag.prototype = {
paint:function(){
ctx.save();
var ap = 1, l = this.arcArray.length;
var x, y, apl;
apl = this.alphaStart;
for (var i = l - 1; i >= 0; i--) {
x = this.arcArray[i].x;
y = this.arcArray[i].y;
apl = apl - 0.1;
if (apl > 0) {
ctx.beginPath();
ctx.arc(x , y , this.radius , 0 , 2 * Math.PI);
ctx.fillStyle = "rgba(" + this.color.a + "," + this.color.b + "," + this.color.c + ", "+ apl +")";
ctx.fill();
};
};