# Why wont the ball animate?

**URL:** <https://discourse.processing.org/t/why-wont-the-ball-animate/15273>\
**Category:** Beginners\
**Created:** [November 6, 2019, 8:39am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273 "2019-11-06T08:39:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![drawrs](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@drawrs](https://discourse.processing.org/u/drawrs)\
**Post date:** [November 6, 2019, 8:39am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/1 "2019-11-06T08:39:45Z")

</div>

```auto
// Where is the circle
let x, y;

function setup() {
  createCanvas(720, 400);
  // Starts in the middle

}

function draw() {
  background(200);
  ball();

}

function ball(x, y) {
  x = width / 2;
  y = height;
  // Draw a circle
  stroke(50);
  fill(100);
  ellipse(x, y, 24, 24);

  // Jiggling randomly on the horizontal axis
  x = x + random(-1, 1);
  // Moving up at a constant speed
  y = y - 10;

  // Reset to the bottom
  if (y < 0) {
    y = height;
  }
}

```

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [November 6, 2019, 8:50am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/2 "2019-11-06T08:50:34Z")

</div>

> [@drawrs](#):
>
> function ball(x, y) {  
> x = width / 2;  
> y = height;

Because you are giving it always the same value

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 6, 2019, 8:51am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/3 "2019-11-06T08:51:10Z")

</div>

-a- please format your code `</> button from menu`  
or why not use online editor

-b- i see the ball

-c- in every draw set to a fix value will not give much animation,  
try  
[https://editor.p5js.org/kll/sketches/ZqxoIW3w3](https://editor.p5js.org/kll/sketches/ZqxoIW3w3)

---

<div class="post-metadata">

**Author:** ![drawrs](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@drawrs](https://discourse.processing.org/u/drawrs)\
**Post date:** [November 6, 2019, 8:59am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/4 "2019-11-06T08:59:16Z")

</div>

how would do this without leaving the brackets empty? like  
function ball (x,y); instead of function ball ();

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 6, 2019, 9:01am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/5 "2019-11-06T09:01:13Z")

</div>

yes, you can give parameter

- in this case it would mean the animation you have to do from main loop
- but set / overwrite them again inside loop not makes sense then

---

<div class="post-metadata">

**Author:** ![drawrs](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@drawrs](https://discourse.processing.org/u/drawrs)\
**Post date:** [November 6, 2019, 9:02am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/6 "2019-11-06T09:02:29Z")

</div>

oh ok so its a waste of time tryna do an animation like that?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 6, 2019, 9:04am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/7 "2019-11-06T09:04:05Z")

</div>

? you want learn function ( with parameter ? )

please check my link again  
what you actually do is creating a local variable,  
independent from the global ‘x’,  
so it might be a idea to use different names?

---

<div class="post-metadata">

**Author:** ![drawrs](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@drawrs](https://discourse.processing.org/u/drawrs)\
**Post date:** [November 6, 2019, 9:06am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/8 "2019-11-06T09:06:48Z")

</div>

oh ok I think i get what is happening here now 🙂 thankyou

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 6, 2019, 9:11am UTC](https://discourse.processing.org/t/why-wont-the-ball-animate/15273/9 "2019-11-06T09:11:57Z")

</div>

i ask you again to repair above !original! code posting  
using `</>` and paste your code inside,  
or just make lines with  
```  
manually above and below your code
