title: detect a color within an area near my cursor
body: <p>I want to be able to detect a color within a square, or circular area (whichever is easier) NEAR my mouse pointer. My example below works but the mouse has to be directly on the color to detect it.
  In my example, I simply used the MS Paint standard red, but I am looking to detect specific colors in a gradient area when my cursor is let's say 100 pixels above, below, to the left or right of the target color, it will detect it. I think I need to loop within a range of pixels around my cursor's current location, but I can't seem to get it.
  Adding to my code would really help as I've already spent too much time on this site and others trying out ideas.</p>
  
  <h2>Thanks!</h2>
  
  <pre><code>import java.awt.Color;
  
  import java.awt.MouseInfo;
  
  import java.awt.Point;
  
  import java.awt.PointerInfo;
  
  import java.awt.Robot;
  
  public class DetectRed {
  
  public static void main(String[] args) throws Exception {
  
  PointerInfo pointer;
  
  pointer = MouseInfo.getPointerInfo();
  
  Point coord = pointer.getLocation();
  
          Robot robot = new Robot();
          robot.delay(2000);
  
          while(true)
          {
              //print coords
              coord = MouseInfo.getPointerInfo().getLocation();
              System.out.println("Coord = " + coord);
  
              //print colors
              Color color = robot.getPixelColor((int)coord.getX(), (int)coord.getY());
              System.out.println("Color = " + color);
  
              if(color.getRed() == 237 &amp;&amp; color.getGreen() == 28 &amp;&amp; color.getBlue() == 36)
              {
                  System.out.println("RED(237,28,36) FOUND");
              }
  
              System.out.println(); //blank line separator
  
              robot.delay(500); //use shorter delay to scan faster...
          }
      }
  }
  </code></pre>