# Why does my bubble not stop at the top?

**URL:** <https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232>\
**Category:** Beginners\
**Created:** [April 13, 2019, 10:21am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232 "2019-04-13T10:21:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 13, 2019, 10:21am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/1 "2019-04-13T10:21:00Z")

</div>

Hi, if anyone could help me figure out why my bubble does not stop once y is greater than the height that would be great 🙂

Thanks in advance.

```auto
Bubble b;

void setup() {
  size(600, 400);
  b = new Bubble();
}

void draw() {
  background(0);
  b.display();
  b.ascend();
  b.top();
}

class Bubble {

  float x;
  float y;
  float d;

  Bubble() {
    x = width/2;
    y = height;
    d = 100;
  }

  void display() {
    fill(255);
    ellipse(x, y, d, d);
  }

  void ascend() {
    y = y - 5;
  }

  void top() {
    if (y > height) {
      y = height;
    }
  }
}

```

---

<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:** [April 13, 2019, 10:29am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/2 "2019-04-13T10:29:40Z")

</div>

look at top()

the error is in this function

the top of the screen is **0** , not height

check your if-clause

Chrisir

---

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 13, 2019, 10:30am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/3 "2019-04-13T10:30:33Z")

</div>

Thanks so much! Now I feel stupid haha

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [April 13, 2019, 10:32am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/4 "2019-04-13T10:32:22Z")

</div>

Hi,

Have a look a this link:  
[https://processing.org/tutorials/drawing/](https://processing.org/tutorials/drawing/)

It explains the coordinate system of processing pretty well =)

---

<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:** [April 13, 2019, 10:33am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/5 "2019-04-13T10:33:38Z")

</div>

also the radius is 50, so it looks better when we wait until the ball completely left the screen

and also when it reappears, it reappears below the screen and slowly ascends

```auto
   if (y < -53) {
      y = height+59;
    }

```

---

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 13, 2019, 10:34am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/6 "2019-04-13T10:34:02Z")

</div>

I understand it, I guess I just don’t know it very well haha. Hopefully it will come with time 🙂

---

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 13, 2019, 10:42am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/7 "2019-04-13T10:42:17Z")

</div>

Okay cool, and the below would also be correct I’m pretty sure? 🙂

```auto
    if (y < -50) {
      y = height+50;
    }

```

---

<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:** [April 13, 2019, 10:55am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/8 "2019-04-13T10:55:34Z")

</div>

I know what you mean, 50

I think it looks slightly better with 53

Nevermind

---

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 13, 2019, 10:57am UTC](https://discourse.processing.org/t/why-does-my-bubble-not-stop-at-the-top/10232/9 "2019-04-13T10:57:45Z")

</div>

I get you now, thanks!
