Advertisement
Guest User

animated bit patterns

a guest
Jul 27th, 2021
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <canvas id="c" width="768" height="768">
  2. <script>
  3.   const context = c.getContext('2d');
  4.  
  5.   function test(x,y,t) {
  6.       return ((x * y)^t) % 17;
  7.   }
  8.  
  9.   const scale = 2;
  10.  
  11.   function draw(t) {
  12.       for (let x = 0; x < c.width / scale; x++) {
  13.         for (let y = 0; y < c.height / scale; y++) {
  14.           if (test(x,y,t)) {
  15.             context.fillStyle = '#000';
  16.            } else {
  17.             context.fillStyle = '#fff';
  18.       }
  19.  
  20.           context.fillRect(x*scale, y*scale, scale, scale);
  21.         }
  22.       }
  23.   }
  24.  
  25.   let t = 0;
  26.  
  27.   window.setInterval(() => { t = (t+1) % 256; draw(t); }, 20);
  28.  
  29. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement