Bubbles (using JavaScript)
This activity belongs to the GeoGebra book GeoGebra Principia.
We can use vectors to modify the movement of an object based on its distance from another object, allowing, for example, collision detection. The problem is that if there are many objects (n), the number of events will be high, as it grows with the square of the number of objects: n(n–1)/2. In these cases, it's best to replace the GeoGebra scripts with faster JavaScript code, as demonstrated in this construction. It shows elastic collisions, and you can verify thee conservation of total kinetic energy at all times.
Author of the construction of GeoGebra: Rafael Losada.