// Homework 7 // Claire Castleman // Section D // ccastlem@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 rY = 0; int rX = 0; int rZ = 0; int x = 0; int y = 0; int z = 0; int rIncrease = 3; int mIncrease = 3; void setup( ) { size( 500, 500, P3D ); f1 = loadFont("f1.vlw"); textFont( f1 ); } void drawInitial() { lights(); directionalLight(128, 128, 128, 0, 0, 1); noStroke(); int cube=width/12; int ball=height/10; int x=0; int y=0; int z=0; translate( width/2, height/2, 0 ); translate( -width/2, -height/2, 0 ); pushMatrix( ); translate( x, y-(height*.05),z); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x-(width*.1), y-(height*.05),z); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x+(width*.1), y-(height*.05),z); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x, y-(height*.05),z+50); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate(x-(width*.1), y-(height*.05),z+50); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x+(width*.1), y-(height*.05), z+50); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x, y-(height*.05),z-50); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x-(width*.1), y-(height*.05), z-50); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x+(width*.1), y-(height*.05), z-50); fill(255,0,0); box( cube ); popMatrix( ); //top 9 cubes pushMatrix( ); translate( x, y+(height*.05), z); fill(255,0,0); box( cube ); popMatrix( ); pushMatrix( ); translate( x, y+(height*.15), z); fill(255,0,0); box( cube ); popMatrix( ); //middle 2 cubes pushMatrix( ); translate( x, y+(height*.25), z ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x-(width*.1), y+(height*.25), z ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x+(width*.1), y+(height*.25), z); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x, y+(height*.25), z+50 ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x-(width*.1), y+(height*.25), z+50 ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x+(width*.1), y+(height*.25), z+50 ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x, y+(height*.25), z-50 ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x-(width*.1), y+(height*.25), z-50 ); fill(255,0,0); box(cube); popMatrix( ); pushMatrix( ); translate( x+(width*.1), y+(height*.25), z-50 ); fill(255,0,0); box(cube); popMatrix( ); //bottom 9 cubes noStroke(); pushMatrix( ); translate( x, y-(height*.25), z ); fill(255,0,0); sphere(ball); popMatrix( ); //sphere or dot of i } 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( 'B', 0, 0, -200); text( 'F', 0, 0, 200); } void keyPressed() { if( key == CODED ) { if( keyCode == LEFT) { rY += rIncrease; } else if( keyCode == RIGHT) { rY -= rIncrease; } else if(keyCode == UP) { rX -= rIncrease; } else if (keyCode == DOWN) { rX += rIncrease; } } else if(key == 'i') { z += mIncrease; } else if(key == 'o') { z -= mIncrease; } else if(key == 'r') { x -= mIncrease; } else if(key == 'l') { x += mIncrease; } else if(key == 'u') { y += mIncrease; } else if(key == 'd') { y -= mIncrease; } else if(key == ',') { rotateZ(radians(rZ += rIncrease)); } else if(key == '.') { rotateZ(radians(rZ -= rIncrease)); } else if( key == ' ') { x=0; y=0; z=0; rX = 0; rY = 0; rZ = 0; } } void draw( ) { translate( width/2, height/2, 0 ); background( #04075A ); rotateX(radians(rX)); rotateY(radians(rY)); rotateZ(radians(rZ)); translate(x, y, z); drawInitial(); drawAxis( ); }