Animations111 / 118
Syzygy Rings
Concentric black-lacquer rings set with glowing beads. They tumble freely, then lock into formations outer ring first (a target with every bead lined up, a cross of edge-on bars) and burst loose again. Each ring follows your cursor a beat after the last; drag to spin, click to line them up.
three.jsthree.jsGyroscopeGyroscopeLacquerLacquerBloomBloomSpringsSpringsGSAPGSAP
Tilt the rings, drag to spinClick to line them up
Tweak
LIVELIVERings
9
#ffffff
Motion
1.0×
2.2s
Usage
Follows your tweaks.
usage.tsx
import { SyzygyRings } from "@/components/inreact/syzygy-rings";
export function Hero() {
return (
<section className="h-[560px] bg-black">
<SyzygyRings rings={9} beadColor="#ffffff" speed={1} hold={2.2} />
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/syzygy-rings.jsonOr copy the source
Install the dependencies, then save this as components/inreact/syzygy-rings.tsx.
terminal
npm install gsap threecomponents/inreact/syzygy-rings.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
import * as THREE from "three";
import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js";
import { OutputPass } from "three/addons/postprocessing/OutputPass.js";
import { RenderPass } from "three/addons/postprocessing/RenderPass.js";
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js";
/**
* Syzygy Rings: concentric black-lacquer rings, each set with two glowing beads, rendered live in
* three.js. The rings tumble freely on their own axes, then lock into formations, outer ring first:
* a flat target with every bead lined up, and a cross of edge-on bars. Then they break loose again.
*
* - Each ring lags a beat behind the one outside it, so a turn ripples inward (follow-through).
* - Locking: each ring winds back slightly (anticipation), swings past its mark (overshoot) and
* lands with a small squash while its beads flare.
* - The whole assembly tilts toward the cursor; drag to spin it, and it coasts when you let go.
* - Click (or Enter / Space): jump to the next formation, or burst a formation back into tumbling.
*
* <div className="h-[560px] bg-black"><SyzygyRings /></div>
*/
export type SyzygyFormation = "free" | "target" | "cross";
export type SyzygyRingsProps = {
/** Number of rings, 4 to 12. */
rings?: number;
/** Bead colour. */
beadColor?: string;
/** Lacquer colour of the rings (keep it dark). */
ringColor?: string;
/** Tumbling speed multiplier. */
speed?: number;
/** Seconds each formation holds before the rings break loose (0 = no autoplay). */
hold?: number;
/** Background colour. */
background?: string;
/** Called when the rings lock into (or leave) a formation. */
onFormation?: (formation: SyzygyFormation) => void;
className?: string;
};
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// a flat ring with a rounded, slightly crowned cross-section: the crown is what draws the soft sheen
function ringGeometry(R: number, w: number, h: number) {
const r = Math.min(w, h) * 0.28;
const pts: THREE.Vector2[] = [];
const ri = R - w, ro = R, hy = h / 2;
const corner = (cx: number, cy: number, a0: number) => {
for (let i = 0; i <= 6; i++) {
const a = a0 + (i / 6) * (Math.PI / 2);
pts.push(new THREE.Vector2(cx + Math.cos(a) * r, cy + Math.sin(a) * r));
}
};
const crown = (y: number, s: number) => {
// a gentle bulge across each face
for (let i = 1; i < 8; i++) {
const u = i / 8;
pts.push(new THREE.Vector2(ro - r - u * (w - 2 * r), y + s * Math.sin(u * Math.PI) * h * 0.08));
}
};
corner(ro - r, -hy + r, -Math.PI / 2);
corner(ro - r, hy - r, 0);
crown(hy, 1);
corner(ri + r, hy - r, Math.PI / 2);
corner(ri + r, -hy + r, Math.PI);
// back face, inner to outer
for (let i = 1; i < 8; i++) {
const u = i / 8;
pts.push(new THREE.Vector2(ri + r + u * (w - 2 * r), -hy - Math.sin(u * Math.PI) * h * 0.08));
}
pts.push(pts[0].clone());
const g = new THREE.LatheGeometry(pts, 180);
g.rotateX(Math.PI / 2); // lathe axis to z: the ring faces the camera
g.computeVertexNormals();
return g;
}
export function SyzygyRings({ rings = 9, beadColor = "#ffffff", ringColor = "#060607", speed = 1, hold = 2.2, background = "#000000", onFormation, className }: SyzygyRingsProps) {
const rootRef = useRef<HTMLDivElement>(null);
const live = useRef({ speed, hold, onFormation, beadColor, ringColor });
live.current = { speed, hold, onFormation, beadColor, ringColor };
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const still = reduced();
const N = Math.max(4, Math.min(12, Math.round(rings)));
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;";
root.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: false, alpha: false, powerPreference: "high-performance" });
} catch {
canvas.remove();
return;
}
const dpr = Math.min(2, Math.max(1.25, window.devicePixelRatio || 1));
renderer.setPixelRatio(dpr);
renderer.setClearColor(new THREE.Color(background), 1);
renderer.toneMapping = THREE.NeutralToneMapping;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
// a dark studio of large soft boxes: black lacquer shows them as broad, soft sheens
const pmrem = new THREE.PMREMGenerator(renderer);
const studio = new THREE.Scene();
const envMat = new THREE.ShaderMaterial({
side: THREE.BackSide,
vertexShader: "varying vec3 vD;\nvoid main(){ vD = position; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }",
fragmentShader: `
varying vec3 vD;
float box(vec3 d, vec3 c, vec2 size, float soft){
vec3 n = normalize(c);
float f = dot(d, n);
if (f < 0.0) return 0.0;
vec3 u = normalize(cross(abs(n.y) > 0.9 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0), n));
vec3 v = cross(n, u);
vec2 p = vec2(dot(d, u), dot(d, v)) / f;
vec2 q = abs(p) - size;
return smoothstep(soft, 0.0, max(q.x, q.y));
}
void main(){
vec3 d = normalize(vD);
vec3 c = vec3(0.003);
c += vec3(1.0) * box(d, vec3(0.0, 1.0, 0.35), vec2(0.9, 0.5), 0.35) * 2.2;
c += vec3(0.95, 0.97, 1.0) * box(d, vec3(-1.0, 0.2, 0.6), vec2(0.12, 0.8), 0.12) * 2.6;
c += vec3(1.0, 0.98, 0.95) * box(d, vec3(1.0, -0.1, 0.4), vec2(0.08, 0.7), 0.1) * 1.8;
c += vec3(0.9, 0.93, 1.0) * box(d, vec3(0.0, -0.4, 1.0), vec2(0.9, 0.08), 0.12) * 0.9;
gl_FragColor = vec4(c, 1.0);
}`,
});
const envSphere = new THREE.Mesh(new THREE.SphereGeometry(10, 96, 48), envMat);
studio.add(envSphere);
const env = pmrem.fromScene(studio, 0.01).texture;
envSphere.geometry.dispose();
envMat.dispose();
scene.environment = env;
const lacquer = new THREE.MeshPhysicalMaterial({
color: new THREE.Color(live.current.ringColor),
metalness: 0.0,
roughness: 0.22,
clearcoat: 1,
clearcoatRoughness: 0.05,
envMapIntensity: 1.0,
});
const beadMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(live.current.beadColor).multiplyScalar(3) });
const beadGeo = new THREE.SphereGeometry(1, 24, 16);
// ---- the rings ----
const assembly = new THREE.Group(); // drag spin
const tiltRoot = new THREE.Group(); // cursor tilt
scene.add(tiltRoot);
tiltRoot.add(assembly);
type Ang = { x: number; v: number; t: number };
type Ring = {
wrap: THREE.Group; // per-ring lagging tilt (follow-through)
pivot: THREE.Group; // tumble / formation orientation
geo: THREE.BufferGeometry;
ax: Ang; ay: Ang; az: Ang;
wx: number; wy: number; wz: number; // free tumbling rates
lagX: Ang; lagY: Ang; lagK: number;
squash: Ang;
lockAt: number; anticAt: number; locked: boolean; landed: boolean;
goal: [number, number, number];
flare: number;
beads: THREE.Mesh[];
};
const list: Ring[] = [];
const W_BAND = 0.07, H_BAND = 0.16;
let seed = 7;
const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
for (let i = 0; i < N; i++) {
const R = 0.2 + (i / (N - 1)) * 0.8;
const geo = ringGeometry(R, W_BAND, H_BAND);
const wrap = new THREE.Group();
const pivot = new THREE.Group();
wrap.add(pivot);
pivot.add(new THREE.Mesh(geo, lacquer));
const beads: THREE.Mesh[] = [];
for (const s of [1, -1]) {
const b = new THREE.Mesh(beadGeo, beadMat);
b.scale.setScalar(0.021);
b.position.set(0, s * (R + 0.008), H_BAND * 0.32); // set into the rim, toward the front edge
pivot.add(b);
beads.push(b);
}
assembly.add(wrap);
const sgn = () => (rnd() > 0.5 ? 1 : -1);
const a0 = still ? 0 : (rnd() - 0.5) * 2;
list.push({
wrap, pivot, geo,
ax: { x: a0, v: 0, t: a0 },
ay: { x: -a0 * 0.7, v: 0, t: -a0 * 0.7 },
az: { x: 0, v: 0, t: 0 },
wx: sgn() * (0.35 + rnd() * 0.5),
wy: sgn() * (0.3 + rnd() * 0.45),
wz: sgn() * (0.2 + rnd() * 0.4),
lagX: { x: 0, v: 0, t: 0 }, lagY: { x: 0, v: 0, t: 0 },
lagK: 70 - (N - 1 - i) * (40 / N), // inner rings respond later
squash: { x: 0, v: 0, t: 0 },
lockAt: 0, anticAt: 0, locked: false, landed: true,
goal: [0, 0, 0],
flare: 0,
beads,
});
}
const camera = new THREE.PerspectiveCamera(30, 1, 0.1, 50);
const composer = new EffectComposer(renderer, new THREE.WebGLRenderTarget(4, 4, { type: THREE.HalfFloatType, samples: 4 }));
composer.addPass(new RenderPass(scene, camera));
const bloom = new UnrealBloomPass(new THREE.Vector2(4, 4), 0.38, 0.18, 1.0); // only the beads (above 1.0) bloom
composer.addPass(bloom);
composer.addPass(new OutputPass());
let W = 0, H = 0;
const resize = () => {
const w = root.clientWidth, h = root.clientHeight;
if (w < 2 || h < 2 || (w === W && h === H)) return;
W = w;
H = h;
renderer.setSize(W, H, false);
composer.setPixelRatio(dpr);
composer.setSize(W, H);
camera.aspect = W / H;
const t = Math.tan(THREE.MathUtils.degToRad(15));
camera.position.set(0, 0, Math.max(2.5 / (2 * t), 2.5 / (2 * t * camera.aspect)));
camera.lookAt(0, 0, 0);
camera.updateProjectionMatrix();
};
resize();
const ro = new ResizeObserver(resize);
ro.observe(root);
// ---- choreography ----
const step = (s: Ang, k: number, c: number, dt: number) => {
const h = dt / 2;
for (let i = 0; i < 2; i++) {
s.v += (k * (s.t - s.x) - c * s.v) * h;
s.x += s.v * h;
}
};
const near = (a: number, base: number, period: number) => base + Math.round((a - base) / period) * period;
let mode: SyzygyFormation = still ? "target" : "free";
let t = 0;
let modeAt = 0;
let lastInteract = -9;
const order: SyzygyFormation[] = ["target", "cross"];
let nextForm = 0;
const lock = (f: SyzygyFormation) => {
mode = f;
modeAt = t;
list.forEach((r, i) => {
// outer rings lead, inner ones follow a beat later
const delay = (N - 1 - i) * 0.055;
r.anticAt = t + delay;
r.lockAt = t + delay + 0.13;
r.locked = false;
r.landed = false;
let gx: number, gy: number;
if (f === "target") {
gx = near(r.ax.x, 0, Math.PI);
gy = near(r.ay.x, 0, Math.PI);
} else {
// alternate rings stand edge-on as horizontal and vertical bars
if (i % 2 === 0) {
gx = near(r.ax.x, Math.PI / 2, Math.PI);
gy = near(r.ay.x, 0, Math.PI);
} else {
gx = near(r.ax.x, 0, Math.PI);
gy = near(r.ay.x, Math.PI / 2, Math.PI);
}
}
r.goal = [gx, gy, near(r.az.x, 0, Math.PI)];
});
live.current.onFormation?.(f);
};
const release = (kick: number) => {
mode = "free";
modeAt = t;
list.forEach((r, i) => {
r.locked = false;
r.landed = true;
// burst loose: each ring is thrown its own way, and its target leaps ahead so they fan apart at once
const s = kick * (1 + i * 0.08);
r.ax.v += r.wx * s;
r.ay.v += r.wy * s;
r.az.v += r.wz * kick;
r.ax.t = r.ax.x + r.wx * s * 0.32;
r.ay.t = r.ay.x + r.wy * s * 0.32;
r.az.t = r.az.x + r.wz * kick * 0.3;
});
live.current.onFormation?.("free");
};
const advance = () => {
if (still) return;
if (mode === "free") {
lock(order[nextForm]);
nextForm = (nextForm + 1) % order.length;
} else release(4.5);
};
if (still) {
list.forEach((r) => {
r.ax.x = r.ax.t = 0;
r.ay.x = r.ay.t = 0;
r.landed = true;
r.locked = true;
r.goal = [0, 0, 0];
});
}
// drag spin (coasts like a body in space) and cursor tilt
const spin = { x: 0, y: 0, vx: 0, vy: 0 };
const tiltX = { x: 0, v: 0, t: 0 }, tiltY = { x: 0, v: 0, t: 0 };
let pointer: { x: number; y: number } | null = null;
let drag: { x: number; y: number; t: number; sx: number; sy: number; t0: number; id: number } | null = null;
let visible = true;
const io = new IntersectionObserver(([e]) => (visible = e.isIntersecting), { rootMargin: "80px" });
io.observe(root);
const col = new THREE.Color();
const tick = (_time: number, dms: number) => {
const dt = Math.min(0.05, Math.max(0.001, dms / 1000));
t += dt;
const L = live.current;
lacquer.color.set(L.ringColor);
const sp = still ? 0 : L.speed;
// autoplay: tumble, lock, hold, break loose, lock into the next formation
if (!still && L.hold > 0 && t - lastInteract > 3) {
if (mode === "free" && t - modeAt > 3.0) {
lock(order[nextForm]);
nextForm = (nextForm + 1) % order.length;
} else if (mode !== "free" && t - modeAt > L.hold + 1.1) release(3);
}
const px = pointer ? (pointer.x / W) * 2 - 1 : 0;
const py = pointer ? -((pointer.y / H) * 2 - 1) : 0;
tiltX.t = still ? 0 : -py * 0.42;
tiltY.t = still ? 0 : px * 0.55;
step(tiltX, 34, 8, dt);
step(tiltY, 34, 8, dt);
tiltRoot.rotation.set(tiltX.x, tiltY.x, 0);
if (!drag) {
const f = Math.exp(-dt * 0.9);
spin.vx *= f;
spin.vy *= f;
// once the throw has mostly coasted out, the assembly drifts back to face you (front or back)
const slow = 1 - Math.min(1, Math.hypot(spin.vx, spin.vy) / 1.5);
spin.vx += (near(spin.x, 0, Math.PI) - spin.x) * 5 * slow * dt - spin.vx * 2.2 * slow * dt;
spin.vy += (near(spin.y, 0, Math.PI) - spin.y) * 5 * slow * dt - spin.vy * 2.2 * slow * dt;
spin.x += spin.vx * dt;
spin.y += spin.vy * dt;
}
assembly.rotation.set(spin.x, spin.y, 0);
let flareSum = 0;
list.forEach((r) => {
if (mode === "free") {
// free tumbling: the targets keep moving, the springs chase them
r.ax.t += r.wx * sp * dt;
r.ay.t += r.wy * sp * dt;
r.az.t += r.wz * sp * dt;
step(r.ax, 18, 5.5, dt);
step(r.ay, 18, 5.5, dt);
step(r.az, 18, 5.5, dt);
} else {
if (t >= r.anticAt && t < r.lockAt) {
// anticipation: wind back a little against the coming turn
r.ax.t = r.ax.x - Math.sign(r.goal[0] - r.ax.x) * 0.1;
r.ay.t = r.ay.x - Math.sign(r.goal[1] - r.ay.x) * 0.1;
} else if (t >= r.lockAt) {
r.ax.t = r.goal[0];
r.ay.t = r.goal[1];
r.az.t = r.goal[2];
r.locked = true;
}
const k = r.locked ? 62 : 30;
const c = r.locked ? 8.2 : 7;
step(r.ax, k, c, dt);
step(r.ay, k, c, dt);
step(r.az, k * 0.7, c, dt);
if (r.locked && !r.landed && Math.abs(r.ax.x - r.goal[0]) + Math.abs(r.ay.x - r.goal[1]) < 0.05) {
// it lands: a small squash, and its beads flare
r.landed = true;
r.squash.v -= 1.6;
r.flare = 1;
}
}
// follow-through: each ring's share of the tilt arrives a little later than the one outside it
r.lagX.t = tiltX.x;
r.lagY.t = tiltY.x;
step(r.lagX, r.lagK, 9, dt);
step(r.lagY, r.lagK, 9, dt);
r.wrap.rotation.set(r.lagX.x - tiltX.x, r.lagY.x - tiltY.x, 0);
r.pivot.rotation.set(r.ax.x, r.ay.x, r.az.x);
step(r.squash, 260, 13, dt);
const sq = r.squash.x;
r.pivot.scale.set(1 - sq * 0.05, 1 - sq * 0.05, 1 + sq * 0.35);
r.flare *= Math.exp(-dt * 2.2);
flareSum += r.flare;
r.beads.forEach((b) => b.scale.setScalar(0.021 * (1 + r.flare * 0.35)));
});
col.set(L.beadColor).multiplyScalar(2.6 + (flareSum / N) * 2.5 + (mode !== "free" ? 0.6 : 0));
beadMat.color.copy(col);
if (visible && W) composer.render(dt);
};
gsap.ticker.add(tick);
// ---- input ----
const local = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const onMove = (e: PointerEvent) => {
pointer = local(e);
if (!drag) return;
const now = performance.now();
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
const ddt = Math.max(8, now - drag.t) / 1000;
const k = 3.2 / Math.max(240, Math.min(W, H));
spin.y += dx * k;
spin.x += dy * k;
spin.vy = THREE.MathUtils.lerp(spin.vy, (dx * k) / ddt, 0.5);
spin.vx = THREE.MathUtils.lerp(spin.vx, (dy * k) / ddt, 0.5);
drag.x = e.clientX;
drag.y = e.clientY;
drag.t = now;
lastInteract = t;
};
const onDown = (e: PointerEvent) => {
if (e.button !== 0) return;
const now = performance.now();
drag = { x: e.clientX, y: e.clientY, t: now, sx: e.clientX, sy: e.clientY, t0: now, id: e.pointerId };
spin.vx = spin.vy = 0;
lastInteract = t;
try {
root.setPointerCapture(e.pointerId);
} catch {
/* synthetic pointers can't be captured */
}
};
const onUp = (e: PointerEvent) => {
if (!drag) return;
const moved = Math.hypot(e.clientX - drag.sx, e.clientY - drag.sy);
const quick = performance.now() - drag.t0 < 450;
try {
root.releasePointerCapture(drag.id);
} catch {
/* not captured */
}
if (performance.now() - drag.t > 90) spin.vx = spin.vy = 0; // held still before letting go
drag = null;
lastInteract = t;
if (moved < 7 && quick) {
spin.vx = spin.vy = 0;
advance();
}
};
const onLeave = () => {
if (!drag) pointer = null;
};
const onKey = (e: KeyboardEvent) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
lastInteract = t;
advance();
}
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
root.addEventListener("pointercancel", onUp);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
io.disconnect();
ro.disconnect();
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("pointercancel", onUp);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("keydown", onKey);
list.forEach((r) => r.geo.dispose());
beadGeo.dispose();
lacquer.dispose();
beadMat.dispose();
env.dispose();
pmrem.dispose();
composer.dispose();
renderer.dispose();
canvas.remove();
};
}, [rings, background]);
return (
<div
ref={rootRef}
tabIndex={0}
role="button"
aria-label="Rings. Drag to spin them, press Enter to change the formation."
className={["relative h-full min-h-[260px] w-full cursor-grab touch-none overflow-hidden outline-none select-none active:cursor-grabbing", className].filter(Boolean).join(" ")}
style={{ background }}
/>
);
}
export default SyzygyRings;
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
8 propsringsnumberNumber of rings, 4 to 12.default 9default 9beadColorstringBead colour.default "#ffffff"default "#ffffff"ringColorstringLacquer colour of the rings (keep it dark).default "#060607"default "#060607"speednumberTumbling speed multiplier.default 1default 1holdnumberSeconds each formation holds (0 = no autoplay).default 2.2default 2.2onFormation(f: "free" | "target" | "cross") => voidCalled when the rings lock into or leave a formation.backgroundstringBackground colour.default "#000000"default "#000000"classNamestringExtra classes (it fills its parent).