Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. window.onload = function () {
  2. function randomChar(charSet) {
  3. var rand = charSet[Math.floor(Math.random() * charSet.length)];
  4. // var rand = String.fromCharCode(1e2 + Math.random() * 33);
  5. return rand;
  6. }
  7. function randomRange(min, max) {
  8. return Math.floor(Math.random() * (max - min + 1)) + min;
  9. }
  10. function newMatrixLine(speed, charSet, charLength, charHeight) {
  11. //create line
  12. var elemLine = document.createElement('div');
  13. elemLine.style.top = '-' + (charLength * charHeight) + 'px';
  14. elemLine.style.left = randomRange(0, window.innerWidth) + 'px';
  15. elemLine.style.position = 'fixed';
  16. document.body.appendChild(elemLine);
  17.  
  18. //create line letters
  19. for (let i = 0; i < charLength; i++) {
  20. var elemLetter = document.createElement('div');
  21. elemLetter.innerHTML = randomChar(charSet);
  22. elemLetter.style.color = linesColor;
  23. elemLine.appendChild(elemLetter);
  24. }
  25.  
  26. //move line interval (delete after fall)
  27. var interval1 = setInterval(function () {
  28. var elemLineTop = parseInt(elemLine.style.top);
  29. if (elemLineTop < (window.innerHeight)) {
  30. elemLine.style.top = elemLineTop + moveByNumPixels + 'px';
  31. //console.log('moving');
  32. }
  33. else {
  34. elemLine.remove();
  35. clearInterval(interval1);
  36. }
  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. //create lines at interval
  53. var interval2 = setInterval(function () {
  54. if (document.body.children.length < maxLines) {
  55. for (let i = 0; i < randomRange(1, maxLinesPerGroup); i++) {
  56. //speed, charSet, charLength
  57. newMatrixLine(randomRange(minLineSpeedInterval, maxLineSpeedInterval), charSet, randomRange(minCharLength, maxCharLength), charHeight);
  58. }
  59. }
  60. }, linesGroupCreationInterval);
  61. document.body.style.background = bodyColor;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement