Ulam Spiral
in
Share your Work
•
1 year ago
Hi all, a newbie here,
this is my first time posting code.
I've made a very simple sketch to draw an
Ulam Spiral.
Critics are welcome.
- int posX;
- int posY;
- float cellsize = 0.5;
- float distan = cellsize;
- void setup() {
- size(700, 700);
- smooth();
- posX = width/2;
- posY = height/2;
- noLoop();
- }
- void draw() {
- background(255);
- ellipseMode(CENTER);
- noStroke();
- fill(0);
- ellipse(posX, posY, cellsize, cellsize);
- translate(posX, posY);
- rotate(PI/2);
- int count = 2;
- float tot = width/distan;
- for (int r=1;r<tot;r++) {
- for (int j=1;j<=r;j++) {
- if (primo(count)) {
- fill(0);
- }
- else {
- noFill();
- }
- ellipse(distan*j, 0, cellsize, cellsize);
- count++;
- }
- translate(distan*r, 0);
- rotate(PI/2);
- for (int j=1;j<=r;j++) {
- if (primo(count)) {
- fill(0);
- }
- else {
- noFill();
- }
- ellipse(distan*j, 0, cellsize, cellsize);
- count++;
- }
- translate(distan*r, 0);
- rotate(PI/2);
- }
- println("test");
- }
- boolean primo(int p) {
- for (int m=2;m<p;m++) {
- if (p % m == 0) {
- return false;
- }
- }
- println(p);
- return true;
- }