Visualizations
210 / 500

210 · Simulation

Tsunami

A quake lifts the seafloor and a tsunami races across a live nautical chart.

The ocean is a grid of real depths (an island arc over a deep trench, a continental shelf, banks and atolls) and the wave obeys the linear shallow-water equations on a staggered grid, so it travels at the square root of g times depth: jetliner speed over the abyss, a crawl on the shelf. Refraction toward shallow water, wrapping around islands and shoaling growth all fall out of that one rule. Every cell records when the wave first passed, and marching squares turns those times into the red 30-minute isochrones of a warning-center chart, while tide gauges on the coasts draw their marigrams.

Try it. Click anywhere in the sea to set off a quake there. Hover to read the depth and wave speed. Tap the title box or press M to switch to a maximum-wave-height map, use the arrow keys or plus and minus to change speed, Space to pause and R for a random quake.

  • Linear shallow-water equations
  • Arakawa C-grid
  • Marching squares isochrones
  • Okada-style seafloor uplift
  • Cached chart layer

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 tsunami simulation on an ocean map 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 and is sharp on high-DPI screens. Behind it, keep a grid of about 300 by 190 cells, each with an ocean depth in metres.
- Generate the depths with a small noise function you write yourself: a basin around 4,000 m deep, a shelf under 200 m along one side, and a few islands (depth below zero is land).
- Use a staggered grid: surface height eta at cell centers, u and v velocities on the faces between cells.
- Each step, update u and v from the slope of eta (u -= g * dt / dx * the difference in eta), then update eta from the depth-weighted flow across the cell's faces. Zero the faces next to land so coasts reflect, and pick dt from the deepest water so the Courant number stays below 0.5.
- On click, add a smooth bump of eta where the visitor clicked.
- Draw the depths once into an offscreen canvas (paper white for deep water, blue for shallow, tan for land). Each frame, draw eta on top through ImageData at grid size scaled up: red for crests, blue for troughs.

Once that works, make it beautiful:
- Record when each cell first sees the wave and draw 30-minute arrival contours with marching squares, like a warning-center map.
- Damp the wave in a band along the edges so it leaves the map.
- Add a few coastal tide gauges that plot their water level over time.

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 maximum-wave-height map, nonlinear runup onto land, or real bathymetry.
PreviousThree-Body BalletTwenty-two periodic three-body orbits, inked like calligraphy until a nudge breaks them. NextSlime MoldSimple agents leave trails that self-organize into living networks.

Related visualizations

  • Glowing SurfFluids Moonlit waves break on a beach and the plankton in them flash electric blue.
  • Rogue WavesFluids A storm swell where walls of water rise from nowhere through nonlinear focusing.
  • Ocean3D Rolling waves at sunset, built from layered Gerstner waves.
  • Seismic ShadowPhysics Quake waves curve through a cutaway Earth, leaving the shadows that revealed its core.
  • Mountain Wave CloudsSimulation Wind over a range rings into lee waves, and saucer clouds stack at the crests.
  • Topographic SurveyGenerative art Eroded terrain printed as a survey sheet with labeled contours, streams and hillshade.
  • Ship WakeFluids A boat carves the 19.47 degree Kelvin wake, which emerges from dispersion alone.
  • Flood DioramaFluids A dam fails above a miniature town and a muddy flood spreads through the valley.
  • SolitonsFluids Solitary waves in a canal pass through each other unchanged, drawn as a Victorian plate.

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

← More from Emergent Mind Labs