float scaleRate = 100; void setup() { size(640, 512, P3D); noStroke(); } void draw() { background(0); pushMatrix(); translate( width/2, height/2, 0 ); //lights(); ambientLight(102,102,102); directionalLight(153, 153, 153, 500, 500, -500); scale(scaleRate/100); manageRotation(); //table //tabletop fill( #E3AB4E ); drawBox( 0, 108, 0, 302, 9, 302 ); //legs drawBox( -128, 188, 128, 20, 150, 20 ); drawBox( 128, 188, 128, 20, 150, 20 ); drawBox( 128, 188, -128, 20, 150, 20 ); drawBox( -128, 188, -128, 20, 150, 20 ); //undertable and drawer fill( #D9A144 ); drawBox( 0, 135, 0, 272, 50, 272 ); fill( #CF973A ); drawBox( 0, 125, 143, 130, 30, 15 ); drawBox( 0, 123, 153, 8 ); //cloth fill( #FFFFFF ); //to right underneath drawBox( 77, 115, 107, 100, 15, 100, 0, -3 , 10 ); drawBox( 77, 107, 107, 102, 15, 100, 0, -3 , 3 ); //to left drawBox( -20, 100, 111, 110, 10, 100, 0, 0 , -3 ); drawBox( 25, 100, 86, 110, 10, 100, 2, 55 , -3 ); drawBox( -45, 115, 110, 80, 20, 100, 0, 0 , -9 ); drawBox(-70,120,118, 40,60,100, 0,-20,10); drawBox(-77,160,161, 20,60,10, 0,0,-60); //to right on top drawBox(80,90,50, 40,80,107, 0,20,40); drawBox(89,40,-20, 10,70,70, 10,30,40); drawBox(125,65,20, 30,50,110, 0,20,40); drawBox( 145, 85, 25, 60,50,100 , 0,20,0); drawBox( 180, 140, 60, 40, 80, 80, -6,17,0 ); drawBox( 205, 185, 90, 30, 30, 60, 0,10,0 ); //vases //green one fill( #83AC46 ); drawVase(-110,38,-110, 77,140,77, 7,8); //with brown string fill( #FFFFD4 ); drawVase(-7,54,-60, 100,100,100, 39,15); fill( #CF973A ); drawBox(-47,-31,-28.7, 1,100,3, 0,75.5,0); drawBox(-26,-31,-110, 1,100,3, 0,75.5,0); drawBox(-36.5,-80.5,-69.25, 84,1,3, 0,75.5,0); //white one with lid fill( #FFFFFF ); drawVase(-80,73,20, 56,60,56, -5,2); drawBox(-80,36,20, 44,16,44, 0,-5,0); drawBox(-80,26,20, 10, 0,-5,0); //bowl fill( #FAF7E4 ); drawBowl(6,83,93, 144,20,144, 0,0,-3, 5); //fruit fill( #F4EC32 ); drawSphere( 45,75,90, 27, 0,0,0 ); fill( #FFF04D ); drawSphere( 49,59,76, 28, -16,-22,0 ); fill( #FABB47 ); drawSphere( 54,67,118, 27, 0,-10,-4 ); fill( #FFCE53 ); drawSphere( 28,72,118, 26, 19,-3,0 ); fill( #F78A45); drawSphere( 19,58,90, 30, 35,0,30 ); fill( #F5F758 ); drawSphere( -28,68,70, 27, 0,0,9 ); fill( #FCD240 ); drawSphere( 3,69,126, 28, 15,45,0 ); fill( #F4A540 ); drawSphere( -25,70,120, 27, 30,0,15 ); fill( #FFDA4B ); drawSphere( -46,63,100, 30, -33,0,21 ); fill( #FCFD75 ); drawSphere( -13,51,114, 25, 15,0,10 ); fill( #FBCC34 ); drawSphere( -6,38,94, 29, -3,20,1 ); popMatrix(); } void keyPressed() { if (keyCode == UP) { if ( scaleRate < 300 ) scaleRate++; } else if (keyCode == DOWN) { if ( scaleRate > 1 ) scaleRate--; } } void drawBox( float x, float y, float z, float s, float rx, float ry, float rz ) { pushMatrixAndRotate( x, y, z, rx, ry, rz ); box( s ); popMatrix(); } void drawBox( float x, float y, float z, float w, float h, float d, float rx, float ry, float rz ) { pushMatrixAndRotate( x, y, z, rx, ry, rz ); box( w, h, d ); popMatrix(); } void drawBox( float x, float y, float z, float s ) { pushMatrix(); translate( x, y, z ); box( s ); popMatrix(); } void drawBox( float x, float y, float z, float w, float h, float d ) { pushMatrix(); translate( x, y, z ); box( w, h, d ); popMatrix(); } void drawBowl( float x, float y, float z, float w, float h, float d, float rx, float ry, float rz, float bowlWidth) { pushMatrix(); translate(x,y,z); rotateX( radians( rx ) ); rotateY( radians( ry ) ); rotateZ( radians( rz ) ); float oneFifthW = (w-(bowlWidth*2)) / 5; float oneFifthD = (d-(bowlWidth*2)) / 5; //sides translate( ((oneFifthW*1.5)+(bowlWidth/2)),0,0); box( bowlWidth, h-(bowlWidth*2), oneFifthD*3 ); translate( 0-((oneFifthW*3)+bowlWidth),0,0); box( bowlWidth, h-(bowlWidth*2), oneFifthD*3 ); translate( ((oneFifthW*1.5)+(bowlWidth/2)),0,((oneFifthD*1.5)+(bowlWidth/2))); box( oneFifthW*3, h-(bowlWidth*2), bowlWidth ); translate( 0,0,0-((oneFifthD*3)+bowlWidth)); box( oneFifthW*3, h-(bowlWidth*2), bowlWidth ); //base translate( 0,(h/2)-(bowlWidth/2),((oneFifthD*1.5)+(bowlWidth/2))); box(oneFifthW*3,bowlWidth,oneFifthD*3); //rims translate( (oneFifthW*2)+(bowlWidth/2),0-(h-bowlWidth),0 ); box( oneFifthW+bowlWidth, bowlWidth, (oneFifthD*3)+(bowlWidth*2)); translate( 0-((oneFifthW*4)+bowlWidth),0,0 ); box( oneFifthW+bowlWidth, bowlWidth, (oneFifthD*3)+(bowlWidth*2)); translate( (oneFifthW*2)+(bowlWidth/2),0,(oneFifthD*2)+(bowlWidth/2) ); box( (oneFifthW*3)+(bowlWidth*2), bowlWidth, oneFifthD+bowlWidth ); translate( 0,0,0-((oneFifthD*4)+bowlWidth) ); box( (oneFifthW*3)+(bowlWidth*2), bowlWidth, oneFifthD+bowlWidth ); popMatrix(); } void drawSphere( float x, float y, float z, float s, float rx, float ry, float rz) { pushMatrix(); translate(x,y,z); rotateX( radians( rx ) ); rotateY( radians( ry ) ); rotateZ( radians( rz ) ); float partSphere = s/5; //sides translate( (s/2)-(partSphere/2), 0, 0 ); box( partSphere, s-(partSphere*2), s-(partSphere*2) ); translate( 0-(s-partSphere), 0, 0 ); box( partSphere, s-(partSphere*2), s-(partSphere*2) ); translate( (s/2)-(partSphere/2), 0, 0-((s/2)-(partSphere/2)) ); box( s-(partSphere*2), s-(partSphere*2), partSphere ); translate( 0, 0, s-partSphere ); box( s-(partSphere*2), s-(partSphere*2), partSphere ); //bottom & top translate( 0, 0, 0-((s/2)-(partSphere/2)) ); box( s-(partSphere*2), s, s-(partSphere*2) ); popMatrix(); } void drawVase( float x, float y, float z, float w, float h, float d, float r, float vaseWidth) { pushMatrix(); translate(x,y,z); rotateY( radians( r ) ); //sides translate( (w/2)-(vaseWidth/2), 0, 0 ); box( vaseWidth, h-(vaseWidth*2), d-(vaseWidth*2) ); translate( 0-(w-vaseWidth), 0, 0 ); box( vaseWidth, h-(vaseWidth*2), d-(vaseWidth*2) ); translate( (w/2)-(vaseWidth/2), 0, 0-((d/2)-(vaseWidth/2)) ); box( w-(vaseWidth*2), h-(vaseWidth*2), vaseWidth ); translate( 0, 0, d-vaseWidth ); box( w-(vaseWidth*2), h-(vaseWidth*2), vaseWidth ); //bottom translate( 0, (h/2)-(vaseWidth/2), 0-((d/2)-(vaseWidth/2)) ); box( w-(vaseWidth*2), vaseWidth, d-(vaseWidth*2) ); //top translate(0-((w-(vaseWidth*2))/3), 0-(h-vaseWidth), 0); box((w-(vaseWidth*2))/3, vaseWidth, d-(vaseWidth*2)); translate((w-(vaseWidth*2))/1.5, 0, 0); box((w-(vaseWidth*2))/3, vaseWidth, d-(vaseWidth*2)); translate(0-((w-(vaseWidth*2))/3), 0, 0-((d-(vaseWidth*2))/3)); box((w-(vaseWidth*2))/3, vaseWidth, (d-(vaseWidth*2))/3); translate(0, 0, (d-(vaseWidth*2))/1.5); box((w-(vaseWidth*2))/3, vaseWidth, (d-(vaseWidth*2))/3); popMatrix(); } void manageRotation() { rotateX(((height/2) - ((mouseY/float(height) * TWO_PI) - (height/2)))*2); rotateY((mouseX/float(width) * TWO_PI)*2); } void pushMatrixAndRotate( float x, float y, float z, float rx, float ry, float rz ) { pushMatrix(); translate( x, y, z ); rotateX( radians( rx ) ); rotateY( radians( ry ) ); rotateZ( radians( rz ) ); }