
// MouseFollower.java
// Jeff Traer-Bernstein
// Robert Sedgewick and Kevin Wayne
// Slightly reformatted by Andrew Davison, Nov. 2022

/* Draw a blue filled circle wherever the mouse is, in 
   cyan (light blue) if the mouse is pressed.

   Usage:
     > compile MouseFollower.java
     > run MouseFollower
*/


public class MouseFollower
{
  public static void main(String[] args)
  {
    StdDraw.enableDoubleBuffering();
    while (true) {
      // mouse click
      if (StdDraw.isMousePressed()) 
        StdDraw.setPenColor(StdDraw.CYAN);
      else    
        StdDraw.setPenColor(StdDraw.BLUE);

      // mouse location
      StdDraw.clear();
      double x = StdDraw.mouseX();
      double y = StdDraw.mouseY();
      StdDraw.filledCircle(x, y, 0.05);
      StdDraw.show();
      StdDraw.pause(10);
    }
  } /* main */

} // end of MouseFollower class
