Firefly Field

It is night, and groups of fireflies fly over the field. The fireflies that see each other come to flash together. Move the lantern: the fireflies near it follow it. Bring the groups together, until all the fireflies flash at one moment, three times in a row, before the dawn.

Connecting
A flash Fireflies Fireflies with a slow clock The light of the lantern: the fireflies in it follow it

Bring the groups together with the lantern.

Use the arrow keys or W, A, S and D to move the lantern, or click or touch a point of the field: the lantern goes there. The fireflies in its light follow it. Hold Shift (or Fast) to move the lantern faster than the fireflies: it leaves them where they are.

A signal in the data

The data of a boid is what its neighbors see. The data of a firefly has the time of its last flash. A firefly reads the data of its neighbors: no message goes from firefly to firefly.

A sync that no firefly makes

Each firefly has a clock. When it sees a neighbor flash, it moves its own clock a little forward, and more when its own flash is near. That is all. The flashes of a group come together from these small changes.

The groups of the field

The number of groups comes from boids:flocks/2: the fireflies that see each other, from neighbor to neighbor. Two groups flash together only when they are one group.

Rules that are functions

The lantern is a rule of each firefly: a function that reads the place of the lantern. The wind is the rule flow of the library, with a field that is a function.

Read the code of the game.