GodUIGodUI
129Follow on X

Anatomy of Topographic Drift

How an 18px noise grid, a 16-case marching-squares switch, and a creeping z-offset redraw contour lines every frame and freeze under reduced motion.

01/04Sample the field

Each corner is valueNoise(i·cell·scale, j·cell·scale + z). Contour count is separate: lineCount levels get stroked later.

Grid
cell ≈ 18px sample spacing
Field
noiseScale = 0.004
Levels
lineCount default 9
tsx
field[j * stride + i] = valueNoise(i * cell * noiseScale,       // default noiseScale = 0.004j * cell * noiseScale + z,);
01

Sample the field

TopographicDrift draws on a canvas. Every frame it samples a value-noise field onto a coarse grid, connects isolines with marching squares, and nudges the noise's z-offset so the terrain slowly drifts. The canvas clears and redraws; it keeps no path geometry between frames.

Corners sit on an ~18px lattice. Each corner stores one noise value:

lineCount (default 9) is the number of elevation levels you stroke afterward, not the number of grid cells.

The dots in the diagram are those sample corners. Their shade shows noise amplitude so you can see the field before any lines are drawn.

02/04Marching squares → isolines
one cell · bitmask
levels · mid alpha peak

Filled corners are above the level. The segment is the isoline, interpolated where the field crosses level on each edge.

Cases
16 configs · skip 0 and 15
Alpha
0.1 + 0.25×(1−|0.5−level|×2)
tsx
let id = 0;if (tl > level) id |= 8;if (tr > level) id |= 4;if (br > level) id |= 2;if (bl > level) id |= 1;if (id === 0 || id === 15) continue;const top = x + cell * ((level - tl) / (tr - tl || 1e-6));// …right, bottom, left — then switch (id) { case 1: seg(…); … }
02

Marching squares → isolines

For every cell and every level l / (lineCount + 1), the four corners become a 4-bit mask (tl|tr|br|bl). Mask 0 and 15 skip (all below / all above). Everything else picks edge midpoints by linear interpolation and strokes one or two segments, following the classic 16-case table.

Stroke alpha peaks on mid-levels and falls off toward the extremes:

tsx
 
0.1 + 0.25 * (1 - Math.abs(0.5 - level) * 2)
03/04Drift is just z

There is no path morphing. The tick advances z, sampleField() runs again, and marching squares redraw. Offscreen / hidden / reduced motion stop the loop.

z-offset
z += 0.0015 × speed
Lifecycle
IO · visibility · reduced freeze
tsx
const tick = () => {z += 0.0015 * speed;draw(); // sampleField() + marching squares againrafId = requestAnimationFrame(tick);};
03

Drift is just z

The "living map" feeling is one line in the tick:

Same lifecycle as the other canvas backgrounds: ResizeObserver rebuilds the grid, IntersectionObserver and visibilitychange pause offscreen / when the tab hides, and prefers-reduced-motion stops the loop on a still frame.

Color comes from --foreground (or a color prop), re-probed when the document theme mutates, so light and dark both stay legible without a baked palette.

04/04Result
04

The result

Sample → march → nudge z, every frame. The canvas holds no mesh and morphs no paths.

Motion Score

Topographic DriftCC: Paint-triggering
Ccanvas paint2D canvas marching-squares each frame
Each property is graded by how the browser runs it, from S (composited off the main thread) down to F (layout thrashing); the component takes the worst. MotionScore methodology →