-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfirework.min.js
More file actions
1 lines (1 loc) · 1.08 KB
/
Copy pathfirework.min.js
File metadata and controls
1 lines (1 loc) · 1.08 KB
1
class Firework{constructor(t){this.target=t,this.startingX=100+Math.random()*(window.innerWidth-100),this.vel=this.velVector(),this.pos={x:this.startingX,y:window.innerHeight};let e=["red","#10e6db","lightgreen","orange","#10e6db"];this.colour=e[Math.floor(Math.random()*e.length)],this.explosionParticles=[],this.exploded=!1}velVector(){let t=this.target.x-this.startingX,e=this.target.y-window.innerHeight,i=(t**2+e**2)/100,s=Math.sqrt(t**2/i),o=Math.sqrt(e**2/i);return t<0&&(s*=-1,console.log(s,-o)),{x:s,y:-o}}step(){if(this.pos.y>this.target.y)this.pos.x+=this.vel.x,this.pos.y+=this.vel.y,strokeWeight(6),stroke(this.colour),point(this.pos.x,this.pos.y);else{0!=this.explosionParticles.length||this.exploded||this.explode();let t=0;for(let e of this.explosionParticles)strokeWeight(2),stroke(this.colour),point(e.x,e.y),e.x+=e.velX,e.y+=e.velY,e.velY+=.05,(e.y>window.innerHeight||e.x<0||e.x>window.innerWidth)&&this.explosionParticles.splice(t,1),t++}}explode(){for(let t=0;t<200;t++)this.explosionParticles.push({x:this.pos.x,y:this.pos.y,velX:random(-5,5),velY:random(-5,5)});this.exploded=!0}}