// Homework 7 // Amy Nichols // Section D // aenichol@andrew.cmu.edu // DO NOT ALTER THE COMMENT THAT STARTS ON THE NEXT LINE -- DETAILS IN CLASS /* Lateral Motion Commands


move in ---- [i]
move out --- [o]

move right - [r]
move left -- [l]

move up ---- [u]
move down -- [d]


Rotational Motion Commands


rotate left (y axis) --- [left arrow]
rotate right(y axis) --- [right arrow]

rotate up ( x axis ) --- [up arrow]
rotate down ( x axis ) - [down arrow]

rotate CCW ( z axis ) -- [,]
rotate CW (z axis ) ---- [.]


reset to zero ---------- [space]

*/ // Declare gobal variables here PFont f1; int rotAmount, rotIncrease, rotXAmount, rotYAmount; int x = 0; int y = 0; int z = 0; void setup( ) { size( 500, 500, P3D ); lights( ); f1 = loadFont("f1.vlw"); textFont( f1 ); background( #04075A ); lights( ); noStroke( ); rotAmount = 0; rotXAmount = 0; rotYAmount = 0; rotIncrease = 1; y = 0; x = 0; z = 0; } // void draw( ) { translate( width/2 + x, height/2 + y, 0 + z ); background( #04075A ); rotate(radians(rotAmount)); rotateX(radians(rotXAmount)); rotateY(radians(rotYAmount)); drawInitial( ); drawAxis( ); } void keyPressed( ) { if (key == CODED) { if (keyCode == LEFT) { rotYAmount -= rotIncrease; } else if (keyCode == RIGHT) { rotYAmount += rotIncrease; } else if (keyCode == UP) { rotXAmount -= rotIncrease; } else if (keyCode == DOWN) { rotXAmount += rotIncrease; } } else if (key == ',') // CCW { rotAmount -= rotIncrease; } else if (key == '.') // CW { rotAmount += rotIncrease; } else if (key == 'f') { rotIncrease++; } else if (key == 's') { rotIncrease--; } else if (key == 'i') { z = z + width/100; } else if (key == 'o') { z = z - width/100; } else if (key == 'r') { x = x + width/100; } else if (key == 'l') { x = x - width/100; } else if (key == 'u') { y = y - width/100; } else if (key == 'd') { y = y + width/100; } else if (key == ' ') { rotAmount = 0; rotYAmount = 0; rotXAmount = 0; x = 0; y = 0; z = 0; } } void drawInitial( ) { int x = 0; int y = 0; int z = 0; int depth = 0; int radius = (int)(.05*width); int edge = (int)(.08*width); background( #04075A ); lights( ); directionalLight(155, 155, 155, 15, 20, -1); directionalLight(155, 155, 155, 85, 20, -1); noStroke( ); // red top spheres pushMatrix( ); translate( x, y-(height*.3), z+(depth) ); fill( #AF1747 ); sphere( radius ); popMatrix( ); pushMatrix( ); translate( x, y-(height*.3), z+(depth + 60) ); fill( #AF1747 ); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x, y-(height*.3), z+(depth - 60) ); fill( #AF1747 ); sphere( radius/2 ); popMatrix( ); // green boxes pushMatrix( ); translate( x-(width*.09), y-(height*.15), z+(depth) ); fill( #71F500 ); rotateZ(radians(115)); box( edge*2, edge/3, edge ); popMatrix( ); pushMatrix( ); translate( x+(width*.09), y-(height*.15), z+(depth) ); fill( #71F500 ); rotateZ(radians(-115)); box( edge*2, edge/3, edge); popMatrix( ); pushMatrix( ); translate( x, y, z+(depth) ); fill( #71F500 ); rotateY(radians(45)); rotateZ(radians(45)); box(edge/2); popMatrix( ); pushMatrix( ); translate( x+(width*.08), y, z+(depth) ); fill( #71F500 ); rotateY(radians(45)); rotateZ(radians(45)); box(edge/2); popMatrix( ); pushMatrix( ); translate( x-(width*.08), y, z+(depth) ); fill( #71F500 ); rotateY(radians(45)); rotateZ(radians(45)); box(edge/2); popMatrix( ); pushMatrix( ); translate( x-(width*.23), y+(height*.14), z+(depth) ); fill( #71F500 ); rotateZ(radians(115)); box( edge*2, edge/3, edge); popMatrix( ); pushMatrix( ); translate( x+(width*.23), y+(height*.14), z+(depth) ); fill( #71F500 ); rotateZ(radians(-115)); box( edge*2, edge/3, edge); popMatrix( ); // orange middle spheres pushMatrix( ); translate( x+(width*.17), y, z+(depth) ); fill( #F55A00 ); sphere( radius ); popMatrix( ); pushMatrix( ); translate( x+(width*.17), y, z+(depth - 60) ); fill( #F55A00 ); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x+(width*.17), y, z+(depth + 60) ); fill( #F55A00 ); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x-(width*.17), y, z+(depth) ); fill( #F55A00 ); sphere( radius ); popMatrix( ); pushMatrix( ); translate( x-(width*.17), y, z+(depth + 60) ); fill( #F55A00 ); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x-(width*.17), y, z+(depth - 60) ); fill( #F55A00 ); sphere( radius/2 ); popMatrix( ); // yellow spheres - bottom pushMatrix( ); translate( x+(width*.30), y+(height*.28), z+(depth) ); fill( #F5A400 ); sphere( radius ); popMatrix( ); pushMatrix( ); translate( x+(width*.30), y+(height*.28), z+(depth + 60) ); fill( #F5A400 ); rotateZ(radians(45)); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x+(width*.30), y+(height*.28), z+(depth - 60) ); fill( #F5A400 ); rotateZ(radians(45)); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x-(width*.30), y+(height*.28), z+(depth) ); fill( #F5A400 ); sphere( radius ); popMatrix( ); pushMatrix( ); translate( x-(width*.30), y+(height*.28), z+(depth + 60) ); fill( #F5A400 ); rotateZ(radians(45)); sphere( radius/2 ); popMatrix( ); pushMatrix( ); translate( x-(width*.30), y+(height*.28), z+(depth - 60) ); fill( #F5A400 ); rotateZ(radians(45)); sphere( radius/2 ); popMatrix( ); // A middle line pushMatrix( ); translate( x, y, z+(depth) ); fill( #94F0ED, 95 ); box(edge*4, edge/10, edge*5); popMatrix( ); // Top/bottom platforms pushMatrix( ); translate( x+(width*.30), y+(height*.28), z+(depth) ); fill( #94F0ED, 95 ); box( edge*3, edge/10, edge*5 ); popMatrix( ); pushMatrix( ); translate( x-(width*.30), y+(height*.28), z+(depth) ); fill( #94F0ED, 95 ); box( edge*3, edge/10, edge*5 ); popMatrix( ); pushMatrix( ); translate( x, y-(height*.3), z+(depth) ); fill( #94F0ED, 95 ); box( edge*2, edge/10, edge*5); popMatrix( ); // Side platforms pushMatrix( ); translate( x-(width*.17), y, z+(depth) ); fill( #94F0ED, 95 ); rotateZ(radians(115)); box( edge*7.5, edge/10, edge*4 ); popMatrix( ); pushMatrix( ); translate( x+(width*.17), y, z+(depth) ); fill( #94F0ED, 95 ); rotateZ(radians(-115)); box( edge*7.5, edge/10, edge*4 ); popMatrix( ); } void drawAxis( ) { fill( 255 ); sphere(1); stroke( 255, 0, 0 ); strokeWeight( 1 ); line( -200, 0, 0, 200, 0, 0); text( 'W', -200, 0, 0); text( 'E', 200, 0, 0); stroke( 0, 255, 0 ); line( 0, -200, 0, 0, 200, 0 ); text( 'N', 0, -200, 0); text( 'S', 0, 200, 0); stroke(255, 255, 0 ); line( 0, 0, -200, 0, 0, 200); text( 'F', 0, 0, 200); text( 'B', 0, 0, -200); }