Visualizations
438 / 500

438 · Physics

Discharge Tubes

Glowing gas tubes whose colors are computed from their real spectral lines.

Each tube's glow is not picked from a palette. Every gas is a table of its strongest emission lines (hydrogen's straight from the Rydberg formula), and the lines are summed through the CIE 1931 color matching functions into XYZ, converted to linear sRGB, and tone mapped so the bright capillary over-exposes toward white like a photograph. A bloom pyramid of repeatedly halved buffers adds the halo and the reflections on the bench. The spectroscope splits the selected tube into its lines; for hydrogen, electrons fall between Bohr energy levels and each fall fires a photon at its line, and for the other gases a chromaticity diagram shows the glow as the center of mass of its lines.

Try it. Click a tube (or press 1 to 7) to point the spectroscope at it. Drag a gas tube onto Mix to pour it in, or drag the Mix sliders to blend your own color. Click a hydrogen energy level to drop an electron from it, hover the spectrum to read wavelengths, and press Space to switch the power off and strike the tubes again.

  • CIE 1931 color matching
  • Spectrum to sRGB
  • Bloom pyramid
  • Rydberg formula

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 glowing gas discharge tube display with JavaScript and the HTML canvas element, where each tube's color is computed from its real spectral lines. 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, stays sharp on high-DPI screens (scale by devicePixelRatio), and has a near-black background.
- Write the CIE 1931 color matching functions as the Wyman, Sloan and Shirley multi-lobe Gaussian fit (three short formulas for x, y and z bar), so no data tables are needed.
- Give four gases a short list of their strongest visible lines as [wavelength in nm, relative intensity]: hydrogen (656.3, 486.1, 434.0, 410.2), neon (a dozen lines between 585 and 703), sodium (589.0 and 589.6) and mercury (404.7, 435.8, 546.1, 577.0, 579.1).
- For each gas, sum intensity times the matching functions to get X, Y and Z, convert to linear sRGB with the standard 3x3 matrix, add white until no channel is negative, scale so the largest channel is 1, then gamma encode.
- Draw a row of vertical tubes (rounded rectangles with a thin bright core) in those colors, and below them a black strip that shows the selected tube's lines as thin vertical bars at their wavelengths, each tinted with its own spectral color.

Once that works, make it beautiful:
- Add bloom: draw the glowing parts into a small offscreen canvas, shrink it two or three times with drawImage, and add the copies back over the scene with globalCompositeOperation = "lighter".
- Over-expose the tube cores so they burn toward white while the halo keeps the gas's color.
- Click a tube to show its spectrum, and add a wavelength axis in nanometers.

Explain the color science 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 hydrogen energy level diagram that fires photons at its lines, mixing gases into new colors, or plotting each tube on a CIE chromaticity diagram.
PreviousWaterfall IllusionStare for twenty seconds, then watch a frozen picture drift the other way. NextGAN DuelA generator and a discriminator fight live over a 2D target, failure modes and all.

Related visualizations

  • Chromaticity LabMath Draw any light's spectrum and watch it land on the CIE 1931 horseshoe.
  • Blacksmith's ForgePhysics Heat, hammer and quench a steel bar whose glow and temper colors come from physics.
  • Rubens' TubeSound Gas flames on a brass pipe rise and dip with the standing sound wave inside.
  • CRT MonitorRetro An emulated electron beam, decaying phosphors and a shadow mask, under a 7x loupe.
  • Aperture DiffractionPhysics Draw any aperture and see its diffraction pattern in true spectral color.
  • Soap FilmFluids A draining soap film swirls with true thin-film colors until it turns black and pops.
  • AuroraNature Curtains of oxygen and nitrogen light on tilted field lines, mirrored in a lake.
  • Neon SignType and image Type a word and watch it get bent into glowing glass tubes on a brick wall.
  • Optical BenchPhysics A blueprint ray tracer: prisms, lenses, mirrors and a fiber with real glass dispersion.

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

← More from Emergent Mind Labs