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

/*
 * Fading line segments for the VanishingScribble example
 * 
 * A simple active object that controls a line that fades from black
 * through shades of grey, then is removed from the canvas when it becomes
 * white
 *
 * Jim Teresco, Siena College, CSIS 120, Fall 2011
 *
 * $Id: FadingLine.java 1541 2011-02-15 21:09:53Z terescoj $
 */

public class FadingLine extends ActiveObject {

    // amount and speed of the fade
    private static final double FADE_BY = 2;
    private static final int DELAY_TIME = 33;
    private static final int INITIAL_DELAY = 1000;

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

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

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

        // activate!
        start();
    }

    // change the line's color periodically so it fades to white
    public void run() {

        pause(INITIAL_DELAY);
        int hue = 0;
        while (hue < 255) {
            line.setColor(new Color(hue, hue, hue));
            pause(DELAY_TIME);
            hue += FADE_BY;
        }
        line.removeFromCanvas();
    }
}
