//Homework #7
//Erica D. Cochran
//ericac@andrew.cmu.edu
//Section B
//Copyright © Erica D. Cochran
//September 30, 2009
//Carnegie Mellon University
//Exploring Programming with Graphics
//Pittsburgh, PA, USA
//All Rights Reserved
/**
Lateral Motion Commands
move away ---- [ a ] ____________ move closer -- [ c ]
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]
*/
// set screen size and init variables width and height:
PFont f1;
PImage rose;
int depth;
float xtrans, ytrans, ztrans;
float xrot, yrot, zrot;
float transDelta, rotDelta;
void setup( )
{
size( 500, 500, P3D );
background( #04075A );
f1 = loadFont("f1.vlw");
rose = loadImage ("rose.JPG");
depth = height;
draw3DInitials ();
//moves up, down, right and left
xtrans = 0;
ytrans = 0;
ztrans = 0;
//rotates
xrot = 0;
yrot = 0;
zrot = 0;
transDelta = 2;
rotDelta = 2;
}
void draw( )
{
background( #04075A );
// This moves the (0,0,340) point to the center of the window
// Do not remove or alter this line of code
translate( width/2, height/2, 0 );
// You MUST call the translate and rotate function here?
translate (xtrans, ytrans, ztrans);
rotateX (radians (xrot));
rotateY (radians (yrot));
rotateZ (radians (zrot));
// do not alter or move these two function calls!
lights( );
drawAxis( );
// Call your funcion(s) here:
draw3DInitials ();
}
void keyPressed( )
{
if (key == 'r')
{
xtrans = xtrans + transDelta;
}
else if (key == 'l')
{
xtrans = xtrans - transDelta;
}
else if (key == 'u')
{
ytrans = ytrans - transDelta;
}
else if (key == 'd')
{
ytrans = ytrans + transDelta;
}
else if (key == 'c')
{
ztrans = ztrans + transDelta;
}
else if (key == 'a')
{
ztrans = ztrans - transDelta;
}
else if (keyCode == UP)
{
xrot = xrot + rotDelta;
}
else if (keyCode == DOWN)
{
xrot = xrot - rotDelta;
}
else if (keyCode == RIGHT)
{
yrot = yrot + rotDelta;
}
else if (keyCode == LEFT)
{
yrot = yrot - rotDelta;
}
else if (key == ',')
{
zrot = zrot - rotDelta;
}
else if (key == '.')
{
zrot = zrot + rotDelta;
}
else if (key == ' ')
{
xtrans = 0;
ytrans = 0;
ztrans = 0;
xrot = 0;
yrot = 0;
zrot = 0;
}
}
void drawAxis( )
{
textFont( f1 );
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 draw3DInitials ()
{
stroke(255,0,0);
float xvar, yvar;
xvar = 250;
yvar = 250;
//Long vert part of E
pushMatrix();
translate(width*.367-xvar, height*.5-yvar, 0);
fill(250,10,10,100);
box(.1*width, .667*height, .2*depth);
popMatrix();
//Long vert part of E
pushMatrix();
translate(width*.367-xvar, height*.5-yvar, -10);
fill(250,10,10,245);
box(.1*width, .667*height, .05*depth);
popMatrix();
//Top horiz extra bar
stroke(250,130,5);
pushMatrix();
translate(width*.567-xvar, height*.2-yvar, -10);
fill(250,130,50,250);
box(width*.233, height*.033, depth*.05);
popMatrix();
//Begin top horiz
stroke(0,0,255);
pushMatrix();
translate(width*.433-xvar, height*.2-yvar, 0);
fill(10,240,200,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.5-xvar, height*.2-yvar, 0);
fill(10,240,200,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.567-xvar, height*.2-yvar, 0);
fill(10,240,200,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.63-xvar, height*.2-yvar, 0);
fill(10,240,200,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.7-xvar, height*.2-yvar, 0);
fill(10,240,200,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
//Middle horiz extra bar
stroke(250,130,5);
pushMatrix();
translate(width*.5-xvar, height*.5-yvar, -10);
fill(250,130,50,250);
box(width*.1, height*.033, depth*.05);
popMatrix();
//Begin middle horiz
stroke(0,0,255);
pushMatrix();
translate(width*.433-xvar, height*.5-yvar, 0);
fill(10,175,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.5-xvar, height*.5-yvar, 0);
fill(10,175,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.567-xvar, height*.5-yvar, 0);
fill(10,175,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
//Bottom horiz extra bar
stroke(250,130,5);
pushMatrix();
translate(width*.567-xvar, height*.8-yvar, -10);
fill(250,130,50,250);
box(width*.233, height*.033, depth*.05);
popMatrix();
//Begin bottom horiz
stroke(0,0,255);
pushMatrix();
translate(width*.433-xvar, height*.8-yvar, 0);
fill(10,60,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.5-xvar, height*.8-yvar, 0);
fill(10,60,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.567-xvar, height*.8-yvar, 0);
fill(10,60,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.63-xvar, height*.8-yvar, 0);
fill(10,60,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
pushMatrix();
translate(width*.7-xvar, height*.8-yvar, 0);
fill(10,60,240,200);
box(width*.033, height*.066, depth*.2);
popMatrix();
//Image of Rose
pushMatrix();
translate(width*.5-(xvar*1.0995), height*.5-(yvar*1.1975), -50);
tint (255, 120);
image (rose, width*.033, height*.066, width*.033, height*.066);
popMatrix();
}