int timer; int siz; float step, offset; int clickX,clickY; float rotX, rotY; float curl, twist; //------------------------- void setup(){ size(300,300,P3D); framerate(30); step = 0.05; rotY = -0.6; rotX = 0.4; siz = 6; curl = 1f; twist = 1f; fill(128,64); stroke(0,64); } //------------------------- void drawExpansion(int level, float x, float y, float z, float offset){ float parameter = noise(offset); float rot = twist*0.2*( noise(offset+314.1592)*PI-PI*0.5 ); rotateY(curl*(parameter-0.5)*PI); beginShape(POLYGON); vertex(0f,-siz,0f); vertex(0f,siz,0f); vertex(2*siz,cos(rot)*siz,sin(rot)*siz); vertex(2*siz,-cos(rot)*siz,-sin(rot)*siz); endShape(); translate(2*siz,0,0); rotateX(rot); if(level!=0) drawExpansion( level-1, x, y, z, offset+step); } //------------------------- void draw(){ background(225); translate(width/2,height/2); if(mousePressed){ rotX += (mouseY-clickY)*0.002; rotY += (mouseX-clickX)*0.002; } rotateX( rotX ); rotateY( rotY ); timer++; drawExpansion( timer/4, 0f, 0f, 0f, offset); } //------------------------- void keyPressed(){ if(key==' '){ timer = 0; offset = offset += TWO_PI*7; } if(key=='+') siz += 1; if(key=='-') siz -= 1; if(key=='m') siz += 1; if(key=='n') siz -= 1; if(key=='a') curl += 0.005; if(key=='s') curl -= 0.005; if(key=='z') twist += 0.01; if(key=='x') twist -= 0.01; } //------------------------- void mousePressed(){ clickX = mouseX; clickY = mouseY; }