A toy brain, honestly labelled
This is an educational simulation inspired by how small insect brains turn smells into movement. It is not a model of a real fruit fly. The real Drosophila brain has around 140,000 neurons, and its complete wiring diagram, the connectome, was published in 2024 after years of work. Here, a virtual fly has two odour sensors, sixteen spiking neurons and two motor units. The point is to show, in a form you can watch, how a nervous system can learn a useful behaviour from a simple reward signal.
What the fly senses and does
Each food source releases an odour that fades with distance. The fly's two antennae sit slightly to the left and right of its head and measure the odour where they are. Like real sensory neurons that adapt to background levels, the sensors respond to the difference between the two sides on a logarithmic scale. These signals drive a layer of leaky integrate-and-fire neurons with fixed random wiring: each neuron's voltage leaks away over time, rises with input and, when it crosses a threshold, fires a spike and resets. In the activity view, neurons flash yellow when they spike. The spikes feed two motor units that turn the fly left or right while it walks forward.
How it learns
In learning mode, the connections from the spiking neurons to the motor units start near zero, so the fly wanders randomly. A little random noise is added to the motor commands, and the simulation keeps an eligibility trace recording which neurons were active when each random nudge happened. After each step, a reward signal compares the odour at the fly's body with the previous step: getting closer to food is good, moving away is bad. Like the dopamine signals that gate learning in insect and mammal brains, this single number tells every connection whether its recent contribution helped. Connections that pushed in a rewarded direction get stronger; others weaken. This rule is known as node perturbation, a simple form of reward-modulated learning.
What to look for
- Run learning mode at a higher speed and watch the food-per-1,000-steps figure rise as the fly starts turning toward odour.
- Compare with the hard-wired brain, where each side's neurons drive the opposite turn, like a Braitenberg vehicle, and with the random brain.
- Click in the arena to drop extra food and watch the fly respond.
In our tests over many runs, the learning fly typically ends up finding food several times more often than the untrained one. Everything is computed in your browser, a few kilobytes of JavaScript with no external libraries.