Object Detection

This is the one my students came up with. It looks for the color where the mouse is. If the color of the mouse coordinates. This works if our target is the only object on the screen with our target color. To make this happen, we need a new variable type, color. At the beginning of your program you'll need to declare your variable:

color cpoint;

Again, cpoint is just a name and you could give it a different name and it will still work. Next we need to read the color under our mouse pointer.

cpoint = get (mouseX, mouseY);

Now the RGB color value of the pixel at our mouse pointer is stored in the variable cpoint. Then we just ask the question:

  if (cpoint==color(0,255,0))

If true then the user hit the target, if false then they missed. I really like this method of object detection because it is really simple and it doesn't matter what shape the object is. You could also easily reverse it and ask if you clicked on the background color instead. This way you could have a multicolored object and still have no problems.