Guest User

Untitled

a guest
Feb 26th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.31 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. let SECONDS = 20;
  5. let FRAMERATE = 50;
  6. function repaint(canvas, context, pixels) {
  7.   let width = canvas.width;
  8.   let height = canvas.height;
  9.   var offset = 0;
  10.   let redColor = [255, 0, 0];
  11.   let cyanColor = [0, 255, 255];
  12.   let randomColor = [redColor, cyanColor][Math.floor(Math.random() * 2)];
  13.   for (var y = 0; y < height; y++) {
  14.    for (var x = 0; x < width; x++) {
  15.      pixels.data[offset++] = randomColor[0]; // R
  16.      pixels.data[offset++] = randomColor[1]; // G
  17.      pixels.data[offset++] = randomColor[2]; // B
  18.      pixels.data[offset++] = 0xFF; // A
  19.    }
  20.  }
  21.  context.putImageData(pixels, 0, 0);
  22. }
  23. function quit(timerId) {
  24.  clearInterval(timerId);
  25. }
  26. function init() {
  27.  let canvas = document.getElementById('myCanvas');
  28.  canvas.width = screen.width;
  29.  canvas.height = screen.height;
  30.  if (canvas) {
  31.    let context = canvas.getContext('2d');
  32.    if (context) {
  33.      let pixels = context.createImageData(canvas.width, canvas.height);
  34.      let myTimer = setInterval(repaint, 1000 / FRAMERATE, canvas, context, pixels);
  35.      if (myTimer && SECONDS > 0) {
  36.         setTimeout(quit, SECONDS * 1000, myTimer);
  37.       }
  38.     }
  39.   }
  40. }
  41. </script>
  42. </head>
  43. <body style="margin: 0px" onload="init()">
  44. <canvas id="myCanvas"></canvas>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment