# Circle grows on left side of screen, not right

**URL:** <https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243>\
**Category:** Coding Questions\
**Created:** [January 6, 2019, 2:48am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243 "2019-01-06T02:48:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neutron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neutron/32/3122_2.png) [@Neutron](https://discourse.processing.org/u/Neutron)\
**Post date:** [January 6, 2019, 2:48am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/1 "2019-01-06T02:48:35Z")

</div>

Hello, I’m new to programming and I was just playing around with processing.

I created a program where a circle follows your mouse and grows if it touches the edges of the screen. For some reason it works only when the circle is on the left side of the screen, but not the right.

Can someone help me out. Here is the code:

```auto
int size = 20;

void setup(){
  size(800, 800, P2D);
}

void draw(){
  background(0);
  fill(200, 120, 60);
  ellipse(mouseX, mouseY, size, size);
  if(mouseX == width || mouseX == 0){
    size++;
  }
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [January 6, 2019, 3:10am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/2 "2019-01-06T03:10:33Z")

</div>

Have you tried debugging your code? Here’s a guide that might help you:

> **[Debugging Processing](https://happycoding.io/tutorials/processing/debugging)**
>
> How to fix errors in your code.

For example, if I were you I would print out the value of the `mouseX` variable. I think you’ll find that it doesn’t quite get to the exact value of the `width` variable.

This is because if you have a window that’s 800 pixels wide, then the rightmost pixel is 799. This is because the leftmost pixel is 0 instead of 1.

Also, I think you’ll find that if you move the mouse very fast, the value of `mouseX` can move by several pixels each frame and the value will not be exactly `0` or `width - 1` anyway. You might want to check for a distance instead of an exact value.

Here’s another guide that might come in handy:

> **[Processing Collision Detection](https://happycoding.io/tutorials/processing/collision-detection)**
>
> Learn how to trigger an action when objects overlap in Processing!

---

<div class="post-metadata">

**Author:** ![Neutron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neutron/32/3122_2.png) [@Neutron](https://discourse.processing.org/u/Neutron)\
**Post date:** [January 6, 2019, 3:52am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/3 "2019-01-06T03:52:14Z")

</div>

I understand now, I got it working.

Thanks!

---

<div class="post-metadata">

**Author:** ![HartzaQ](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hartzaq/32/3106_2.png) [@HartzaQ](https://discourse.processing.org/u/HartzaQ)\
**Post date:** [January 6, 2019, 8:07am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/4 "2019-01-06T08:07:19Z")

</div>

Screen width is 800. Coordinates starts from 0 on the left side, so coordinate of the right side is 799. This applies to arrays or any other indexing starting from zero. You need to decrease one from the end to get the last index or a coordinate in this case.

Try this instead:

```auto
if(mouseX == width-1 || mouseX == 0){

```

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [January 6, 2019, 9:00am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/5 "2019-01-06T09:00:44Z")

</div>

Note that this does not solve the other problem I pointed out.

---

<div class="post-metadata">

**Author:** ![HartzaQ](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hartzaq/32/3106_2.png) [@HartzaQ](https://discourse.processing.org/u/HartzaQ)\
**Post date:** [January 6, 2019, 3:09pm UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/6 "2019-01-06T15:09:26Z")

</div>

True. I should have read your comment properly.

---

<div class="post-metadata">

**Author:** ![Neutron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neutron/32/3122_2.png) [@Neutron](https://discourse.processing.org/u/Neutron)\
**Post date:** [January 7, 2019, 12:25am UTC](https://discourse.processing.org/t/circle-grows-on-left-side-of-screen-not-right/7243/7 "2019-01-07T00:25:43Z")

</div>

It’s going to be running on full screen so mouse speed doesn’t really matter.

Thanks for the help guys
