
// InteractiveLines.java
// Robert Sedgewick and Kevin Wayne
// Slightly reformatted by Andrew Davison, Nov. 2022

/* Interactively draw lines by treating the mouse press and
   release as the two end points of a line.

   Usage:
     > compile InteractiveLines.java
     > run InteractiveLines
*/


public class InteractiveLines
{

  public static void main(String[] args)
  {
    while (true) {
      // wait for the mousebutton to be pressed
      while (!StdDraw.isMousePressed()) {
        // do nothing
      }

      // capture the mouse's location now that it has been pressed
      double x1 = StdDraw.mouseX();
      double y1 = StdDraw.mouseY();

      // wait for the button to be released
      while (StdDraw.isMousePressed()) {
        // do nothing
      }

      // capture the mouse's location now that it has been released
      double x2 = StdDraw.mouseX();
      double y2 = StdDraw.mouseY();

      // draw a line between the two coordinates
      StdDraw.line(x1, y1, x2, y2);
    }
  } /* main */


} // end of InteractiveLines class
