# Problem with missing ball (foo)

**URL:** https://discourse.processing.org/t/problem-with-missing-ball-foo/19276
**Category:** Coding Questions
**Created:** [April 1, 2020, 5:08am UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276 "2020-04-01T05:08:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)
#### Post date: [April 1, 2020, 5:08am UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/1 "2020-04-01T05:08:43Z")

</div>

I have a sketch (see below) where a ball moves. When I tested it, everything seems to work but now the ball has gone off the screen to the right somewhere. How do I get my ball back?

```auto
Ball[] balls = new Ball[1];

void setup() {
    size(400, 400);
  
balls[0] = new Ball(40, 127); // diameter and colour
}

void draw() {
    background(255);
  for (int i = 0; i < balls.length; i++) {
    balls[i].display();
    balls[i].move();

  }

  
}

class Ball {
  float dia;
  float x;
  float y; 
  float col;
  float xspeed;
  float yspeed;
  float r;

  Ball (float tempD, float tempC) {
    x = random(0+dia, width-dia);
    y = random(0+dia, height-dia);
    dia = tempD;
    col = tempC;
    r = dia/2;
    xspeed = 1.0;
    yspeed = 0.0;
  }

  void display() {
    noStroke();
    fill(col);
    ellipse(x, y, dia, dia);
  }

  void move() {

    x = x + xspeed;
    y = y + yspeed;
  }

}

```

---

<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 1, 2020, 2:02pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/2 "2020-04-01T14:02:32Z")

</div>

You can check for the screen border and then reverse the direction of the movement

see [https://www.processing.org/examples/bounce.html](https://www.processing.org/examples/bounce.html)

Remark

color is not really float. Either use int or even color.

see [https://www.processing.org/reference/color\_datatype.html](https://www.processing.org/reference/color_datatype.html)

---

<div class="post-metadata">

### Author: ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)
#### Post date: [April 1, 2020, 4:39pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/3 "2020-04-01T16:39:17Z")

</div>

Thanks. This was my very poor attempt to make an April’s fool joke. I liked the idea that someone could be foolish enough to try to get their ball back. Looks like the joke is on me!

Noted about color not being a float.

---

<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 1, 2020, 4:58pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/4 "2020-04-01T16:58:18Z")

</div>

Hey! How do you say?

You sent me in the April! 😉

I like it!!!

I was about to write restart your Sketch!

To get your ball back.

I am the April fool… 😉

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [April 1, 2020, 5:52pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/5 "2020-04-01T17:52:49Z")

</div>

I almost answered this post too!  
🙂

---

<div class="post-metadata">

### Author: ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)
#### Post date: [April 1, 2020, 6:20pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/6 "2020-04-01T18:20:17Z")

</div>

Next year @debxyz 😉

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [April 1, 2020, 6:22pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/7 "2020-04-01T18:22:42Z")

</div>

LOL  
I’ll mark my calendar.  
😀

---

<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 1, 2020, 8:01pm UTC](https://discourse.processing.org/t/problem-with-missing-ball-foo/19276/8 "2020-04-01T20:01:25Z")

</div>

😉

Warm regards

Chrisir
