Created
October 5, 2011 22:40
-
-
Save sixthgear/1265954 to your computer and use it in GitHub Desktop.
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
| 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