Skip to content
WANCRAFT

E.49Backgrounds & Effects

Topographic Lines

Animated contour lines traced with marching squares over an evolving noise terrain.

NewReactCanvasTailwindadvanced

Overview

Topographic Lines samples a two-octave simplex-noise height field on a coarse grid and traces its contours with marching squares, like a living survey map. Every Nth contour becomes an accent index line, and a mouse pointer raises a soft hill that the lines flow around. Contours are batched into two paths per frame, redraws are capped at 30fps, and the loop stops offscreen, in hidden tabs and whenever the terrain is frozen and the pointer is still. Reduced motion draws one still map.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/topo-lines.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/topo-lines.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/topo-lines.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { TopoLines } from "@/components/ui/topo-lines";

export function TopoLinesExample() {
  return (
    <div className="relative h-80 w-full overflow-hidden rounded-xl">
      <TopoLines />
    </div>
  );
}

03Props

PropTypeDefaultDescription
levelsnumber16Contour levels across the height range (min 2).
lineWidthnumber1Contour stroke width in px; index lines are 1.4× wider.
speednumber1Terrain evolution speed; 0 freezes it.
accentEverynumber5Draw every Nth contour as an accent index line; 0 disables.
accentstring"#FF7448"Index line colour (any CSS colour).
scalenumber1Terrain zoom; higher values give broader landforms.
cellSizenumber6Marching-squares cell size in px (min 3). Smaller is smoother but costs more CPU.
interactivebooleantrueA mouse or pen pointer raises a soft hill under it.
childrenReactNode—Optional content layered above the lines.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Marching squares over a two-octave simplex height field, with interpolated crossings
  • 02Only the levels crossing each cell are visited; contours batch into two Path2D strokes
  • 03Redraws capped at 30fps; idles when frozen and the pointer is still
  • 04Eased pointer hill that the contours bend around
  • 05Ink follows light/dark themes; accent index lines every N levels
  • 06DPR-aware canvas (capped at 2), ResizeObserver, pauses offscreen and in hidden tabs
motion · continuousinput · pointerinput · viewport

05Accessibility

  • The canvas is aria-hidden and ignores pointer events; layered content stays fully interactive.
  • prefers-reduced-motion draws a single still map and disables the pointer hill.
  • Only mouse and pen pointers raise the hill, so touch scrolling never triggers redraws.

06Limitations

  • Cost grows with area ÷ cellSize²; keep cellSize ≥ 5 for full-viewport backgrounds on low-end devices.