asafefe.dev
Lab

Lab/22

Ripple Water

A height field where each cell averages its neighbors and subtracts its last value, so waves spread and interfere. The dots or letters below shift with the slope, as if seen through water.

  • Canvas
  • Simulation
  • Interaction
Click or drag on the water
0.975

Installation

Add Ripple Water to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-ripple-water

Or by URL: https://asafefe.dev/r/lab-ripple-water.json

Brings along

  • utils
  • @soultel/lab-canvas

Usage

example.tsx10 lines
import { RippleWater } from "@/components/lab/ripple-water"

export function Hero() {
  return (
    <section className="relative h-[420px] touch-none">
      <RippleWater className="absolute inset-0" />
      <h1 className="pointer-events-none relative">Hello</h1>
    </section>
  )
}

Props

PropTypeDefaultDescription
pattern"dots" | "text""dots"What the water refracts.
textstring"ripple"Letters for the text pattern.
spacingnumber14Distance between dots or letters in px.
dampingnumber0.975Energy kept per step, 0.9 to 0.995.
resolutionnumber4Simulation cell size in px.
strengthnumber1Ripple strength multiplier.
hoverRipplesbooleantrueA light wake follows the mouse.
introbooleantrueOne ripple in the middle on load.
color / accentColorstring"var(--foreground)", "var(--primary)"Calm color and crest color.
refRef<RippleWaterHandle>-drop(x, y, strength) and clear().