// This assignment took around 6-7 hours, my interesting procedure creates a clown with various expressions
/** Class Ball extends YourTurtle, Bouncing Ball */
import java.awt.*;
public class Ball extends YourTurtle {
  private int radius= 0; // radius of ball
  private int vx= 0;    // number of pixels ball moves on x-axis
  private int vy= 0;    // number of pixels ball moves on y-axis
  
  /** returns radius of circle */
  public int getRadius() {
    return radius;
  }
  
  /** returns number of vx pixels it moves in x direction */
  public int getVX() {
    return vx;
  }
  
  /** returns number of vy pixels it moves in y direction */
  public int getVY() {
    return vy;
  }
  
  /** Constructor: a window without anything in it */
  public Ball() {
      clear();
  }
 
  
  /** Constructor: turtle starts at (x, y), has speed 
   * (vx, vy), has radius r, and is drawn with Color c as an int.
   * make sure that parameter c is an int for simplicity */
  public Ball (int x, int y, int vx, int vy, int r, int c) {
    radius= r;
    moveTo(x, y, 0);
    this.vx= vx;
    this.vy= vy;
    setColor(c);
    fillCircle(r*2);
  }
  
 
  
  /** moves the ball once as given by its speed (vx, vy),
   * bounces off the walls */
  public void moveBallOnce() {
    Color save= getColor(); 
    setColor(12);
    fillCircle(radius*2);
    setColor(save);
    if((getY() + getVY()) < radius) {  // test for relation of ball to walls
      this.vy= -getVY();
    }
    if((getX() + getVX()) < radius) {
      this.vx= -getVX();
    }
    if((getX() + getVX()) > (getWidth() - radius)) {
      this.vx= -getVX();
    }
    if((getY() + getVY()) > (getHeight() - radius)) {
      this.vy= -getVY();
    }
    moveTo(getX() + getVX(), getY() + getVY(), 0);
    fillCircle(radius*2);
  }
  
  /** method that puts ball perpetually in motion */
  public void inMotion() {
    int k= 0;
    while(k == 0) {
      pause(100);
      moveBallOnce();
    }
  }
  
  /**My own method that draws a clown whose mouth expressions
   * and nose size depends on parameter (int k)
   * 0 < k < 100 for best results*/
  public void clown(int k) {
    setColor(11);
    moveTo(80, 80, 45);
    drawStar(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    setAngle(315);
    drawStar(25);
    moveTo(65, 65, 45);
    drawStar(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    setAngle(270);
    drawStar(25);
    moveTo(90, 25, 45);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    drawStarUp(25);
    moveTo(70, 75, 270);
    setColor(2);
    move(180);
    setAngle(315);
    move(75);
    setAngle(0);
    move(85);
    setAngle(45);
    move(75);
    setAngle(90);
    move(180);
    moveTo(120, 120, 0);
    setColor(1);
    drawCircle(80);
    moveTo(200, 120, 0);
    drawCircle(80);
    moveTo(140, 120, 0);
    fillCircle(40);
    moveTo(180, 120, 0);
    fillCircle(40);
    moveTo(160, 180, 0);
    setColor(11);
    fillCircle(k);
    moveTo(160, 250, 0);
    fillRectangle(110, 60);
    setColor(12);
    fillRectangle(k, 50);
  }
  
}


