boolean clicked = false; PFont font16; void setup(){ font16 = loadFont("FFScala-16.vlw"); size(800,600); background(0,0,0); frameRate(2); } void draw(){ if(!clicked){ background(0); translate(width/2,height*(1.0/4.0)); textFont(font16, 16); fill(255, 255, 255); text("-- Nautilus Shells --\n\nDrawn with golden ratio approximation of Fibonacci numbers. \n\n Click to draw.",-225,100); } } void mousePressed(){ clicked = true; println("Mouse Pressed!"); background(0); resetMatrix(); translate(400,300); smooth(); repaint(); delay(100); double rot = 0.0645; strokeWeight(2.0); stroke(109,130,210,192); rotate(PI/2); pushMatrix(); for(int i=0; i<10; i++){ drawNautilus(rot,0.5); rotate(0.1); } popMatrix(); pushMatrix(); for(int i=0; i<10; i++){ drawNautilus(-rot,0.5); rotate(-0.1); } popMatrix(); repaint(); delay(100); stroke(111,220,107,192); translate(230,0); strokeWeight(1.5); pushMatrix(); for(int i=0; i<5; i++){ drawMiniNautilus(2.5*rot,0.50); rotate(0.35); } popMatrix(); pushMatrix(); for(int i=0; i<5; i++){ drawMiniNautilus(-2.5*rot,0.50); rotate(-0.35); } popMatrix(); repaint(); delay(100); pushMatrix(); translate(-130,250); for(int i=0; i<10; i++){ drawMiniNautilus(2.5*rot,1.0); rotate(-0.25); } popMatrix(); pushMatrix(); translate(-130,-250); for(int i=0; i<10; i++){ drawMiniNautilus(-2.5*rot,1.0); rotate(0.25); } popMatrix(); } double fibonacci(double s){ return Math.pow(goldenRatio,s)/Math.sqrt(5); } void drawNautilus(double rot, double mul){ pushMatrix(); double s = 0.0; double lastFib = 0.0; for(s=0.0; s<15; s+=0.025){ double newFib = fibonacci(s); double rotFib[] = getRotatedPoint(newFib,0.0,rot*mul); line((int)lastFib, 0, (int)rotFib[0], (int)rotFib[1]); lastFib = newFib; rotate((float)rot); } popMatrix(); } void drawMiniNautilus(double rot, double mul){ pushMatrix(); double s = 0.0; double lastFib = 0.0; for(s=0.0; s<18; s+=0.05){ double newFib = fibonacci(s); double rotFib[] = getRotatedPoint(newFib,0.0,rot*mul); line((int)lastFib, 0, (int)rotFib[0], (int)rotFib[1]); lastFib = newFib; rotate((float)rot); } popMatrix(); } double goldenRatio = (1+Math.sqrt(5)) / 2; double[] getRotatedPoint(double inX, double inY, double rotation){ double newX = Math.cos(rotation)*inX - Math.sin(rotation)*inY; double newY = Math.sin(rotation)*inX + Math.cos(rotation)*inY; return new double[] {newX, newY}; }