Visualizations
255 / 500

255 · Fluids

Water Ripples

Raindrops on a koi pond, with ripples that bend the scene below.

Two height buffers hold the water surface now and one step ago. Each step, a point's new height is the average of its neighbors minus its old height, a cheap discrete wave equation, with slight damping. The slope of the surface offsets which pixel of the background shows through, which fakes refraction over a procedurally drawn pond bed.

Try it. Move or drag across the water to make ripples. Tap to call the koi over.

  • Discrete wave equation
  • Refraction by displacement
  • Double buffering

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 an interactive water ripple effect over a pond 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. Run the simulation at half resolution (one cell per 2 CSS pixels) and scale the result up with drawImage.
- Paint a pond bed procedurally into an offscreen canvas at the grid size: a dark teal gradient with a few hundred pebbles drawn as ellipses with radial gradients, then read it once with getImageData.
- Keep two Float32Array height buffers, current and previous. Each step, for every interior cell: next = (left + right + up + down) / 2 - previous, then multiply by 0.985 for damping. Write next into the previous buffer and swap.
- To render, compute the slope at each cell (left minus right, up minus down), offset the pixel you read from the pond image by the slope times about 8 (fake refraction), and add the slope to the brightness for glints.
- Make the mouse disturb the water when it moves, and drop a raindrop at a random spot every few hundred milliseconds.

Once that works, make it beautiful:
- Add caustics: brighten pixels where the surface curvature (the discrete Laplacian of height) focuses light.
- Draw a few koi fish swimming over the bed each frame before you sample it, so they wobble under the ripples. Bend each body along a trail of the head's recent positions.
- Float some lily pads on top that are not refracted, and add a soft vignette.

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 reflecting ripples off the lily pads, using a photo as the pond bed, or letting the fish react to splashes.
PreviousAsteroidsThe arcade classic with glowing vector lines and an AI pilot. NextPenrose PentagridFive grids of parallel lines dualize into a living Penrose tiling of stained glass.

Related visualizations

  • SPH WaterFluids Thousands of particles that slosh, splash and pour like a liquid.
  • Rain on GlassFluids Raindrops bead, merge and run down a fogged window, each a tiny upside-down city.
  • Faraday WavesFluids A shaken dish of liquid locks into stripes, squares, hexagons and a 12-fold quasicrystal.
  • Glowing SurfFluids Moonlit waves break on a beach and the plankton in them flash electric blue.
  • Ocean3D Rolling waves at sunset, built from layered Gerstner waves.
  • Pond DropNature A drop of pond water under a brightfield microscope, with a focus knob you can turn.
  • Pool CausticsPhysics Sunlight bent by a rippling pool surface draws a living net of light on the tiles.
  • Rogue WavesFluids A storm swell where walls of water rise from nowhere through nonlinear focusing.
  • Flood DioramaFluids A dam fails above a miniature town and a muddy flood spreads through the valley.

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

← More from Emergent Mind Labs