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

/*
 * Falling line segments for the VanishingScribble example
 * 
 * A simple active object that controls a line that falls down the
 * canvas and disappears when it goes off the end.
 *
 * Jim Teresco, Siena College, CSIS 120, Fall 2011
 *
 * $Id: FallingLine.java 1553 2011-02-28 02:11:43Z terescoj $
 */

public class FallingLine extends ActiveObject {

    // size and speed of falling lines
    private static final double INITIAL_Y_SPEED = 0.0001;
    private static final int DELAY_TIME = 33;
    private static final int INITIAL_DELAY = 100;

    // the line controlled by this instance
    private Line line;

    // how far to fall before stopping and disappearing?
    private double yMax;

    // Draw a ball and start it falling.
    public FallingLine(Location start, Location end, DrawingCanvas aCanvas) {

        // draw the line at its initial position
        line = new Line(start, end, aCanvas);

        // ask the canvas how big it is so we know when to stop
        yMax = aCanvas.getHeight();

        // activate!
        start();
    }

    // move the line repeatedly until it falls off screen
    public void run() {

        pause(INITIAL_DELAY);

        // start out with a slow fall, then accelerate
        double ySpeed = INITIAL_Y_SPEED;

        while ((line.getStart().getY() <= yMax) ||
        (line.getEnd().getY() <= yMax)) {
            line.move(0, ySpeed);
            ySpeed = ySpeed * 1.1;
            pause(DELAY_TIME);
        }
        line.removeFromCanvas();
    }
}
