Advertisement
Guest User

colored-parallax-primes

a guest
May 18th, 2018
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. packSize=100; // Number of integers per cell
  2. cellSize=5; // Number of pixels per cell
  3.  
  4. window.isPrime=function(n)
  5. {
  6.  for(var i = 2, s = Math.sqrt(n); i <= s; i++)
  7.   if(n % i === 0) return false;
  8.  return n !== 1;
  9. }
  10.  
  11. window.numberOfPrimes=function()
  12. {
  13.  var primes = 0;
  14.  var myNum=curNum+x;
  15.  for (var i=0;i<packSize;i++)
  16.  {
  17.   if (isPrime(myNum))primes +=1 ;
  18.   myNum+=y;
  19.  }
  20.  return primes;
  21. }
  22.  
  23. window.drawLine=function()
  24. {
  25.  for (x=0;x<y;x++)
  26.  {
  27. var primes = numberOfPrimes();
  28. var ratio = primes/packSize;
  29. var color = ratio * 0xffffff;
  30. console.log(primes);
  31. console.log(ratio);
  32. console.log(Math.round(color).toString(16));
  33. ctx.fillStyle="#" + Math.round(color).toString(16);
  34.   ctx.fillRect (500+x*cellSize-y*cellSize/2,y*cellSize,cellSize+1,cellSize+1);
  35.  }
  36.  curNum+=packSize*y;
  37.  y++;
  38.  if (y<1000/cellSize) setTimeout("drawLine()",10);
  39. }
  40.  
  41. curNum=1;
  42. canvas = document.getElementById("canvas");
  43. ctx = canvas.getContext("2d");
  44. y=1;
  45. drawLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement