Thor
YaBB Newbies
Offline
Posts: 8
Fibonnaci tile set and spiral
Feb 15th , 2009, 12:22am
I couldn't find one, so I made a short script to generate a fibonnaci tile set and corresponding spiral. For some reason I find them aesthetically pleasing, so I'll see if I can render them in a more interesting way later on. As for the implementation, it's probably terribly clunky and mathmatically inelegant, so please feel free to tell me how's it's really done. Thanks, Thor. void setup() { size(1000, 1000); smooth(); noFill(); background(255); stroke(0, 100); drawFibonnaciTiles(500); } void drawFibonnaciTiles(int iterations) { rect(width/2, height/2, 1, 1); int posx = width/2; int posy = height/2; int fibprev = 1; int fibnew = 0; for (int fib = 1; fib < iterations;) { for (int a = 0; a < 4; a++) { if (a == 0) { fibnew = fib + fibprev; fibprev = fib; fib = fibnew; arc(posx + fib, posy + fib, fib*2, fib*2, PI, TWO_PI-PI/2); rect(posx, posy, fib, fib); posx = posx + fib; } if (a == 1) { fibnew = fib + fibprev; fibprev = fib; fib = fibnew; arc(posx, posy + fib, fib*2, fib*2, TWO_PI-PI/2, TWO_PI); rect(posx, posy, fib, fib); posx = posx - fibprev; posy = posy + fib; } if (a == 2) { fibnew = fib + fibprev; fibprev = fib; fib = fibnew; arc(posx, posy, fib*2, fib*2, 0, PI/2); rect(posx, posy, fib, fib); posx = posx - fib - fibprev; posy = posy - fibprev; } if (a == 3) { fibnew = fib + fibprev; fibprev = fib; fib = fibnew; arc(posx + fib, posy, fib*2, fib*2, PI/2, PI); rect(posx, posy, fib, fib); posy = posy - fib - fibprev; } } } }