Bit Tunnel
Fly down a spinning tunnel walled with neon ones and zeros. Thousands of hollow neon digits in cyan, blue, violet and pink line the walls of a helical tunnel that spins as you fly, its rings packing tighter and tighter toward a black heart. Every digit keeps its true shape at every size (they sit on a conformal, log-polar grid), the bits flip as they pass, the inner rings streak with the spin, and the nearest digits melt into soft, out-of-focus light. It moves like flight, with momentum and no springs: scrolling is thrust, so keep scrolling and you keep flying deeper, the digits streaking past, then you coast back to a cruise. The cursor steers the tunnel's vanishing point, and a click flares a big electric-blue digit right in front of you with a surge of speed; now and then one flares on its own.
Tweak
LIVELIVENeon
Tunnel
Flight
Interactive
Scroll to fly, steer with the cursor, click to flare a digit
Usage
Follows your tweaks.
import { BitTunnel } from "@/components/inreact/bit-tunnel";
export function Hero() {
return (
<BitTunnel
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the tunnel */}
</BitTunnel>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/bit-tunnel.jsonOr copy the source
Install the dependencies, then save this as components/inreact/bit-tunnel.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);
/**
* Bit Tunnel: fly down a spinning tunnel walled with neon ones and zeros.
*
* Thousands of hollow neon digits in cyan, blue, violet and pink line the
* walls of a helical tunnel that spins as you fly, its rings packing tighter
* and tighter toward a black heart. Every digit keeps its true shape at every
* size (they sit on a conformal, log-polar grid), the bits flip as they pass,
* the inner rings streak with the spin, and the nearest digits melt into soft,
* out-of-focus light.
*
* It moves like flight, with momentum and no springs: scrolling is thrust, so
* keep scrolling and you keep flying deeper, the digits streaking past; stop
* and you coast back to a cruise. The cursor steers the tunnel's vanishing
* point, and a click flares a big electric-blue digit right in front of you
* with a surge of speed (now and then one flares on its own).
*
* <BitTunnel className="h-screen w-full">
* <YourHero />
* </BitTunnel>
*
* WebGL2: the digits are drawn once into a small glyph atlas and laid out by
* one shader, with a real bloom (1/4 and 1/16 size) for the neon. Pauses
* off-screen; reduced motion shows a still frame; a CSS gradient without
* WebGL2.
*/
export interface BitTunnelProps {
/** Neon colours of the digits. */
cyan?: string;
blue?: string;
violet?: string;
pink?: string;
/** Colour of the big flaring digits. */
flare?: string;
/** Background colour. */
background?: string;
/** Digits around each ring (more = smaller digits). */
density?: number;
/** How tightly the tunnel twists. */
twist?: number;
/** Speed of the idle cruise and spin. */
speed?: number;
/** How hard scrolling thrusts you deeper. */
thrust?: number;
/** Strength of the neon bloom. */
glow?: number;
/** Steer, click flare, scroll flight. */
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 MAXF = 4; // flaring digits at once
const CELL = 128; // glyph cell in the atlas, px
const QUAD = `#version 300 es
in vec2 aQ; out vec2 vUv;
void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `#version 300 es
precision highp float;
uniform sampler2D uAtlas;
uniform vec2 uRes, uVp; // css px; vanishing point
uniform float uDpr, uN, uTwist, uTravel, uSpin, uSpeed, uSpinV, uTime, uIntro;
uniform vec3 uC1, uC2, uC3, uC4, uFlareC, uBg;
uniform vec4 uFlare[${MAXF}]; // x, y, size (css px), start time
uniform float uFlareChar[${MAXF}];
in vec2 vUv;
out vec4 o;
const float TAU = 6.2831853;
float h21(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
// one digit (0 or 1) from the atlas; lc in 0..1 within its cell, y up
float glyph(float ch, vec2 lc, float lod) {
if (lc.x < 0.0 || lc.x > 1.0 || lc.y < 0.0 || lc.y > 1.0) return 0.0;
return textureLod(uAtlas, vec2((ch + lc.x) * 0.5, 1.0 - lc.y), lod).r;
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float minD = min(uRes.x, uRes.y);
vec2 d = p - uVp;
float r = max(length(d), 1.0);
float rn = r / minD;
float ang = atan(d.y, d.x);
// conformal tunnel coordinates: around the ring (u) and along its depth (v); equal steps keep glyphs true
float N = uN;
// digits pack along each ring like a line of text (narrow cells around, rows spaced by their height)
float v0 = log(rn) * N / TAU;
float u0 = ang / TAU * N * 1.75;
// the cell size on screen, for detail level and focus
float cellPx = r * TAU / N * uDpr; // row height on screen
float lodBase = log2(${CELL}.0 / max(cellPx, 1.0));
// near digits (the outer edge) go soft, as if out of focus
float focus = smoothstep(0.42, 1.1, rn) * 2.2;
vec3 col = vec3(0.0);
// the inner rings streak with the spin, as the eye sees fast rotation near the heart
float spinStreak = uSpinV + 1.6 * (1.0 - smoothstep(0.07, 0.3, rn));
// streaks: a few taps along the spin (around the ring) and the flight (along the depth)
for (int k = 0; k < 4; k++) {
float t = (float(k) + 0.5) / 4.0 - 0.5; // evenly spaced taps: a clean streak, no noise
float u = u0 + uSpin * 1.75 + v0 * uTwist + t * spinStreak;
float v = v0 - uTravel + t * uSpeed;
vec2 id = floor(vec2(u, v));
vec2 f = fract(vec2(u, v));
vec2 cid = vec2(mod(id.x, floor(N * 1.75)), id.y);
float hh = h21(cid + 3.1);
// gaps in the wall, denser in the middle depths
float dens = 0.75;
if (hh > dens) continue;
// the bits flip as they pass
float flip = floor(uTime * (0.4 + 1.6 * h21(cid + 9.4)) + h21(cid + 1.7) * 10.0);
float ch = step(0.5, h21(cid + flip * 0.137));
// the glyph within its cell, a little inset, upright along the ring (top facing out)
vec2 lc = (f - 0.5) / vec2(1.0, 0.8) + 0.5;
float ink = glyph(ch, lc, lodBase + focus);
// neon colour: mostly cyan and blue, some violet and pink
float hc = h21(cid + 5.5);
vec3 c = hc < 0.36 ? uC1 : (hc < 0.68 ? uC2 : (hc < 0.84 ? uC3 : uC4));
float twinkle = 0.75 + 0.5 * h21(cid + flip * 0.31);
col += c * ink * twinkle;
}
col /= 4.0;
// light falls off toward the black heart and dims gently toward the near edge
float heart = smoothstep(0.035, 0.16, rn);
float band = 1.2 * exp(-pow((rn - 0.2) / 0.17, 2.0)) + 0.4;
col *= heart * band * 1.65;
// big flaring digits in front of you
for (int i = 0; i < ${MAXF}; i++) {
vec4 F = uFlare[i];
if (F.z <= 0.0) continue;
float age = uTime - F.w;
if (age < 0.0 || age > 1.6) continue;
float life = smoothstep(0.0, 0.18, age) * smoothstep(1.6, 0.7, age);
float sz = F.z * (1.0 + age * 0.35); // it drifts toward you as it fades
vec2 lc = (p - F.xy) / sz + 0.5;
lc.y = 1.0 - lc.y;
float g = glyph(uFlareChar[i], lc, log2(${CELL}.0 / (sz * uDpr)) + 0.3);
float halo = glyph(uFlareChar[i], lc, log2(${CELL}.0 / (sz * uDpr)) + 3.0);
col += uFlareC * (g * 0.85 + halo * 0.55) * life;
}
// on load the tunnel lights up from its heart outward
col *= smoothstep(0.0, 0.25, uIntro) * smoothstep(rn - 0.1, rn + 0.15, uIntro * 1.4);
o = vec4(uBg + col, 1.0);
}`;
const BLUR = `#version 300 es
precision mediump float;
uniform sampler2D uTex; uniform vec2 uStep; in vec2 vUv; out vec4 o;
void main() {
vec4 c = texture(uTex, vUv) * 0.2270;
c += (texture(uTex, vUv + uStep * 1.3846) + texture(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture(uTex, vUv + uStep * 3.2308) + texture(uTex, vUv - uStep * 3.2308)) * 0.0703;
o = c;
}`;
const BRIGHT = `#version 300 es
precision mediump float;
uniform sampler2D uTex; in vec2 vUv; out vec4 o;
void main() {
vec3 c = texture(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
o = vec4(c * smoothstep(0.25, 0.8, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision highp float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow;
in vec2 vUv; out vec4 o;
float h(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.9 + texture(uWide, vUv).rgb * 0.45;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.85, 0.0) * 0.9);
col += (h(gl_FragCoord.xy) - 0.5) / 255.0;
o = vec4(clamp(col, 0.0, 1.0), 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 BitTunnel({
cyan = "#4fd8ff",
blue = "#4a6bff",
violet = "#a46bff",
pink = "#ff5fb4",
flare = "#5f86ff",
background = "#000000",
density = 1,
twist = 0.12,
speed = 1,
thrust = 1,
glow = 0.75,
interactive = true,
scroller,
children,
className,
}: BitTunnelProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ cyan, blue, violet, pink, flare, background, density, twist, speed, thrust, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { cyan, blue, violet, pink, flare, background, density, twist, speed, thrust, glow, interactive };
redraw.current?.();
}, [cyan, blue, violet, pink, flare, background, density, twist, speed, thrust, glow, 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("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(circle at 45% 47%, ${p.background} 0 6%, ${p.blue}55 16%, ${p.pink}33 32%, ${p.background} 70%)`;
canvas.remove();
return;
}
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.bindAttribLocation(pr, 0, "aQ");
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, [
"uAtlas", "uRes", "uVp", "uDpr", "uN", "uTwist", "uTravel", "uSpin", "uSpeed", "uSpinV", "uTime", "uIntro",
"uC1", "uC2", "uC3", "uC4", "uFlareC", "uBg", "uFlare", "uFlareChar",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow"]);
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
const vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const drawQuad = () => gl.drawArrays(gl.TRIANGLES, 0, 3);
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 t of Object.values(T)) {
gl.deleteFramebuffer(t.fb);
gl.deleteTexture(t.tex);
}
T = null;
};
// ---- the glyph atlas: a hollow neon 0 and 1 ----
const atlasTex = gl.createTexture()!;
const buildAtlas = () => {
const c = document.createElement("canvas");
c.width = CELL * 2;
c.height = CELL;
const ctx = c.getContext("2d")!;
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, c.width, c.height);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `500 ${Math.round(CELL * 0.86)}px 'Helvetica Neue', 'Avenir Next', Arial, sans-serif`;
["0", "1"].forEach((ch, i) => {
const x = i * CELL + CELL / 2, y = CELL / 2 + CELL * 0.04;
// a neon tube: a bright stroked outline with a faint fill inside
ctx.globalAlpha = 0.16;
ctx.fillStyle = "#fff";
ctx.fillText(ch, x, y);
ctx.globalAlpha = 1;
ctx.strokeStyle = "#fff";
ctx.lineWidth = CELL * 0.055;
ctx.lineJoin = "round";
ctx.strokeText(ch, x, y);
});
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
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);
};
buildAtlas();
let disposed = false;
document.fonts?.ready.then(() => {
if (disposed) return;
buildAtlas();
draw();
});
let w = 1, h = 1, dpr = 1, rs = 1;
const resize = () => {
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 = Math.max(1, Math.round(canvas.width * rs)), sh = Math.max(1, Math.round(canvas.height * rs));
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();
// ---- flight: momentum, no springs ----
const s = { intro: still ? 1 : 0 };
let flow = 0;
let travel = 0, vel = still ? 0 : 6; // rings per second; on load you arrive at speed
let spin = 0;
let vpx = 0, vpy = 0, vpTX = 0, vpTY = 0; // vanishing point offset (steering)
let lastST = 0;
const flares: { x: number; y: number; size: number; t: number; ch: number }[] = [];
const flareBuf = new Float32Array(MAXF * 4);
const flareChars = new Float32Array(MAXF);
let nextFlare = 2.5;
const cruise = () => 0.55 * Math.max(0, props.current.speed);
const MAXV = 14;
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();
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
const N = Math.round(100 * Math.max(0.4, Math.min(2.5, p.density)));
const speedOver = Math.max(0, vel - cruise());
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.uniform1i(US.uAtlas, 0);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uVp, w * 0.47 + vpx, h * 0.47 + vpy);
gl.uniform1f(US.uDpr, dpr * (X.scene.w / canvas.width));
gl.uniform1f(US.uN, N);
gl.uniform1f(US.uTwist, p.twist);
gl.uniform1f(US.uTravel, travel);
gl.uniform1f(US.uSpin, spin);
// streak lengths in cells: along the depth from the flight speed, around the ring from the spin
gl.uniform1f(US.uSpeed, Math.min(2.5, speedOver * 0.08));
gl.uniform1f(US.uSpinV, 0.04 + Math.min(1.5, speedOver * 0.04));
gl.uniform1f(US.uTime, flow);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform3fv(US.uC1, rgb(p.cyan));
gl.uniform3fv(US.uC2, rgb(p.blue));
gl.uniform3fv(US.uC3, rgb(p.violet));
gl.uniform3fv(US.uC4, rgb(p.pink));
gl.uniform3fv(US.uFlareC, rgb(p.flare));
gl.uniform3fv(US.uBg, rgb(p.background));
flareBuf.fill(0);
flareChars.fill(0);
flares.forEach((f, i) => {
flareBuf.set([f.x, f.y, f.size, f.t], i * 4);
flareChars[i] = f.ch;
});
gl.uniform4fv(US.uFlare, flareBuf);
gl.uniform1fv(US.uFlareChar, flareChars);
drawQuad();
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();
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, Math.max(0, p.glow));
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
const thrustBy = (dv: number) => {
vel = Math.max(-MAXV, Math.min(MAXV, vel + dv));
};
const flareAt = (x: number, y: number) => {
const minD = Math.min(w, h);
flares.push({ x, y, size: minD * (0.1 + Math.random() * 0.06), t: flow, ch: Math.random() < 0.5 ? 0 : 1 });
while (flares.length > MAXF) flares.shift();
};
// ---- cursor steers the vanishing point ----
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const move = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const p = local(e);
vpTX = (p.x / w - 0.5) * w * 0.18;
vpTY = (p.y / h - 0.5) * h * 0.18;
};
const leave = () => {
vpTX = 0;
vpTY = 0;
};
// ---- click: a big digit flares in front of you, with a surge ----
const down = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const p = local(e);
flareAt(p.x, p.y);
thrustBy(4 * Math.max(0, props.current.thrust));
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll is thrust: keep scrolling to keep flying deeper ----
let lastScroll = 0;
const st = still
? null
: ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
const y = self.scroll();
const dy = y - lastScroll;
lastScroll = y;
lastST = performance.now();
if (!props.current.interactive || Math.abs(dy) > 2000) return;
thrustBy(dy * 0.006 * Math.max(0, props.current.thrust));
},
});
if (st) lastScroll = st.scroll();
const wheel = (e: WheelEvent) => {
if (still || !props.current.interactive) return;
if (performance.now() - lastST < 80) return;
const dy = e.deltaMode === 1 ? e.deltaY * 16 : e.deltaY;
thrustBy(Math.max(-200, Math.min(200, dy)) * 0.006 * Math.max(0, props.current.thrust));
};
host.addEventListener("wheel", wheel, { passive: true });
// ---- loop ----
let visible = true;
let prev = performance.now();
let slow = 0;
let intro: gsap.core.Tween | null = null;
const tick = () => {
const t = performance.now();
const rawDt = (t - prev) / 1000;
const dt = Math.min(0.05, rawDt);
prev = t;
if (!visible) return;
flow += dt;
vel += (cruise() - vel) * (1 - Math.exp(-dt * 0.7));
travel += vel * dt;
if (travel > 1e5 || travel < -1e5) travel = 0;
spin += (0.6 * Math.max(0, props.current.speed) + Math.abs(vel) * 0.15) * dt;
const k = 1 - Math.exp(-dt * 2.5);
vpx += (vpTX - vpx) * k;
vpy += (vpTY - vpy) * k;
// now and then a digit flares on its own
if (flow > nextFlare) {
const minD = Math.min(w, h);
const a = Math.random() * Math.PI * 2, rr = minD * (0.22 + Math.random() * 0.12);
flareAt(w * 0.47 + Math.cos(a) * rr, h * 0.47 + Math.sin(a) * rr);
nextFlare = flow + 5 + Math.random() * 4;
}
for (let i = flares.length - 1; i >= 0; i--) if (flow - flares[i].t > 1.7) flares.splice(i, 1);
slow = slow * 0.97 + (rawDt > 1 / 45 ? 0.03 : 0);
if (slow > 0.5 && rs === 1) {
rs = 0.8;
resize();
}
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
if (still) {
draw();
redraw.current = draw;
} else {
intro = gsap.to(s, { intro: 1, duration: 2.2, ease: "power2.out", delay: 0.05 });
io.observe(host);
gsap.ticker.add(tick);
}
return () => {
disposed = true;
redraw.current = null;
gsap.ticker.remove(tick);
intro?.kill();
st?.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
host.removeEventListener("wheel", wheel);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(atlasTex);
gl.deleteProgram(sceneProg);
gl.deleteProgram(blurProg);
gl.deleteProgram(brightProg);
gl.deleteProgram(compProg);
gl.deleteBuffer(vbo);
gl.deleteVertexArray(vao);
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>
);
}
export default BitTunnel;
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
15 propscyanstringNeon colour of the digits.default "#4fd8ff"default "#4fd8ff"bluestringNeon colour of the digits.default "#4a6bff"default "#4a6bff"violetstringNeon colour of the digits.default "#a46bff"default "#a46bff"pinkstringNeon colour of the digits.default "#ff5fb4"default "#ff5fb4"flarestringColour of the big flaring digits.default "#5f86ff"default "#5f86ff"backgroundstringBackground colour.default "#000000"default "#000000"densitynumberDigits around each ring (more = smaller digits).default 1default 1twistnumberHow tightly the tunnel twists.default 0.12default 0.12speednumberSpeed of the idle cruise and spin.default 1default 1thrustnumberHow hard scrolling thrusts you deeper.default 1default 1glownumberStrength of the neon bloom.default 0.75default 0.75interactivebooleanSteer, click flare, scroll flight.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the tunnel.classNamestringSize it, e.g. h-screen w-full.