/* * scrambler_fractal.pde * * Short program to draw 'scrambler' or propeller fractal. * mouse-click to increase generation * press 'r' to reset * arrow keys to pan * + / - to zoom in / out * Uses a simple method to figure out how many points to plot - * a better method would be, well, better. */ //globals updated by mouse and keyboard int gen = 0; int rad = 80; float xb, yb; int thick = 2; void setup() { size(640, 480); xb = width/2; yb = height/2; } //move up the generations by clicking //note - to resent you need to press the 'r' key void mousePressed(){ gen++; } //primitive zoom and pan commands void keyPressed(){ if ( key == '+') rad++; if ( key == '-') rad--; if ( keyCode == UP) yb+=10; if ( keyCode == DOWN) yb-=10; if ( keyCode == LEFT) xb+=10; if (keyCode == RIGHT) xb-=10; } void draw() { //drawing characteristics background(250); float f = 0.0; stroke(0); noFill(); strokeWeight(thick); //shape beginShape(); float x, y; int gr = 100*(gen + 1); // the 'sampling' increases with each generation float factor; //while loop moves around the circle while(f < TWO_PI) { x = xb; y = yb; int last = +1; //for loop adds to the expression for each generation for(int i=0; i <= gen; i++){ factor = pow(2,i); x = x + cos(factor*f)*rad/factor; y = y + last*sin(factor*f)*rad/factor; last = last*(-1); } vertex(x, y); f += PI/gr; } endShape(); }