Consolidating Molecools Demo
The 'Molecool' class has been an important player in many of our simulations. It is a software 'factory' that creates circles that bounce around in the canvas. The 'cools' can interact, collide, change color, go dormant, etc.
This movie demonstrates several behaviors:
- When 'cools' are created, the driver code checks to see if they are 'too close' to previous cools. When possible, they are positioned so as to not overlap.
- These cools are created with the same diameter, but with random hues in [0, 360].
- When the movie starts, the colors are muted because the 'cools' are 'dormant' until a left-mouse-click awakes them. Then, their colors become vibrant and they start moving at a constant speed in a random direction.
- Because there are so many, the 'cools' are very crowded, and if you look closely at the opening scene, some do indeed overlap: the driver software tries to avoid this but after so many passes, the placement loop throws up its hands (we don't want it going infinite!) and just places them even if they lie on top of others.
- They do not collide, but the distance between them is monitored. With each 'cool' checking all other 'cool' locations, the movements are very slow at first: there's a lot of work going on!
- When a 'cool' is 'close enough' to another 'cool' with a similar hue (within a given 'delta'), the smaller is removed and the remaining one grows by a given percentage and takes on the average of the two similar but different hues.
- As a result, the crowd starts thinning and we start seeing larger 'cools' in the canvas, and because there are fewer to compare, they start moving faster.
- Eventually, the remaining cools will consolidate if their hues are different enough and the 'cool' population normalizes with representative hues from the color wheel.
Explore the source code for this Python3 app.
Last update: 11/03/19