Visualizations
466 / 500

466 · Nature

Action Potential

Hodgkin-Huxley spikes race down an axon while every ion channel opens and shuts.

The axon is a cable of 240 compartments, each running the 1952 Hodgkin-Huxley squid axon equations with their sodium activation (m), sodium inactivation (h) and potassium activation (n) gates. Gates advance with the exact exponential update and the cable is solved semi-implicitly with a tridiagonal (Thomas) solve every 10 microseconds of model time, played back in slow motion. Every channel on the membrane reads its own compartment's gates: the sodium channel's flap opens with m cubed, its ball and chain plugs the pore as h falls, the potassium gate follows n to the fourth, and ions pour through at the real current. Myelin cuts the internode capacitance fifty-fold so the spike leaps between nodes of Ranvier about four times faster, the temperature factor speeds every gate until the spike fails (heat block), and TTX removes sodium conductance until conduction stops.

Try it. Click anywhere on the axon to stimulate it there (two spikes head both ways, and colliding spikes annihilate), or press Stimulate or Space to fire from the cell body. Toggle Myelin (M) and TTX (T), change the temperature with the minus and plus buttons or the arrow keys, and drag the probe (or use left and right) to choose where the scope below records. Left alone, it walks through myelin, collisions, TTX and heat block on its own.

  • Hodgkin-Huxley model
  • Implicit cable equation (Thomas algorithm)
  • Rush-Larsen gate integration

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build an animated action potential traveling down an axon, using the Hodgkin-Huxley equations, JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window and stays sharp on high-DPI screens.
- Model the axon as 200 compartments. Each has a voltage V (start at -65 mV) and the three gates m, h and n, initialized to their resting steady states. Use the standard Hodgkin-Huxley rate functions (alpha and beta for each gate), gNa = 120, gK = 36, gL = 0.3, ENa = 50, EK = -77 and EL = -54.4.
- Each step (dt = 0.01 ms): update each gate toward its steady state with gate = inf + (gate - inf) * exp(-dt / tau). Then update V from the ionic currents plus a coupling term K * (Vleft - 2V + Vright) to its neighbors. Keep K small enough to be stable, or solve the coupling implicitly with the Thomas algorithm.
- Run a few hundred steps per second of real time, so the spike moves in slow motion.
- Draw the axon as a horizontal tube colored by V (dark blue at rest, bright gold at the peak) and plot V along the axon underneath it.
- Clicking injects a short pulse of current at that point.

Once that works, make it beautiful:
- Draw sodium and potassium channels along the membrane whose gates open with m cubed, h and n to the fourth, and spawn little ions that flow through them in proportion to the current.
- Add a scope that records V, m, h and n over time at one point.
- Add a temperature control using the factor 3 to the power of ((T - 6.3) / 10) on every rate, and watch the spike fail when it gets hot.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as myelin with nodes of Ranvier, a toxin slider that blocks sodium channels, or two spikes colliding head on.
PreviousBroad-Nib CalligraphyA dip pen writes italic and uncial letters; thick and thin come from the nib angle. NextMinesweeper OracleEvery hidden cell shows its exact mine probability while an AI plays the safest move.

Related visualizations

  • Neuron GrowthNature A Golgi-stained circuit grows its dendrites and axons, wires up, then fires.
  • Spiking RasterMachine learning A thousand Izhikevich neurons learn by spike timing and ripple with travelling waves.
  • CochleaSound An unrolled inner ear: traveling waves on the basilar membrane sort a chord by pitch.
  • Wireworld CircuitsEmergence A four-rule cellular automaton runs a six-bit counter and logic gates on a PCB.
  • Circuit SimulatorPhysics A SPICE-style solver runs a live schematic: LEDs blink, capacitors charge, current flows.
  • Heart TissueSimulation Spiral waves, arrhythmia and defibrillation in a living sheet of heart muscle.
  • LightningSimulation Branching lightning that grows from a dielectric breakdown model.
  • Run and TumbleNature Hundreds of E. coli turn a random walk into a climb up a sugar gradient.
  • DendritesSimulation Supercooled melt freezes into branching dendrites, with latent heat glowing between arms.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs