Animations117 / 118
Orbit Drop
A wobbling drop of clear liquid glass holding a pearly planet with rainbow stripes and pearls in orbit, all refracted through its beaded skin. It leans toward your cursor like jelly while the pearls drift after it; drag to tumble it, click to squash it and burst the pearls outward.
three.jsthree.jsTransmissionTransmissionLiquidLiquidNoiseNoiseSpringsSpringsGSAPGSAP
Move and the drop leans to youClick to burst the pearls
Tweak
LIVELIVEInside
6
#cfc9bf
1.00
Drop
1.0×
Usage
Follows your tweaks.
usage.tsx
import { OrbitDrop } from "@/components/inreact/orbit-drop";
export function Hero() {
return (
<section className="h-[600px] bg-black">
<OrbitDrop pearls={6} pearl="#cfc9bf" stripes={1} wobble={1} />
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/orbit-drop.jsonOr copy the source
Install the dependencies, then save this as components/inreact/orbit-drop.tsx.
terminal
npm install gsap threecomponents/inreact/orbit-drop.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
import * as THREE from "three";
/**
* Orbit Drop: a wobbling drop of clear liquid glass holding a pearly planet with iridescent stripes
* and a handful of pearls in orbit, rendered live in three.js. The shell is real transmission, so
* everything inside is refracted through it; its skin morphs slowly and carries tiny droplet beads.
*
* - The drop leans toward your cursor like jelly, and the pearls drift toward it as if pulled.
* - Drag to tumble the drop; it coasts like a body in space and settles to a slow turn.
* - Click (or Enter / Space): the drop squashes and wobbles, the pearls burst outward and spring
* back into orbit.
*
* <div className="h-[600px] bg-black"><OrbitDrop /></div>
*/
export type OrbitDropProps = {
/** Number of pearls in orbit, 2 to 10. */
pearls?: number;
/** Colour of the pearls and the planet. */
pearl?: string;
/** Strength of the rainbow stripes on the planet, 0 to 1. */
stripes?: number;
/** How much the drop's skin moves (multiplier). */
wobble?: number;
/** Background colour. */
background?: string;
className?: string;
};
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// compact 3D simplex noise (Ashima / Stefan Gustavson, MIT)
const NOISE = `
vec3 m289(vec3 x){ return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec4 m289(vec4 x){ return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec4 perm(vec4 x){ return m289(((x * 34.0) + 1.0) * x); }
float snoise(vec3 v){
const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);
vec3 i = floor(v + dot(v, C.yyy));
vec3 x0 = v - i + dot(i, C.xxx);
vec3 g = step(x0.yzx, x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min(g.xyz, l.zxy);
vec3 i2 = max(g.xyz, l.zxy);
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy;
vec3 x3 = x0 - 0.5;
i = m289(i);
vec4 p = perm(perm(perm(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));
vec4 j = p - 49.0 * floor(p * (1.0 / 49.0));
vec4 x_ = floor(j * (1.0 / 7.0));
vec4 y_ = floor(j - 7.0 * x_);
vec4 x = (x_ * 2.0 + 0.5) / 7.0 - 1.0;
vec4 y = (y_ * 2.0 + 0.5) / 7.0 - 1.0;
vec4 h = 1.0 - abs(x) - abs(y);
vec4 b0 = vec4(x.xy, y.xy);
vec4 b1 = vec4(x.zw, y.zw);
vec4 s0 = floor(b0) * 2.0 + 1.0;
vec4 s1 = floor(b1) * 2.0 + 1.0;
vec4 sh = -step(h, vec4(0.0));
vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
vec3 p0 = vec3(a0.xy, h.x);
vec3 p1 = vec3(a0.zw, h.y);
vec3 p2 = vec3(a1.xy, h.z);
vec3 p3 = vec3(a1.zw, h.w);
vec4 norm = inversesqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;
vec4 m = max(0.5 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);
m = m * m;
return 105.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
}`;
export function OrbitDrop({ pearls = 6, pearl = "#cfc9bf", stripes = 1, wobble = 1, background = "#000000", className }: OrbitDropProps) {
const rootRef = useRef<HTMLDivElement>(null);
const live = useRef({ pearl, stripes, wobble });
live.current = { pearl, stripes, wobble };
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const still = reduced();
const NP = Math.max(2, Math.min(10, Math.round(pearls)));
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.25, window.devicePixelRatio || 1));
renderer.setPixelRatio(dpr);
renderer.setClearColor(new THREE.Color(background), 1);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 0.82;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
// a low-key studio: one big soft light overhead, thin strips for the glass to catch
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);
// nearly black: just a few hard lights for the wet glass to flash
vec3 c = vec3(0.002) + vec3(0.35) * smoothstep(0.05, 0.0, abs(d.y - 0.05));
c += vec3(1.0, 0.97, 0.93) * box(d, vec3(0.25, 1.0, 0.2), 0.18, 0.06) * 7.0;
c += vec3(1.0) * box(d, vec3(-1.0, 0.35, 0.25), 0.12, 0.05) * 4.0;
c += vec3(1.0) * box(d, vec3(0.8, -0.6, 0.5), 0.12, 0.04) * 7.0;
c += vec3(0.95) * box(d, vec3(-0.5, -0.75, 0.5), 0.08, 0.03) * 6.0;
c += vec3(0.9, 0.93, 1.0) * box(d, vec3(1.0, 0.2, -0.4), 0.08, 0.03) * 3.0;
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 key = new THREE.SpotLight(0xfff1e2, 70, 12, 0.42, 0.55, 1.6); // a tight pool of light from above: tops lit, undersides falling to black
key.position.set(1.4, 4.4, 1.2);
scene.add(key, key.target);
const world = new THREE.Group(); // tumble
scene.add(world);
// ---- the planet: pearly white with rainbow stripes that wander round it ----
const stripeU = { value: live.current.stripes };
const timeU = { value: 0 };
const planetMat = new THREE.MeshPhysicalMaterial({ color: new THREE.Color(pearl), roughness: 0.34, clearcoat: 1, clearcoatRoughness: 0.1, envMapIntensity: 0.1 });
planetMat.onBeforeCompile = (sh) => {
sh.uniforms.uStripes = stripeU;
sh.uniforms.uTime = timeU;
sh.vertexShader = sh.vertexShader
.replace("#include <common>", "#include <common>\nvarying vec3 vObj;")
.replace("#include <begin_vertex>", "#include <begin_vertex>\nvObj = position;");
sh.fragmentShader = sh.fragmentShader
.replace(
"#include <common>",
`#include <common>
uniform float uStripes, uTime;
varying vec3 vObj;
${NOISE}
vec3 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 <emissivemap_fragment>",
// wavy bands round the planet; each one runs through the spectrum along its length
`#include <emissivemap_fragment>
{
vec3 p = normalize(vObj);
// bands that curl and wander: latitude lines pushed around by slow noise
float wave = p.y * 2.4 + snoise(p * 1.0 + vec3(0.0, uTime * 0.06, 0.0)) * 0.8;
float band = smoothstep(0.12, 0.065, abs(fract(wave) - 0.5)); // ribbons
float seg = smoothstep(0.25, 0.75, snoise(p * 2.6 + 3.1) * 0.5 + 0.5);
vec3 col = mix(vec3(0.16, 0.12, 0.5), spectrum(fract(dot(p, vec3(0.6, 0.9, 0.4)) * 0.8 + wave * 0.15 + uTime * 0.03)), seg);
diffuseColor.rgb = mix(diffuseColor.rgb, col * 0.55, band * uStripes * 0.9);
totalEmissiveRadiance += col * band * seg * uStripes * 0.22;
}`,
);
};
planetMat.customProgramCacheKey = () => "orbit-drop-planet-4";
const planet = new THREE.Mesh(new THREE.SphereGeometry(0.5, 128, 96), planetMat);
world.add(planet);
// ---- pearls in orbit ----
const pearlMat = new THREE.MeshPhysicalMaterial({ color: new THREE.Color(pearl), roughness: 0.48, envMapIntensity: 0.05 });
const pearlGeo = new THREE.SphereGeometry(1, 48, 32);
type Pearl = { m: THREE.Mesh; r: number; incl: THREE.Quaternion; w: number; ph: number; pos: THREE.Vector3; vel: THREE.Vector3; size: number };
const plist: Pearl[] = [];
let seed = 11;
const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
for (let i = 0; i < NP; i++) {
const size = 0.14 + rnd() * 0.11;
const m = new THREE.Mesh(pearlGeo, pearlMat);
m.scale.setScalar(size);
world.add(m);
const incl = new THREE.Quaternion().setFromEuler(new THREE.Euler((rnd() - 0.5) * 1.6, rnd() * Math.PI, (rnd() - 0.5) * 1.2));
plist.push({ m, r: 0.7 + rnd() * 0.12, incl, w: (0.35 + rnd() * 0.45) * (rnd() > 0.3 ? 1 : -1), ph: rnd() * Math.PI * 2, pos: new THREE.Vector3(), vel: new THREE.Vector3(), size });
}
// ---- the liquid shell ----
const U = {
uTime: { value: 0 },
uWob: { value: 1 },
uLean: { value: new THREE.Vector3() }, // direction and strength, in the drop's own space
uSquash: { value: 0 },
uNM: { value: new THREE.Matrix3() }, // object to view, for the bead normals
};
const shellMat = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
transmission: 1,
roughness: 0.0,
thickness: 0.32,
ior: 1.33,
dispersion: 0.45,
attenuationColor: new THREE.Color(0xf0f2f6),
attenuationDistance: 3,
specularIntensity: 1,
envMapIntensity: 1.3,
clearcoat: 1,
clearcoatRoughness: 0.02,
});
shellMat.onBeforeCompile = (sh) => {
Object.assign(sh.uniforms, U);
sh.vertexShader = sh.vertexShader
.replace(
"#include <common>",
`#include <common>
uniform float uTime, uWob, uSquash;
uniform vec3 uLean;
varying vec3 vObj;
${NOISE}
// the skin: slow lumpy swells, a lean toward the cursor, and a squash along y
vec3 skin(vec3 n){
float f = snoise(n * 0.7 + vec3(0.0, uTime * 0.12, 0.0)) * 0.085 + snoise(n * 1.4 - uTime * 0.08) * 0.015; // slow, smooth swells: an egg, never lumpy
f *= uWob;
f += max(dot(n, normalize(uLean + 1e-5)), 0.0) * length(uLean) * 0.22;
vec3 p = n * (1.0 + f);
p.y *= 1.0 - uSquash;
p.xz *= 1.0 + uSquash * 0.5;
return p;
}`,
)
.replace(
"#include <beginnormal_vertex>",
`vec3 sn = normalize(position);
vec3 st = normalize(abs(sn.y) < 0.99 ? cross(sn, vec3(0.0, 1.0, 0.0)) : cross(sn, vec3(1.0, 0.0, 0.0)));
vec3 sb = cross(sn, st);
vec3 sp = skin(sn);
vec3 sa = skin(normalize(sn + st * 0.01)) - sp;
vec3 sc = skin(normalize(sn + sb * 0.01)) - sp;
vec3 objectNormal = normalize(cross(sa, sc));
if (dot(objectNormal, sn) < 0.0) objectNormal = -objectNormal;
vObj = sn;`,
)
.replace("#include <begin_vertex>", "vec3 transformed = sp;");
sh.fragmentShader = sh.fragmentShader
.replace(
"#include <common>",
`#include <common>
varying vec3 vObj;
uniform float uTime;
uniform mat3 uNM;
vec3 h33(vec3 p){
p = vec3(dot(p, vec3(127.1, 311.7, 74.7)), dot(p, vec3(269.5, 183.3, 246.1)), dot(p, vec3(113.5, 271.9, 124.6)));
return fract(sin(p) * 43758.5453);
}
${NOISE}
// running water: thin wavy ridges, stretched along one direction, only over parts of the skin
float streak(vec3 q){
float w = snoise(vec3(q.x * 1.3, q.y * 13.0 + uTime * 0.22, q.z * 1.3) + vec3(snoise(q * 1.4) * 0.45, 0.0, 0.0)); // long runs, not closed loops
float r = pow(1.0 - abs(w), 7.0);
return r * smoothstep(0.1, 0.5, snoise(q * 1.1 + 4.0));
}
// the nearest bead of water: xyz = offset from its centre over its radius, w = 1 inside one
vec4 bead(vec3 p){
vec3 i = floor(p), f = fract(p);
vec4 best = vec4(0.0);
float bd = 1.0;
for (int x = -1; x <= 1; x++)
for (int y = -1; y <= 1; y++)
for (int z = -1; z <= 1; z++){
vec3 g = vec3(float(x), float(y), float(z));
vec3 r = h33(i + g);
vec3 o = f - (g + r * 0.8 + 0.1);
float rad = mix(0.12, 0.5, pow(fract(r.x * 7.3 + r.z * 3.1), 1.6));
float q = length(o) / rad;
if (fract(r.y * 13.1) > 0.3 && q < bd){ bd = q; best = vec4(o / rad, 1.0); }
}
return best;
}`,
)
.replace(
"#include <normal_fragment_maps>",
// beads of moisture on the skin: small round bumps that bend the light
`#include <normal_fragment_maps>
float wetShine = 0.0;
{
// each bead is a little dome: its edge tilts the surface hard, so it reads as a dark lens with a lit rim
vec3 bq = vObj * 13.0 + vec3(snoise(vObj * 3.0), snoise(vObj * 3.0 + 7.0), snoise(vObj * 3.0 + 13.0)) * 0.55; // uneven beads
vec4 b = bead(bq);
if (b.w > 0.5){
vec3 n0 = normalize(vObj);
vec3 t = b.xyz - n0 * dot(b.xyz, n0);
float s = clamp(length(t), 0.0, 0.97);
vec3 tilt = normalize(t + 1e-5) * (s / sqrt(1.0 - s * s));
normal = normalize(normal + normalize(uNM * tilt) * min(length(tilt), 3.0) * 0.55);
}
// streaks and smears: the gradient of the running-water ridges tilts the glass, so they flash as bright wavy lines
{
vec3 q = normalize(vObj);
float e = 0.004;
float s0 = streak(q);
vec3 g = vec3(streak(q + vec3(e, 0.0, 0.0)) - s0, streak(q + vec3(0.0, e, 0.0)) - s0, streak(q + vec3(0.0, 0.0, e)) - s0) / e;
g -= q * dot(g, q);
normal = normalize(normal + uNM * g * 0.012);
wetShine = s0;
}
}`,
)
.replace(
"#include <dithering_fragment>",
`#include <dithering_fragment>
{
float fr = pow(1.0 - abs(dot(normalize(normal), normalize(vViewPosition))), 1.5);
gl_FragColor.rgb += vec3(0.95, 0.97, 1.0) * wetShine * (0.18 + 0.7 * fr);
}`,
);
};
shellMat.customProgramCacheKey = () => "orbit-drop-shell-4";
const shell = new THREE.Mesh(new THREE.SphereGeometry(1, 192, 128), shellMat);
world.add(shell);
const camera = new THREE.PerspectiveCamera(30, 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(15));
camera.position.set(0, 0, Math.max(2.6 / (2 * t), 2.6 / (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 rot = { x: 0.2, y: 0, vx: 0, vy: 0 };
const squash: Sp = { x: 0, v: 0, t: 0 };
const lean = new THREE.Vector3(), leanV = new THREE.Vector3(), leanT = new THREE.Vector3();
const pull = new THREE.Vector3();
let 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;
const calls: gsap.core.Tween[] = [];
const tmp = new THREE.Vector3(), tgt = new THREE.Vector3();
const inv = new THREE.Quaternion();
const burst = () => {
if (still) return;
squash.v -= 1.2; // anticipation: it gathers itself up
calls.push(
gsap.delayedCall(0.12, () => {
squash.v += 4.2;
plist.forEach((p) => {
tmp.copy(p.pos).normalize();
p.vel.addScaledVector(tmp, 2.4 + Math.random() * 1.2);
});
}),
);
};
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;
U.uTime.value = still ? 0 : t;
timeU.value = still ? 0 : t;
U.uWob.value = L.wobble;
stripeU.value = L.stripes;
planetMat.color.set(L.pearl);
pearlMat.color.set(L.pearl);
// tumble: a slow turn plus whatever a drag threw, coasting out
if (!drag) {
const f = Math.exp(-dt * 1.0);
rot.vx *= f;
rot.vy *= f;
rot.y += (rot.vy + (still ? 0 : 0.16)) * dt;
rot.x += rot.vx * dt;
rot.x += (0.2 - rot.x) * (1 - Math.exp(-dt * 0.4));
}
world.rotation.set(rot.x, rot.y, Math.sin(t * 0.21) * 0.08);
planet.rotation.y = t * 0.35;
// the planet drifts off-centre, so it too presses against the glass at times
planet.position.set(Math.cos(t * 0.23) * 0.2, Math.sin(t * 0.31) * 0.16, Math.sin(t * 0.19) * 0.12);
// the cursor, as a direction in the drop's own space
if (pointer && !drag && !still) {
const px = (pointer.x / W) * 2 - 1, py = -((pointer.y / H) * 2 - 1);
tmp.set(px * 1.4, py * 1.4, 0.6);
inv.copy(world.quaternion).invert();
leanT.copy(tmp).applyQuaternion(inv).multiplyScalar(Math.min(1, Math.hypot(px, py) * 1.2));
pull.copy(leanT).multiplyScalar(0.22);
} else {
leanT.set(0, 0, 0);
pull.set(0, 0, 0);
}
// the lean is a soft spring, so the jelly overshoots and settles
tmp.subVectors(leanT, lean).multiplyScalar(28).addScaledVector(leanV, -6.5);
leanV.addScaledVector(tmp, dt);
lean.addScaledVector(leanV, dt);
U.uLean.value.copy(lean);
step(squash, 120, 6.5, dt);
U.uSquash.value = squash.x * 0.12;
// pearls: each chases its orbit point (plus the cursor's pull), springing back after a burst
plist.forEach((p) => {
const a = p.ph + (still ? 0 : t * p.w);
tgt.set(Math.cos(a) * p.r, 0, Math.sin(a) * p.r).applyQuaternion(p.incl).add(pull);
tmp.subVectors(tgt, p.pos).multiplyScalar(18).addScaledVector(p.vel, -4.2);
p.vel.addScaledVector(tmp, dt);
p.pos.addScaledVector(p.vel, dt);
// keep them inside the drop
const lim = 0.93 - p.size * 0.55; // they ride right against the skin, where the glass stretches them
if (p.pos.length() > lim) {
p.pos.setLength(lim);
p.vel.multiplyScalar(0.5);
}
p.m.position.copy(p.pos);
});
scene.updateMatrixWorld();
camera.updateMatrixWorld();
U.uNM.value.getNormalMatrix(new THREE.Matrix4().multiplyMatrices(camera.matrixWorldInverse, shell.matrixWorld));
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 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(260, Math.min(W, H));
rot.y += dx * k;
rot.x += dy * k;
rot.vy = THREE.MathUtils.lerp(rot.vy, (dx * k) / ddt, 0.5);
rot.vx = THREE.MathUtils.lerp(rot.vx, (dy * k) / ddt, 0.5);
drag.x = e.clientX;
drag.y = e.clientY;
drag.t = now;
};
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 };
rot.vx = rot.vy = 0;
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) rot.vx = rot.vy = 0;
drag = null;
if (moved < 7 && quick) {
rot.vx = rot.vy = 0;
burst();
}
};
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);
[planet.geometry, pearlGeo, shell.geometry].forEach((g) => g.dispose());
[planetMat, pearlMat, shellMat].forEach((m) => m.dispose());
env.dispose();
pmrem.dispose();
renderer.dispose();
canvas.remove();
};
}, [pearls, background]);
return (
<div
ref={rootRef}
tabIndex={0}
role="button"
aria-label="A liquid drop holding a planet and orbiting pearls. Move to lean it, drag to tumble it, press Enter to burst the pearls."
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 OrbitDrop;
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 propspearlsnumberNumber of pearls in orbit, 2 to 10.default 6default 6pearlstringColour of the pearls and the planet.default "#cfc9bf"default "#cfc9bf"stripesnumberStrength of the rainbow stripes on the planet, 0 to 1.default 1default 1wobblenumberHow much the drop's skin moves.default 1default 1backgroundstringBackground colour.default "#000000"default "#000000"classNamestringExtra classes (it fills its parent).