
import objectdraw.*;

/*
 * Draw spirals on the screen as the mouse is moved.
 * The most simple formula for a spiral in polar 
 * coordinates is:  radius = theta
 */

public class Spirals extends WindowController {

    // center of current spiral
    private Location center;

    // theta of paremetric equations for spiral
    private double theta;

    // end points of latest line drawn
    private Location lastPoint;

    private double radius=0.3;
    // used in onMouseDrag
    private Location newPoint;
    
    // Use position of mouse press to determine center of 
    // spiral
    public void onMousePress(Location point) {
        center = point;
        lastPoint = new Location(center.getX()+radius, center.getY());
        theta = 0.0;
    }

    // Each time the mouse is moved, plot a new point on the
    // spiral
    public void onMouseDrag(Location point) {
        theta = theta + 0.2;
        newPoint = new Location(center.getX() + radius * Math.cos(theta),
                                center.getY() + radius * Math.sin(theta));
        
        new Line(lastPoint, newPoint, canvas);
        lastPoint = newPoint;
        radius = radius + 0.2;

    }
}
