import acm.program.*;
import acm.graphics.*;
import java.awt.*;

public class SolarSystem extends GraphicsProgram {
    public void run() {
        addBody(1.9891e30,   0.000, 0.0000,  Color.YELLOW, "Sun");
        addBody(3.3022e23,  57.909, 0.4787,  Color.CYAN,   "Mercury");
        addBody(4.8685e24, 108.209, 0.3502,  Color.GREEN,  "Venus");
        addBody(5.9736e24, 149.598, 0.29783, Color.BLUE,   "Earth");
        addBody(6.4185e23, 227.939, 0.24077, Color.RED,    "Mars");
        addBody(1.0000e20,  49.397, 0.7051,  Color.MAGENTA,"Encke"); // Comet Encke

        while(true) {
            this.pause(20);
            
            for(int i = 0; i < this.getElementCount(); i++) {
                GObject o = this.getElement(i);
                if(o instanceof Body) ((Body) o).updateDirection(this);
            }
            for(int i = 0; i < this.getElementCount(); i++) {
                GObject o = this.getElement(i);
                if(o instanceof Body) ((Body) o).step();
            }
        }
    }
    
    // Adds a body into the window with the given parameters.
    private void addBody(double mass, double dist, double vel,
            Color hue, String name) {
        Body b = new Body(this.getWidth() / 2, this.getHeight() / 2 - dist,
            mass, name, vel, 0);
        b.setFillColor(hue);
        this.add(b);
    }
}
