Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. window.onload = function() {
  2. function randomChar(charSet) {
  3. var rand = charSet[Math.floor(Math.random() * charSet.length)];
  4.  
  5. //var rand = String.fromCharCode(1e2+Math.random()*33);
  6.  
  7. return rand;
  8. }
  9. function randomRange(min, max) {
  10. return Math.floor(Math.random() * (max - min + 1)) + min;
  11.  
  12. }
  13. function newMatrixLine( speed, charSet, charLength, charHeight){
  14. var elemLine = document.createElement('div');
  15. elemLine.style.top = '-'+(charLength * charHeight)+'px';
  16. elemLine.style.left = randomRange(0, window.innerWidth)+'px';
  17. elemLine.style.position = 'fixed';
  18. document.body.appendChild(elemLine);
  19.  
  20. for(let i = 0; i < charLength; i++){
  21. var elemLetter = document.createElement('div);
  22. elemLetter.innerHtml = randomChar(charSet);
  23. elemLetter.style.color = linesColor;
  24. elemLine.appendChild(elemLetter);
  25. }
  26.  
  27. var interval1 = setInterval(function(){
  28. var elemLineTop = parseInt(elemLine.style.top);
  29.  
  30. if(elemLineTop < (window.innerHeight)) {
  31. elemLine.style.top = elemLineTop + moveByNumPixels + 'px';
  32. //console.log('moving');
  33. }
  34. else {
  35. elemLine.remove();
  36. clearInterval(interval1);}
  37. }, speed);
  38. }
  39. var moveByNumPixels = 8.6;
  40. var linesGroupCreationInterval = 1;
  41. var maxLinesPerGroup = 1;
  42. var charSet = ['a', 'b', 'c'];
  43. var charHeight = 18.6;
  44. var bodyColor = '#000';
  45. var linesColor = 'lime';
  46. var minLineSpeedInterval = 16;
  47. var maxLineSpeedInterval = 28;
  48. var minCharLength = 4;
  49. var maxCharLength = 150;
  50. var maxLines = 40;
  51.  
  52. var interval2 = setInterval(function(){
  53. if(document.body.children.length < maxLines) {
  54. for(let i = 0; i < randomRange(1, maxLinesPerGroup); i++) {
  55. newMatrixLine(randomRange(minLineSpeedInterval, maxLineSpeedInterval), charSet, randomRange(minCharLength, maxCharLength), charHeight);
  56. }
  57. }
  58. }, linesGroupCreationInterval);
  59. document.body.style.background = bodyColor;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement