Drag and zoom with your fingers
Rotate your screen for full viewㅤ

Floids

Self-organization is a fascinating concept. For a long time, people believed that order could only be a product of rational design: be it by human or God. But in fact, self-organization is the intrinsic property of the matter itself. Scientists have discovered countless examples of emergent behavior, where complex features of a system arise from its elements following a set of rules or physical laws. We can see it everywhere: from water vapor crystallizing into snowflakes and peptide folding in a 3D protein structre to ant trails and traffic jams.

This 3D simulation is meant as a small interactive illustration of this concept. It was inspired by two naturally occurring phenomena: flashing synchronization of certain firefly species and birds flocking. This small world is populated by agents called Floids, each observing its surroundings and following a few simple rules to decide when to fire and where to fly. Populated randomly at first, they soon form synchronized groups. To spice things up, I introduced a hunter – an agent that disturbs the floids and wreaks havoc on this idyll. The interplay of the forces of order and disorder, the yin and yang, is mesmerizing.

You can tune the simulation parameters in the control panel on the right, zoom in and out with the mouse or touchscreen, and spin the world by dragging it. A short explanation of the rules is given below. The source code can be found on the project GitHub page, and discussion is on Twitter.

Firing

For over a century, the ability of certain firefly species in Asia and North America to flash in rhythmic synchrony remained a mystery. How do fireflies choose a single conductor of their forest light orchestra? Turns out they don't. Instead, each firefly fires cyclically according to its internal clock. Every time a firefly sees its neighbors firing, it slightly nudges its clock, decreasing the time difference. These slight tweaks, by individuals over time, eventually lead to full synchronization. More information on firefly algorithms can be found in this paper.

When experimenting with the algorithm implementation, I observed the best results when the fireflies nudge their clock proportionally to the sine of the phase difference with the just fired neighbors. This way, the synchronization is initially quick but slows down as the phase differences become small. You can adjust the cycle duration, nudging force, and the graphics shader parameters in the Firing control panel.

Flocking

Similarly to the amazing fireflies, birds' flocking or fish' schooling emerges from each individual observing its neighbors and following a set of simple rules. In 1986, Craig Reynolds created a simulation called Boids, where each agent (generally called boids, here floids) follows three rules describing coherence, alignment, and avoidance. These rules are illustrated in the figure below. The filled red circle is the visibility radius of a given floid (bigger for coherence and alignment), the red dotted line shows the neighbors inside the radius, the green arrows are the neighbor’s velocities (matter for alignment), and the red arrow is the resulting force. Subjected to these forces, floids change their velocity according to Newton's second law.

Coherence moves the floid towards the center of mass of its neighbors. Alignment moves the floid towards the average heading of its neighbors. Finally, avoidance moves the floid away from its closest neighbors. By playing with the corresponding coefficients in the Flocking panel, you can observe all kinds of behavior: from gas-like filling of all the available space to the formation of one or several highly organized groups.

Hunter

The emergence of self-organization is great, but it gets boring when floids bunch in a single flock and fully synchronize the clocks. To spicy things up, we can introduce a source of chaos – a hunter. It is a special agent that chases the floids within its hunting range (white circle in the figure). When chasing, it becomes brighter. If the hunter is in the visible radius of a floid, the latter panicks and flees away. It also cannot keep track of time and messes up the internal clock (confusion).

You can play with the corresponding parameters in the Hunter panel. You can decrease its aggressiveness or even disable it altogether to bring perfect harmony and peace into this little world.

Created by Dmitry E. Kravchenko