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

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```