Stream Lines
A deep current of fine dashed lines on dark teal, seen with depth. Hundreds of hair-thin columns of dashes flow slowly downward, each at its own pace, with brighter runs drifting along them; the lines fan out toward the top and bottom, and from a crisp centre the dashes soften and smear into long radial streaks toward the edges, like a zoom blur, the focus gliding gently toward your cursor. It moves like a real liquid, smooth and gooey with no springs: the cursor stirs the current and the lines are dragged along with your stroke, swirl, drift downstream and settle back. A click turns a soft swirl into the water, scrolling drives the current (it speeds up with momentum, the dashes stretching into streaks, then eases back), and on load the lines pour in from the top.
Tweak
LIVELIVELines
Current
Interactive
Stir the current with the cursor, click to swirl it, scroll to drive it
Usage
Follows your tweaks.
import { StreamLines } from "@/components/inreact/stream-lines";
export function Hero() {
return (
<StreamLines
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the lines */}
</StreamLines>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/stream-lines.jsonOr copy the source
Install the dependencies, then save this as components/inreact/stream-lines.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);
/**
* Stream Lines: a deep current of fine dashed lines on dark teal.
*
* Hundreds of hair-thin columns of dashes flow slowly downward, each at its own
* pace, with brighter runs drifting along them. The field is seen with depth:
* the lines fan out toward the top and bottom, and from a crisp centre the
* dashes soften and smear into long radial streaks toward the edges, like a
* zoom blur, the focus drifting gently toward the cursor.
*
* It moves like a real liquid, smooth and gooey with no springs: the cursor
* stirs the current (a viscous velocity field: the lines are dragged along
* with your stroke, the stir spreads and fades, and the swirl is carried
* downstream with the flow before it settles), a click turns a soft swirl
* into the water, and scrolling drives the current (it speeds up with
* momentum, the dashes stretching into streaks, then eases back). On load the
* lines pour in from the top.
*
* <StreamLines className="h-screen w-full">
* <YourHero />
* </StreamLines>
*
* WebGL2: one shader draws every line, anti-aliased at one device pixel. Pauses
* off-screen; reduced motion shows a still frame; a CSS line pattern without
* WebGL2.
*/
export interface StreamLinesProps {
/** Colour of the lines. */
color?: string;
/** Colour the lines near the cursor brighten toward. */
highlight?: string;
/** Background colour (it darkens gently toward the corners). */
background?: string;
/** Distance between the lines, css px. */
spacing?: number;
/** Length of one dash and gap, css px. */
dash?: number;
/** Speed of the idle current. */
speed?: number;
/** How much the field bows with the current. */
bend?: number;
/** Depth: how far the lines fan out and how strongly the edges blur into streaks. */
depth?: number;
/** How strongly the cursor stirs the current. */
stir?: number;
/** Strength of the bloom on bright runs. */
glow?: number;
/** Cursor stirs the current, click swirls it, scroll drives it. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the lines. */
children?: ReactNode;
className?: string;
}
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 vec2 uRes, uFocus; // css px
uniform float uDpr, uSp, uDash, uFlow, uStretch, uTime, uBend, uDepth, uIntro;
uniform vec3 uColor, uHi, uBg;
uniform sampler2D uField; // the stirred liquid: xy displacement, zw velocity (css px)
in vec2 vUv;
out vec4 o;
float h11(float x) { return fract(sin(x * 127.1) * 43758.5453); }
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); }
float noise1(float x) { float i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f); return mix(h11(i), h11(i + 1.0), f); }
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float minD = min(uRes.x, uRes.y);
vec2 c = uRes * 0.5;
// the liquid: a smooth (C1) read of the stirred field, so the lines bend without kinks
vec2 gs = vec2(textureSize(uField, 0));
vec2 g = p / uRes * gs - 0.5;
vec2 gf = fract(g);
gf = gf * gf * (3.0 - 2.0 * gf);
vec4 F = texture(uField, (floor(g) + gf + 0.5) / gs);
vec2 ps = p - F.xy;
// depth: the lines fan out toward the top and bottom, the dashes lengthen toward the edges
vec2 q = (ps - c) / minD;
float P = 0.3 * uDepth;
float sx = 1.0 + P * 1.7 * q.y * q.y;
float bow = (sin(q.y * 2.2 + uTime * 0.09) * 0.6 + sin(q.y * 4.1 - uTime * 0.055 + q.x * 1.7) * 0.4) * uBend;
float x = (q.x / sx - bow * 0.018) * minD;
float kk = max(P * 1.6, 1e-3);
float yw = asinh(kk * q.y) / kk * minD / (1.0 + P * 1.3 * q.x * q.x);
// radial blur: crisp around the focus, softening and smearing into streaks toward the edges
float rb = length((p - uFocus) / (0.5 * length(uRes)));
float blur = uDepth * pow(smoothstep(0.12, 1.05, rb), 1.4);
float soft = 1.0 + 0.7 * blur;
// which column, and how far from its hair-thin centre line (in screen px)
float col = floor(x / uSp + 0.5);
float dx = abs(x - col * uSp) * sx;
float px = 1.0 / uDpr;
float line = 1.0 - smoothstep(px * 0.35 * soft, px * 1.15 * soft, dx);
line /= pow(soft, 0.5);
// toward the edges the field thins out: fewer, longer streaks
line *= smoothstep(blur * 0.55 - 0.12, blur * 0.55 + 0.12, h11(col * 3.13 + 0.7));
// dashes flowing down this column, each column at its own pace
float speed = 0.75 + 0.5 * h11(col * 1.37);
float y = yw - uFlow * speed - h11(col * 7.1) * 500.0;
float period = uDash * (0.8 + 0.6 * h11(col * 5.9)) * (1.0 + blur * 4.5);
float cellY = floor(y / period);
float fd = fract(y / period);
float hd = h21(vec2(col, cellY));
float duty = clamp(0.3 + 0.55 * hd + uStretch * 0.5 + blur * 0.55, 0.3, 0.93);
float present = max(step(0.16, h21(vec2(col * 1.7, cellY * 1.3 + 4.0))), max(uStretch, smoothstep(0.35, 0.85, blur)));
float edge = min((0.6 / uDpr + blur * 4.0) / period, duty * 0.45);
float dash = smoothstep(0.0, edge, fd) * (1.0 - smoothstep(duty - edge, duty, fd)) * present;
// bright runs and faint stretches drift along each column; some columns are quieter
float run = noise1(y / (uDash * 6.0) + col * 3.3);
float bright = mix(0.22, 1.25, smoothstep(0.35, 0.85, run)) * (0.55 + 0.45 * h11(col * 4.7));
// an occasional brighter packet travels down a column
float pk = fract(y / (uDash * 90.0) + h11(col * 9.3));
bright += smoothstep(0.985, 1.0, pk) * 1.5 * step(0.6, h11(col * 2.9));
// where the liquid is moving, the lines catch the light
float stir = smoothstep(40.0, 700.0, length(F.zw));
vec3 lc = mix(uColor, uHi, stir * 0.85);
bright *= 1.0 + stir * 0.8;
// on load the lines pour in from the top
float pour = smoothstep(p.y / uRes.y - 0.1, p.y / uRes.y + 0.05, uIntro * 1.15);
// deep teal, darkening gently toward the corners
vec2 vq = (p - c) / (uRes * 0.5);
vec3 bg = uBg * (1.0 - 0.5 * smoothstep(0.3, 1.4, length(vq * vec2(1.0, 0.85))));
vec3 colr = bg + lc * line * dash * bright * pour;
o = vec4(colr, 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.4, 0.9, 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.85 + texture(uWide, vUv).rgb * 0.2;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.9, 0.0));
col += (h(gl_FragCoord.xy) + h(gl_FragCoord.yx + 17.0) - 1.0) / 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 StreamLines({
color = "#7d9799",
highlight = "#bff3f0",
background = "#03161a",
spacing = 8,
dash = 6.5,
speed = 1,
bend = 1.5,
depth = 1,
stir = 1,
glow = 0.45,
interactive = true,
scroller,
children,
className,
}: StreamLinesProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, highlight, background, spacing, dash, speed, bend, depth, stir, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, highlight, background, spacing, dash, speed, bend, depth, stir, glow, interactive };
redraw.current?.();
}, [color, highlight, background, spacing, dash, speed, bend, depth, stir, 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 = `repeating-linear-gradient(90deg, ${p.color}55 0 1px, transparent 1px ${p.spacing}px), ${p.background}`;
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, [
"uRes", "uFocus", "uDpr", "uSp", "uDash", "uFlow", "uStretch", "uTime", "uBend", "uDepth", "uIntro",
"uColor", "uHi", "uBg", "uField",
]);
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;
};
let w = 1, h = 1, dpr = 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);
// the lines are a pixel wide: draw at full resolution so they stay crisp
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)),
};
// the liquid grid: 64 cells across, about square cells
const nx = 64;
const ny = Math.max(8, Math.min(128, Math.round((nx * h) / w)));
if (nx !== GX || ny !== GY) {
GX = nx;
GY = ny;
field = new Float32Array(GX * GY * 4);
tmp = new Float32Array(GX * GY * 4);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, GX, GY, 0, gl.RGBA, gl.FLOAT, field);
}
};
// ---- the stirred liquid: a small viscous velocity field on the CPU (css px, px/s) ----
let GX = 0, GY = 0;
let field = new Float32Array(4);
let tmp = new Float32Array(4);
const fieldTex = gl.createTexture()!;
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
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);
resize();
// ---- the current: velocity with momentum; it eases back to the idle flow (no springs) ----
const s = { intro: still ? 1 : 0 };
let flow = 0, flowV = 0, time = 0;
let lastST = 0;
// pointer: where it is and how fast it moves; the focus drifts toward it
const ptr = { x: 0, y: 0, vx: 0, vy: 0, t: 0, in: false };
let fx = -1, fy = -1, hover = 0;
let fieldLive = false;
const splashes: { x: number; y: number; dir: number; left: number }[] = [];
let spin = 1;
const stepField = (dt: number) => {
const n = GX * GY;
const cw = w / GX, ch = h / GY;
const minD = Math.min(w, h);
const k = Math.max(0, props.current.stir);
// the cursor drags the liquid along with it, like a spoon through water
if (ptr.in && k > 0) {
const sig = 0.17 * minD;
const reach = sig * 2.6;
const pull = 1 - Math.exp(-dt * 3);
const x0 = Math.max(0, Math.floor((ptr.x - reach) / cw)), x1 = Math.min(GX - 1, Math.ceil((ptr.x + reach) / cw));
const y0 = Math.max(0, Math.floor((ptr.y - reach) / ch)), y1 = Math.min(GY - 1, Math.ceil((ptr.y + reach) / ch));
const tvx = ptr.vx * k * 0.45, tvy = ptr.vy * k * 0.45;
for (let j = y0; j <= y1; j++)
for (let i = x0; i <= x1; i++) {
const ddx = (i + 0.5) * cw - ptr.x, ddy = (j + 0.5) * ch - ptr.y;
const wgt = Math.exp(-(ddx * ddx + ddy * ddy) / (sig * sig)) * pull;
const o = (j * GX + i) * 4;
field[o + 2] += (tvx - field[o + 2]) * wgt;
field[o + 3] += (tvy - field[o + 3]) * wgt;
}
}
// a click: a soft swirl, as if a finger turned in the water (rotation opens no gaps, nothing crosses)
for (const sp of splashes) {
const sig = 0.15 * minD;
const share = Math.min(dt, sp.left) / 0.5; // the swirl is turned in over half a second
const amp = 900 * Math.max(0.3, k) * sp.dir * share;
for (let j = 0; j < GY; j++)
for (let i = 0; i < GX; i++) {
const ddx = (i + 0.5) * cw - sp.x, ddy = (j + 0.5) * ch - sp.y;
const wgt = Math.exp(-(ddx * ddx + ddy * ddy) / (sig * sig)) * amp;
const o = (j * GX + i) * 4;
field[o + 2] += (-ddy / sig) * wgt;
field[o + 3] += (ddx / sig) * wgt;
}
}
for (let i = splashes.length - 1; i >= 0; i--) if ((splashes[i].left -= dt) <= 0) splashes.splice(i, 1);
// the swirl is carried downstream with the current (semi-Lagrangian shift)
const shift = Math.max(-GY, Math.min(GY, (flowV * dt) / ch));
// viscosity spreads the stir, drag fades it, and the bent lines settle back
const visc = 1 - Math.exp(-dt * 16);
const fade = Math.exp(-dt * 1.0);
const settle = Math.exp(-dt * 0.7);
const lim = 0.06 * minD;
let live = false;
let peak = 0;
for (let j = 0; j < GY; j++) {
const sy = Math.min(GY - 1, Math.max(0, j - shift));
const ja = Math.floor(sy), jb = Math.min(GY - 1, ja + 1), ft = sy - ja;
for (let i = 0; i < GX; i++) {
const o = (j * GX + i) * 4;
const oa = (ja * GX + i) * 4, ob = (jb * GX + i) * 4;
const il = (j * GX + Math.max(0, i - 1)) * 4, ir = (j * GX + Math.min(GX - 1, i + 1)) * 4;
const iu = (Math.max(0, j - 1) * GX + i) * 4, idn = (Math.min(GY - 1, j + 1) * GX + i) * 4;
for (let c = 0; c < 4; c++) {
const adv = field[oa + c] + (field[ob + c] - field[oa + c]) * ft;
const avg = (field[il + c] + field[ir + c] + field[iu + c] + field[idn + c]) * 0.25;
tmp[o + c] = adv + (avg - adv) * visc * (c < 2 ? 0.6 : 1);
}
}
}
for (let o = 0; o < n * 4; o += 4) {
let vx = tmp[o + 2] * fade, vy = tmp[o + 3] * fade;
const dx = (tmp[o] + vx * dt) * settle, dy = (tmp[o + 1] + vy * dt) * settle;
peak = Math.max(peak, dx * dx + dy * dy);
if (Math.abs(vx) < 0.05) vx = 0;
if (Math.abs(vy) < 0.05) vy = 0;
field[o] = dx;
field[o + 1] = dy;
field[o + 2] = vx;
field[o + 3] = vy;
if (vx !== 0 || vy !== 0 || Math.abs(dx) > 0.01 || Math.abs(dy) > 0.01) live = true;
}
// the bend is limited as a whole, never cell by cell, so it keeps its smooth bell shape
if (peak > lim * lim) {
const sc = lim / Math.sqrt(peak);
for (let o = 0; o < n * 4; o += 4) {
field[o] *= sc;
field[o + 1] *= sc;
}
}
if (live || fieldLive) {
if (!live) field.fill(0);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, GX, GY, gl.RGBA, gl.FLOAT, field);
}
fieldLive = live;
};
const cruise = () => 14 * Math.max(0, props.current.speed); // px per second
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;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uFocus, fx < 0 ? w / 2 : fx, fy < 0 ? h / 2 : fy);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uSp, Math.max(3, p.spacing));
gl.uniform1f(US.uDash, Math.max(2, p.dash));
gl.uniform1f(US.uFlow, flow);
gl.uniform1f(US.uStretch, Math.min(1, Math.max(0, (flowV - cruise()) / 600)));
gl.uniform1f(US.uTime, time);
gl.uniform1f(US.uBend, still ? 0.6 * p.bend : Math.max(0, p.bend));
gl.uniform1f(US.uDepth, Math.max(0, p.depth));
gl.uniform1f(US.uIntro, s.intro);
gl.uniform3fv(US.uColor, rgb(p.color));
gl.uniform3fv(US.uHi, rgb(p.highlight));
gl.uniform3fv(US.uBg, rgb(p.background));
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.uniform1i(US.uField, 0);
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);
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);
// ---- cursor: it stirs the liquid; its speed is what drags the lines ----
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);
const t = performance.now();
if (ptr.in) {
const dt = Math.max(8, t - ptr.t) / 1000;
const cap = 3200;
const vx = Math.max(-cap, Math.min(cap, (p.x - ptr.x) / dt));
const vy = Math.max(-cap, Math.min(cap, (p.y - ptr.y) / dt));
ptr.vx += (vx - ptr.vx) * 0.5;
ptr.vy += (vy - ptr.vy) * 0.5;
} else {
ptr.vx = ptr.vy = 0;
}
ptr.x = p.x;
ptr.y = p.y;
ptr.t = t;
ptr.in = true;
};
const leave = () => {
ptr.in = false;
};
// ---- click: a soft swirl, alternating direction ----
const down = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
spin = -spin;
splashes.push({ ...local(e), dir: spin, left: 0.5 });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll drives the current: it speeds up with momentum, then eases back ----
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;
flowV = Math.max(-700, Math.min(700, flowV + dy * 2.2));
},
});
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;
flowV = Math.max(-700, Math.min(700, flowV + Math.max(-200, Math.min(200, dy)) * 2.2));
};
host.addEventListener("wheel", wheel, { passive: true });
// ---- loop ----
let visible = true;
let prev = performance.now();
let intro: gsap.core.Tween | null = null;
const tick = () => {
const t = performance.now();
const dt = Math.min(0.05, (t - prev) / 1000);
prev = t;
if (!visible) return;
time += dt;
// viscous drag: the current eases back toward its idle flow
flowV += (cruise() - flowV) * (1 - Math.exp(-dt * 0.55));
flow += flowV * dt;
if (flow > 1e6 || flow < -1e6) flow = 0;
// the pointer's speed dies away when it rests; the focus glides toward it (light: smooth, no overshoot)
if (t - ptr.t > 40) {
const calm = Math.exp(-dt * 14);
ptr.vx *= calm;
ptr.vy *= calm;
}
hover += ((ptr.in && props.current.interactive ? 1 : 0) - hover) * (1 - Math.exp(-dt * 1.0));
const ease = 1 - Math.exp(-dt * 0.8);
const tx = w / 2 + (ptr.x - w / 2) * 0.4 * hover, ty = h / 2 + (ptr.y - h / 2) * 0.4 * hover;
fx = fx < 0 ? w / 2 : fx + (tx - fx) * ease;
fy = fy < 0 ? h / 2 : fy + (ty - fy) * ease;
stepField(dt);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
if (still) {
draw();
redraw.current = draw;
} else {
flowV = 200; // the lines pour in, slowly
intro = gsap.to(s, { intro: 1, duration: 3.4, ease: "power2.out", delay: 0.05 });
io.observe(host);
gsap.ticker.add(tick);
}
return () => {
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(fieldTex);
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 StreamLines;
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
14 propscolorstringColour of the lines.default "#7d9799"default "#7d9799"highlightstringColour the lines near the cursor brighten toward.default "#bff3f0"default "#bff3f0"backgroundstringBackground colour (it darkens gently toward the corners).default "#03161a"default "#03161a"spacingnumberDistance between the lines, css px.default 8default 8dashnumberLength of one dash and gap, css px.default 6.5default 6.5speednumberSpeed of the idle current.default 1default 1bendnumberHow much the field bows with the current.default 1.5default 1.5depthnumberHow far the lines fan out and how strongly the edges blur into radial streaks.default 1default 1stirnumberHow strongly the cursor stirs the current.default 1default 1glownumberStrength of the bloom on bright runs.default 0.45default 0.45interactivebooleanCursor stirs the current, click swirls it, scroll drives it.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the lines.classNamestringSize it, e.g. h-screen w-full.