# Check x&y when they are the correct color

**URL:** <https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830>\
**Category:** Coding Questions\
**Created:** [June 21, 2021, 8:27am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830 "2021-06-21T08:27:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [June 21, 2021, 8:27am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830/1 "2021-06-21T08:27:35Z")

</div>

this code prints the word same if the color on coordinates x,y is the same as one of the team colors. how do i check what x and y are at the moment that they are one of the team colors and place a circle there.

```auto
int x=1;
int y=1;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
color ring1 = color(undefined team rgb value);
color ring2 = color(undefined team rgb value);
color ring3 = color(undefined team rgb value);

Robot robot;
void setup() {
  size(1500, 3000);
  try {
    robot = new Robot();
  } 
  catch (Exception e) {
    println(e.getMessage());
  }
}
void draw() {
  background(0);
  Rectangle r = new Rectangle(y, x, width, height);
  BufferedImage img1 = robot.createScreenCapture(r);
  PImage img2 = new PImage(img1);
  image(img2, 0, 0);
  get(x,y);
  x++;
  y++;
  color colorFromGet = get(x,y);

if ( colorFromGet == ring1 ){
  print("same");}
if ( colorFromGet == ring2 ){
  print("same");} 
if ( colorFromGet == ring3 ){
  print("same");} 
     
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [June 21, 2021, 8:36am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830/2 "2021-06-21T08:36:22Z")

</div>

You may want to add a print statement to tell you what the values of `x` and `y` are:

```auto
print( "x=" + x + " y=" + y );

```

You could put this after a print statement that prints “same”, or perhaps right after you get the color.

Also, realize that the points you are checking are (2,2), (3,3), (4,4), (5,5)… etc. This may not be what you want.

Also, the line `get(x,y)` on its own isn’t doing anything and can be removed.

Also, you might want to put the `x++; y++;` lines at the end of draw.

Also, check that the Rectangle you are making has the right arguments. Right now, it’s got `y` first and `x` second. Perhaps that’s wrong?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 21, 2021, 10:41am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830/3 "2021-06-21T10:41:29Z")

</div>

Hello @MoonAlien822,

I looks like you are continuing this topic:

> [@ScreenCapture with Robot Class (code not working)](https://discourse.processing.org/t/screencapture-with-robot-class-code-not-working/30551):
>
> i have an irl card that has the rgb value:11, 96, 133. i made a code that, scans the screen for that color so when you have the app camera open it says kaart gevonden (found card in dutch) on the screen. but it is not working, any ideas why? here is the code int x=1; int y=1; import java.awt.Robot; import java.awt.image.BufferedImage; import java.awt.Rectangle; color pas = color(11, 96, 133); Robot robot; void setup() { size(1500, 3000); try { robot = new Robot(); } catch (Ex…

`:)`

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [June 21, 2021, 10:55am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830/4 "2021-06-21T10:55:15Z")

</div>

i understand the confusion but its not the same thing actually, i used part of that code to make this but its a new program.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 21, 2021, 11:00am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830/5 "2021-06-21T11:00:06Z")

</div>

> [@MoonAlien822](#):
>
> `get(x,y);`

This is in all your code examples.

What is this doing in your code?

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [June 21, 2021, 11:00am UTC](https://discourse.processing.org/t/check-x-y-when-they-are-the-correct-color/30830/6 "2021-06-21T11:00:57Z")

</div>

it was part of my original code before someone suggested another way and i forgot to delete it
