How to set an area of pixels in an if statement?

Hello. I need help with setting an area of pixels in an if statement. I am still kind of new here so please don’t pay attention to any wrong terminology I use.

In an if statement I need to use not only the one position as an argument, but an area of pixels and I don’t know how to do it. I will try to use the example of what I have in my mind below and use // where I don’t understand how to do the thing.

if(xpos == //area from pixels (0,5) to (15,5)){
xspeed*=-1
}

This is just a random example but I am having troubles of setting that area in a code, so I would appreciate some help if you have time :slight_smile:

1 Like

if(xpos >= 0 && xpos <= 15){

Additionally you can check whether ypos == 5

Hello @MaxU89,

Take a look at this example:

And also examples that come with Processing:

Do a search for Logical Operators on the Processing website if you are not familiar with these.

:)

1 Like

Yes

 // Test if the cursor is over the box 
  if (mouseX > bx-boxSize && 
     mouseX < bx+boxSize && 
      mouseY > by-boxSize && 
      mouseY < by+boxSize) {
    overBox = true;