Contour Terrain
A dark 3D landscape, ray-marched and seen at a steep angle, its slopes traced by fine glowing topographic contour lines that crowd on the steep ground and open out on the flats. Every line stays crisp, the land falling away into the dark with distance. The land swells under your cursor with the lines bunching around it, a click rolls a ripple through the terrain, scrolling flies you across it, and when idle the land slowly shifts.
Tweak
LIVELIVEColour
Terrain
Light
Motion
Interactive
The land swells under the cursor, clicks send a ripple
Usage
Follows your tweaks.
import { ContourTerrain } from "@/components/inreact/contour-terrain";
export function Hero() {
return (
<ContourTerrain
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the terrain */}
</ContourTerrain>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/contour-terrain.jsonOr copy the source
Install the dependencies, then save this as components/inreact/contour-terrain.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Contour Terrain: a dark landscape drawn as glowing topographic contour lines.
*
* A real 3D heightfield, ray-marched and seen at an angle, its slopes traced by
* fine silver contour lines that crowd together on the steep ground and open
* out on the flats. Every line is crisp; depth comes from the land falling
* away into the dark and the light raking across its slopes. A tight bloom
* lifts the brightest lines, and the blacks stay black.
*
* It reacts: the land swells up under your cursor, the lines bunching around
* it, and a light follows you across the slopes; a click sends a ripple
* rolling out through the terrain; scrolling flies you across the land. On
* load the lines are drawn in from the valley up as the camera settles. When
* idle the land slowly shifts, so the lines never stop flowing.
*
* <ContourTerrain className="h-screen w-full">
* <YourHero />
* </ContourTerrain>
*
* WebGL: one ray-marching shader, then bloom at 1/4 and 1/16 size. GSAP drives
* every motion. Pauses off-screen; reduced motion shows a still frame; a CSS
* gradient without WebGL.
*/
export interface ContourTerrainProps {
/** Colour of the contour lines. */
line?: string;
/** Colour of the land between them. */
ground?: string;
/** Background colour. */
background?: string;
/** How many contour lines (lines per unit of height). */
lines?: number;
/** How tall and rugged the land is. */
relief?: number;
/** How quickly the land fades into the dark with distance. */
depth?: number;
/** Brightness of the lines. */
intensity?: number;
/** Strength of the bloom. */
glow?: number;
/** Speed of the idle drift. */
speed?: number;
/** Cursor swell and light, click ripple. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the terrain. */
children?: ReactNode;
className?: string;
}
const QUAD = `attribute vec2 aQ; varying vec2 vUv; void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `
#extension GL_OES_standard_derivatives : enable
precision highp float;
uniform vec2 uRes, uMouse, uRipC;
uniform vec2 uCam;
uniform float uTime, uFlow, uFly, uIn, uTilt, uHover, uSwell, uRip, uRipAmp, uLines, uRelief, uDepth, uIntensity;
uniform vec3 uLine, uGround, uBg;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float vnoise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
for (int i = 0; i < 5; i++) {
v += a * vnoise(p);
p = m * p;
a *= 0.42;
}
return v;
}
// the land: rolling hills with a drift, the swell under the cursor, a ripple from a click
float height(vec2 xz) {
vec2 q = xz * 0.4 + vec2(uFlow * 0.05, uFly + uFlow * 0.02);
float h = fbm(q + vec2(fbm(q * 0.6 + 3.0), fbm(q * 0.6 + 8.0)) * 1.1);
h = (h - 0.45) * 3.4 * uRelief;
vec2 dm = xz - uMouse;
h += uSwell * 0.55 * exp(-dot(dm, dm) / 0.35) * uHover;
float dr = length(xz - uRipC);
h += sin(dr * 7.0 - uRip * 14.0) * 0.09 * exp(-pow((dr - uRip * 4.5) / 0.7, 2.0)) * uRipAmp;
return h;
}
void main() {
vec2 sp = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
// a camera above the land, looking down at a steep angle
// the camera drifts and leans with the cursor, so near ground slides past far ground: real parallax
vec3 ro = vec3(uCam.x, 2.6 + uCam.y * 0.25, -1.6);
float ct = cos(uTilt), st = sin(uTilt);
float yaw = -uCam.x * 0.08;
vec3 fw = normalize(vec3(sin(yaw) * ct, -st, cos(yaw) * ct));
vec3 rt = normalize(vec3(fw.z, 0.0, -fw.x));
vec3 up = cross(fw, rt);
vec3 rd = normalize(fw * 1.25 + rt * sp.x + up * sp.y);
// march the heightfield
float t = 0.2;
float hit = 0.0;
float lt = t;
for (int i = 0; i < 110; i++) {
vec3 q = ro + rd * t;
float d = q.y - height(q.xz);
if (d < 0.0) { hit = 1.0; break; }
lt = t;
t += max(d * 0.4, 0.003 * t);
if (t > 16.0) break;
}
// refine the crossing so the lines do not break up
if (hit > 0.5) {
float a = lt, b = t;
for (int i = 0; i < 6; i++) {
float m = 0.5 * (a + b);
vec3 q = ro + rd * m;
if (q.y - height(q.xz) < 0.0) b = m; else a = m;
}
t = 0.5 * (a + b);
}
vec3 p = ro + rd * t;
vec3 col = uBg;
if (hit > 0.5) {
float h = height(p.xz);
vec2 e = vec2(0.01, 0.0);
vec3 n = normalize(vec3(height(p.xz - e.xy) - height(p.xz + e.xy), 2.0 * e.x, height(p.xz - e.yx) - height(p.xz + e.yx)));
// contour lines on the surface, antialiased
float hv = h * uLines;
// distance to the nearest contour, in contour units: 0 on a line
float f = 0.5 - abs(fract(hv) - 0.5);
// the slope of the height on screen, from the true normal (screen derivatives break at ridgelines)
float grad = length(n.xz) / max(n.y, 0.08);
float pixW = t / (uRes.y * 1.25) / max(abs(dot(n, -rd)), 0.12);
float wraw = uLines * grad * pixW * 1.4 + 1e-4;
float wpx = clamp(wraw, 1e-4, 0.45);
// a fine line with a silky falloff: a crisp core and a soft shoulder
float lw = min(wpx * 0.6, 0.16);
float ln = 1.0 - smoothstep(0.0, lw, f);
ln += exp(-f / max(lw * 1.8, 1e-4)) * 0.18 * (1.0 - smoothstep(0.1, 0.35, wpx));
// where lines crowd closer than a pixel, or across a ridge's edge, fade to their average glow instead of aliasing
float crowd = smoothstep(0.14, 0.32, wraw);
ln = mix(ln, lw * 0.18, crowd);
// far off the lines thin away before they can alias
ln *= smoothstep(10.0, 6.5, t);
// grazing slopes smear a line across many pixels: let those fade rather than blur
ln *= smoothstep(0.04, 0.2, abs(dot(n, -rd)));
// every fifth line a touch brighter, like an index contour
float idx = 1.0 + 0.35 * step(4.5, mod(floor(hv + 0.5), 5.0));
// lit from the upper left, plus the cursor's light
vec3 L = normalize(vec3(-0.5, 0.9, 0.4));
float dif = 0.35 + 0.65 * max(dot(n, L), 0.0);
vec2 dm = p.xz - uMouse;
float cl = exp(-dot(dm, dm) / 0.6) * uHover;
// drawn in from the valleys up on load
float rev = smoothstep(h - 0.15, h + 0.15, (uIn * 2.6 - 1.4) * uRelief);
// depth: the land falls away into the dark, near lines bright, far lines dim
float fog = exp(-max(t - 3.4, 0.0) * 0.3 * uDepth);
// a soft sheen on the slopes facing the light, so the land has volume between the lines
float sheen = pow(max(dot(reflect(-L, n), -rd), 0.0), 6.0);
col = uGround * (0.1 + 0.9 * dif * dif) * fog * fog * 0.18 + uLine * sheen * 0.04 * fog * fog;
col += uLine * ln * idx * (0.4 + 1.3 * dif * dif) * fog * (1.0 + cl * 1.2) * uIntensity * rev * 1.6;
col += uLine * exp(-pow((length(p.xz - uRipC) - uRip * 4.5) / 0.25, 2.0)) * uRipAmp * ln * 0.8;
}
// beyond the land: pure dark, no haze
if (hit < 0.5) col = uBg;
gl_FragColor = vec4(col, 1.0);
}`;
const BLUR = `
precision mediump float;
uniform sampler2D uTex;
uniform vec2 uStep;
varying vec2 vUv;
void main() {
vec4 c = texture2D(uTex, vUv) * 0.2270;
c += (texture2D(uTex, vUv + uStep * 1.3846) + texture2D(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture2D(uTex, vUv + uStep * 3.2308) + texture2D(uTex, vUv - uStep * 3.2308)) * 0.0703;
gl_FragColor = c;
}`;
const BRIGHT = `
precision mediump float;
uniform sampler2D uTex;
varying vec2 vUv;
void main() {
vec3 c = texture2D(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
gl_FragColor = vec4(c * smoothstep(0.55, 0.95, l), 1.0);
}`;
const COMPOSITE = `
precision mediump float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow, uTime;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture2D(uScene, vUv).rgb;
vec3 bl = texture2D(uBloom, vUv).rgb * 0.55 + texture2D(uWide, vUv).rgb * 0.2;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.9, 0.0) * 1.2);
col = min(col, vec3(1.0));
vec2 q = vUv - 0.5;
col *= 1.0 - 0.5 * dot(q, q);
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = vec4(col, 1.0);
}`;
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function rgb(hex: string): [number, number, number] {
let h = hex.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (c) => c + c);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
export function ContourTerrain({
line = "#e4e4e4",
ground = "#8a8a8a",
background = "#0e0e0e",
lines = 18,
relief = 1,
depth = 1,
intensity = 1,
glow = 0.5,
speed = 1,
interactive = true,
scroller,
children,
className,
}: ContourTerrainProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ line, ground, background, lines, relief, depth, intensity, glow, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { line, ground, background, lines, relief, depth, intensity, glow, speed, interactive };
redraw.current?.();
}, [line, ground, background, lines, relief, depth, intensity, glow, speed, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
const gl = canvas.getContext("webgl", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `repeating-radial-gradient(ellipse at 45% 45%, ${p.background} 0 14px, ${p.line}44 15px 16px), ${p.background}`;
canvas.remove();
return;
}
gl.getExtension("OES_standard_derivatives");
const build = (fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, QUAD],
[gl.FRAGMENT_SHADER, fs],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(pr, sh);
}
gl.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
const sceneProg = build(SCENE);
const blurProg = build(BLUR);
const brightProg = build(BRIGHT);
const compProg = build(COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const US = uni(sceneProg, ["uRes", "uMouse", "uRipC", "uCam", "uTime", "uFlow", "uFly", "uIn", "uTilt", "uHover", "uSwell", "uRip", "uRipAmp", "uLines", "uRelief", "uDepth", "uIntensity", "uLine", "uGround", "uBg"]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const quad = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const drawQuad = (pr: WebGLProgram) => {
const a = gl.getAttribLocation(pr, "aQ");
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.enableVertexAttribArray(a);
gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 3);
gl.disableVertexAttribArray(a);
};
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number };
const target = (tw: number, th: number): Target => {
const tex = gl.createTexture()!;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
const fb = gl.createFramebuffer()!;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th };
};
let T: { scene: Target; a: Target; b: Target; c: Target; d: Target } | null = null;
const freeTargets = () => {
if (!T) return;
for (const x of Object.values(T)) {
gl.deleteFramebuffer(x.fb);
gl.deleteTexture(x.tex);
}
T = null;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
// ray marching is heavy: cap the resolution, the lines are antialiased in the shader
dpr = Math.min(window.devicePixelRatio || 1, 2);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
const sw = canvas.width, sh = canvas.height;
freeTargets();
T = {
scene: target(sw, sh),
a: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
b: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
c: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
d: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
};
};
resize();
// ---- state: every value GSAP moves ----
// the cursor and ripples live on the ground plane (x, z)
const s = { in: still ? 1 : 0, tilt: still ? 0.62 : 0.9, hover: 0, swell: 0, mx: 0, mz: 3, rip: 0, ripAmp: 0, rx: 0, rz: 3, fly: 0, rush: 0, cx: 0, cy: 0 };
let time = 0, flow = 0;
const blurPass = (src: Target, dst: Target, dx: number, dy: number) => {
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb);
gl.viewport(0, 0, dst.w, dst.h);
gl.useProgram(blurProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, src.tex);
gl.uniform1i(UB.uTex, 0);
gl.uniform2f(UB.uStep, dx / src.w, dy / src.h);
drawQuad(blurProg);
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, X.scene.w, X.scene.h);
gl.uniform2f(US.uMouse, s.mx, s.mz);
gl.uniform2f(US.uRipC, s.rx, s.rz);
gl.uniform2f(US.uCam, s.cx + Math.sin(time * 0.11) * 0.18, s.cy + Math.sin(time * 0.083) * 0.12);
gl.uniform1f(US.uTime, time);
gl.uniform1f(US.uFlow, flow);
gl.uniform1f(US.uFly, s.fly);
gl.uniform1f(US.uIn, s.in);
gl.uniform1f(US.uTilt, s.tilt);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uSwell, s.swell);
gl.uniform1f(US.uRip, s.rip);
gl.uniform1f(US.uRipAmp, s.ripAmp);
gl.uniform1f(US.uLines, p.lines);
gl.uniform1f(US.uRelief, p.relief);
gl.uniform1f(US.uDepth, p.depth);
gl.uniform1f(US.uIntensity, p.intensity);
gl.uniform3fv(US.uLine, rgb(p.line));
gl.uniform3fv(US.uGround, rgb(p.ground));
gl.uniform3fv(US.uBg, rgb(p.background));
drawQuad(sceneProg);
gl.bindFramebuffer(gl.FRAMEBUFFER, X.a.fb);
gl.viewport(0, 0, X.a.w, X.a.h);
gl.useProgram(brightProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, X.scene.tex);
gl.uniform1i(UR.uTex, 0);
drawQuad(brightProg);
blurPass(X.a, X.b, 1, 0);
blurPass(X.b, X.a, 0, 1);
blurPass(X.a, X.c, 1, 0);
blurPass(X.c, X.d, 0, 1);
blurPass(X.d, X.c, 1.8, 0);
blurPass(X.c, X.d, 0, 1.8);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.useProgram(compProg);
[X.scene.tex, X.a.tex, X.d.tex].forEach((tex, i) => {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tex);
});
gl.uniform1i(UC.uScene, 0);
gl.uniform1i(UC.uBloom, 1);
gl.uniform1i(UC.uWide, 2);
gl.uniform1f(UC.uGlow, p.glow);
gl.uniform1f(UC.uTime, time);
drawQuad(compProg);
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the camera tips down over the land and the lines draw in from the valleys up ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { in: 1, duration: 3, ease: "power2.inOut" }, 0)
.to(s, { tilt: 0.62, duration: 3.6, ease: "expo.out" }, 0);
// ---- screen point -> the ground plane (the same camera as the shader, at mean ground height) ----
const toGround = (x: number, y: number) => {
const sx = (x - w / 2) / h, sy = -(y - h / 2) / h;
const ct = Math.cos(s.tilt), st = Math.sin(s.tilt);
const fw = [0, -st, ct], up = [0, ct, st];
const rd = [sx, fw[1] * 1.25 + up[1] * sy, fw[2] * 1.25 + up[2] * sy];
const n = Math.hypot(rd[0], rd[1], rd[2]);
const dy = rd[1] / n;
const t = dy < -0.02 ? -2.6 / dy : 12;
return { x: (rd[0] / n) * t, z: -1.6 + (rd[2] / n) * t };
};
// ---- cursor: the land swells under it and a light follows ----
const mxTo = gsap.quickTo(s, "mx", { duration: 1.2, ease: "power3" });
const mzTo = gsap.quickTo(s, "mz", { duration: 1.2, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 1.2, ease: "power2.inOut" });
const swellTo = gsap.quickTo(s, "swell", { duration: 1.8, ease: "power2.out" });
const cxTo = gsap.quickTo(s, "cx", { duration: 2.2, ease: "power3" });
const cyTo = gsap.quickTo(s, "cy", { duration: 2.2, ease: "power3" });
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
let first = true;
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
const g = toGround(p.x, p.y);
if (first) {
gsap.set(s, { mx: g.x, mz: g.z });
first = false;
}
mxTo(g.x);
mzTo(g.z);
hoverTo(1);
swellTo(1);
cxTo((p.x / w - 0.5) * 0.5);
cyTo((p.y / h - 0.5) * -0.5);
};
const leave = () => {
first = true;
hoverTo(0);
swellTo(0);
cxTo(0);
cyTo(0);
};
// ---- click: a ripple rolls out through the land ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
const g = toGround(p.x, p.y);
s.rx = g.x;
s.rz = g.z;
gsap.killTweensOf(s, "rip,ripAmp");
gsap.fromTo(s, { rip: 0 }, { rip: 1, duration: 3, ease: "sine.out" });
gsap.fromTo(s, { ripAmp: 1 }, { ripAmp: 0, duration: 3, ease: "power1.in" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: fly across the land ----
const flyTo = gsap.quickTo(s, "fly", { duration: 1.8, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => flyTo(self.progress * 1.2),
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const loop = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt;
flow += dt * props.current.speed * 0.6;
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
return () => {
gsap.ticker.remove(loop);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
13 propslinestringColour of the contour lines.default "#e4e4e4"default "#e4e4e4"groundstringColour of the land between them.default "#8a8a8a"default "#8a8a8a"backgroundstringBackground colour.default "#0e0e0e"default "#0e0e0e"linesnumberHow many contour lines (lines per unit of height).default 18default 18reliefnumberHow tall and rugged the land is.default 1default 1depthnumberHow quickly the land fades into the dark with distance.default 1default 1intensitynumberBrightness of the lines.default 1default 1glownumberStrength of the bloom.default 0.5default 0.5speednumberSpeed of the idle drift.default 1default 1interactivebooleanCursor swell and light, click ripple.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the terrain.classNamestringSize it, e.g. h-screen w-full.