Type Vortex
Your word, set in rings that swirl like a whirlpool. Dozens of thin rings of type circle a dark centre, the letters upright along each ring, and swirling arms run through them: inside the arms the letters stand full size, between them they shrink to dots, so the type reads as a slowly turning spiral. It moves like water in a whirlpool: the inner rings turn faster than the outer ones and every ring has its own momentum. Stir with the cursor and the rings around it speed up, the spin spreading to their neighbours and slowly calming, while the letters near the cursor swell as if under a lens. A click sends a ripple through the rings that swells the letters as it passes, scrolling drains the rings inward and spins them before they coast, and on load the type spirals in from the centre.
Tweak
LIVELIVEType
Vortex
Interactive
Stir the whirlpool with the cursor, click for a ripple
Usage
Follows your tweaks.
import { TypeVortex } from "@/components/inreact/type-vortex";
export function Hero() {
return (
<TypeVortex
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the type */}
</TypeVortex>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/type-vortex.jsonOr copy the source
Install the dependencies, then save this as components/inreact/type-vortex.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);
/**
* Type Vortex: your word, set in rings that swirl like a whirlpool.
*
* Dozens of thin rings of type circle a dark centre, the letters upright along
* each ring. Swirling arms run through the rings: inside them the letters
* stand full size, between them they shrink to dots, so the type reads as a
* slowly turning spiral.
*
* It moves like water in a whirlpool: the inner rings turn faster than the
* outer ones, and every ring has its own momentum. Stir with the cursor and the
* rings around it speed up, the spin spreading to their neighbours and slowly
* calming, while the letters near the cursor swell as if under a lens. A click
* sends a ripple through the rings that swells the letters as it passes;
* scrolling drains the rings inward and spins them, then they coast; and on load
* the type spirals in from the centre.
*
* <TypeVortex text="INREACT" className="h-screen w-full">
* <YourHero />
* </TypeVortex>
*
* WebGL2: the word is drawn once into a glyph atlas, and one shader lays it
* around every ring (one letter per cell, mipmapped so small letters stay
* crisp). Pauses off-screen; reduced motion shows a still frame; a static
* pattern without WebGL2.
*/
export interface TypeVortexProps {
/** The word set around the rings. */
text?: string;
/** Font family for the letters. */
font?: string;
/** Font weight. */
weight?: number;
/** Colour of the letters. */
color?: string;
/** Background colour. */
background?: string;
/** Height of a ring of type, css px. */
size?: number;
/** Number of swirling arms. */
arms?: number;
/** Speed of the whirlpool. */
speed?: number;
/** Strength of the bloom on the letters. */
glow?: number;
/** Where the vortex centre sits, [x, y] from 0 to 1 of the stage. */
center?: [number, number];
/** Stir with the cursor, click ripple, scroll drain. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the type. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
const NRING = 256; // ring phases kept by ring id (wraps)
const CELL_W = 64, CELL_H = 96; // 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, uPhase;
uniform vec2 uRes, uCen, uMouse; // css px
uniform float uDpr, uH, uCells, uAspectCell, uTime, uArms, uDrain, uSpin, uHover, uIntro, uLodBase;
uniform vec3 uColor, uBg;
uniform vec4 uWave[${MAXW}];
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); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(h21(i), h21(i + vec2(1, 0)), f.x), mix(h21(i + vec2(0, 1)), h21(i + vec2(1, 1)), f.x), f.y);
}
// how full-size the letters are at a point: swirling arms through the rings, with soft dark bands
float fullness(float ang, float r) {
float minD = min(uRes.x, uRes.y);
float rr = r / minD;
// two sets of arms turning against each other make rich, lobed swirls
float arm = sin(ang * uArms - log(rr + 0.02) * 2.6 + uSpin * 0.35 + uTime * 0.12);
float arm2 = sin(ang * (uArms - 1.0) + log(rr + 0.02) * 1.7 - uSpin * 0.2 - uTime * 0.07 + 1.3);
float band = sin(rr * 13.0 - uTime * 0.25 + uSpin * 0.2);
float wob = noise(vec2(ang * 1.6, rr * 5.0) + uTime * 0.05) - 0.5;
float f = 0.55 + 0.3 * arm + 0.2 * arm2 + 0.18 * band + 0.3 * wob;
return smoothstep(0.18, 0.6, f);
}
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 - uCen;
float r = length(d);
float ang = atan(d.y, d.x); // grows clockwise on screen
// rings drain inward as you scroll: each ring keeps its own id (and phase) as it moves
float rp = r / uH + uDrain;
float id = floor(rp);
float yl = fract(rp); // 0 inner edge, 1 outer edge (letter tops face out)
float rMid = (id + 0.5 - uDrain) * uH; // this ring's radius
if (rMid < uH * 1.2) { o = vec4(uBg, 1.0); return; }
// this ring's turn (whirlpool: each ring has its own phase, kept in a small texture)
float phase = texture(uPhase, vec2((mod(id, ${NRING}.0) + 0.5) / ${NRING}.0, 0.5)).r;
// letters per ring: a whole number, so the word closes seamlessly around the circle
float circ = TAU * max(rMid, uH);
float n = max(3.0, floor(circ / (uH * uAspectCell)));
float a = fract((ang + phase) / TAU + 0.5); // 0..1 around the ring
float k = floor(a * n);
float xl = fract(a * n); // across the letter
float chr = mod(k + id * 3.0, uCells); // which letter of the word (rings are offset)
// the letter's own centre decides its size, so each letter scales whole
float angC = (k + 0.5) / n * TAU - 0.5 * TAU - phase;
vec2 cpos = uCen + vec2(cos(angC), sin(angC)) * rMid;
float full = fullness(angC, rMid);
// the cursor is a lens: letters near it swell and brighten
vec2 dm = (cpos - uMouse) / minD;
float lens = exp(-dot(dm, dm) / 0.015) * uHover;
// click ripples swell the letters as they pass
float rip = 0.0;
for (int i = 0; i < ${MAXW}; i++) {
vec4 W = uWave[i];
if (W.w <= 0.0) continue;
float age = uTime - W.z;
if (age < 0.0 || age > 3.0) continue;
float rr = length(cpos - W.xy) / minD;
float fr = rr - age * 0.5;
rip += exp(-fr * fr / 0.004) * exp(-age * 1.1) * W.w;
}
// on load the type spirals in from the centre
float rc = rMid / length(uRes);
float intro = smoothstep(rc - 0.02, rc + 0.12, uIntro * 1.2);
float sc = mix(0.3, 1.0, clamp(full + lens * 0.9 + rip * 0.8, 0.0, 1.0)) * intro;
sc = min(sc * (1.0 + lens * 0.35 + rip * 0.2), 1.25);
// sample the glyph, scaled about the cell centre
vec2 lc = vec2(xl - 0.5, yl - 0.5) / max(sc, 0.05) + 0.5;
float ink = 0.0;
if (sc > 0.01 && lc.x >= 0.0 && lc.x <= 1.0 && lc.y >= 0.0 && lc.y <= 1.0) {
vec2 auv = vec2((chr + lc.x) / uCells, 1.0 - lc.y);
float lod = uLodBase - log2(max(sc, 0.05));
ink = textureLod(uAtlas, auv, lod).r;
}
float bright = (0.72 + 0.28 * full) * (1.0 + lens * 0.4 + rip * 0.6);
vec3 col = mix(uBg, uColor * bright, ink);
o = vec4(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.6, 1.0, 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;
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.85 + texture(uWide, vUv).rgb * 0.15;
vec3 x = sc + bl * uGlow;
o = vec4(min(x / (1.0 + max(x - 0.9, 0.0)), vec3(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];
}
const DEFAULT_CENTER: [number, number] = [0.47, 0.5];
export function TypeVortex({
text = "INREACT",
font = "'Futura', 'Century Gothic', 'Avenir Next', 'Montserrat', 'Helvetica Neue', Arial, sans-serif",
weight = 600,
color = "#f2f2f2",
background = "#000000",
size = 10,
arms = 3,
speed = 1,
glow = 0.3,
center = DEFAULT_CENTER,
interactive = true,
scroller,
children,
className,
}: TypeVortexProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ text, font, weight, color, background, size, arms, speed, glow, center, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { text, font, weight, color, background, size, arms, speed, glow, center, interactive };
redraw.current?.();
}, [text, font, weight, color, background, size, arms, speed, glow, center, 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-radial-gradient(circle at ${p.center[0] * 100}% ${p.center[1] * 100}%, ${p.color}22 0 ${p.size * 0.6}px, transparent ${p.size * 0.6}px ${p.size}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, [
"uAtlas", "uPhase", "uRes", "uCen", "uMouse", "uDpr", "uH", "uCells", "uAspectCell", "uTime", "uArms", "uDrain", "uSpin",
"uHover", "uIntro", "uLodBase", "uColor", "uBg", "uWave",
]);
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: the word (and a gap) drawn once, one letter per cell ----
const atlasTex = gl.createTexture()!;
let cells = 1;
let atlasKey = "";
const buildAtlas = () => {
const p = props.current;
const word = (p.text || "INREACT").toUpperCase() + " ";
const key = `${word}|${p.font}|${p.weight}`;
if (key === atlasKey) return;
atlasKey = key;
cells = word.length;
const c = document.createElement("canvas");
c.width = CELL_W * cells;
c.height = CELL_H;
const ctx = c.getContext("2d")!;
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#fff";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `${p.weight} ${Math.round(CELL_H * 0.78)}px ${p.font}`;
for (let i = 0; i < cells; i++) {
const ch = word[i];
const mw = ctx.measureText(ch).width;
// squeeze wide letters into their cell so neighbours never collide
const sx = Math.min(1, (CELL_W * 0.92) / Math.max(1, mw));
ctx.save();
ctx.translate(i * CELL_W + CELL_W / 2, CELL_H / 2 + CELL_H * 0.03);
ctx.scale(sx, 1);
ctx.fillText(ch, 0, 0);
ctx.restore();
}
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();
// fonts may arrive after the first draw: rebuild once they are ready
let disposed = false;
document.fonts?.ready.then(() => {
if (disposed) return;
atlasKey = "";
buildAtlas();
draw();
});
// ---- the whirlpool: one phase and one spin per ring id ----
const phaseTex = gl.createTexture()!;
const phase = new Float32Array(NRING);
const stir = new Float32Array(NRING); // extra angular velocity from the hand, rad/s
const tmp = new Float32Array(NRING);
gl.bindTexture(gl.TEXTURE_2D, phaseTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, NRING, 1, 0, gl.RED, gl.FLOAT, phase);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
// stagger the rings so the word never lines up across them
for (let i = 0; i < NRING; i++) phase[i] = ((i * 2.399) % (Math.PI * 2));
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);
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();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0 };
let flow = 0;
let drain = 0, drainV = 0; // rings per second flowing inward (momentum, coasting)
let spin = 0;
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
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;
buildAtlas();
const X = T;
const H = Math.max(6, p.size);
gl.bindTexture(gl.TEXTURE_2D, phaseTex);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, NRING, 1, gl.RED, gl.FLOAT, phase);
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.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, phaseTex);
gl.uniform1i(US.uPhase, 1);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uCen, p.center[0] * w, p.center[1] * h);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uH, H);
gl.uniform1f(US.uCells, cells);
gl.uniform1f(US.uAspectCell, CELL_W / CELL_H);
gl.uniform1f(US.uTime, flow);
gl.uniform1f(US.uArms, Math.max(1, Math.round(p.arms)));
gl.uniform1f(US.uDrain, drain);
gl.uniform1f(US.uSpin, spin);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uLodBase, Math.max(0, Math.log2(CELL_H / (H * dpr))));
gl.uniform3fv(US.uColor, rgb(p.color));
gl.uniform3fv(US.uBg, rgb(p.background));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
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);
// ring id under a screen point
const ringAt = (x: number, y: number) => {
const p = props.current;
const H = Math.max(6, p.size);
const r = Math.hypot(x - p.center[0] * w, y - p.center[1] * h);
return Math.floor(r / H + drain);
};
// ---- cursor: stir the whirlpool; the letters near it swell ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.3, ease: "power2.out" });
const myTo = gsap.quickTo(s, "my", { duration: 0.3, ease: "power2.out" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.5, ease: "sine.out" });
let first = true;
let last = { x: 0, y: 0, t: 0 };
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 now = performance.now();
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
last = { x: p.x, y: p.y, t: now };
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
// the hand's motion around the centre is angular velocity, stirred into the rings under it
const cx = props.current.center[0] * w, cy = props.current.center[1] * h;
const rx = p.x - cx, ry = p.y - cy;
const rr = Math.max(30, Math.hypot(rx, ry));
const dt = Math.max(0.008, (now - last.t) / 1000);
const angVel = (rx * (p.y - last.y) - ry * (p.x - last.x)) / (rr * rr) / dt; // rad/s
const ring = ringAt(p.x, p.y);
for (let k = -6; k <= 6; k++) {
const idx = (((ring + k) % NRING) + NRING) % NRING;
const wgt = Math.exp(-(k * k) / 10);
stir[idx] += angVel * wgt * 0.25;
stir[idx] = Math.max(-4, Math.min(4, stir[idx]));
}
last = { x: p.x, y: p.y, t: now };
};
const leave = () => {
first = true;
hoverTo(0);
};
// ---- click: a ripple through the rings ----
const down = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: flow, s: 1 });
if (waves.length > MAXW) waves.shift();
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll drains the rings inward and spins the whirlpool; then it coasts ----
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;
if (!props.current.interactive || Math.abs(dy) > 2000) return;
drainV = Math.max(-25, Math.min(25, drainV + dy * 0.03));
},
});
if (st) lastScroll = st.scroll();
// ---- 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;
const p = props.current;
const sp = Math.max(0, p.speed);
flow += dt * sp;
const H = Math.max(6, p.size);
// the drain coasts and slows like water (viscous drag)
drain += drainV * dt;
drainV *= Math.exp(-dt * 1.4);
if (drain > 1e5 || drain < -1e5) drain = 0;
spin += (0.2 * sp + Math.abs(drainV) * 0.08) * dt;
// whirlpool: inner rings turn faster (about 1/r), plus the stirred spin, which spreads to the
// neighbours (viscosity) and slowly calms
const minD = Math.min(w, h);
for (let i = 0; i < NRING; i++) {
const l = stir[(i + NRING - 1) % NRING], r = stir[(i + 1) % NRING];
tmp[i] = stir[i] * 0.9 + (l + r) * 0.05;
}
const calm = Math.exp(-dt * 0.55);
for (let i = 0; i < NRING; i++) stir[i] = tmp[i] * calm;
for (let i = 0; i < NRING; i++) {
// the ring id's current radius on screen
const ringR = (((i - drain) % NRING) + NRING) % NRING * H + H * 0.5;
const base = (0.09 * sp * minD * 0.25) / (ringR + minD * 0.12) + 0.02 * sp + Math.abs(drainV) * 0.04;
phase[i] = (phase[i] + (base + stir[i]) * dt) % (Math.PI * 2);
}
for (let i = waves.length - 1; i >= 0; i--) if (flow - waves[i].t > 3.1) waves.splice(i, 1);
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.4, 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);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(atlasTex);
gl.deleteTexture(phaseTex);
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 TypeVortex;
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 propstextstringThe word set around the rings.default "INREACT"default "INREACT"fontstringFont family for the letters (a geometric sans by default).weightnumberFont weight.default 600default 600colorstringColour of the letters.default "#f2f2f2"default "#f2f2f2"backgroundstringBackground colour.default "#000000"default "#000000"sizenumberHeight of a ring of type, css px.default 10default 10armsnumberNumber of swirling arms.default 3default 3speednumberSpeed of the whirlpool.default 1default 1glownumberStrength of the bloom on the letters.default 0.3default 0.3center[number, number]Where the vortex centre sits, 0 to 1 of the stage.default [0.47, 0.5]default [0.47, 0.5]interactivebooleanStir with the cursor, click ripple, scroll drain.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the type.classNamestringSize it, e.g. h-screen w-full.