Created
September 4, 2015 14:15
-
-
Save ethan2-0/9634d03578484b7df39e to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.ArrayList; | |
// Stuff to remember: | |
// * ellipseMode -> can take CENTER to do what you expect | |
final int width = 600; | |
final int height = 600; | |
boolean[] primality; | |
final int scale = 5; | |
void setup() { | |
size(600, 600); | |
primality = sieve(); | |
int x = 0; | |
int y = 0; | |
fill(0, 0, 0); | |
for(int i = 0; i < primality.length; i++) { | |
if(x > width / scale) { | |
x = 0; | |
y++; | |
} | |
x++; | |
if(primality[i]) { | |
rect(x * scale, y * scale, scale, scale); | |
} | |
} | |
} | |
boolean[] sieve() { | |
// Everyone loves the sieve of erastosthenes | |
boolean[] primality = new boolean[10000]; | |
for(int i = 0; i < primality.length; i++) { | |
primality[i] = true; | |
} | |
for(int i = 2; i < primality.length / 2; i++) { | |
if(primality[i] == false) { | |
continue; | |
} | |
for(int j = 2 * i; j < primality.length; j += i) { | |
primality[j] = false; | |
} | |
} | |
return primality; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment