Learn creative coding writing simple programs

62. A screen full of bouncing circles

In episode 15 we created a program that displayed one circle bouncing on the four borders of the screen. We now take that program and modify it so it can show any number of bouncing circles.
The original program used four global variables. Two for storing the horizontal and vertical position of the circle, and two for storing the direction in which the circle is moving.
Those four variables must now be arrays. The arrays will hold the horizontal position of each circle, the vertical position, the horizontal motion amount, and the verticla motion amount.
Because there are several circles now, we have to use a while loop to go through each circle in the array to draw it and move it to a new position.
We could have created several circles when the program starts, but instead we begin with no circles, and let the user click the screen to add new ones.

Tags: array, bouncing, circles, ball

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus