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

//@width 500
//@height 400

/*
 * A program to simulate the Fall in Williamstown.
 * Click in the window and leaves will start to fall...
 */
public class Fall extends WindowController {

  /* the size of the screen */
  private final int SCREEN_LEFT = 0;
  private final int SCREEN_TOP = 0;
  private final int SCREEN_HEIGHT = 400;
  private final int SCREEN_WIDTH = 500;

  /* locations, sizes, and colors of grass and sun */
  private final int SUN_INSET = 50;
  private final int SUN_SIZE = 70;
  private final double GRASS_LINE = SCREEN_HEIGHT * 0.63;
  private final double GRASS_HEIGHT = SCREEN_HEIGHT * .04;
  private final double SKY_LINE = GRASS_LINE + GRASS_HEIGHT;
  private final double GRASS_WIDTH = 2;
  private final Color SKY_BLUE = new Color(100, 100, 200);
  private final Color GRASS_GREEN = new Color(0, 200, 0);

  /* the images loaded from the harddrive */
  private Image leafpic1;
  private Image leafpic2;

  public void begin() {
    this.resize(500,444);

    // get leaf pictures
    leafpic1 = getImage("leaf1.gif");
    leafpic2 = getImage("leaf2.gif");

    // draw solid sky, grass and sun
    new FilledRect(0, 0, SCREEN_WIDTH, SKY_LINE, canvas).setColor(SKY_BLUE);
    new FilledRect(0, SKY_LINE, SCREEN_WIDTH, SCREEN_HEIGHT - GRASS_LINE, canvas).setColor(GRASS_GREEN);
    new FilledOval(SUN_INSET, SUN_INSET, SUN_SIZE, SUN_SIZE, canvas).setColor(Color.yellow);

    // add the blades of grass
    double bladePosition = 0;   // where to draw next blade of grass

    while (bladePosition < SCREEN_WIDTH) {
      FilledRect blade = 
        new FilledRect(bladePosition, GRASS_LINE, GRASS_WIDTH, GRASS_HEIGHT,canvas);
      blade.setColor(GRASS_GREEN);

      bladePosition = bladePosition + (2 * GRASS_WIDTH);
    }
  }

  public void onMouseClick(Location point) {
    // make a new leaf dropping tree when the user clicks
    new Tree(leafpic1, leafpic2, SCREEN_WIDTH, SCREEN_HEIGHT, canvas);
  }
}
