Monday, November 4, 2013

Project 3

I think the critique went well. Barry said that I should make the font bigger for reading when displaying to the class. I will keep that in mind for any text I use on the next project. I was able to make this project do everything that I wanted it to. If I were to extend it I'd make it pause to make it easier to make a screenprint. Also, I had to comment out the part that used coded keys to make screen prints of it because I had them clear the screen. This caused the screen to be cleared when trying to take a screen shot until I commented it out. I think I'd prefer to work on something else for the next project rather than extending this.
I used techniques not discussed in class in making my project like writing my own functions. For others in the class who don't know me, I have a degree in computer science and engineering and worked as a programmer for 3 1/2 years. Even though I am new to processing and only used Java in a class back in the 90s, I have general knowledge of how to go about programming so learning this is mostly becoming familiar with the syntax for me.
Here are some screen shots of my project:


 
Here is the code:
 
 float angle=0.0;
float r;
float s;
float t;
String shape;
String direction;
PFont font;
void setup(){
  size(600,600);
  background(0); //set background to black
  smooth();
  font = loadFont("TimesNewRomanPSMT-48.vlw");
  textFont(font);
  textSize(18);
  text("Press t for triangles, e for ellipses and q for quads.  Move by using the mouse. Press a coded key to clear the screen. Press 1 to rotate in a clockwise direction and any other key to rotate counterclockwise.",75,150,450,300); 
}
void draw(){
  translate(mouseX, mouseY); //move axis to mouse location
  rotate(angle);   //rotate axis
  r=random(255);      //set 3 random numbers changes every time run
  s=random(255);
  t=random(255);
  fill(int(r),int(s),int(t));  /*convert random numbers to int and
                                 use to generate random color*/
                                
  if (shape == "triangle"){                              
    triangle(20,20,60,150,85,115);  //show triangle
  }
  if (shape == "quad"){
     quad(30,30,60,90,150,150,300,100);  //show quad
   }
   if (shape == "ellipse"){
     ellipse(10,10,150,225);  //show ellipse
   }
   if (direction =="counterclockwise"){
     angle += 0.1;
   } else{
       direction ="clockwise";
       angle -=0.1;
   }
      
  if (keyPressed && (key == CODED) ) {
   // background(0);  //clear screen
    }
    if (keyPressed){
      if (key == '1'){
      direction = "clockwise";  //change rotation direction 
       } else {
       direction ="counterclockwise";
       } 
    }
  if (keyPressed){
    if ((key == 'q')||(key == 'Q' )) {
      shape = "quad";
    }
    if ((key == 'e') ||(key == 'E')){
      shape = "ellipse";
      } else
      if((key == 't')||(key =='T')){
      shape = "triangle";
      }
   }
   displayShape(shape);
   selectDirection(direction);
     }
//This function sets the shape displayed
String displayShape(String shape){
    String newShape;
    newShape = shape; 
    return newShape;
  }
//This function selects the direction of rotation 
String selectDirection(String direction){
   String newDirection;
   newDirection = direction;
   return newDirection;
 }

No comments:

Post a Comment