package physics;

import stdlib.Color;
import stdlib.StdDraw;

/*************************************************************************
 *  Compilation:  javac BouncingBalls.java
 *  Execution:    java BouncingBalls N
 *  Dependencies: Ball.java StdDraw.java
 *
 *  Creates an array of N bouncing balls and animates them.
 *
 *  % java BouncingBalls 10
 *
 *************************************************************************/

public class BouncingBalls { 

    public static void main(String[] args) {

        // number of bouncing balls
//        int N = Integer.parseInt(args[0]);
    	int N = 10;

        StdDraw sd = new StdDraw();
        // set boundary to box with coordinates between -1 and +1
        sd.setXscale(-1.0, +1.0);
        sd.setYscale(-1.0, +1.0);

        // create an array of N random balls
        Ball[] balls = new Ball[N];
        for (int i = 0; i < N; i++)
            balls[i] = new Ball();

        // do the animation loop
        while(true) {
            StdDraw.clear(Color.GRAY);
            sd.setPenColor(Color.WHITE);
            sd.filledSquare(0.0, 0.0, 1.0);
            sd.setPenColor(Color.BLACK);
            for (int i = 0; i < N; i++) {
                balls[i].move();
                balls[i].draw();
            }
            sd.show(10);
        }
    }
}
