Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int A[]; // prime number container
- int count=1;// no of primes allocated
- int i;// loop variable declared global to preserve memory
- int x;//co ordinate
- int y;//co ordinate
- int c = 1;// starting point
- int step=1;// the upper limit that describes how far must (x,y) traverse to make the outer edge of the spiral
- int direction = -1; // simple variable that reverses the direction after every horizontal and vertical spiral edge draw. (x++,y) X //step, (x,y++) X step. then (x--,y) X step, (x,y--) X step step++ and repeat.
- int s = 0;// remove for v1.2, keep for v 1.1
- int imgno=1;// offset
- int p; // spiral overflow variable
- void setup()
- {
- size(600, 600);
- orientation(LANDSCAPE);
- background(255);
- A = new int[4000000];
- A[0]=2;
- x=width/2;
- y=height/2;
- /*while ( (s++)<c)
- {
- prime(s);
- //println(s);
- }*/
- }
- void draw()
- {
- background(255);
- p=1;
- c=imgno;
- //s=0;
- x=width/2;
- y=height/2;
- step = 1;
- println("point1");
- if (prime(c))
- point(x, y);
- while (p<=360200)
- {
- direction*=-1;
- for (int d=0;d<step;d++)
- {
- x=x+direction;
- c=c+1;
- p++;
- if (prime(c))
- point(x, y);
- println("point = "+x+","+y);
- }
- for (int d=0;d<step;d++)
- {
- y=y+direction;
- c=c+1;
- p++;
- if (prime(c))
- point(x, y);
- println("point = "+x+","+y);
- }
- println("step= "+step);
- step++;
- }
- imgno++;
- //save("prime"+imgno+".jpeg");
- delay(20);
- }
- boolean prime(int n)
- {
- if (n==1)
- return false;
- else if (n==2)
- return true;
- else
- {
- for (int i=0;((i<count)&&(A[i]<=sqrt(n)));i++)
- {
- println("A["+i+"]"+"="+A[i]+" n= "+n);
- if (n%A[i]==0)
- return false;
- }
- }
- A[count] = n;
- count++;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement