Why wont the ball animate?

// 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;
  }
}
1 Like

Because you are giving it always the same value

2 Likes

-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

1 Like

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

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

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

? 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?

1 Like

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

1 Like

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