Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- packSize=100; // Number of integers per cell
- cellSize=5; // Number of pixels per cell
- window.isPrime=function(n)
- {
- for(var i = 2, s = Math.sqrt(n); i <= s; i++)
- if(n % i === 0) return false;
- return n !== 1;
- }
- window.numberOfPrimes=function()
- {
- var primes = 0;
- var myNum=curNum+x;
- for (var i=0;i<packSize;i++)
- {
- if (isPrime(myNum))primes +=1 ;
- myNum+=y;
- }
- return primes;
- }
- window.drawLine=function()
- {
- for (x=0;x<y;x++)
- {
- var primes = numberOfPrimes();
- var ratio = primes/packSize;
- var color = ratio * 0xffffff;
- console.log(primes);
- console.log(ratio);
- console.log(Math.round(color).toString(16));
- ctx.fillStyle="#" + Math.round(color).toString(16);
- ctx.fillRect (500+x*cellSize-y*cellSize/2,y*cellSize,cellSize+1,cellSize+1);
- }
- curNum+=packSize*y;
- y++;
- if (y<1000/cellSize) setTimeout("drawLine()",10);
- }
- curNum=1;
- canvas = document.getElementById("canvas");
- ctx = canvas.getContext("2d");
- y=1;
- drawLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement