Animations115 / 118
Coin Halo
A halo of polished silver coins, each turning on its own axis so a twisting wave runs round the ring, with your emblem engraved in every face. Circle it and the coins nearest your cursor turn to face you; drag to spin it, click a coin to send a domino cascade of flips round the halo.
three.jsthree.jsChromeChromeWaveWaveEngravingEngravingSpringsSpringsGSAPGSAP
Circle the halo, the coins face youClick a coin for a cascade
Tweak
LIVELIVEHalo
12
#e6e7ec
Motion
1.0×
Usage
Follows your tweaks.
usage.tsx
import { CoinHalo } from "@/components/inreact/coin-halo";
// your emblems as SVG path data (100 x 100 box); the coins use them in turn
const emblems = [
"M50 14 L60 40 L86 50 L60 60 L50 86 L40 60 L14 50 L40 40 Z",
"M16 76 L42 30 L54 50 L64 36 L86 76 Z",
];
export function Hero() {
return (
<section className="h-[600px] bg-black">
<CoinHalo emblems={emblems} count={12} metal="#e6e7ec" speed={1} onCoin={(i) => console.log(i)} />
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/coin-halo.jsonOr copy the source
Install the dependencies, then save this as components/inreact/coin-halo.tsx.
terminal
npm install gsap threecomponents/inreact/coin-halo.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
import * as THREE from "three";
import { SVGLoader } from "three/addons/loaders/SVGLoader.js";
/**
* Coin Halo: a ring of polished silver coins, each turning on its own axis so a twisting wave runs
* round the halo, rendered live in three.js. Every coin is real geometry (a thick lathed body with a
* raised lip) with your emblem engraved into both faces.
*
* - Circle the halo with your cursor: the coins nearest it turn their faces to you.
* - Drag to spin the whole halo; it coasts like a wheel and settles back to a slow turn.
* - Click a coin (or press Enter / Space): a domino cascade sends a full flip round the ring from
* that coin, each one winding back first and overshooting as it lands.
*
* Emblems are SVG path strings drawn in a 100 x 100 box; the coins take them in turn.
*
* <div className="h-[600px] bg-black"><CoinHalo /></div>
*/
export type CoinHaloProps = {
/** SVG path data for the emblems (100 x 100 box); the coins use them in turn. */
emblems?: string[];
/** Number of coins in the halo, 6 to 18. */
count?: number;
/** Metal colour. */
metal?: string;
/** Speed of the flip wave (multiplier). */
speed?: number;
/** Background colour. */
background?: string;
/** Called with the index of a clicked coin. */
onCoin?: (index: number) => void;
className?: string;
};
// original line emblems
export const HALO_EMBLEMS = [
"M50 14 L60 40 L86 50 L60 60 L50 86 L40 60 L14 50 L40 40 Z", // spark
"M50 14 L81 32 L81 68 L50 86 L19 68 L19 32 Z M50 30 L67 40 L67 60 L50 70 L33 60 L33 40 Z", // hex nut
"M16 76 L42 30 L54 50 L64 36 L86 76 Z", // peaks
"M50 16 A34 34 0 1 0 50.1 16 Z M50 34 A16 16 0 1 1 49.9 34 Z", // ring
];
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const TAU = Math.PI * 2;
// an engraved outline of an emblem: a thin stroke of every contour, laid flat on the face
function engraving(d: string) {
const data = new SVGLoader().parse(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="${d}"/></svg>`);
const style = SVGLoader.getStrokeStyle(4.6, "#000", "round", "round", 4);
const geos: THREE.BufferGeometry[] = [];
data.paths.forEach((p) =>
p.toShapes().forEach((sh) => {
[sh, ...sh.holes].forEach((c) => {
const pts = c.getPoints(48);
if (pts.length > 1 && !pts[0].equals(pts[pts.length - 1])) pts.push(pts[0].clone());
const g = SVGLoader.pointsToStroke(pts, style);
if (g) geos.push(g);
});
}),
);
// merge by hand (positions only)
let n = 0;
geos.forEach((g) => (n += g.attributes.position.count));
const pos = new Float32Array(n * 3);
let o = 0;
geos.forEach((g) => {
pos.set(g.attributes.position.array as Float32Array, o);
o += g.attributes.position.count * 3;
g.dispose();
});
const out = new THREE.BufferGeometry();
out.setAttribute("position", new THREE.BufferAttribute(pos, 3));
out.translate(-50, -50, 0);
out.scale(0.0115, -0.0115, 1); // SVG y runs down
out.computeVertexNormals();
return out;
}
export function CoinHalo({ emblems = HALO_EMBLEMS, count = 12, metal = "#e6e7ec", speed = 1, background = "#000000", onCoin, className }: CoinHaloProps) {
const rootRef = useRef<HTMLDivElement>(null);
const live = useRef({ metal, speed, onCoin });
live.current = { metal, speed, onCoin };
const key = emblems.join("|") + count;
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const still = reduced();
const N = Math.max(6, Math.min(18, Math.round(count)));
const list = emblems.length ? emblems : HALO_EMBLEMS;
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: true, alpha: false, powerPreference: "high-performance" });
} catch {
canvas.remove();
return;
}
const dpr = Math.min(2, Math.max(1.5, 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 high-contrast studio: big soft boxes and hard strips on black, so polished silver reads as
// bold white sweeps against deep blacks
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, float r, float s){ return smoothstep(r, r - s, acos(clamp(dot(d, normalize(c)), -1.0, 1.0))); }
void main(){
vec3 d = normalize(vD);
vec3 c = vec3(0.025) + vec3(0.07) * smoothstep(-0.6, 0.9, d.y); // a dim room: silver reads as bright sweeps over deep darks
c += vec3(1.0) * box(d, vec3(-0.5, 0.7, 0.6), 0.6, 0.3) * 4.5;
c += vec3(1.0) * box(d, vec3(0.9, 0.1, 0.4), 0.3, 0.1) * 5.0;
c += vec3(0.95, 0.97, 1.0) * box(d, vec3(0.1, -0.8, 0.6), 0.45, 0.2) * 2.0;
c += vec3(1.0) * smoothstep(0.04, 0.0, abs(d.y - 0.15)) * smoothstep(-0.2, 0.6, d.z) * 2.2;
c += vec3(1.0) * box(d, vec3(-0.2, 0.3, -1.0), 0.5, 0.3) * 1.8;
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;
// ---- the coin ----
const CR = 0.5, H = 0.072; // radius, half thickness
const prof = [
[0.0001, H - 0.012], [CR * 0.8, H - 0.012], [CR * 0.82, H + 0.012], [CR * 0.95, H + 0.012], [CR, H - 0.008],
[CR + 0.006, 0], [CR, -H + 0.008], [CR * 0.95, -H - 0.012], [CR * 0.82, -H - 0.012], [CR * 0.8, -H + 0.012], [0.0001, -H + 0.012],
].map(([x, y]) => new THREE.Vector2(x, y));
const coinGeo = new THREE.LatheGeometry(prof, 128);
coinGeo.rotateX(Math.PI / 2); // faces along z
coinGeo.computeVertexNormals();
const silver = new THREE.MeshPhysicalMaterial({ color: new THREE.Color(metal), metalness: 1, roughness: 0.1, envMapIntensity: 1.25 });
const etch = new THREE.MeshPhysicalMaterial({ color: 0x5a5b61, metalness: 1, roughness: 0.38, envMapIntensity: 0.6, side: THREE.DoubleSide });
const emGeos = list.map((d) => engraving(d));
emGeos.forEach((g) => g.scale(CR / 0.62, CR / 0.62, 1));
// ---- the halo ----
const tilt = new THREE.Group(); // cursor tilt
const halo = new THREE.Group(); // spin in its own plane
tilt.add(halo);
scene.add(tilt);
const RING = 1.85;
type Coin = { pivot: THREE.Group; a: number; th: { x: number; v: number; t: number }; kick: { x: number; v: number; t: number }; radial: THREE.Vector3 };
const coins: Coin[] = [];
for (let i = 0; i < N; i++) {
const a = (i / N) * TAU;
const slot = new THREE.Group();
slot.position.set(Math.cos(a) * RING, Math.sin(a) * RING, 0);
const pivot = new THREE.Group();
slot.add(pivot);
pivot.add(new THREE.Mesh(coinGeo, silver));
const g = emGeos[i % emGeos.length];
const f1 = new THREE.Mesh(g, etch);
f1.position.z = H - 0.011;
const f2 = new THREE.Mesh(g, etch);
f2.position.z = -H + 0.011;
f2.rotation.y = Math.PI;
// keep each emblem upright as the coin sits round the ring
f1.rotation.z = a - Math.PI / 2;
f2.rotation.z = -(a - Math.PI / 2);
pivot.add(f1, f2);
halo.add(slot);
coins.push({ pivot, a, th: { x: 0, v: 0, t: 0 }, kick: { x: 0, v: 0, t: 0 }, radial: new THREE.Vector3(Math.cos(a), Math.sin(a), 0) });
}
const camera = new THREE.PerspectiveCamera(28, 1, 0.1, 50);
let W = 0, Hh = 0;
const resize = () => {
const w = root.clientWidth, h = root.clientHeight;
if (w < 2 || h < 2 || (w === W && h === Hh)) return;
W = w;
Hh = h;
renderer.setSize(W, Hh, false);
camera.aspect = W / Hh;
const t = Math.tan(THREE.MathUtils.degToRad(14));
camera.position.set(0, 0, Math.max(5.5 / (2 * t), 5.5 / (2 * t * camera.aspect)));
camera.lookAt(0, 0, 0);
camera.updateProjectionMatrix();
};
resize();
const ro = new ResizeObserver(resize);
ro.observe(root);
// ---- motion ----
type Sp = { x: number; v: number; t: number };
const step = (s: Sp, 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 angd = (a: number, b: number) => ((((a - b + Math.PI) % TAU) + TAU) % TAU) - Math.PI;
let wave = 0;
let spin = 0, spinV = 0;
const tiltX: Sp = { x: 0, v: 0, t: 0 }, tiltY: Sp = { x: 0, v: 0, t: 0 };
const focus: Sp = { x: 0, v: 0, t: 0 };
let focusA = 0;
let t = 0;
let pointer: { x: number; y: number } | null = null;
let drag: { a: number; t: number; sx: number; sy: number; t0: number; id: number } | null = null;
const calls: gsap.core.Tween[] = [];
const ndc = new THREE.Vector2();
const ray = new THREE.Raycaster();
const plane = new THREE.Plane();
const hit = new THREE.Vector3();
const q = new THREE.Quaternion();
// the pointer's angle round the halo (in the halo's own turning frame) and its distance from the ring
const haloAngle = (px: number, py: number) => {
ndc.set((px / W) * 2 - 1, -(py / Hh) * 2 + 1);
ray.setFromCamera(ndc, camera);
const n = new THREE.Vector3(0, 0, 1).applyQuaternion(tilt.getWorldQuaternion(q));
plane.setFromNormalAndCoplanarPoint(n, new THREE.Vector3());
if (!ray.ray.intersectPlane(plane, hit)) return null;
tilt.worldToLocal(hit);
return { a: Math.atan2(hit.y, hit.x), r: Math.hypot(hit.x, hit.y) };
};
const cascade = (from: number) => {
if (still) return;
live.current.onCoin?.(from);
coins.forEach((c, i) => {
const steps = Math.min(Math.abs(i - from), N - Math.abs(i - from));
calls.push(
gsap.delayedCall(steps * 0.07, () => {
c.kick.t -= 0.35; // wind back
calls.push(gsap.delayedCall(0.1, () => (c.kick.t += 0.35 + TAU)));
}),
);
});
};
let visible = true;
const io = new IntersectionObserver(([e]) => (visible = e.isIntersecting), { rootMargin: "80px" });
io.observe(root);
const tick = (_time: number, dms: number) => {
const dt = Math.min(0.05, Math.max(0.001, dms / 1000));
t += dt;
const L = live.current;
silver.color.set(L.metal);
if (!still) wave += dt * 1.6 * L.speed;
// the halo turns slowly; a drag throws it and it coasts back to that drift
if (!drag) {
spinV += ((still ? 0 : 0.12) - spinV) * (1 - Math.exp(-dt * 0.8));
spin += spinV * dt;
}
halo.rotation.z = spin;
const px = pointer ? (pointer.x / W) * 2 - 1 : 0;
const py = pointer ? -((pointer.y / Hh) * 2 - 1) : 0;
tiltX.t = still ? -0.3 : -0.3 - py * 0.22;
tiltY.t = still ? 0 : px * 0.3;
step(tiltX, 22, 7, dt);
step(tiltY, 22, 7, dt);
tilt.rotation.set(tiltX.x, tiltY.x, 0);
// where the cursor circles the halo, the coins turn to face it
const ha = pointer && !drag && !still ? haloAngle(pointer.x, pointer.y) : null;
focus.t = ha && ha.r > RING * 0.35 && ha.r < RING * 1.8 ? 1 : 0;
if (ha) focusA = ha.a - spin;
step(focus, 26, 8, dt);
coins.forEach((c) => {
// the free twist: two turns of phase round the ring, so the wave reads as a corkscrew
const free = wave - c.a * 2;
const face = Math.round(free / Math.PI) * Math.PI;
const w = Math.max(0, focus.x) * Math.exp(-Math.pow(angd(c.a, focusA) / 0.75, 2));
c.th.t = free + (face - free) * w;
step(c.th, 90, 13, dt);
step(c.kick, 46, 7.2, dt);
c.pivot.quaternion.setFromAxisAngle(c.radial, c.th.x + c.kick.x);
});
if (visible && W) renderer.render(scene, camera);
};
gsap.ticker.add(tick);
// ---- input ----
const pos = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const onMove = (e: PointerEvent) => {
pointer = pos(e);
if (!drag) return;
const ha = haloAngle(pointer.x, pointer.y);
if (!ha) return;
const now = performance.now();
const d = angd(ha.a, drag.a);
const ddt = Math.max(8, now - drag.t) / 1000;
spin += d;
spinV = THREE.MathUtils.lerp(spinV, d / ddt, 0.5);
drag.a = ha.a;
drag.t = now;
};
const onDown = (e: PointerEvent) => {
if (e.button !== 0) return;
const p = pos(e);
const ha = haloAngle(p.x, p.y);
const now = performance.now();
drag = { a: ha ? ha.a : 0, t: now, sx: e.clientX, sy: e.clientY, t0: now, id: e.pointerId };
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) spinV = 0;
spinV = THREE.MathUtils.clamp(spinV, -8, 8);
drag = null;
if (moved < 7 && quick) {
const p = pos(e);
const ha = haloAngle(p.x, p.y);
const a = ha ? ha.a - spin : 0;
const i = ((Math.round((a / TAU) * N) % N) + N) % N;
cascade(i);
}
};
const onLeave = () => {
if (!drag) pointer = null;
};
const onKey = (e: KeyboardEvent) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
cascade(0);
}
};
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);
calls.forEach((c) => c.kill());
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);
coinGeo.dispose();
emGeos.forEach((g) => g.dispose());
silver.dispose();
etch.dispose();
env.dispose();
pmrem.dispose();
renderer.dispose();
canvas.remove();
};
}, [key, background]); // eslint-disable-line react-hooks/exhaustive-deps
return (
<div
ref={rootRef}
tabIndex={0}
role="button"
aria-label="A halo of turning coins. Circle it and they face you, drag to spin it, press Enter for a cascade."
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 CoinHalo;
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
7 propsemblemsstring[]SVG path data for the emblems (100 x 100 box); the coins use them in turn.default four line emblemsdefault four line emblemscountnumberNumber of coins in the halo, 6 to 18.default 12default 12metalstringMetal colour.default "#e6e7ec"default "#e6e7ec"speednumberSpeed of the flip wave.default 1default 1onCoin(index) => voidCalled with the index of a clicked coin.backgroundstringBackground colour.default "#000000"default "#000000"classNamestringExtra classes (it fills its parent).