/**My procedure draws a yellow face proportional 
 * to an int especified by the user. The user can 
 * also choose to put a mustache and hair on the face.*/

import java.awt.*;
import javax.swing.*;
/** Assignment A4: using a Ball */
public class Ball extends YourTurtle {
  /**  */
  private int radius; //gives the radius of the ball
  private int vx; //ball moves vx pixels in the horizontal direction
  private int vy; //ball moves vy pixels in the vertical direction
  
  /** =  Radius of ball*/
  public int getRadius(){
    return radius;
  }
  
  /** = horizontal direction movement*/
  public int getVx(){
    return vx;
  }
  
  /**= vertical direction movement*/
  public int getVy(){
    return vy;
  }
  
  
  
  /** Constructor: a ball starting at (x,y).Ball has
   * speed (vx, vy), radius r and color c.*/
  public Ball(int x, int y, int vx, int vy, int r, Color c) {
    moveTo(x,y,90);
    this.vx= vx;
    this.vy= vy;
    radius= r;
    setColor(c);
    fillCircle(radius);
  }
  
  /** = moves the ball once, as given by its speed (vx, vy)*/
  public void moveBallOnce(){
    Color save= getColor();
    setColor(Color.white);
    fillCircle(radius);
    setColor(save);
    moveTo(getX()+vx,getY()+vy,0);
    fillCircle(radius);
    if (getY() < radius){
      vy= - vy; 
    }
    if (getX() < radius){
      vx= - vx;
    }
    if (getHeight()-radius < getY()){
      vy= - vy; 
    }
    if (getWidth()-radius < getX()){
      vx= - vx;
    }
  }
  
  /** = The ball stays perpetually in motion. */
  
  public void inMotion(){
    int k=1;
    while (k ==1){
      pause(100);
      moveBallOnce();
    }
  }
  
  /** Constructor: a window without anything in it */
  public Ball() {
      clear();
  }
  
  
  /** =Draw a face with size proportional to d, color of eyes = eyecolor.
   * If mustache is true face has mustache with color equals muscolor. 
   * If hair is true, face has hair with color equals haircolor*/
  
  public void drawFace(int d, boolean mustache, boolean hair, 
                       Color eyecolor, Color muscolor, Color haircolor){
    boolean m= mustache;
    boolean h= hair;
    //Draw head
    moveTo(getHeight()/2, getWidth()/2, 90);
    setColor(13);
    fillCircle(15*d);
    //Draw eyes
    moveTo((getHeight()/2)+3*d, (getWidth()/2)-3*d, 90);
    setColor(eyecolor);
    fillCircle(2*d);
    moveTo((getHeight()/2)-3*d, (getWidth()/2)-3*d, 90);
    fillCircle(2*d);
    //Draw nose
    moveTo((getHeight()/2)-1*d, (getWidth()/2)-3*d, 270);
    setColor(java.awt.Color.black);
    move(3*d);
    setAngle(0);
    move(2*d);
    setAngle(90);
    move(3*d);
    //draw the mouth
    moveTo((getHeight()/2)-2*d, (getWidth()/2)+2*d, 0);
    int k=0;
    setColor(java.awt.Color.white);
    while (k !=5){
      fillRectangle(1*d,1*d);
      liftPen();
      move(1*d);
      putPenDown();
      k=k+1;
    }
    setColor(1);
    //Draw a mustache if mustache is true
    if (m){
      setColor(muscolor);
      moveTo((getHeight()/2)-3*d, (getWidth()/2)+1*d, 0);
      int a=0;
      while (a !=7){
        fillCircle(2*d);
        move(1*d);
        a=a+1;
      }
      //Draw the hair
      if(h){
        setColor(haircolor);
        moveTo((getHeight()/2)-2*d, (getWidth()/2)-7*d,0);
        int f=0;
        while (f!=2){
          fillCircle(3*d);
          move(1*d);
          setAngle(90);
          move(1*d);
          setAngle(0);
          f=f+1;
        }
        int e=0;
        while (e !=2){
          move(1*d);
          setAngle(270);
          move(1*d);
          fillCircle(3*d);          
          setAngle(0);
          e=e+1;
        }
      }
    }
  }
}

/**It took me about 6hr to complete this assignment*/

