/** A bouncing ball
    Matt Spencer & Ariel Waitz
    CS100J Spring 2005
    
    Execute the following to turn this instance into the
    nucleus of a Borom atom with radius 25! neat!
    
    b= new Ballaew42mhs38(30, 40, 20);
    b.bohr_model_of_Boron(25);
    
    
    */

import java.math.*;

public class Ballaew42mhs38 extends Turtle {
  private int radius, vx, vy;
  private int c1= 1;
  
  /** Constructor: a ball with radius r starting at (x,y)
     *  at angle 0, velocity (vx, vy), and color c as given in Turtle.tColor */
  public Ballaew42mhs38 (int x, int y, int vx, int vy, int r, int c) {
    c1= c;
    this.moveTo(x, y, 0);
    this.vx = vx;
    this.vy = vy;
    this.radius = r;
    this.tColor(c1);
    this.fillCircle(2*r);
  }

  /** Constructor: a ball with radius r starting at the midpoint
     *  at angle 0, velocity (vx, vy), and color c as given in Turtle.tColor*/
  public Ballaew42mhs38 (int vx, int vy, int r, int c) {
    this.moveTo(this.getWidth()/2, this.getHeight()/2, 0);
    c1= c;
    this.vx = vx;
    this.vy = vy;
    this.radius = r;
    this.tColor(c1);
    this.fillCircle(2*r);
  }
  
  /** Constructor: a ball with radius r starting at the midpoint
     *  at angle 0, velocity (vx, vy), and color is black*/
  public Ballaew42mhs38 (int vx, int vy, int r) {
    this.moveTo(this.getWidth()/2, this.getHeight()/2, 0);
    this.vx = vx;
    this.vy = vy;
    this.radius = r;
    this.tColor(c1);
    this.fillCircle(2*r);
  }
  
  /**Constructor: a grey ball with radius 5, where n is the electron number*/
  public Ballaew42mhs38 (int x, int y) {
    moveTo(x, y, 0);
    tColor(5);
    fillCircle(10);
  }
  
  //** returns the radius of the Ball
  public int getRadius(){
    return radius;
  }
  
  //** returns the horizontal acceleration of the Ball
  public int getVX(){
    return vx;
  }

  //** returns the vertical acceleration  of the Ball
  public int getVY(){
    return vy;
  }
  
  /**move ball once in direction (vx, vy)*/
  public void moveBallOnce() {
    int colorsave= c1;
    this.tColor(12);
    this.fillCircle(2*radius);
    if (getHeight()-getY() < radius) {
      vy= -vy;
    }
    if(getY()<radius) {
      vy= -vy;
    }
    if (getWidth()-getX() < radius) {
      vx= -vx;
    }
    if(getX()<radius) {
      vx= -vx;
    }
    this.moveTo(getX()+vx,getY()+vy,0);
    this.tColor(colorsave);
    this.fillCircle(2*radius); 
  }
  
  /**puts ball in perpetual motion */
  public void inMotion(){
    int x = 1;
    while (4%2 != x){ 
      pause(100);
      this.moveBallOnce(); 
    }
  }
  
  /**puts two balls in perpetual motion */
  public static void inMotion(Ballaew42mhs38 b1, Ballaew42mhs38 b2){
    int x = 1;
    while (4%2 != x){ 
      b1.moveBallOnce();
      b1.pause(100);
      b2.moveBallOnce();
      b2.pause(100);
    }
  }
  
  /**turns this instance into the nucleus of a Borom atom
   * with radius nucsize*/
  public void bohr_model_of_Boron(int nucsize) {
    
    //creating the nucleus
    clear();
    tColor(12);
    fillCircle(getRadius()*2);  //erases the current circle
    moveTo(getWidth()/2, getHeight()/2, 0); //places the turtle at the center of the jframe
    tColor(1); //sets the color to black
    fillCircle(2*nucsize); //draws the nucleus
    
    //creates the electrons
    Ballaew42mhs38 b1= new Ballaew42mhs38(this.getX()+this.radius+40, this.getY()+this.radius+40);
    Ballaew42mhs38 b2= new Ballaew42mhs38(this.getX()+this.radius+60, this.getY()+this.radius +60);
    Ballaew42mhs38 b3= new Ballaew42mhs38(this.getX()+this.radius +80, this.getY()+this.radius +80);
    Ballaew42mhs38 b4= new Ballaew42mhs38(this.getX()+this.radius +100, this.getY()+this.radius +100);
    Ballaew42mhs38 b5= new Ballaew42mhs38(this.getX()+this.radius +120, this.getY()+this.radius +120);
    
    int i= 0; //counter (angle)
    while ( i != -1    ) { //infinite loop
     
     b1.tColor(12); 
     b1.fillCircle(10); //erase b1 at its current position      
       //moves the ball to a multiple of the (cosine, sine) of i
     b1.moveTo(this.getX()+(int)(113.14*Math.cos(i/5*Math.PI/180)),this.getY()+(int)(113.14*Math.sin(i/5*Math.PI/180)), 0) ;
     b1.tColor(5);
     b1.fillCircle(10); //draws it
     
     b2.tColor(12);
     b2.fillCircle(10);
       //moves the ball to a multiple of the (cosine, sine) of i
     b2.moveTo((this.getX()+(int)(84.58*Math.cos(i/4*Math.PI/180))),(this.getY()+(int)(84.85*Math.sin(-i/4*Math.PI/180))), 0) ;
     b2.tColor(5);
     b2.fillCircle(10);
     
     b3.tColor(12);
     b3.fillCircle(10);
       //moves the ball to a multiple of the (cosine, sine) of i
     b3.moveTo((this.getX()+(int)(56.56*Math.cos(i/3*Math.PI/180))),(this.getY()+(int)(56.56*Math.sin(i/3*Math.PI/180))), 0) ;
     b3.tColor(5);
     b3.fillCircle(10);
     
     b4.tColor(12);
     b4.fillCircle(10);
       //moves the ball to a multiple of the (cosine, sine) of i
     b4.moveTo((this.getX()+(int)(141.42*Math.cos(i/2*Math.PI/180))),(this.getY()+(int)(141.42*Math.sin(-i/2*Math.PI/180))), 0) ;
     b4.tColor(5);
     b4.fillCircle(10);
     
     b5.tColor(12);
     b5.fillCircle(10);
       //moves the ball to a multiple of the (cosine, sine) of i
     b5.moveTo((this.getX()+(int)(169.71*Math.cos(i*Math.PI/180))),(this.getY()+(int)(169.71*Math.sin(i*Math.PI/180))), 0) ;
     b5.tColor(5);
     b5.fillCircle(10);
     
     pause(5); //pauses, to give the effect of motion
       
     i= i+1;  //increases the angle
    }
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
}