/*
 * This Turtle class contains sample source codes for Homework 2
 * Please look at drawRobot() method below
 */

/**
 * Class that represents a turtle which is similar to a Logo turtle.
 * This class inherts from SimpleTurtle and is for students
 * to add methods to.
 *
 * Copyright Georgia Institute of Technology 2004
 * @author Barb Ericson ericson@cc.gatech.edu
 */
public class Turtle extends SimpleTurtle
{
  ////////////////// constructors ///////////////////////
  
  /** Constructor that takes the x and y and a picture to
   * draw on
   * @param x the starting x position
   * @param y the starting y position
   * @param picture the picture to draw on
   */
  public Turtle (int x, int y, Picture picture) 
  {
    // let the parent constructor handle it
    super(x,y,picture);
  }
  
  /** Constructor that takes the x and y and a model
   * display to draw it on
   * @param x the starting x position
   * @param y the starting y position
   * @param modelDisplayer the thing that displays the model
   */
  public Turtle (int x, int y, ModelDisplay modelDisplayer) 
  {
    // let the parent constructor handle it
    super(x,y,modelDisplayer);
  }
  
  /** Constructor that takes the model display
   * @param modelDisplay the thing that displays the model
   */
  public Turtle (ModelDisplay modelDisplay) 
  {
    // let the parent constructor handle it
    super(modelDisplay);
  }
  
  /**
   * Constructor that takes a picture to draw on
   * @param p the picture to draw on
   */
  public Turtle (Picture p)
  {
    // let the parent constructor handle it
    super(p);
  }  
  
  /////////////////// methods ///////////////////////

  // This method will draw a robot
  // containing a head, face, body, hands, and legs
  public void drawRobot()
  {
    setPenWidth(5);
    drawHead();
    drawFace();
    drawBody();
    drawHand();
    drawLegs();
  }

  // This method will move turtle to specific location (x,y) without drawing
  public void moveTurtle(int x, int y)
  {
    penUp();
    moveTo( x, y );
    penDown();
  }
  
  public void drawHead()
  {
    moveTurtle( 290, 170 );
    drawSquare( 60 );
  }  
  
  public void drawFace()
  { 
    moveTurtle( 310, 140 );    
    forward(20);
    moveTurtle( 330, 140 );    
    forward(20);
    moveTurtle( 310, 150 );    
    turnRight();
    forward(20);
    turnLeft();
  }

  public void drawBody()
  {
    moveTurtle( 280, 310 );
    drawRectangle( 80, 120 );
  }
  
  public void drawHand()
  {
    // left hand (arm)
    moveTurtle( 280, 200 );
    turn(-45);
    forward(100);
    turn(45);

    // right hand (arm)
    moveTurtle( 360, 200 );
    turn(45);
    forward(100);
    turn(-45);    
  }

  public void drawLegs()
  {
    // left leg
    moveTurtle( 270, 360 );
    drawTriangle(40);
    
    // right leg
    moveTurtle( 330, 360 );
    drawTriangle(40);
  }

  public void drawSquare(int len)
  {
    for( int i=0; i<4; i++)
    {
      forward(len);
      turnRight();
    }
  }
  
  public void drawRectangle(int w, int h)
  {    
    forward(h);
    turnRight();
    forward(w);
    turnRight();    
    forward(h);
    turnRight();
    forward(w);
    turnRight();
  }

  public void drawTriangle(int len)
  {
    turn(30);
    forward(len);
    turn(120);
    forward(len);
    turn(120);
    forward(len);
    turnRight();
  }
  
} // end of class Turtle, put all new methods before this
