//Our interesting procedure is atomOrbitals(), and the time spent was about 3 hours

import java.awt.*;

/**an instance is a ball on a Jframe*/
public class Ball extends YourTurtle{
  private int radius;
  private int vx;
  private int vy;
  
  /**returns radius*/
  public int getRadius(){
    return radius;
  }
  
  /**returns vx*/
  public int getVx(){
    return vx;
  }
  
  /**returns vy*/
  public int getVy(){
    return vy;
  }
  
  /**Constructor: turtle starts at (x,y), has speed (vx, vy), radius (r), and color (c)*/
  public Ball(int x, int y, int vx, int vy, int r, Color c){
    this.vx= vx;
    this.vy= vy;
    radius= r;
    setColor(c);
    moveTo(x, y, 0);
    fillCircle(2*r);
  }
  
  /**Constructor: turtle starts at (getWidth/2, getHeight/2), has speed (vx, vy), radius (r), and color (1)*/
  public Ball(int vx, int vy, int r){
    this.vx= vx;
    this.vy= vy;
    radius= r;
    setColor(1);
    moveTo(getWidth()/2, getHeight()/2, 0);
    fillCircle(2*r);
  }
  
  /**moves the ball once vx horizontally and vy vertically*/
  public void moveBallOnce(){
    Color save= getColor();
    setColor(12);
    fillCircle(2*radius);
    moveTo(getVx() + getX(), getVy() + getY(), 0);
    setColor(save);
    fillCircle(2*radius);
    if(getY()<getRadius()){
      vy= -vy;
    }
    if(getY()>getHeight()-getRadius()){
      vy= -vy;
    }
    if(getX()<getRadius()){
      vx= -vx;
    }
    if(getX()>getWidth()-getRadius()){
      vx= -vx;
    }
  }
  
  /** moves the ball continuously vx horizontally and vy vertically */
  public void inMotion(){
    int k= 0;
    //k will always be equal or greater than 0, so this goes on forever
    while(k>=0){
      pause(100);
      moveBallOnce();
      k= k + 1;
    }
  }
  
  /** creates 8 electrons that move around the ball with electron size depending on ball radius*/
  public void atomOrbitals(){
    int w=0;
    int x=-3*getRadius()+250;
    int y=-3*getRadius()+250;
    //w will always be equal or greater than 0, so this goes on forever
    while(w>=0){
      pause(500/getRadius());
      clear();
      w=w+1;
      moveTo(250,250,0);
      fillCircle(2*getRadius());
      if(x==3*getRadius()+250){
        x=-3*getRadius()+250;
      }
      
      if(y==3*getRadius()+250){
        y=-3*getRadius()+250;
      }
      
      setAngle(90);
      moveTo(250,x,90);
      fillCircle(getRadius()/2);
      
      moveTo(y,x,90);
      fillCircle(getRadius()/2);
      
      moveTo(y,250,90);
      fillCircle(getRadius()/2);
      
      moveTo(500-y,250,90);
      fillCircle(getRadius()/2);
      
      moveTo(250,500-x,90);
      fillCircle(getRadius()/2);
      
      moveTo(y,500-x,90);
      fillCircle(getRadius()/2);
      
      moveTo(500-y,500-x,90);
      fillCircle(getRadius()/2);
      
      moveTo(500-y,x,90);
      fillCircle(getRadius()/2);
      x=x+1;
      y=y+1;
    }    
  }
}