Advertisement
nzisaacnz

gcd

Sep 21st, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.16 KB | None | 0 0
  1. <html>
  2.   <head>
  3.    
  4.   </head>
  5.   <body>
  6.     <input type="range" min="0" max="1000" id="T" onmousemove="Draw()" style="width:100%;"/>
  7.     <canvas id="cvs" width="900" height="900" style="background-color:#000;"></canvas>
  8.     <script>
  9.       function gcd(a,b)
  10.       {
  11.         while(b!=0)
  12.         {
  13.           var c = a%b;
  14.           a=b;
  15.           b=c;
  16.         }
  17.         return a;
  18.       }
  19.       var offsetx,offsety;
  20.       offsetx = offsety = 450;
  21.       var map = new Array();
  22.       for(var x=0; x<900; x++)
  23.      {
  24.        var row = new Array();
  25.        for(var y=0; y<900; y++)
  26.        {
  27.          row.push(gcd(x-offsetx,y-offsety));
  28.        }
  29.        map.push(row);
  30.      }
  31.      var g = cvs.getContext("2d");
  32.      function Draw()
  33.      {
  34.        g.clearRect(0,0,cvs.width,cvs.height);
  35.        var threshold = Math.exp(T.value/100);
  36.        for(var x=0; x<900; x++)
  37.        {
  38.          for(var y=0; y<900; y++)
  39.          {
  40.            if(map[x][y]>threshold)
  41.             {
  42.               g.fillStyle="hsl("+map[x][y]+",100%,50%)";
  43.               g.fillRect(x,y,1,1);
  44.             }
  45.           }
  46.         }
  47.       }
  48.     </script>
  49.   </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement