The fruit fly escape circuit, and how the game's fly dodges
Reach for a fly and it is gone before your hand arrives. Fruit fly eyes carry neurons that detect approaching objects, and their signal runs through one thick neuron straight to the motor neuron that kicks the middle legs. The fly in this game runs that pathway, extracted from public connectome data, inside your browser.
A reduced model built from part of the real fruit fly nervous system (the escape circuit and a few more), extracted from connectome data. It is far smaller than the real brain (about 139,000 neurons), and the links from enemy position to visual input and from neural output to movement are our own design choices for the game.
Neurons that see things coming
When something heads straight at you, its image on the eye grows faster and faster. That is looming. The fly visual system has neuron types tuned to it, most famously LPLC2 and LC4.
LPLC2 was reported to respond selectively to motion spreading outward in all directions (Klapoetke et al. 2017, Nature). Ache et al. 2019 (Current Biology) reported that LPLC2 mostly carries the object's angular size, LC4 its expansion speed, and that both converge on the Giant Fiber.
The hemibrain data we use lists 85 LPLC2 and 71 LC4 neurons. The game uses every one of them as an input.
The Giant Fiber and the jump
The Giant Fiber (descending neuron DNp01) is a thick neuron that runs from the brain down into the ventral nerve cord. One spike drives the motor neuron that extends the middle legs (TTMn) and launches the body.
von Reyn et al. 2014 (Nature Neuroscience) reported that whether and when the Giant Fiber spikes decides between a short, fast takeoff and a longer, stable one. Card and Dickinson 2008 (Current Biology) reported that flies adjust their posture before takeoff to jump away from the threat.
In the MANC data we use, the Giant Fiber makes 146 synapses onto the TTMn on the right side and 135 on the left. That is a heavy link for one neuron onto one motor neuron.
What the game extracts
Brain side, from hemibrain v1.2: 156 input neurons (LPLC2, LC4), 9 descending neurons (Giant Fiber, DNp02, DNp03, DNp04, DNp05, DNp06, DNp11, DNa01, DNa02), and 121 intermediate neurons that get at least 10 synapses from the inputs and give at least 10 to the descending set. That is 286 per brain side.
Nerve cord side, from MANC v1.0: the 9 descending neurons with the same names, plus the 120 neurons that receive the most synapses from them (at least 50). TTMn is among them.
Together: 406 per side, 812 neurons, 11,443 connections, 204,286 synapses. Only connections of 3 or more synapses are kept. The extraction script and its thresholds are in the repository.
How the neurons run
Each neuron is leaky integrate-and-fire. Input pushes the membrane potential up, crossing threshold makes it spike and reset. Values like -52mV rest, -45mV threshold, 20ms membrane time constant and 0.275mV per synapse come straight from the public model of Shiu et al. 2024 (Nature).
The model steps in 0.5ms ticks, 40 ticks per 20ms game step, on a fixed clock that is separate from the 60fps drawing.
Signs on the nerve cord side come from the dataset's predicted transmitters (acetylcholine excitatory, GABA and glutamate inhibitory). The public hemibrain file has no transmitter column, so brain-side links are all excitatory. Left that way, intermediate neurons kept exciting each other and never shut off after the stimulus ended, so on the brain side we kept only the forward links from inputs toward descending neurons.
The mapping between game and neurons
None of the rows below come from the data. We chose them to make a game.
| How fast an enemy or swatter grows in view | Firing rate of LPLC2 and LC4 inputs (up to 200Hz) |
| Which direction each input neuron sees | Not in the data. Spread evenly over half the visual field by ID order |
| Left brain | hemibrain is mostly the right side, so we mirror it |
| TTMn spike | Escape jump, away from the inputs that fired most recently |
| Left/right difference of 8 descending neurons | Turn away from the busier side |
| Sum of descending activity | Walk up to 1.8x faster |
| Final movement | 60% neural output + 40% baseline (move away from close enemies, slow wander) |
Where it differs from a real fly
A real fruit fly brain has about 139,000 neurons (Dorkenwald et al. 2024, Nature). This game carries a narrow escape pathway only. Nothing about food, mates or where to go.
Weapons follow game rules and have nothing to do with the circuit. Jump distance and the pause before the next jump are game rules too.
So we do not claim you are watching a real fly brain steer. What we can claim is narrower: whether the fly jumps when a swatter comes down is decided by neurons wired with real synapse counts.
What the circuit does in a run
On launch day we ran the same game 40 times per setting with no human. With 60% neural share and a sensible weapon-picking rule, the median run lasted 4:45 and 20% of runs reached 6 minutes.
Same setup with the jump switched off: the median dropped to 2:19 and no run reached 6 minutes. Almost all swatter dodges are that jump.
Picking weapons at random gave a median of 3:34. The circuit moves the fly, but your picks decide the run.
Data credits
The neural model uses neuron IDs and synapse counts extracted from the two public datasets below. Both are released under CC BY 4.0.
- hemibrain v1.2 (Janelia FlyEM). Scheffer LK, Xu CS, et al. (2020) A connectome and analysis of the adult Drosophila central brain. eLife 9:e57443. doi:10.7554/eLife.57443. CC BY 4.0
- MANC v1.0 (Janelia FlyEM). Takemura S, et al. (2024) A connectome of the male Drosophila ventral nerve cord. eLife 13:RP97769. doi:10.7554/eLife.97769. CC BY 4.0
- Neuron parameters come from the public code (MIT) of Shiu PK, et al. (2024) A Drosophila computational brain model reveals sensorimotor processing. Nature 634:210-219.
Changes: we kept only the escape pathway, mirrored the right-brain data to make a left brain, and dropped recurrent links on the brain side. Full rules are in the guide.