Advertisement
FHWWCTeam

firework.js

Jan 9th, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // <![CDATA[
  2. var bits=80; // how many bits
  3. var speed=33; // how fast - smaller is faster
  4. var bangs=5; // how many can be launched simultaneously (note that using too many can slow the script down)
  5. var colours=new Array("#03f", "#f03", "#0e0", "#93f", "#0cf", "#f93", "#f0c");
  6. //                     blue    red     green   purple  cyan    orange  pink
  7.  
  8. /****************************
  9. *      Fireworks Effect     *
  10. *(c)2004-14 mf2fm web-design*
  11. *  http://www.mf2fm.com/rv  *
  12. * DON'T EDIT BELOW THIS BOX *
  13. ****************************/
  14. var bangheight=new Array();
  15. var intensity=new Array();
  16. var colour=new Array();
  17. var Xpos=new Array();
  18. var Ypos=new Array();
  19. var dX=new Array();
  20. var dY=new Array();
  21. var stars=new Array();
  22. var decay=new Array();
  23. var swide=1000;
  24. var shigh=600;
  25. var boddie;
  26.  
  27. if (typeof('addRVLoadEvent')!='function') function addRVLoadEvent(funky) {
  28.   var oldonload=window.onload;
  29.   if (typeof(oldonload)!='function') window.onload=funky;
  30.   else window.onload=function() {
  31.     if (oldonload) oldonload();
  32.     funky();
  33.   }
  34. }
  35.  
  36. addRVLoadEvent(light_blue_touchpaper);
  37.  
  38. function light_blue_touchpaper() { if (document.getElementById) {
  39.   var i;
  40.   boddie=document.createElement("div");
  41.   boddie.style.position="fixed";
  42.   boddie.style.top="0px";
  43.   boddie.style.left="0px";
  44.   boddie.style.overflow="visible";
  45.   boddie.style.zIndex = '9999';
  46.   boddie.style.width="1px";
  47.   boddie.style.height="1px";
  48.   boddie.style.backgroundColor="transparent";
  49.   document.body.appendChild(boddie);
  50.   set_width();
  51.   for (i=0; i<bangs; i++) {
  52.     write_fire(i);
  53.     launch(i);
  54.     setInterval('stepthrough('+i+')', speed);
  55.   }
  56. }}
  57.  
  58. function write_fire(N) {
  59.   var i, rlef, rdow;
  60.   stars[N+'r']=createDiv('|', 12);
  61.   boddie.appendChild(stars[N+'r']);
  62.   for (i=bits*N; i<bits+bits*N; i++) {
  63.     stars[i]=createDiv('*', 13);
  64.     boddie.appendChild(stars[i]);
  65.   }
  66. }
  67.  
  68. function createDiv(char, size) {
  69.   var div=document.createElement("div");
  70.   div.style.font=size+"px monospace";
  71.   div.style.position="absolute";
  72.   div.style.zIndex = '9999';
  73.   div.style.backgroundColor="transparent";
  74.   div.appendChild(document.createTextNode(char));
  75.   return (div);
  76. }
  77.  
  78. function launch(N) {
  79.   colour[N]=Math.floor(Math.random()*colours.length);
  80.   Xpos[N+"r"]=swide*0.5;
  81.   Ypos[N+"r"]=shigh-5;
  82.   bangheight[N]=Math.round((0.5+Math.random())*shigh*0.4);
  83.   dX[N+"r"]=(Math.random()-0.5)*swide/bangheight[N];
  84.   if (dX[N+"r"]>1.25) stars[N+"r"].firstChild.nodeValue="/";
  85.   else if (dX[N+"r"]<-1.25) stars[N+"r"].firstChild.nodeValue="\\";
  86.   else stars[N+"r"].firstChild.nodeValue="|";
  87.   stars[N+"r"].style.color=colours[colour[N]];
  88. }
  89.  
  90. function bang(N) {
  91.   var i, Z, A=0;
  92.   for (i=bits*N; i<bits+bits*N; i++) {
  93.     Z=stars[i].style;
  94.     Z.left=Xpos[i]+"px";
  95.     Z.top=Ypos[i]+"px";
  96.     if (decay[i]) decay[i]--;
  97.     else A++;
  98.     if (decay[i]==15) Z.fontSize="7px";
  99.     else if (decay[i]==7) Z.fontSize="2px";
  100.     else if (decay[i]==1) Z.visibility="hidden";
  101.     if (decay[i]>1 && Math.random()<.1) {
  102.        Z.visibility="hidden";
  103.        setTimeout('stars['+i+'].style.visibility="visible"', speed-1);
  104.     }
  105.     Xpos[i]+=dX[i];
  106.     Ypos[i]+=(dY[i]+=1.25/intensity[N]);
  107.  
  108.   }
  109.   if (A!=bits) setTimeout("bang("+N+")", speed);
  110. }
  111.  
  112. function stepthrough(N) {
  113.   var i, M, Z;
  114.   var oldx=Xpos[N+"r"];
  115.   var oldy=Ypos[N+"r"];
  116.   Xpos[N+"r"]+=dX[N+"r"];
  117.   Ypos[N+"r"]-=4;
  118.   if (Ypos[N+"r"]<bangheight[N]) {
  119.     M=Math.floor(Math.random()*3*colours.length);
  120.     intensity[N]=5+Math.random()*4;
  121.     for (i=N*bits; i<bits+bits*N; i++) {
  122.       Xpos[i]=Xpos[N+"r"];
  123.       Ypos[i]=Ypos[N+"r"];
  124.       dY[i]=(Math.random()-0.5)*intensity[N];
  125.       dX[i]=(Math.random()-0.5)*(intensity[N]-Math.abs(dY[i]))*1.25;
  126.       decay[i]=16+Math.floor(Math.random()*16);
  127.       Z=stars[i];
  128.       if (M<colours.length) Z.style.color=colours[i%2?colour[N]:M];
  129.       else if (M<2*colours.length) Z.style.color=colours[colour[N]];
  130.       else Z.style.color=colours[i%colours.length];
  131.       Z.style.fontSize="13px";
  132.       Z.style.visibility="visible";
  133.     }
  134.     bang(N);
  135.     launch(N);
  136.   }
  137.   stars[N+"r"].style.left=oldx+"px";
  138.   stars[N+"r"].style.top=oldy+"px";
  139. }
  140.  
  141. window.onresize=set_width;
  142. function set_width() {
  143.   var sw_min=999999;
  144.   var sh_min=999999;
  145.   if (document.documentElement && document.documentElement.clientWidth) {
  146.     if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  147.     if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  148.   }
  149.   if (typeof(self.innerWidth)!="undefined" && self.innerWidth) {
  150.     if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  151.     if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  152.   }
  153.   if (document.body.clientWidth) {
  154.     if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  155.     if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  156.   }
  157.   if (sw_min==999999 || sh_min==999999) {
  158.     sw_min=800;
  159.     sh_min=600;
  160.   }
  161.   swide=sw_min;
  162.   shigh=sh_min;
  163. }
  164. // ]]>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement