import objectdraw.*;
 
// Draws lovely spirals on the screen wherever the mouse is clicked
public class Spiral extends WindowController {
    
    // equation for a spiral in polar coordinates is theta = radius
    private double theta;
    
    // end points of latest line drawn
    private Location lastPoint;
    private Location newPoint;
    
    // center of current spiral
    private Location center;
    
    // How many points to draw per circle
    private static double STEPS_PER_ROTATION = 25;
    
    // Amount to add to angle at each step
    private double increment = 2*Math.PI/STEPS_PER_ROTATION;
    
    // Use position of mouse press to determine center of spiral
    public void onMousePress(Location point) {
        center = point;
        lastPoint = center;
        theta = increment;
        
        while( theta < 30*Math.PI) {
            newPoint = new Location( center.getX() + theta * Math.cos(theta),
                                     center.getY() + theta * Math.sin(theta)
                                     );
            new Line(lastPoint, newPoint,  canvas);
            
            theta = theta + increment;
            lastPoint = newPoint;           
        }
    }
    
    // clear drawing when mouse enters
    public void onMouseEnter(Location point){
        canvas.clear();
    }
}
