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

**URL:** https://discourse.processing.org/t/how-to-set-an-area-of-pixels-in-an-if-statement/41006
**Category:** Coding Questions
**Created:** [February 22, 2023, 7:10pm UTC](https://discourse.processing.org/t/how-to-set-an-area-of-pixels-in-an-if-statement/41006 "2023-02-22T19:10:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MaxU89](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@MaxU89](https://discourse.processing.org/u/MaxU89)
#### Post date: [February 22, 2023, 7:10pm UTC](https://discourse.processing.org/t/how-to-set-an-area-of-pixels-in-an-if-statement/41006/1 "2023-02-22T19:10:57Z")

</div>

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.

```auto
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 🙂

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 22, 2023, 9:11pm UTC](https://discourse.processing.org/t/how-to-set-an-area-of-pixels-in-an-if-statement/41006/2 "2023-02-22T21:11:15Z")

</div>

> [@MaxU89](#):
>
> `if(xpos == //area from pixels (0,5) to (15,5)){`

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

Additionally you can check whether ypos == 5

---

<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: [February 22, 2023, 9:44pm UTC](https://discourse.processing.org/t/how-to-set-an-area-of-pixels-in-an-if-statement/41006/3 "2023-02-22T21:44:48Z")

</div>

Hello @MaxU89,

Take a look at this example:

> **[Mouse Functions / Examples](https://processing.org/examples/mousefunctions.html)**
>
> Click on the box and drag it across the screen.

And also examples that come with Processing:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/a/cab6617bd2a00c20c096a446294600a98cfc73fe.png)

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

`:)`

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 23, 2023, 8:45am UTC](https://discourse.processing.org/t/how-to-set-an-area-of-pixels-in-an-if-statement/41006/4 "2023-02-23T08:45:15Z")

</div>

Yes

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

```
