Backgrounds07 / 118
Binary Warp
A flight down a tunnel of ones and zeros. Swirling liquid-silver walls stream past, split by shards of shadow, around a bright ring and a dark heart, while hundreds of 0s and 1s fly out of the dark toward you in true perspective. Steer with your cursor, click to punch into warp, and scroll to fly deeper as the view stays pinned.
WebGLWebGLReal bloomReal bloomCursor steeringCursor steeringGSAP scroll flightGSAP scroll flightReduced-motion safeReduced-motion safe
Steer the flightClick to warpScroll to fly deeper
Tweak
LIVELIVEColour
#e9f4fa
#7d8798
#000000
Tunnel
480
1.00
1.00
Motion
1.00
Interactive
Cursor steering and click warp
Usage
Follows your tweaks.
usage.tsx
import { BinaryWarp } from "@/components/inreact/binary-warp";
export function Hero() {
return (
<BinaryWarp
className="h-[220vh] w-full"
>
{/* optional: your hero content, pinned above the tunnel */}
</BinaryWarp>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/binary-warp.jsonOr copy the source
Install the dependencies, then save this as components/inreact/binary-warp.tsx.
terminal
npm install gsapcomponents/inreact/binary-warp.tsx
"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Binary Warp: flying down a tunnel of ones and zeros.
*
* A tunnel of swirling silver light opens around a dark centre, split by
* shards of shadow and lit by a bright ring. Hundreds of 0s and 1s stream
* out of the dark toward you, tiny and dense in the distance, huge as they
* rush past the edges.
*
* It reacts: the vanishing point follows your cursor, so you steer the flight,
* and digits near the cursor scatter. A click punches into warp: the stream
* surges and a flash of light rolls down the tunnel. Make it taller than the
* screen and the view pins while scrolling flies you deeper, faster with your
* scroll speed. On load you drop out of warp into the tunnel.
*
* <BinaryWarp className="h-[220vh] w-full">
* <YourHero />
* </BinaryWarp>
*
* WebGL: one shader for the tunnel, one draw call for the digits, real
* bloom. GSAP drives the steering, warp, scroll and intro. Pauses off-screen;
* reduced motion shows a still frame.
*/
export interface BinaryWarpProps {
/** Colour of the digits and the hottest light. */
light?: string;
/** Colour of the silver tunnel walls. */
silver?: string;
/** Background, deep in the tunnel. */
background?: string;
/** Number of digits in flight. */
digits?: number;
/** Speed of the flight. */
speed?: number;
/** Brightness of the tunnel walls. */
intensity?: number;
/** Strength of the soft bloom. */
glow?: number;
/** Cursor steering, click warp. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the tunnel. */
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); }`;
// the tunnel: swirling liquid-silver walls, shards of shadow, a bright ring, a dark heart
const TUNNEL = `
precision highp float;
uniform vec2 uRes, uC;
uniform float uTime, uFlow, uIn, uFlash, uIntensity, uZoom;
uniform vec3 uLight, uSilver, uBg;
varying vec2 vUv;
const float PI = 3.14159265;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(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, 0.0)), f.x), mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x), f.y);
}
// noise that wraps around the tunnel (period 1 in x)
float wnoise(vec2 p, float per) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
vec2 i1 = vec2(mod(i.x + 1.0, per), i.y);
vec2 i0 = vec2(mod(i.x, per), i.y);
return mix(mix(hash(i0), hash(i1), f.x), mix(hash(i0 + vec2(0.0, 1.0)), hash(i1 + vec2(0.0, 1.0)), f.x), f.y);
}
float wfbm(vec2 p, float per) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 5; i++) { v += a * wnoise(p, per); p = p * 2.0 + vec2(0.0, 7.3); per *= 2.0; a *= 0.5; }
return v;
}
void main() {
vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
vec2 d = (p - uC) / uZoom;
float r = length(d);
float a = atan(d.y, d.x) / (2.0 * PI) + 0.5; // 0..1 around the tunnel
float depth = log(max(r, 1e-4));
float t = uTime;
// the walls: liquid silver swirling as it streams past, with sharp metallic highlights
float per = 9.0;
vec2 q = vec2(a * per + depth * 1.3, depth * 2.2 - uFlow * 0.55);
// every noise that wraps around the tunnel keeps a whole-number period, so there is no seam
float w = wfbm(q + vec2(wfbm(vec2(q.x, q.y * 0.7) + vec2(0.0, t * 0.05), per) * 1.6, 0.0), per);
float w2 = wfbm(vec2(q.x * 2.0, q.y * 1.6) + vec2(w * 1.2, 3.1), per * 2.0);
float ridge = 1.0 - abs(w * 2.0 - 1.0);
float ridge2 = 1.0 - abs(w2 * 2.0 - 1.0);
// polished chrome: cool blue-steel bands and warmer beige ones, deep darks between, sharp highlights
float band = smoothstep(0.42, 0.68, wfbm(vec2(q.x, q.y * 0.5) + vec2(0.0, 9.1), per));
vec3 steel = mix(uSilver * vec3(0.9, 1.0, 1.2), uSilver * vec3(1.18, 1.06, 0.86), band);
vec3 col = steel * (0.22 + 0.85 * smoothstep(0.38, 0.9, w));
col += uLight * (pow(ridge, 8.0) * 0.6 * smoothstep(0.3, 0.7, w) + pow(ridge2, 14.0) * 0.45);
// shards of shadow radiating from the centre, and a few light streaks between them
float shard = wnoise(vec2(a * 46.0, depth * 0.35 - uFlow * 0.08), 46.0);
col *= mix(1.0, 0.03, smoothstep(0.58, 0.78, shard));
float streak = wnoise(vec2(a * 70.0, depth * 0.8 - uFlow * 0.3), 70.0);
col += uLight * smoothstep(0.86, 0.98, streak) * 0.22 * smoothstep(0.12, 0.3, r);
// the bright ring around the dark heart, cloudy and alive
// the bright cloudy ring around the dark heart
float cloud = wfbm(vec2(a * 9.0, t * 0.15 + depth * 3.0), 9.0);
float ring = exp(-pow((r - 0.24) / 0.07, 2.0)) * pow(0.25 + cloud, 2.0);
col += uLight * ring * 0.85;
// a flash of light rolling down the tunnel after a warp
col += uLight * uFlash * exp(-pow(depth - mix(-2.6, 0.6, 1.0 - uFlash), 2.0) * 6.0) * 0.8;
// contrast like polished chrome: deep darks, bright ridges
col = col * col * 1.5;
// overall brightness: brightest at the ring, holding silver toward the edges
col *= 0.75 + 0.3 * exp(-pow((r - 0.28) / 0.3, 2.0));
// walls sit in the mid-tones so the white digits and ring stand out above them
col *= uIntensity * 0.46;
// the dark heart of the tunnel
float heart = smoothstep(0.1, 0.2, r);
col = mix(uBg, col, heart);
col *= uIn;
gl_FragColor = vec4(col, 1.0);
}`;
// digits: upright billboards drawn from a 0|1 atlas
const DIGIT_VERT = `
attribute vec4 aD; // x, y (px), size (px), alpha
attribute float aG; // 0 or 1
uniform vec2 uRes;
uniform float uDpr, uSizeMul;
varying float vA, vG, vS;
void main() {
vA = aD.w;
vS = aD.z;
vG = aG;
gl_PointSize = aD.z * uDpr * uSizeMul;
vec2 clip = aD.xy / uRes * 2.0 - 1.0;
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
}`;
const DIGIT_FRAG = `
precision mediump float;
uniform sampler2D uGlyphs;
uniform vec3 uLight;
uniform float uHalo;
varying float vA, vG, vS;
void main() {
vec2 uv = vec2((vG + gl_PointCoord.x) * 0.5, gl_PointCoord.y);
// the halo pass samples a blurred mip of the glyph: a soft luminous aura behind each digit
float g = uHalo > 0.5 ? texture2D(uGlyphs, uv, 3.5).r : texture2D(uGlyphs, uv).r;
// full-strength white so the digits catch the bloom and glow
// only the big, near digits carry a halo, and a faint one: many small halos would fog the tunnel
float a = uHalo > 0.5 ? g * vA * 0.16 * smoothstep(18.0, 90.0, vS) : clamp(g * vA * 1.5, 0.0, 1.0);
gl_FragColor = vec4(uLight * a, a);
}`;
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.8, 1.0, 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 * 1.2 + texture2D(uWide, vUv).rgb * 0.35;
// linear up to full white, a soft roll-off only above it: white digits stay white
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.35 * 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];
}
/** Two glyphs drawn as clean strokes (a ring and a bar), so they look the same on every device. */
function glyphAtlas() {
const c = document.createElement("canvas");
c.width = 512;
c.height = 256;
const x = c.getContext("2d")!;
x.fillStyle = "#000";
x.fillRect(0, 0, 512, 256);
x.strokeStyle = "#fff";
x.lineCap = "round";
x.lineJoin = "round";
x.lineWidth = 34;
// 0: a tall glowing ring
x.beginPath();
x.ellipse(128, 128, 50, 84, 0, 0, Math.PI * 2);
x.stroke();
// 1: a bar with a small flag
x.beginPath();
x.moveTo(350, 78);
x.lineTo(392, 46);
x.lineTo(392, 212);
x.stroke();
return c;
}
export function BinaryWarp({
light = "#e9f4fa",
silver = "#7d8798",
background = "#000000",
digits = 480,
speed = 1,
intensity = 1,
glow = 1,
interactive = true,
scroller,
children,
className,
}: BinaryWarpProps) {
const hostRef = useRef<HTMLDivElement>(null);
const viewRef = useRef<HTMLDivElement>(null);
const props = useRef({ light, silver, background, digits, speed, intensity, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { light, silver, background, digits, speed, intensity, glow, interactive };
redraw.current?.();
}, [light, silver, background, digits, speed, intensity, glow, interactive]);
useEffect(() => {
const host = hostRef.current;
const view = viewRef.current;
if (!host || !view) 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;";
view.prepend(canvas);
const gl = canvas.getContext("webgl", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
view.style.background = `radial-gradient(circle at 47% 55%, #000 6%, ${props.current.light} 16%, ${props.current.silver} 40%, #111 90%)`;
canvas.remove();
return;
}
const build = (vs: string, fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, vs],
[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 tunnelProg = build(QUAD, TUNNEL);
const digitProg = build(DIGIT_VERT, DIGIT_FRAG);
const blurProg = build(QUAD, BLUR);
const brightProg = build(QUAD, BRIGHT);
const compProg = build(QUAD, COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const UT = uni(tunnelProg, ["uRes", "uC", "uTime", "uFlow", "uIn", "uFlash", "uIntensity", "uZoom", "uLight", "uSilver", "uBg"]);
const UD = uni(digitProg, ["uRes", "uDpr", "uGlyphs", "uLight", "uHalo", "uSizeMul"]);
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);
};
const glyphs = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, glyphs);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, glyphAtlas());
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_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);
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.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
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);
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 = () => {
const vh = scroller ? scroller.clientHeight : window.innerHeight;
host.style.setProperty("--bw-view", `${vh}px`);
dpr = Math.min(window.devicePixelRatio || 1, 2);
w = Math.max(1, view.clientWidth);
h = Math.max(1, view.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();
// ---- the digits in flight: angle, radius, depth, glyph ----
const MAX = 1400;
const da = new Float32Array(MAX), dr = new Float32Array(MAX), dz = new Float32Array(MAX), dg = new Float32Array(MAX), dj = new Float32Array(MAX);
const spawn = (i: number, anywhere: boolean) => {
// digits stream along rays out of the centre, like data lines
da[i] = ((Math.floor(Math.random() * 56) + 0.5 + (Math.random() - 0.5) * 0.3) / 56) * Math.PI * 2;
dr[i] = 0.7 + Math.random() * 1.7;
dz[i] = anywhere ? 0.4 + Math.random() * 7 : 6.5 + Math.random() * 1.5;
dg[i] = Math.random() < 0.5 ? 0 : 1;
dj[i] = 0;
};
for (let i = 0; i < MAX; i++) spawn(i, true);
const dBuf = gl.createBuffer();
const gBuf = gl.createBuffer();
const out = new Float32Array(MAX * 4);
// ---- state: every value moved by GSAP ----
const s = { in: still ? 1 : 0, boost: still ? 0 : 7, flash: 0, cx: 0, cy: 0, mx: -1e4, my: -1e4, hover: 0, zoom: 1, fly: 1 };
let time = 0, flow = 0;
const base = () => ({ x: (-0.03 * h) / h, y: -0.05 });
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 step = (dt: number) => {
const p = props.current;
const v = dt * p.speed * (0.55 + s.boost) * 1.4;
for (let i = 0; i < MAX; i++) {
dz[i] -= v;
if (dz[i] < 0.28) spawn(i, false);
dj[i] *= Math.exp(-dt * 2.5);
}
};
const draw = () => {
const p = props.current;
const X = T!;
const c = base();
const C = { x: c.x + s.cx, y: c.y + s.cy };
const zoom = s.zoom * s.fly;
// 1. the tunnel
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.disable(gl.BLEND);
gl.useProgram(tunnelProg);
gl.uniform2f(UT.uRes, X.scene.w, X.scene.h);
gl.uniform2f(UT.uC, C.x, C.y);
gl.uniform1f(UT.uTime, time);
gl.uniform1f(UT.uFlow, flow);
gl.uniform1f(UT.uIn, s.in);
gl.uniform1f(UT.uFlash, s.flash);
gl.uniform1f(UT.uIntensity, p.intensity);
gl.uniform1f(UT.uZoom, zoom);
gl.uniform3fv(UT.uLight, rgb(p.light));
gl.uniform3fv(UT.uSilver, rgb(p.silver));
gl.uniform3fv(UT.uBg, rgb(p.background));
drawQuad(tunnelProg);
// 2. the digits, far ones first so near ones sit on top
const n = Math.min(MAX, Math.max(0, Math.round(p.digits)));
const cxp = w / 2 + C.x * h, cyp = h / 2 - C.y * h;
const scaleR = h * 0.42 * zoom;
let k = 0;
const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => dz[b] - dz[a]);
const gl1 = new Float32Array(n);
for (const i of order) {
const z = dz[i];
let x = cxp + Math.cos(da[i]) * (dr[i] * scaleR) / z;
let y = cyp - Math.sin(da[i]) * (dr[i] * scaleR) / z;
// digits near the cursor scatter away from it
const ddx = x - s.mx, ddy = y - s.my;
const dd = Math.hypot(ddx, ddy);
const reach = h * 0.18;
if (dd < reach && s.hover > 0) {
const f = (1 - dd / reach) ** 2 * s.hover;
dj[i] = Math.max(dj[i], f);
}
if (dj[i] > 0.001 && dd > 0) {
x += (ddx / dd) * dj[i] * h * 0.06;
y += (ddy / dd) * dj[i] * h * 0.06;
}
const size = Math.min(480, (h * 0.15 * zoom) / z);
const fadeIn = Math.min(1, (8 - z) / 1.5);
const fadeOut = Math.min(1, (z - 0.28) / 0.25);
// digits glow white; they fade out over the dark heart so it stays black
const rr = Math.hypot(x - cxp, y - cyp) / (h * zoom);
const clearHeart = Math.min(1, Math.max(0, (rr - 0.13) / 0.08));
out.set([x, y, size, Math.max(0, fadeIn * fadeOut) * Math.min(1, 0.6 + 2.5 / z) * clearHeart * s.in], k * 4);
gl1[k] = dg[i];
k++;
}
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
gl.useProgram(digitProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, glyphs);
gl.uniform1i(UD.uGlyphs, 0);
gl.uniform2f(UD.uRes, w, h);
gl.uniform1f(UD.uDpr, dpr * (X.scene.w / canvas.width));
gl.uniform3fv(UD.uLight, rgb(p.light));
const aD = gl.getAttribLocation(digitProg, "aD");
const aG = gl.getAttribLocation(digitProg, "aG");
gl.bindBuffer(gl.ARRAY_BUFFER, dBuf);
gl.bufferData(gl.ARRAY_BUFFER, out.subarray(0, k * 4), gl.DYNAMIC_DRAW);
gl.enableVertexAttribArray(aD);
gl.vertexAttribPointer(aD, 4, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, gBuf);
gl.bufferData(gl.ARRAY_BUFFER, gl1, gl.DYNAMIC_DRAW);
gl.enableVertexAttribArray(aG);
gl.vertexAttribPointer(aG, 1, gl.FLOAT, false, 0, 0);
// halo first (additive, 1.9x larger, blurred), then the crisp digit on top
gl.blendFunc(gl.ONE, gl.ONE);
gl.uniform1f(UD.uHalo, 1);
gl.uniform1f(UD.uSizeMul, 1.6);
gl.drawArrays(gl.POINTS, 0, k);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
gl.uniform1f(UD.uHalo, 0);
gl.uniform1f(UD.uSizeMul, 1);
gl.drawArrays(gl.POINTS, 0, k);
gl.disableVertexAttribArray(aD);
gl.disableVertexAttribArray(aG);
gl.disable(gl.BLEND);
// 3. bloom from the brightest light
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.b, 1.6, 0);
blurPass(X.b, X.a, 0, 1.6);
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);
// 4. composite
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();
if (still) draw();
});
ro.observe(host);
ro.observe(view);
if (scroller) ro.observe(scroller);
if (still) {
flow = 3;
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
gl.deleteTexture(glyphs);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: drop out of warp into the tunnel ----
const intro = gsap
.timeline({ delay: 0.05 })
.to(s, { in: 1, duration: 1.4, ease: "power2.out" }, 0)
.to(s, { boost: 0, duration: 2.6, ease: "expo.out" }, 0)
.fromTo(s, { flash: 1 }, { flash: 0, duration: 1.8, ease: "power2.out" }, 0.2);
// ---- cursor: steer the flight, scatter the digits ----
const cxTo = gsap.quickTo(s, "cx", { duration: 1.6, ease: "power3" });
const cyTo = gsap.quickTo(s, "cy", { duration: 1.6, ease: "power3" });
const mxTo = gsap.quickTo(s, "mx", { duration: 0.3, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.3, ease: "power3" });
const local = (e: PointerEvent) => {
const r = view.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
if (s.mx < -1e3) gsap.set(s, { mx: p.x, my: p.y });
mxTo(p.x);
myTo(p.y);
// the vanishing point leans toward the cursor: you steer
cxTo(((p.x - w / 2) / h) * 0.22);
cyTo((-(p.y - h / 2) / h) * 0.22);
};
const enter = () => {
if (props.current.interactive) gsap.to(s, { hover: 1, duration: 0.6, ease: "power2.out", overwrite: "auto" });
};
const leave = () => {
gsap.to(s, { hover: 0, duration: 0.8, ease: "power2.out", overwrite: "auto" });
cxTo(0);
cyTo(0);
};
// a click punches into warp
const down = () => {
if (!props.current.interactive) return;
gsap.fromTo(s, { boost: 6 }, { boost: 0, duration: 2.2, ease: "power3.out", overwrite: "auto" });
gsap.fromTo(s, { flash: 1 }, { flash: 0, duration: 1.4, ease: "power2.out", overwrite: false });
};
view.addEventListener("pointermove", move);
view.addEventListener("pointerenter", enter);
view.addEventListener("pointerleave", leave);
view.addEventListener("pointerdown", down);
// ---- scroll: the view pins and you fly deeper, faster with your scroll speed ----
const flyTo = gsap.quickTo(s, "fly", { duration: 1.2, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top top",
end: () => `+=${Math.max(host.offsetHeight - view.offsetHeight, view.offsetHeight * 0.8)}`,
invalidateOnRefresh: true,
onUpdate: (self) => {
flyTo(1 + self.progress * 1.6);
const v = Math.abs(self.getVelocity()) / 1500;
if (v > s.boost) gsap.to(s, { boost: Math.min(4, v), duration: 0.2, overwrite: "auto", onComplete: () => void gsap.to(s, { boost: 0, duration: 1.2, ease: "power2.out" }) });
},
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const tick = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
const sp = props.current.speed;
time += dt * sp;
flow += dt * sp * (0.6 + s.boost * 1.2);
step(dt);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(tick);
return () => {
gsap.ticker.remove(tick);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
view.removeEventListener("pointermove", move);
view.removeEventListener("pointerenter", enter);
view.removeEventListener("pointerleave", leave);
view.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(glyphs);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate", className].filter(Boolean).join(" ")} style={{ background }}>
<div ref={viewRef} className="sticky top-0 h-[var(--bw-view,100vh)] max-h-full touch-pan-y overflow-hidden">
{children && <div className="relative z-10 h-full">{children}</div>}
</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
11 propslightstringColour of the digits and the hottest light.default "#e9f4fa"default "#e9f4fa"silverstringColour of the silver tunnel walls.default "#7d8798"default "#7d8798"backgroundstringBackground, deep in the tunnel.default "#000000"default "#000000"digitsnumberNumber of digits in flight.default 480default 480speednumberSpeed of the flight.default 1default 1intensitynumberBrightness of the tunnel walls.default 1default 1glownumberStrength of the soft bloom.default 1default 1interactivebooleanCursor steering and click warp.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, pinned above the tunnel.classNamestringMake it taller than the screen, e.g. h-[220vh] w-full: the view pins and scrolling flies you deeper.