Sitemap
Dan Ionescu

Dan Ionescu

Computer engineer, living in Paris (France). Interested in computer science, math, natural language processing, artificial intelligence and more

3 min readOct 25, 2026

--

Fireflies’ Synchronization in Rust

One more advantage of LLMs that can code for us: experiments that I had wanted to try for a long time, but was too lazy to implement, can now be completed in about an hour of vibe coding with Claude.

Inspired by this wonderful book, I wanted to explore the emergence of synchronization in large systems.

The first example is the synchronization of fireflies. Observed in nature, it looks almost magical, yet it can be explained by a remarkably simple mathematical model.

Each firefly is represented as an oscillator. When its internal state reaches a threshold, it flashes. Imagine that each firefly has an internal value ranging from 0 to 100. At every time step, this value increases. When it reaches 100, the firefly flashes and resets its state back to 0.

The key mechanism is that whenever a firefly flashes, it increases the internal state of all its neighboring fireflies by 10. Despite the simplicity of this rule, a population of one million fireflies reaches synchronization surprisingly quickly.

Get Dan Ionescu’s stories in your inbox

Join Medium for free to get updates from this writer.

The most important parameter is the number of connections between fireflies. Around 40 connections, a clear phase transition appears. By 60 connections, the entire system becomes fully synchronized.

Press enter or click to view image in full size
at 40 connections two synchronized groups emerge
Press enter or click to view image in full size
at 41 connections 99.7% of the fireflies are synchronized
Press enter or click to view image in full size

What I find fascinating is that no firefly knows anything about the global state of the system. There is no leader, no centralized control, and no explicit coordination. Each firefly follows a simple local rule, yet large-scale order emerges spontaneously.

This is one of the most beautiful ideas in complex systems: collective intelligence can arise from the interaction of many simple agents. Fireflies are just one example. Similar mechanisms appear in biology, social systems, neural networks, financial markets, and even distributed computing.

And thanks to modern LLMs, exploring these ideas has become dramatically easier. What once required days of programming can now be prototyped in an afternoon, leaving more time to focus on the interesting part: understanding the patterns that emerge.

The code is Rust with the GPUI graphical library. It is of course open-source and can be found here.

--

--

Dan Ionescu
Dan Ionescu

Written by Dan Ionescu

Computer engineer, living in Paris (France). Interested in computer science, math, natural language processing, artificial intelligence and more