Created
March 10, 2015 16:43
-
-
Save mpfund/b8a31562cd730820c79e to your computer and use it in GitHub Desktop.
Prime Factors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="bignumber.js"></script> | |
<canvas id='c' width="200" height="200"> | |
</canvas> | |
<script> | |
function prime_factors(n){ | |
var factors = []; | |
var d = 2; | |
while (n > 1){ | |
while (n % d == 0){ | |
factors.push(d); | |
n = parseInt(n/d); | |
} | |
d = d + 1; | |
} | |
return factors | |
} | |
var k = document.getElementById('c'); | |
var ctx = c.getContext('2d'); | |
ctx.fillStyle = "black"; | |
for(var x=0;x<40000;x++){ | |
var primes =prime_factors(x); | |
for(var k=0;k<primes.length;k++){ | |
var index =primes[k] +1; | |
var posX = index % 200; | |
var posY = parseInt(index / 200); | |
ctx.fillRect(posX,posY,1,1); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment