Advertisement
caLLowCreation

Overlay Fire

Nov 7th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.10 KB | None | 0 0
  1.  
  2. <head></head>
  3. <body></body>
  4.  
  5. <script>var pP=[],tP,cX,cY,c,ctx,w=1920;h=1080;pi=2*Math.PI;var canvasName="pablo"</script>
  6. <script>function init(){c=document.createElement('canvas');c.width=w;c.height=h;ctx=c.getContext('2d');ctx.globalCompositeOperation="lighter";c.id=canvasName;c.style.position='absolute';c.style.left="0px";c.style.pointerEvents="none";c.style.top="0px";document.body.appendChild(c);};</script>
  7. <script></script>
  8. <script>init();
  9.  
  10. //var mx=40,sp=5,sz=50,np=200,sx=w/2,sy=h/2;
  11. var mx=100,sp=5,sz=150,np=50,sx=155,sy=h-140;
  12.  
  13. function Particle(x,y,xs,ys){this.x=x;this.y=y;this.xs=xs;this.ys=ys;this.lt=0;}
  14.  
  15. for(var i=0;i<np;i++)
  16. {
  17.  const p=new Particle(sx,sy,(Math.random()*2*sp-sp)/2,0-Math.random()*2*sp);
  18.  pP.push(p);
  19. }
  20. let counter = 0;
  21. const maxCounter = 2000;
  22. let colorToggle = false;
  23.  
  24. let r = 255;
  25. let g = 255;
  26. let b = 255;
  27. let a = 1;
  28.    
  29. function burn(flame){
  30.  {
  31.    //ctx.fillStyle="rgba("+(260-(flame.lt*2))+","+((flame.lt*2)+50)+","+(flame.lt*2)+","+(((mx-flame.lt)/mx)*0.4)+")";
  32.    
  33.    
  34.     // caLLow added BELOW
  35.     counter++;
  36.     if(counter > maxCounter) {
  37.         counter = 0;
  38.         colorToggle = !colorToggle;
  39.     }
  40.    
  41.     const rMax = (260-(flame.lt*2));
  42.     const val = counter / maxCounter;
  43.    
  44.     if(colorToggle) {
  45.         r = rMax - rMax * val;
  46.         g = ((flame.lt*2)+50);
  47.         b = (flame.lt*2);
  48.         a = (((mx-flame.lt)/mx)*0.1);
  49.     }
  50.     else { 
  51.         r = rMax * val;
  52.         g = ((flame.lt*2)+50);
  53.         b = (flame.lt*2);
  54.         a = (((mx-flame.lt)/mx)*0.1);
  55.     }
  56.     // caLLow added ABOVE
  57.    
  58.     ctx.fillStyle="rgba("+r+","+g+","+b+","+a+")";
  59.     ctx.beginPath();
  60.     ctx.arc(flame.x,flame.y,(mx-flame.lt)/mx*(sz/2)+(sz/2),0,pi);
  61.     ctx.fill();
  62.     flame.x+=flame.xs;
  63.     flame.y+=flame.ys;
  64.     flame.lt++;
  65.  
  66.     if(flame.lt >= mx * (Math.random() * sp))
  67.     {
  68.       flame.x = sx;
  69.       flame.y = sy;
  70.       flame.xs = (Math.random()*2*sp-sp)/2;
  71.       flame.ys = 0-Math.random()*2*sp;
  72.       flame.lt = 0;
  73.     }
  74.   }
  75. }
  76.  
  77. function fire(){
  78.   ctx.clearRect(0,0,w,h);
  79.   pP.map(burn);
  80. }
  81.  
  82. //setInterval(function(){requestAnimationFrame(fire)}, 25);
  83. setInterval(function(){requestAnimationFrame(fire)}, 100);
  84.  
  85. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement