Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. <script type="text/javascript">
  2. // <![CDATA[
  3. var colour="#D5E986"; // what colour are the blobs
  4. var framerate=24; // FPS
  5. var blobs=20; // how many blobs are in the jar
  6. var bsize = '50px';
  7. var enableWAT = 0;
  8. var charc=String.fromCharCode(9679); // a blob - can be changed to charc='hello' or charc='*' for a different effect
  9. var div;
  10. var xpos=[];
  11. var ypos=[];
  12. var zpos=[];
  13. var dx=[];
  14. var dy=[];
  15. var dz=[];
  16. var blob=[];
  17. var swide=800;
  18. var shigh=600;
  19.  
  20. window.onload=createBlobs;
  21. window.onresize=updateWidth;
  22.  
  23.  
  24. function createBlobs() {
  25. var i, dvs;
  26. div=document.createElement('div');
  27. dvs=div.style;
  28. dvs.position='fixed';
  29. dvs.left='0px';
  30. dvs.top='0px';
  31. dvs.width='1px';
  32. dvs.height='1px';
  33. document.body.appendChild(div);
  34. updateWidth();
  35. for (i=0; i<blobs; i++) {
  36. createBlob(i);
  37. }
  38. moveBlobs();
  39. }
  40.  
  41. function createBlob(ref) {
  42. var dv, sy;
  43. dv=document.createElement('div');
  44. dv.appendChild(document.createTextNode(charc));
  45. sy=dv.style;
  46. sy.position='absolute';
  47. sy.textAlign="center";
  48. sy.fontSize=bsize;
  49. sy.color='rgba(0,0,0,0)';
  50. ypos[ref]=Math.floor(shigh*Math.random());
  51. dy[ref]=(0.5+Math.random())*(Math.random()>.5?2:-2);
  52. xpos[ref]=Math.floor(swide*Math.random());
  53. dx[ref]=(0.5+Math.random())*(Math.random()>.5?2:-2);
  54. zpos[ref]=Math.random()*20;
  55. dz[ref]=(0.5+Math.random())*(Math.random()>.5?.5:-.5);
  56. blob[ref]=dv;
  57. div.appendChild(blob[ref]);
  58. updateBlob(ref);
  59. }
  60.  
  61. function updateBlobPosition(ref, xy) {
  62. if (xy=='y') {
  63. dx[ref]=(0.5+Math.random())*sign(dx[ref]);
  64. dy[ref]=(0.5+Math.random())*-sign(dy[ref]);
  65. }
  66. else {
  67. dx[ref]=(0.5+Math.random())*-sign(dx[ref]);
  68. dy[ref]=(0.5+Math.random())*sign(dy[ref]);
  69. }
  70. }
  71.  
  72. function sign(a) {
  73. if (a<0) return (-2);
  74. else if (a>0) return (2);
  75. else return (0);
  76. }
  77.  
  78. function updateBlob(ref) {
  79. var sy;
  80. sy=blob[ref].style;
  81. sy.top=ypos[ref]+'px';
  82. sy.left=xpos[ref]+'px';
  83. sy.textShadow=colour+' 0px 0px '+zpos[ref]+'px';
  84. if (enableWAT) sy.transform='scale(' + zpos[ref]/5 + ')';
  85. }
  86.  
  87. function moveBlobs() {
  88. for (i=0; i<blobs; i++) {
  89. moveBlob(i);
  90. }
  91. setTimeout("moveBlobs()", 1000/framerate);
  92. }
  93.  
  94. function moveBlob(ref) {
  95. if (ypos[ref]+dy[ref]<-50 || ypos[ref]+dy[ref]>shigh) updateBlobPosition(ref, 'y');
  96. ypos[ref]+=dy[ref];
  97. if (xpos[ref]+dx[ref]<-50 || xpos[ref]+dx[ref]>swide) updateBlobPosition(ref, 'x');
  98. xpos[ref]+=dx[ref];
  99. if (zpos[ref]+dz[ref]<0 || zpos[ref]+dz[ref]>20) dz[ref]=-dz[ref];
  100. zpos[ref]+=dz[ref];
  101. updateBlob(ref);
  102. }
  103.  
  104. function updateWidth() {
  105. var sw_min=999999;
  106. var sh_min=999999;
  107. if (document.documentElement && document.documentElement.clientWidth) {
  108. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  109. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  110. }
  111. if (typeof(self.innerWidth)!="undefined" && self.innerWidth) {
  112. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  113. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  114. }
  115. if (document.body.clientWidth) {
  116. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  117. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  118. }
  119. if (sw_min==999999 || sh_min==999999) {
  120. sw_min=800;
  121. sh_min=600;
  122. }
  123. swide=sw_min;
  124. shigh=sh_min;
  125. }
  126. // ]]>
  127. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement