// View Rotation float xr, yr = 0; // mouse coordinates relative to center of window int px=0, dz=0, oz=0; void setup() { size(400, 400, P3D); colorMode(RGB, 1); } void draw() { float w=float(width); float h=float(height); // window sizes background(0.5, 0.5, 0.5); // grey background translate(w/2, h/2, 0.0); // center view wrt window if (mousePressed) {dz=oz+px-mouseX;} xr = (mouseX/w-0.5) * TWO_PI; yr = (mouseY/h-0.5) * TWO_PI; translate(0,0,dz); rotateX(-yr/2); rotateY(xr); scale(100); pyramid(9); } void mousePressed() { px=mouseX; oz=dz;} void mouseReleased() { dz=oz+px-mouseX; } void pyramid(int rec) { if (rec>0) {cube(); pushMatrix(); translate (0.0, -0.4, 0.0); scale(0.7); pyramid(rec-1); popMatrix(); }; } void cube () { pushMatrix(); scale (1.0,0.2,1.0); beginShape(QUADS); fill(0, 1, 1); vertex(-1, 1, 1); vertex( 1, 1, 1); vertex( 1, -1, 1); vertex(-1, -1, 1); fill(1, 1, 1); vertex( 1, 1, 1); vertex( 1, 1, -1); vertex( 1, -1, -1); vertex( 1, -1, 1); fill(1, 1, 0); vertex( 1, 1, -1); vertex(-1, 1, -1); vertex(-1, -1, -1); vertex( 1, -1, -1); fill(0, 1, 0); vertex(-1, 1, -1); vertex(-1, 1, 1); vertex(-1, -1, 1); vertex(-1, -1, -1); fill(0, 0, 1); vertex(-1, 1, -1); vertex( 1, 1, -1); vertex( 1, 1, 1); vertex(-1, 1, 1); fill(1, 0, 0); vertex(-1, -1, -1); vertex( 1, -1, -1); vertex( 1, -1, 1); vertex(-1, -1, 1); endShape(); popMatrix(); }