
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 {
  private static final double THETA_STEP = 0.2;

  // center of current spiral
  private Location center;

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

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

  // used in onMouseDrag
  private Location newPoint;

  // Use position of mouse press to determine center of 
  // spiral
  public void onMousePress(Location point) {
    center = point;
    lastPoint = center;
    theta = 0.0;
  }

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

    new Line(lastPoint, newPoint, canvas);
    lastPoint = newPoint;
    
    theta = theta + THETA_STEP;

  }
}

