Animations114 / 118
Pleat Ring
A soft matte black ring with a pleated band running round it: where it passes, the tube ripples into sharp ribs of iridescent chrome that split the light into rainbows, then falls smooth again. The band follows your cursor round the ring; drag to throw it, click to send a ripple of pleats all the way round.
three.jsthree.jsVertex shaderVertex shaderIridescenceIridescenceChromeChromeSpringsSpringsGSAPGSAP
Circle the ring, the pleats followClick to send a ripple
Tweak
LIVELIVERing
38
#18181b
1.00
Motion
1.0×
Usage
Follows your tweaks.
usage.tsx
import { PleatRing } from "@/components/inreact/pleat-ring";
export function Hero() {
return (
<section className="h-[560px]">
<PleatRing ribs={38} color="#18181b" holo={1} speed={1} />
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/pleat-ring.jsonOr copy the source
Install the dependencies, then save this as components/inreact/pleat-ring.tsx.
terminal
npm install gsap threecomponents/inreact/pleat-ring.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
import * as THREE from "three";
/**
* Pleat Ring: a soft matte black ring with a pleated band running round it, rendered live in three.js.
* Where the band passes, the tube ripples up into sharp ribs and those ribs turn to iridescent chrome,
* splitting the light into rainbows; behind it the ring falls smooth and black again. The ribs belong
* to the ring, so as the band moves they rise and sink in place like a wave through a bellows.
*
* - The band follows your cursor round the ring, with inertia, and swells as you come close.
* - Drag along the ring to throw it; it coasts and slows like a spun wheel.
* - Click (or Enter / Space): the ring braces, then a ripple of pleats runs all the way round it in
* both directions, and it rebounds.
*
* <div className="h-[560px]"><PleatRing /></div>
*/
export type PleatRingProps = {
/** Number of ribs round the whole ring. */
ribs?: number;
/** Colour of the smooth part of the ring. */
color?: string;
/** Strength of the rainbow on the pleats, 0 to 1. */
holo?: number;
/** Speed the band travels at on its own (multiplier). */
speed?: number;
/** Background (any CSS background). */
background?: string;
className?: string;
};
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const RR = 1, TR = 0.36;
export function PleatRing({ ribs = 38, color = "#18181b", holo = 1, speed = 1, background = "radial-gradient(120% 90% at 40% 30%, #2c2c2f 0%, #1c1c1e 55%, #141415 100%)", className }: PleatRingProps) {
const rootRef = useRef<HTMLDivElement>(null);
const live = useRef({ ribs, color, holo, speed });
live.current = { ribs, color, holo, speed };
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const still = reduced();
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: true, powerPreference: "high-performance" });
} catch {
canvas.remove();
return;
}
const dpr = Math.min(2, Math.max(1.5, window.devicePixelRatio || 1));
renderer.setPixelRatio(dpr);
renderer.setClearColor(0x000000, 0);
renderer.toneMapping = THREE.NeutralToneMapping;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
// studio: tall strips at both sides and behind (they draw the thin rims and the rib highlights),
// a soft key above
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 strip(vec3 d, vec3 c, float w){ return smoothstep(w, w * 0.35, acos(clamp(dot(normalize(d.xz), normalize(c.xz)), -1.0, 1.0))) * smoothstep(1.2, 0.3, abs(d.y - c.y)); }
void main(){
vec3 d = normalize(vD);
vec3 c = vec3(0.02);
c += vec3(1.0) * strip(d, vec3(-1.0, 0.1, -0.35), 0.09) * 6.0;
c += vec3(1.0) * strip(d, vec3(1.0, 0.0, -0.2), 0.07) * 5.0;
c += vec3(0.9, 0.95, 1.0) * strip(d, vec3(0.3, 0.2, 1.0), 0.18) * 1.6;
c += vec3(1.0, 0.97, 0.94) * smoothstep(0.75, 0.97, dot(d, normalize(vec3(-0.3, 1.0, 0.4)))) * 2.4;
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.02).texture;
envSphere.geometry.dispose();
envMat.dispose();
scene.environment = env;
const back = new THREE.DirectionalLight(0xffffff, 3.4); // a hard backlight for the thin rim
back.position.set(-2.5, 0.6, -2);
scene.add(back);
// ---- the ring ----
const U = {
uC: { value: 0 }, // centre angle of the pleated band
uAmp: { value: 1 },
uWidth: { value: 0.5 },
uN: { value: live.current.ribs },
uWaveA: { value: 0 },
uWaveT: { value: 9 },
uHolo: { value: live.current.holo },
};
const geo = new THREE.TorusGeometry(RR, TR, 96, 720);
const mat = new THREE.MeshPhysicalMaterial({
color: new THREE.Color(live.current.color),
roughness: 0.55,
metalness: 0,
sheen: 0.9,
sheenRoughness: 0.45,
sheenColor: new THREE.Color(0xc4c4cc),
iridescence: 1,
iridescenceIOR: 1.8,
iridescenceThicknessMinimum: 180,
iridescenceThicknessMaximum: 820,
envMapIntensity: 1,
});
mat.onBeforeCompile = (sh) => {
Object.assign(sh.uniforms, U);
const DISP = `
uniform float uC, uAmp, uWidth, uN, uWaveA, uWaveT;
varying float vW;
varying float vRib;
varying float vV;
float angd(float a, float b){ float d = mod(a - b + 3.14159265, 6.2831853) - 3.14159265; return d; }
// the band's strength at ring angle u: the travelling band plus the click ripple
float bandAt(float u){
float d = angd(u, uC);
float w = exp(-pow(d / uWidth, 2.0)) * uAmp;
float r1 = abs(angd(u, uWaveA));
float front = uWaveT * 4.2;
w += exp(-pow((r1 - front) / 0.42, 2.0)) * exp(-uWaveT * 0.9) * smoothstep(0.0, 0.15, uWaveT) * 1.1;
return clamp(w, 0.0, 1.35);
}
float ribAt(float u){ return 0.5 + 0.5 * cos(u * uN); } // full, rounded lobes
vec3 ringP(float u, float v){
float w = bandAt(u);
// ribs swell outward from the tube, more on the outer side; troughs pinch in a little
float h = w * ${TR.toFixed(3)} * (ribAt(u) * (0.3 + 0.12 * (0.5 + 0.5 * cos(v))) - 0.08);
float r = ${TR.toFixed(3)} + h;
return vec3((${RR.toFixed(3)} + r * cos(v)) * cos(u), (${RR.toFixed(3)} + r * cos(v)) * sin(u), r * sin(v));
}`;
sh.vertexShader = sh.vertexShader
.replace("#include <common>", "#include <common>\n" + DISP)
.replace(
"#include <beginnormal_vertex>",
`float tu = atan(position.y, position.x);
vec2 radial = vec2(cos(tu), sin(tu));
vec3 tc = vec3(radial * ${RR.toFixed(3)}, 0.0);
vec3 td = position - tc;
float tv = atan(td.z, dot(td.xy, radial));
vec3 dispP = ringP(tu, tv);
const float E = 0.0025;
vec3 dU = ringP(tu + E, tv) - ringP(tu - E, tv);
vec3 dV = ringP(tu, tv + E) - ringP(tu, tv - E);
vec3 objectNormal = normalize(cross(dU, dV));
if (dot(objectNormal, normal) < 0.0) objectNormal = -objectNormal;
float bw = bandAt(tu);
vW = smoothstep(0.08, 0.7, bw);
vRib = ribAt(tu);
vV = tv;`,
)
.replace("#include <begin_vertex>", "vec3 transformed = dispP;");
sh.fragmentShader = sh.fragmentShader
.replace("#include <common>", "#include <common>\nuniform float uHolo;\nvarying float vW;\nvarying float vRib;\nvarying float vV;\nvec3 spectrum(float h){ return clamp(abs(mod(h * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0); }")
.replace(
"#include <roughnessmap_fragment>",
// the pleats turn to polished chrome; the rest stays soft matte
"#include <roughnessmap_fragment>\nroughnessFactor = mix(roughnessFactor, 0.12, vW);",
)
.replace("#include <metalnessmap_fragment>", "#include <metalnessmap_fragment>\nmetalnessFactor = mix(metalnessFactor, 1.0, vW);")
.replace("#include <color_fragment>", "#include <color_fragment>\ndiffuseColor.rgb = mix(diffuseColor.rgb, vec3(0.92, 0.93, 0.96), vW);")
.replace(
"#include <lights_physical_fragment>",
`#include <lights_physical_fragment>
material.iridescence = vW * uHolo;
material.iridescenceThickness = mix(220.0, 880.0, fract(vRib * 0.85 + vW * 0.3));
material.sheenColor *= (1.0 - vW);`,
)
.replace(
"#include <dithering_fragment>",
// the pleats split their highlights into a spectrum that runs along each rib and slides as it turns
`#include <dithering_fragment>
{
vec3 nV = normalize(normal);
float f = dot(nV, normalize(vViewPosition));
vec3 sp = spectrum(fract(f * 1.3 + vV * 0.32 + vRib * 0.35 + nV.y * 0.4));
float l = dot(gl_FragColor.rgb, vec3(0.299, 0.587, 0.114));
float hot = smoothstep(0.1, 0.8, l);
gl_FragColor.rgb = mix(gl_FragColor.rgb, (sp * 0.6 + 0.4) * l * 1.45, vW * uHolo * hot * 0.75);
}`,
);
};
mat.customProgramCacheKey = () => "pleat-ring-4";
const ring = new THREE.Mesh(geo, mat);
const hold = new THREE.Group(); // cursor tilt + squash
hold.add(ring);
scene.add(hold);
hold.rotation.set(0.22, -0.18, 0);
const camera = new THREE.PerspectiveCamera(26, 1, 0.1, 50);
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);
camera.aspect = W / H;
const t = Math.tan(THREE.MathUtils.degToRad(13));
camera.position.set(0, 0, Math.max(5.3 / (2 * t), 5.3 / (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 band = { a: Math.PI * 0.6, v: 0 }; // the band's angle and angular speed
const amp: Sp = { x: still ? 0.9 : 0, v: 0, t: 1 };
const tiltX: Sp = { x: 0, v: 0, t: 0 }, tiltY: Sp = { x: 0, v: 0, t: 0 };
const squash: Sp = { x: 0, v: 0, t: 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 nrm = new THREE.Vector3();
// where on the ring (as an angle) the pointer sits, and how close it is to the tube
const ringAngle = (px: number, py: number) => {
ndc.set((px / W) * 2 - 1, -(py / H) * 2 + 1);
ray.setFromCamera(ndc, camera);
nrm.set(0, 0, 1).applyQuaternion(ring.getWorldQuaternion(new THREE.Quaternion()));
plane.setFromNormalAndCoplanarPoint(nrm, ring.getWorldPosition(new THREE.Vector3()));
if (!ray.ray.intersectPlane(plane, hit)) return null;
ring.worldToLocal(hit);
return { a: Math.atan2(hit.y, hit.x), d: Math.abs(Math.hypot(hit.x, hit.y) - RR) };
};
const wrap = (d: number) => ((((d + Math.PI) % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2)) - Math.PI;
const burst = (px?: number, py?: number) => {
if (still) return;
const ra = px !== undefined && py !== undefined ? ringAngle(px, py) : null;
squash.v += 1.6; // anticipation: the ring braces
calls.push(
gsap.delayedCall(0.12, () => {
U.uWaveA.value = ra ? ra.a : band.a;
U.uWaveT.value = 0;
squash.v -= 3.4;
}),
);
};
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;
mat.color.set(L.color);
U.uN.value = Math.round(THREE.MathUtils.clamp(L.ribs, 16, 96));
U.uHolo.value = L.holo;
// the band: drifts on its own, chases the cursor round the ring, or coasts after a throw
const pa = pointer && !drag && !still ? ringAngle(pointer.x, pointer.y) : null;
if (drag) {
/* moved by the drag handler */
} else if (pa) {
// a damped chase toward the cursor's angle, along the shorter way round
const d = wrap(pa.a - band.a);
band.v += (d * 26 - band.v * 8.5) * dt;
band.a += band.v * dt;
amp.t = 1 + 0.3 * Math.exp(-Math.pow(pa.d / 0.6, 2));
} else {
const cruise = still ? 0 : 0.9 * L.speed;
band.v += (cruise - band.v) * (1 - Math.exp(-dt * 1.2));
band.a += band.v * dt;
amp.t = 1;
}
U.uC.value = band.a;
step(amp, 30, 9, dt);
U.uAmp.value = Math.max(0, amp.x);
if (U.uWaveT.value < 9) U.uWaveT.value += dt;
const px = pointer ? (pointer.x / W) * 2 - 1 : 0;
const py = pointer ? -((pointer.y / H) * 2 - 1) : 0;
tiltX.t = still ? 0 : -py * 0.25;
tiltY.t = still ? 0 : px * 0.32;
step(tiltX, 24, 7, dt);
step(tiltY, 24, 7, dt);
step(squash, 190, 10, dt);
hold.rotation.set(0.22 + tiltX.x, -0.18 + tiltY.x, 0);
const s = squash.x * 0.045;
hold.scale.set(1 + s, 1 + s, 1 - s * 1.4);
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 ra = ringAngle(pointer.x, pointer.y);
if (!ra) return;
const now = performance.now();
const d = wrap(ra.a - drag.a);
const ddt = Math.max(8, now - drag.t) / 1000;
band.a += d;
band.v = THREE.MathUtils.lerp(band.v, d / ddt, 0.5);
drag.a = ra.a;
drag.t = now;
};
const onDown = (e: PointerEvent) => {
if (e.button !== 0) return;
const p = pos(e);
const ra = ringAngle(p.x, p.y);
const now = performance.now();
drag = { a: ra ? ra.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) band.v = 0;
band.v = THREE.MathUtils.clamp(band.v, -14, 14);
drag = null;
if (moved < 7 && quick) {
const p = pos(e);
burst(p.x, p.y);
}
};
const onLeave = () => {
if (!drag) pointer = null;
};
const onKey = (e: KeyboardEvent) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
burst();
}
};
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);
geo.dispose();
mat.dispose();
env.dispose();
pmrem.dispose();
renderer.dispose();
canvas.remove();
};
}, []);
return (
<div
ref={rootRef}
tabIndex={0}
role="button"
aria-label="A ring with a pleated band. Move round it and the band follows, press Enter to send a ripple."
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 PleatRing;
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
6 propsribsnumberNumber of ribs round the whole ring.default 38default 38colorstringColour of the smooth part of the ring.default "#18181b"default "#18181b"holonumberStrength of the rainbow on the pleats, 0 to 1.default 1default 1speednumberSpeed the band travels at on its own.default 1default 1backgroundstringBackground (any CSS background).default a soft charcoal gradientdefault a soft charcoal gradientclassNamestringExtra classes (it fills its parent).