A star cluster and its HR diagram age side by side across 13 billion years.
Four thousand stars are drawn from the Kroupa mass function into a mass-segregated Plummer sphere, and each follows an evolutionary track built from textbook scalings: main-sequence luminosity and lifetime from mass, then subgiant, red giant, helium burning (a red clump, or a blue loop for heavier stars), the asymptotic giant branch, a planetary nebula and a white dwarf fading along Mestel's cooling law. Stars above eight solar masses become supergiants and explode. Because the most massive stars die first, the main-sequence turnoff walks down the diagram, and its mass is the cluster's age, which is how astronomers date clusters. Colors are true star colors from Planck's law and the CIE color matching functions, and brightness on the plate is visual flux, so hot stars look fainter than their total output.
Try it. Drag the age slider across billions of years or press Space to play. Click any star, in the picture or on the diagram, to follow its whole evolutionary track and read its mass, phase, temperature, luminosity and radius. Arrow keys step through time, R rewinds to the birth of the cluster, and Escape lets go of a star.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build an aging star cluster with its Hertzsprung-Russell diagram, using 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, stays sharp on high-DPI screens (scale by devicePixelRatio), with a dark background. Show the cluster on the left and the diagram on the right.
- Create about 2,000 stars with masses from a power-law initial mass function (many small stars, few big ones) between 0.1 and 40 solar masses.
- For each mass compute a zero-age main-sequence luminosity (roughly L = M^4 below 2 solar masses, 1.4 M^3.5 above), a radius (M^0.8 or M^0.57), the temperature from L = R^2 T^4, and a main-sequence lifetime of 10 billion years times M / L.
- Add a log-scale age slider from 1 million to 13 billion years. A star older than its lifetime becomes a red giant for 10% more of its lifetime (cool and bright), then a white dwarf (hot and faint), or vanishes if it was more massive than 8 suns.
- Plot temperature (hot on the left, log scale) against log luminosity, and place the stars in a Plummer-sphere cluster image, each drawn as a glowing dot whose size grows with its brightness.
Once that works, make it beautiful:
- Color stars with real star colors: integrate Planck's law against a simple fit of the CIE color matching functions and convert to sRGB.
- Pre-render glowing sprites per color, draw them with additive blending, and add diffraction spikes to the brightest stars.
- Label the main-sequence turnoff with its mass, and let a click on any star draw its whole evolutionary track.
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 red clump and white dwarf cooling law, unresolved binary stars, or supernova flashes in the image.