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

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

public class RisingLine 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;

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

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

        // 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() >= 0) ||
        (line.getEnd().getY() >= 0)) {
            line.move(0, ySpeed);
            ySpeed = ySpeed * 1.1;
            pause(DELAY_TIME);
        }
        line.removeFromCanvas();
    }
}
