Advertisement
Guest User

Untitled

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