I want to create a function that can generate two balls that rise at different speeds. I used the parameters of the speed in which it rises called change
and another parameter of its x coordinates called x
, so that they don't originate from the same place. This is a code in processing, so the ellipse, size, fill, stroke, setup and draw functions are built in.
If I call the function, it works, and the ball moves according to the speed that I set. However, if I call the risingball()
function twice, two balls are generated, but both move at the speed that is called with the second executed function. In this case, two balls were generated at x coordinates 150 and 450. The first ball was supposed to move at speed y-10
, and the second ball at speed y-5
, but both are moving at y-5
.
Therefore, they move, but the whole purpose of the code which is making it change doesn't work.
void setup(){
size(600,600);
}
float y = 600;
void risingball(float change, float x){
noStroke();
fill(30,0,30);
y = y-change;
ellipse(x,y, 50,50);
}
void draw(){
background(255);
risingball(10, 450);
risingball(5, 250);
}