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

/*
 * Another Spirograph, with four colors...
 */
public class ColorfulSpirograph extends WindowController {

    // first coordinate of a line segment
    private Location start;

    // color of next spriograph
    private Color currentColor;

    // generator for random numbers between 1 and 4
    private RandomIntGenerator pickAColor = new RandomIntGenerator(1, 4);

    // used when picking a new color
    private int colorNumber;
    
    /*
     * Save the first coordinate of the line, and pick
     * a new random color.
     */
    public void onMousePress(Location point) {
        start = point;

        colorNumber = pickAColor.nextValue();

        if (colorNumber == 1) {
            currentColor = Color.red;
        } else if (colorNumber == 2) {
            currentColor = Color.blue;
        } else if (colorNumber == 3) {
            currentColor = Color.magenta;
        } else {
            currentColor = Color.green;
        }

    }

    /*
     * As the user is dragging draw a line from
     * initial point where mouse pressed to current point.
     */
    public void onMouseDrag(Location point) {
        new Line(start, point, canvas).setColor(currentColor);
    }

}
