Skip to content

Instantly share code, notes, and snippets.

@sixthgear
Created October 5, 2011 22:40
Show Gist options
  • Select an option

  • Save sixthgear/1265954 to your computer and use it in GitHub Desktop.

Select an option

Save sixthgear/1265954 to your computer and use it in GitHub Desktop.
int width = 600;
int height = 600;
int total_points = 100000;
int point_size = 1;
float point_spacing = 1.0;
boolean isPrime(int n) {
if (n < 2) return false;
else if (n == 2) return true;
else if (n % 2 == 0) return false;
for(int i=3; i<=sqrt(n); i+=2) {
if (n % i == 0) return false;
}
return true;
}
void setup() {
size(width, height);
background(0);
smooth();
noStroke();
spiral();
}
void spiral() {
for (int n=0; n<=total_points; n++) {
float theta = -sqrt(n) * TWO_PI;
float r = sqrt(n) * point_spacing;
float x = width/2 + cos(theta) * r;
float y = height/2 + sin(theta) * r;
if(isPrime(n)) {
fill(100,100,255);
ellipse(x,y,point_size*2,point_size*2);
} else {
fill(50);
ellipse(x,y,point_size,point_size);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment