The onset of Chaos. Bouncing balls.

Up a level : Fractals and Chaos
Previous page : A family of fractals , the mod-curves
Next page : On the Bouncing balls program

The program on this page demonstrates the onset of chaos. It demonstrates the famous butterfly effect, where a small difference in the initial conditions may cause large changes after not all too long time.

Several balls are dropped over a semi-circular bowl. The balls are initially separated by a selectable horizontal distance. The balls bounce with total elastic bounces from the bowl and from the walls. Since the slope of the bowl is different at different points along the bowl, balls with even the slightest offset will bounce in slightly different directions. As you will see when trying it, even the smallest offset will lead to wildly different paths of the balls. There are 256 balls, all with different colours.

The buttons

The program can be controlled with the mouse, touch or keys.

  • Wait/Start/Pause/Restart: (Esc or space ) Will start the program, pause it (and the timer stops too), and restart it. It will show the text Wait and be disabled for a second or so in the beginning. This is during the time the program figures out the frame rate.
  • Reset: (R) This will reset the positions to the initial positions, reset all variables and stop the program.
  • Step: (S)This will advance the balls corresponding to a 4 ms actual runtime.
  • Save: (D) Saves the Distance data to the clipboard. If you paste this into an Excel file it will be placed in a column. More on this further down the page.
  • Centre/Left: (C) Toggles between centring the balls above the centre line of the bowl and placing them at the starting point to the left.
  • Best: (B) This toggles between a couple of interesting cases. In the first it allows you to examine some very stable paths. Some, or all, of the balls will move close to the shown parabolic path. You can select the endpoint by dragging the vertical line. More on this further down the page. The second case is another two-bounce case, where you may also drag the grey starting line. The third case is when the balls start very close to the edge, causing them to get into chaos in a surprisingly short time
  • Images/Drawn: (I) Select if the balls are drawn circular disks or images.
  • Trace On/Trace 1/Trace2/Trace Off  (T) Shows a trace after ball 0 or shows the path ball 0 will take.

Below the buttons, you can select the initial horizontal separation of the balls. This is in parts of the canvas. . The smallest separation is 10-17 of the canvas width.  Smaller than this would surpass the 64-bit resolution of the numbers. Even at this separation, some balls will have the same positions. The first setting spreads the balls evenly across the bowl.

A distance of 10-16 of the screen width would, on my old computer, with a screen which is 27 cm wide distance of 0.27 ⋅10-162=2.7⋅10-17  m,  or about 1/30th of the size of a  proton.

Placing the balls

The balls have an initial position, but you may select another position by clicking on a place of your choice. If you have a touch screen you may also touch the screen at the point where you want the balls to start. You can then drag to get set the velocity.

The separation graph

Beneath the graph, there is a smaller graph presenting the mean separation of initially adjacent balls. It plots time vs the log of the mean separation. As you will see it is somewhat linear, indicating that the separation grows exponentially over time. I have not added any scales to the graph since it is mainly used to give some general feeling for the change in distances. If you want to analyse it further, you can press the Save button. The separation is calculated as the average of the distances between balls 0 and 1, then 1 and 2, and so on.

The time at which the balls are separated by a rather arbitrary value calculated from the height and width of the possible positions is shown as the time of Chaos. The save button saves tab-separated columns of data. The sample time (the distance data sampled every 10th ms), the average distance between successive balls at the corresponding time, the times when ball 0 will bounce off of something, and the corresponding times. This data can directly be pasted into an Excel file for further analysis.

The “best” graph

You can move around the graph by dragging the vertical grey line. The parabola shows the possible stable path. It has the property of being perpendicular to the semi-circular bowl at the points where the balls would bounce, and, with the right speed, it will just bounce right back.

If you select the separation 10^0=1 pixel, then Best and Start you will see two stable paths emerge. One, corresponds to the blue set of balls, moving as indicated by the initial parabola, and one, corresponds to the reddish balls,  by repeated bounces through the centre of the bowl. We have in this case two possible so-called attractors.

You can do something similar in the second case. For the third case, select a very small distance between the balls.

The loops

The main program consists of a loop in sync with the screen updates. The speeds of the balls are rescaled to not depend on the refresh rate  of the screen.

The position of a ball is not calculated using some Euler step method or something similar. Instead, it is calculated using the equation of the parabolic path of the ball, The possible collisions with the walls are calculated, and if it is above the bowl, that collision is used. It is found by simply finding the intersection of the parabolic trajectory of the ball and respective wall If the collision is below the bowl, we need to find the actual collision with the bowl.  This is calculated by solving the quartic (fourth degree) equation one can get by the system of equations given by the time-dependent equation of the parabolic trajectory of a ball and the equation of the bowl. The first positive solution is then used. The function for the direction of the ball after the collision was found using some fairly straightforward vector algebra.  More on this here.

The time for the next collision is calculated directly at a given collision. This is then used to check when time has advanced enough for the next step.

The balls as images are sprites taken from a larger image, balls.pgn. I wrote another small program to draw the balls, using radialGradiens -among other things.

Up a level : Fractals and Chaos
Previous page : A family of fractals , the mod-curves
Next page : On the Bouncing balls programLast modified: Dec 28, 2023 @ 21:39