正文
.vy +=
0.02
;
this
.vx *=
0.98
;
this
.vy *=
0.98
;
}
render(ctx){
this
.go();
ctx.beginPath();
ctx.arc(
this
.x,
this
.y,
this
.size,
0
,
Math
.PI *
2
,
false
);
ctx.fill();
}
}
构建烟花类
class Firework{
constructor({x, y = config.height, xEnd, yEnd, count = 300, wait} = {}){
this.x = x || config.width / 8 + Math.random() * config.width * 3 / 4;
this.y = y;
this.xEnd = xEnd || this.x;
this.yEnd = yEnd || config.width / 8 + Math.random() * config.width * 3 / 8;
this.size = 2;
this.velocity = -3;
this.opacity = 0.8;
this.color = `hsla(${360 * Math.random() | 0},80%,60%,1)`;
this.wait = wait || 30 + Math.random() * 30;
this.count = count;
this.particles = [];
this.createParticles();
this.status = 1;
}
createParticles(){
for(let i = 0;i < this.count; ++i){
this.particles.push(new Particle({x:this.xEnd, y:this.yEnd}));
}
}
rise(){
this.y += this.velocity * 1;
this.velocity += 0.005;
if(this.y - this.yEnd <= 50){
this.opacity = (this.y - this.yEnd) / 50;
}