// Our interesting procedure is crazyStuff. We worked on this approximately 
// 3 hours each.
import java.awt.*;
public class Ball extends YourTurtle{
 private int radius; // radius of the ball.
 private int vx; // horizontal velocity of the ball.
 private int vy; // vertical velocity of the ball.
 
 /** Gets the value of the radius. */
 public int getRadius() {
   return radius;
 }
 
 /** Gets the value of the horizontal velocity. */
 public int getVx() {
   return vx;
 }
 
 /**Gets the value of the vertical velocity. */
 public int getVy() {
   return vy;
 }
 
 /** Constructor: a window without anything in it */
 public Ball() {
     clear();
 }
 
 /** Constructor: Starts a new Ball at (x,y) with radius r, velocities
  vX and vY and color c. */
 public Ball(int x,int y,int vX,int vY,int r,int c) {
   moveTo(x,y,0);
   setColor(c);
   radius=r;
   fillCircle(2*r);
   vx=vX;
   vy=vY;
 }
 /** Constructor: Starts a new Ball at the midpoint of the panel, with color
  black, radius r, and velocities vX and vY. */
 public Ball(int vX, int vY, int r) {
   radius=r;
   moveTo(250,250,0);
   setColor(14);
   fillCircle(2*r);
   vx=vX;
   vy=vY;
 }
 /** Makes ball move once vx pixels horizontally, and vy pixels vertically.
  If ball goes off frame, vx or vy are negated.*/
 public void moveBallOnce() {
   Color save = getColor();
   int nx= getX() + vx;
   int ny= getY() + vy;
   setColor(12);
   fillCircle(2* getRadius());
   moveTo( nx, ny, 0);
   setColor(save);
   fillCircle(2* getRadius());
   if ((getY() + radius) > 500){
     vy = -vy;
   }
   else if ((getY() - radius) < 0){
     vy = -vy;
   }
   if ((getX() + radius) > 500){
     vx = -vx;
   }
   else if ((getX() - radius) < 0){
     vx= -vx;
   }
 }
 
 /** Makes ball move infinitely with velocities vx and vy.*/
 public void inMotion(){
   boolean x= true;
   while (x != false){
     pause(100);
     moveBallOnce();
   }
 }
  /** This method displays many shapes and colors using the spiral
   method. p is the speed at which the pattern grows, or shrinks.
   If r= true you see the pattern growing out, if r= false then 
   the pattern shrinks.  It also pauses at specific shapes.*/
  public void crazyStuff(int p, boolean r ){
    double a =1.0;
    if (r==true){
      int b=0;
      while (a != 361){
      spiral(b,a, 1,0);
      if ((a == 90) || (a == 120) || (a == 121) || (a == 135) || 
          (a == 89) || (a == 45) || (a == 60) || (a == 137)   || 
          (a == 270) || (a == 125) || (a == 240) || (a == 300) || 
          (a == 301) || (a == 317) || (a == 269) || (a == 225)){
        pause(1500);
      }
      a=a+1;
      b= b + 2;
      pause(p);
      }
    }
    else {
      int b= 720;
      while (a != 361){
      spiral(b,a, 1,0);
      if ((a == 90) || (a == 120) || (a == 121) || (a == 135) || 
          (a == 89) || (a == 45) || (a == 60) || (a == 137)   || 
          (a == 270) || (a == 125) || (a == 240) || (a == 300) || 
          (a == 301) || (a == 317) || (a == 269) || (a == 225)){
        pause(1500);
      }
      a=a+1;
      b= b - 2;
      pause(p);
      }
    }
  }
}