int timer; int siz; float step, offset; int clickX,clickY; float rotX, rotY; float rot; int rotAxis; //------------------------- void setup(){ size(300,300,P3D); framerate(30); step = 0.05; rotY = -0.6; rotX = 0.4; siz = 30; rot = 1f; fill(128,64); stroke(0,64); } //------------------------- void drawExpansion(int level, float x, float y, float z, float offset){ float parameter = noise(offset); if(rotAxis==0) rotateX(rot*(parameter*PI-PI*0.5)); if(rotAxis==1) rotateY(rot*(parameter*PI-PI*0.5)); if(rotAxis==2) rotateZ(rot*(parameter*PI-PI*0.5)); rect(0f,0f,(float)siz,parameter*siz); translate(0f,parameter*siz,0); 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=='1') rotAxis = 0; if(key=='2') rotAxis = 1; if(key=='3') rotAxis = 2; if(key=='+') siz += 2; if(key=='-') siz -= 2; if(key=='m') siz += 2; if(key=='n') siz -= 2; if(key=='a') rot += 0.005; if(key=='s') rot -= 0.005; } //------------------------- void mousePressed(){ clickX = mouseX; clickY = mouseY; }