r/processing • • Jul 21 '22

Some quick questions

So I have this code and I want the circles to drop at different times but at the same speed, I want the circles to loop back to the top after they disappear from the bottom, and I also want to know how to change the speed of the circles... I know that's quite a bit but any sort of help is appreciated :)

0 Upvotes

4 comments sorted by

3

u/Storyxx Jul 21 '22

Your Code in ab already looks very solid! The only thing to say there is that you could take a look at ArrayLists. They are far more powerful than arrays.

For the different falling times you could use a delay variable that tells the ball when to start their "decend, display, bottom"-cycle. To achive this the variable can be compared against frameCount in your ab file.

You almost already have the code for looping back around. But you are testing for 25 and positioning it back to 25 in that case. With the help of the global variables width and height you are able to test against the window size and then move the ball back to y-position 0.

The speed is also very simple. Instead of incrementing ypos in line 11 in Ball you can add a speed value to it, like this: ypos += speed;

Hope that helped :)

1

u/ali121906 Jul 21 '22

Thanks so much! This was very helpful but I'm not sure where to put the delay... because it seems as though wherever I put it, it delays all of the circles (I want them to fall one or two at a time) or it just makes the program not work...

2

u/AGardenerCoding Jul 21 '22 edited Jul 21 '22

I think perhaps you misunderstood u/Storyxx 's mention of 'delay' as being the function delay(). If you follow the link to the Processing reference, you'll see that

"The screen only updates when the end of draw() is reached, so delay() cannot be used to slow down drawing. For instance, you cannot use delay() to control the timing of an animation."

I believe what was intended was that you use a variable named 'delay', or something like that, to trigger when a Ball should begin its descent "[which] can be compared against frameCount in your ab file." In other words, there is a system-provided variable in a sketch called 'frameCount' which increments with each frame. If you have a variable in your Ball class called, let's say, 'frameToStartOn' that is assigned a frame number on which to start, then comparing the 'frameCount' to 'frameToStartOn' for each particular ball will let that ball begin its descent in that frame.

2

u/ali121906 Jul 21 '22

Oh okay, thanks a lot!