Skip to content

Instantly share code, notes, and snippets.

@ethan2-0
Created September 4, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethan2-0/9634d03578484b7df39e to your computer and use it in GitHub Desktop.
Save ethan2-0/9634d03578484b7df39e to your computer and use it in GitHub Desktop.
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