Visualizations
398 / 500

398 · Physics

Magnetic Bottle

Particles gyrate, bounce and drift in Earth's dipole, filling the radiation belts.

Thousands of charged particles are pushed through Earth's dipole field with the Boris integrator, the energy-conserving scheme used in plasma codes. Nothing else is programmed in, yet three nested motions appear: a tight helix around a field line, a bounce between mirror points where the converging field reflects the particle, and a slow drift around the planet, protons one way and electrons the other. Their light builds up in a fading buffer into the inner and outer belts. The solar wind compresses the field through a Chapman-Ferraro image dipole, and stronger wind scatters electrons into the loss cone so they rain down into aurora rings at the latitude where their field lines meet the ground.

Try it. Click to inject a particle on the shell under the pointer and follow its triple motion. Drag the solar wind slider, or use the arrow keys, to compress the magnetosphere and trigger aurora. Space injects a random particle.

  • Boris particle pusher
  • Magnetic dipole field
  • Long-exposure glow buffer
  • Per-pixel sphere shading

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 a simulation of charged particles trapped in Earth's magnetic field, the Van Allen radiation belts, with 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 full-window black canvas that stays sharp on high-DPI screens and resizes with the window.
- Use units where Earth's radius is 1. The dipole field is B = (r^2 z_hat - 3 z r) / r^5 (moment pointing south, like Earth's).
- Write a tiny 3D camera: rotate world points by an azimuth and an elevation, then divide by depth for perspective. Draw Earth as a shaded blue circle.
- Start a few hundred particles on the equator at distances L between 1.5 and 5, with a speed proportional to L and a pitch angle between 40 and 90 degrees to the field.
- Push each particle with the Boris method: t = (q/m) B dt / 2, s = 2t / (1 + t^2), v' = v + v x t, v = v + v' x s, then x += v dt. Choose q/m so the gyroradius is a few percent of L, with substeps keeping (q/m)|B| dt below 0.3.
- Draw each particle as a small dot with additive blending.

Once that works, make it beautiful:
- Accumulate particle positions in a low-resolution float buffer that fades slowly, then draw it scaled up with lighter blending, so the belts glow as tori. Use warm colors for inner protons and cool for outer electrons, which have the opposite charge and drift the other way.
- Click to add a highlighted particle with a long trail, so its gyration, bounce between mirror points and drift around the planet are all visible.

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 a solar wind slider that compresses the field, aurora where particles rain into the poles, or a textured spinning Earth.
PreviousMissing FundamentalPeel a note's harmonics away, fundamental first, and the heard pitch refuses to move. NextGlenz VectorsNested glassy checkered polyhedra bounce on a glossy floor, then shatter and rebuild.

Related visualizations

  • Iron FilingsPhysics Magnets on paper dusted with iron filings, drawn by line integral convolution.
  • Bubble ChamberPhysics Archival film of particle tracks: tightening spirals, V decays and pairs.
  • AuroraNature Curtains of oxygen and nitrogen light on tilted field lines, mirrored in a lake.
  • Radiating ChargePhysics Shake an electric charge and watch light peel off its field lines at c.
  • Solar SurfaceAstronomy Granulation, sunspots and flaring magnetic loops at the Sun's limb, in three wavelengths.
  • Magnetic PendulumFractals A pendulum over three magnets, and the fractal map of where every release point ends up.
  • Foucault PendulumPhysics A museum pendulum ploughs a rosette into sand as the Earth turns beneath it.
  • Gas Giant WeatherFluids Real 2D fluid dynamics paints turbulent belts, festoons and oval storms on a gas giant.
  • Particle LifeEmergence Colored particles with simple attractions that assemble into living cells.

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

← More from Emergent Mind Labs