import objectdraw.*;
import java.awt.*;

/*
 * Better simulation of the sun and moon... 
 */
public class CelestialCycle extends WindowController 
{
    private FilledRect sky;
    private FilledRect grass;
    private FilledOval orb;
    
    private int velocity = 2;  // rate at which the sun moves.
    
    private static final int SCENE_WIDTH = 400;
    private static final int SKY_HEIGHT = 250;
    private static final int GROUND_HEIGHT = 150;
    private static final int ORB_X = 80;
    private static final int ORB_Y = 0;
    private static final int ORB_DIAMETER = 100;
    
    /*
     * Set up initial scene.
     */
    public void begin() {
        sky = new FilledRect(0, 0, SCENE_WIDTH, SKY_HEIGHT, canvas);
        orb = new FilledOval(ORB_X, ORB_Y, ORB_DIAMETER, ORB_DIAMETER, canvas);
        grass = new FilledRect(0, SKY_HEIGHT, SCENE_WIDTH, GROUND_HEIGHT, canvas);
        
        sky.setColor(Color.blue);
        grass.setColor(Color.green);
        orb.setColor(Color.yellow);
    }
    
    
    /*
     * Move the heavenly body up and down the screen,
     * making it look like day when it is setting and
     * night when it is rising.
     */
    public void onMouseMove(Location point) {
        // Move the orb a little bit either up or down, 
        // depending on velocity.
        orb.move(0, velocity);
        
        // If the orb hits the ground or the top of the window,
        // it should switch directions and change the scene
        // from day to night (or reverse).
        if (orb.getY() > grass.getY()){
            // below horizon, so turn to night
            sky.setColor(Color.black);
            grass.setColor(Color.gray);
            orb.setColor(Color.white);
            
            velocity = -velocity;
            
        } else if (orb.getY() + orb.getHeight() < 0) {
            // above the screen, so turn to day
            sky.setColor(Color.blue);
            grass.setColor(Color.green);
            orb.setColor(Color.yellow);
            
            velocity = -velocity;
        }
    }

}
