import java.awt.*;
    /** DO this:
     
        b= new Ballffc3();
        b.gravity();

       to see a simulation of gravity with a ball. */

    public class Ballffc3 extends Turtle {
    private int radius;
    private int vx;
    private int vy;
    
    /* = radius of the ball */
    public int getRadius() {
        return radius;
    }
    
    /* = x velocity of the ball */
    public int getVx() {
        return vx;
    }
    
    /* = y velocity of the ball */
    public int getVy() {
        return vy;
    }
    
    /**Constructor: generates a ball at position x, y with velocity
     * vy, vx, with radius r and color c */
    public Ballffc3(int x, int y, int vx, int vy, int r, Color c) {
        super(x, y, 0);
        radius = r;
        this.vx = vx;
        this.vy = vy;
        setColor(c);
        draw();
    }
    
    /**Constructor: generates a ball at the center of the pane 
     * with velocity 10, 10, with radius 20 and color red */
    public Ballffc3(){
        super();
        radius = 20;
        vx = 10;
        vy = 10;
        setColor(Color.red);
        draw(); 
    }
    
    //Draws the ball
    private void draw() {
        fillCircle(radius * 2);
    }
    
    /** Moves the ball onece according to its x velocity and y velocity. */
    public void moveBallOnce() {
        //saves the present color
        Color save = getColor();
        if (((getX()+radius)>=width) || (getX()-radius)<=0)
            vx = -vx;
        if (((getY()+radius)>=height || (getY()-radius)<=0))
            vy = -vy;
        setColor(Color.white);
        draw();
        moveTo(getX()+vx,getY()+vy,getAngle());
        setColor(save);
        draw();
    }
    
    /** Sets the ball in motion */
    public void inMotion() {
        int t = 1;
        while(t != 0) {
            moveBallOnce();
            pause(100);
        }
    }
    
    /** Sets b1 and b2 in motion simultaneously */
    public static void inMotion(Ballffc3 b1, Ballffc3 b2) {
                int t = 1;
        while(t != 0) {
            b1.moveBallOnce();
            b2.moveBallOnce();
            b1.pause(100);
        }
    }
    
    public void gravity() {
        int p = 1;
        while(p != 0) {
            if ( getY() < getHeight() ) {
                vy = vy + 10;
            }
            moveBallOnceInelastic(.7);
            pause(70);
        }
    }
    
        /** Moves the ball onece according to its x velocity and y velocity
         * with inelastic collisions. v becomes v*i with each collision*/
    public void moveBallOnceInelastic(double i) {
        //saves the present color
        Color save = getColor();
        //tests for collisions with edges and reduces velocity accordingly
        if ((getX()+radius)>=width)
            vx = (int) ((double) -vx * i);
        if  ((getX()-radius)<=0)
            vx = (int) ((double) -vx * i);
        if ((getY()+radius)>=height)
            vy = (int) ((double) -vy * i);
        if  ((getY()-radius)<=0)
            vy = (int) ((double) -vy * i);
        setColor(Color.white);
        draw();
        moveTo(getX()+vx,getY()+vy,getAngle());
        setColor(save);
        draw();
    }
}