Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <meta charset="utf-8">
  5. <style>
  6. * {
  7. margin: 0;
  8. padding: 0;
  9. }
  10.  
  11. body {
  12. background: black;
  13. }
  14.  
  15. canvas {
  16. display: block;
  17. }
  18. </style>
  19.  
  20. </head>
  21.  
  22. <body>
  23. <canvas id="c"></canvas>
  24. <script>
  25. var coltext = "#00ff00";
  26. //color pattern for matrix
  27. var r = "7f0".split("");
  28. var g = "f80".split("");
  29. var b = "f09".split("");
  30. setInterval(function () {
  31. coltext = "#" + r[Math.floor(Math.random() * r.length)]
  32. + g[Math.floor(Math.random() * g.length)]
  33. + b[Math.floor(Math.random() * b.length)];
  34. }, 3000);
  35.  
  36. window.onload = function () {
  37. var c = document.getElementById("c");
  38. var ctx = c.getContext("2d");
  39. c.height = window.innerHeight;
  40. c.width = window.innerWidth;
  41.  
  42. var matrix = "0123456789ABCDEF";
  43. //converting the string into an array of single characters
  44. matrix = matrix.split("");
  45.  
  46. var font_size = 20;
  47. var columns = c.width / font_size; //number of columns for the rain
  48. //an array of drops - one per column
  49. var drops = [];
  50. //x below is the x coordinate
  51. //1 = y co-ordinate of the drop(same for every drop initially)
  52. for (var x = 0; x < columns; x++) {
  53. drops[x] = 1;
  54. }
  55. //drawing the characters
  56. function draw() {
  57. //translucent BG to show trail
  58. //Black BG for the canvas
  59. ctx.fillStyle = "rgba(0, 0, 0, 0.04)";
  60. ctx.fillRect(0, 0, c.width, c.height);
  61. //a random color to print
  62. // coltext = "#" + r[Math.floor(Math.random() * r.length)]
  63. // + g[Math.floor(Math.random() * g.length)]
  64. // + b[Math.floor(Math.random() * b.length)];
  65.  
  66. ctx.fillStyle = coltext; //color text
  67. ctx.font = 15 + "px arial";
  68. //looping over drops
  69. for (var i = 0; i < drops.length; i++) {
  70. var text = matrix[Math.floor(Math.random() * matrix.length)];
  71. //x = i*font_size, y = value of drops[i]*font_size
  72. ctx.fillText(text, i * font_size, drops[i] * font_size);
  73.  
  74. //sending the drop back to the top randomly after it has crossed the screen
  75. //adding a randomness to the reset to make the drops scattered on the Y axis
  76. if (drops[i] * font_size > c.height && Math.random() > 0.975)
  77. drops[i] = 0;
  78. //incrementing Y coordinate
  79. drops[i]++;
  80. }
  81. }
  82. setInterval(draw, 35);
  83. };
  84. </script>
  85. </body>
  86.  
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement