A grain-by-grain slice of layered regolith as impactors dig craters, in slow motion.
The ground is about two thousand frictional disks in colored strata, simulated with the discrete element method, with contacts that stiffen with impact speed and damp hard on unloading so compacted regolith stays compacted. The impactor vaporizes on contact, as real hypervelocity impactors do, and delivers its energy as the velocity field of Maxwell's Z-model: material under the point is driven down while material near the surface is thrown up and out in a cone. From there it is plain granular physics: the transient bowl opens, the ejecta curtain sweeps outward, the strata fold back into an overturned flap at the rim, and the steep walls slump into the final crater, while cemented bedrock at the bottom resists. The inset is the view from above: each crater is measured rim to rim and stamped onto a height map on the slice line, and a steady rain of smaller impacts with a power-law size distribution drives the surface toward saturation.
Try it. Click the ground to strike it straight down, or drag from the sky to aim: the release point is the target, the drag direction the path and its length the speed. Press 1 to 3 to choose the impactor size, Space for a random impact and R for fresh regolith. Left alone, impacts arrive every few seconds.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a cross-section of an impact crater forming in layered ground, simulated grain by grain, 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 canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Use a black sky with a few stars.
- Fill the lower third of a wide box with about 1,200 disks of slightly different sizes, dropped onto each other row by row so they do not overlap. Color them in four horizontal bands (pale dust on top, then rust, grey and ochre), so you can follow each layer.
- Simulate them with the discrete element method: a spring and damper push overlapping disks apart, friction acts along each contact (capped at 0.6 times the normal force), and gravity pulls everything down. Use many small time steps per frame.
- When I click on the ground, give the grains near the click a sudden kick away from a point just below the surface, strongest close to it and falling off with distance. That kick is the impact.
- Draw every grain as a small shaded circle.
Once that works, make it beautiful:
- Shape the kick like Maxwell's Z-model: mostly radial, but swirling toward the surface near it, so material below is pushed down and material near the surface is thrown up and out in a cone of ejecta.
- Run the impact in slow motion and make fast-moving grains glow, so the ejecta curtain reads like high-speed footage.
- Animate a glowing impactor streaking in before the kick, and label the stages: contact, excavation, modification.
- Add rolling resistance so the crater walls hold a slope and then slump into a bowl.
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 top-down map that accumulates many craters, oblique impacts, or a cemented bedrock layer that flattens crater floors.