Helix Drift
A glossy dark double helix suspended in black, lit like a studio render. Beaded backbones and flat, rounded base pairs at the real 10.5 per turn, in a physically based clearcoat material, catch thin crisp lines of light along every edge. Real glass droplets cling under the bars and float around it, small fragments drift past, and the far side falls softly into the dark. It moves like a real object: it turns calmly by itself; grab it and it turns with your hand, then coasts and settles; scrolling spins it with momentum. Your cursor is a light that sweeps highlights over the surface, the camera leans toward it, and a click sends a pulse of light travelling along the strands.
Tweak
LIVELIVEHelix
Motion
Interactive
Grab to spin, scroll to spin, the cursor is a light, click to send a pulse
Usage
Follows your tweaks.
import { HelixDrift } from "@/components/inreact/helix-drift";
export function Hero() {
return (
<HelixDrift
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the helix */}
</HelixDrift>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/helix-drift.jsonOr copy the source
Install the dependencies, then save this as components/inreact/helix-drift.tsx.
npm install three gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
import * as THREE from "three";
import { RoundedBoxGeometry } from "three/addons/geometries/RoundedBoxGeometry.js";
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";
import { mergeGeometries, mergeVertices } from "three/addons/utils/BufferGeometryUtils.js";
gsap.registerPlugin(ScrollTrigger);
/**
* Helix Drift: a glossy dark double helix suspended in black, lit like a studio render.
*
* A true 3D double helix: beaded backbones and flat, rounded base-pair bars at
* the real 10.5 per turn, in a physically based glossy material (clearcoat over
* a dark body) lit by a studio environment and cold back lights, so every edge
* catches a thin, crisp line of light. Real glass droplets cling under the bars
* and float around it, refracting the dark and ringed with reflections; small
* fragments drift past. Depth comes from light falling into the dark, not blur.
* Supersampled and multisampled so thin highlights never stair-step.
*
* It moves like a real object: it turns calmly by itself; grab it and it turns
* with your hand, then coasts and settles back to its idle turn; scrolling spins
* it with momentum. Your cursor is a light: it sweeps highlights over the glossy
* surface as you move, the camera leans gently toward it, and nearby bubbles
* drift aside. A click sends a pulse of light travelling along the strands. On
* load the camera glides in as the lights come up.
*
* <HelixDrift className="h-screen w-full">
* <YourHero />
* </HelixDrift>
*
* three.js (WebGL2), ACES tone mapping and a soft bloom. Pauses off-screen;
* reduced motion shows a still frame; a CSS gradient without WebGL2.
*/
export interface HelixDriftProps {
/** Colour of the light catching the edges, the cursor light and the pulse. */
color?: string;
/** Colour of the glossy body. */
body?: string;
/** Background colour (the light falls off into it). */
background?: string;
/** Tilt of the helix, degrees. */
angle?: number;
/** Horizontal placement, -1 left to 1 right. */
offset?: number;
/** Speed of the idle turn. */
speed?: number;
/** How many bubbles and droplets. */
bubbles?: number;
/** Strength of the bloom on highlights. */
glow?: number;
/** Grab to spin, scroll to spin, cursor light, click pulse. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the helix. */
children?: ReactNode;
className?: string;
}
const R = 0.85; // helix radius
const P = 3.45; // height of one turn
const TURNS = 5;
const HEIGHT = P * TURNS;
const PAIRS = Math.floor(TURNS * 10.5);
const MAXB = 60;
const MAXD = 18;
const MAXF = 40;
const MAXP = 3;
function hash(n: number) {
const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;
return x - Math.floor(x);
}
function vnoise(x: number) {
const i = Math.floor(x), f = x - i;
const u = f * f * (3 - 2 * f);
return hash(i) * (1 - u) + hash(i + 1) * u;
}
// beaded backbone: a tube whose radius swells at every base pair, with a little organic variation
function strand(phase: number) {
class Strand extends THREE.Curve<THREE.Vector3> {
constructor() {
super();
}
getPoint(t: number, target = new THREE.Vector3()) {
const y = (t - 0.5) * HEIGHT;
const a = (y / P) * Math.PI * 2 + phase;
return target.set(R * Math.cos(a), y, R * Math.sin(a));
}
}
const curve = new Strand();
const TS = TURNS * 300, RS = 28;
const g = new THREE.TubeGeometry(curve, TS, 0.072, RS, false);
const pos = g.getAttribute("position") as THREE.BufferAttribute;
const c = new THREE.Vector3();
const v = new THREE.Vector3();
for (let i = 0; i <= TS; i++) {
const t = i / TS;
curve.getPointAt(t, c);
const bead = Math.max(0, Math.cos(Math.PI * 2 * t * PAIRS - Math.PI));
const s = 1 + 0.26 * bead * bead + (vnoise(t * 90 + phase * 7) - 0.5) * 0.14;
for (let j = 0; j <= RS; j++) {
const k = i * (RS + 1) + j;
v.fromBufferAttribute(pos, k).sub(c).multiplyScalar(s).add(c);
pos.setXYZ(k, v.x, v.y, v.z);
}
}
g.deleteAttribute("uv");
g.deleteAttribute("normal");
const m = mergeVertices(g, 1e-5);
g.dispose();
m.computeVertexNormals();
return m;
}
type Pair = { y: number; a: number };
const PAIR_LIST: Pair[] = Array.from({ length: PAIRS }, (_, k) => {
const y = ((k + 0.5) / PAIRS - 0.5) * HEIGHT;
return { y, a: (y / P) * Math.PI * 2 };
});
function buildHelix() {
const parts: THREE.BufferGeometry[] = [strand(0), strand(Math.PI)];
// base pairs: two flat rounded bars meeting near the axis
PAIR_LIST.forEach(({ y, a }, k) => {
for (const side of [1, -1]) {
const r0 = 0.03, r1 = R - 0.03;
const L = r1 - r0;
const box = new RoundedBoxGeometry(L, 0.072 + 0.012 * hash(k * 2 + side), 0.135, 3, 0.03);
box.deleteAttribute("uv");
const g = mergeVertices(box); // indexed, like the strands, so they can be merged
box.dispose();
g.translate(r0 + L / 2, 0, 0);
g.rotateY(-a + (side < 0 ? Math.PI : 0));
g.translate(0, y, 0);
parts.push(g);
}
});
const geo = mergeGeometries(parts)!;
parts.forEach((p) => p.dispose());
return geo;
}
// small rough fragments drifting past
function fragmentGeo() {
const g = new THREE.IcosahedronGeometry(1, 2);
const pos = g.getAttribute("position") as THREE.BufferAttribute;
const v = new THREE.Vector3();
for (let i = 0; i < pos.count; i++) {
v.fromBufferAttribute(pos, i);
const n = 0.75 + 0.5 * vnoise(v.x * 3 + v.y * 5 + v.z * 7 + 10);
v.multiplyScalar(n);
pos.setXYZ(i, v.x, v.y * 0.7, v.z);
}
g.deleteAttribute("uv");
g.deleteAttribute("normal");
const m = mergeVertices(g);
g.dispose();
m.computeVertexNormals();
return m;
}
// a product-photography studio: tall soft strip lights behind and beside, a dim top light, nothing else.
// Glossy curves reflect them as thin continuous lines along every edge, never as hot spots.
function studio() {
const env = new THREE.Scene();
env.background = new THREE.Color(0x000000);
const panel = (w: number, h: number, power: number, x: number, y: number, z: number) => {
const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h), new THREE.MeshBasicMaterial({ color: new THREE.Color(power, power, power), side: THREE.DoubleSide }));
m.position.set(x, y, z);
m.lookAt(0, 0, 0);
env.add(m);
};
panel(0.7, 12, 3.2, -5, 0.5, -3.2); // strips behind, left and right: the edge lines
panel(0.5, 12, 2.2, 5.2, -0.5, -2.6);
panel(0.35, 12, 1.4, -3.4, 0, 4.6); // thin strips in front: lines along the near faces
panel(0.35, 12, 1.0, 3.8, 0, 4.2);
panel(7, 2.2, 0.35, 0, 6, -1); // soft top light
return env;
}
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
export function HelixDrift({
color = "#dfe8f2",
body = "#22252b",
background = "#000000",
angle = 12,
offset = 0,
speed = 1,
bubbles = 1,
glow = 0.35,
interactive = true,
scroller,
children,
className,
}: HelixDriftProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, body, background, angle, offset, speed, bubbles, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, body, background, angle, offset, speed, bubbles, glow, interactive };
redraw.current?.();
}, [color, body, background, angle, offset, speed, bubbles, glow, 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);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: false, alpha: false, powerPreference: "high-performance" });
} catch {
const p = props.current;
host.style.background = `radial-gradient(40% 70% at 50% 50%, ${p.color}22, transparent 70%), ${p.background}`;
canvas.remove();
return;
}
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.7;
renderer.outputColorSpace = THREE.SRGBColorSpace;
// ---- scene, studio light ----
const scene = new THREE.Scene();
const pmrem = new THREE.PMREMGenerator(renderer);
const env = studio();
const envTex = pmrem.fromScene(env, 0.02).texture;
env.traverse((o) => {
if (o instanceof THREE.Mesh) {
o.geometry.dispose();
(o.material as THREE.Material).dispose();
}
});
scene.environment = envTex;
scene.environmentIntensity = 1.0;
scene.background = new THREE.Color();
scene.fog = new THREE.Fog(0x000000, 5.7, 10.5); // the far side falls into the dark: depth without blur
const camera = new THREE.PerspectiveCamera(30, 1, 0.1, 60);
const tilt = new THREE.Group();
const spin = new THREE.Group();
scene.add(tilt);
tilt.add(spin);
const rimA = new THREE.DirectionalLight(0xffffff, 3.2);
rimA.position.set(-4, 2.5, -5);
const rimB = new THREE.DirectionalLight(0xffffff, 2.2);
rimB.position.set(4.5, -1.5, -4);
const key = new THREE.DirectionalLight(0xffffff, 0.7);
key.position.set(1.5, 5, 4);
const cursorLight = new THREE.PointLight(0xffffff, 0, 6, 2);
cursorLight.position.set(0, 0, 1.6);
scene.add(rimA, rimB, key, cursorLight);
const lightBase = { rimA: 0.5, rimB: 0.3, key: 0.25 };
// ---- the helix: glossy clearcoat over a dark body; a pulse of light can travel along it ----
const uPulse = Array.from({ length: MAXP }, () => new THREE.Vector4(0, 0, 0, -1));
const pulseCol = new THREE.Color();
const helixMat = new THREE.MeshPhysicalMaterial({
color: 0x22252b,
metalness: 0.0,
roughness: 0.4,
clearcoat: 0.45,
clearcoatRoughness: 0.3,
specularIntensity: 0.8,
sheen: 0.35,
sheenRoughness: 0.5,
sheenColor: new THREE.Color(0x8a939e),
});
helixMat.onBeforeCompile = (sh) => {
sh.uniforms.uPulse = { value: uPulse };
sh.uniforms.uPulseCol = { value: pulseCol };
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>\nvarying vec3 vObj;\nuniform vec4 uPulse[${MAXP}];\nuniform vec3 uPulseCol;`)
.replace(
"#include <emissivemap_fragment>",
`#include <emissivemap_fragment>
for (int i = 0; i < ${MAXP}; i++) {
vec4 pu = uPulse[i];
if (pu.w < 0.0) continue;
float d = distance(vObj, pu.xyz);
float ring = exp(-pow(d - pu.w * 1.15, 2.0) / 0.012) * exp(-pu.w * 0.8) * smoothstep(0.0, 0.2, pu.w);
totalEmissiveRadiance += uPulseCol * ring * 0.8;
}`,
);
};
const helixGeo = buildHelix();
const helix = new THREE.Mesh(helixGeo, helixMat);
spin.add(helix);
// ---- real glass: droplets clinging under the bars, bubbles floating around ----
const glassMat = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
metalness: 0,
roughness: 0.03,
transmission: 1,
thickness: 0.35,
ior: 1.33,
attenuationColor: new THREE.Color(0x0d0f12),
attenuationDistance: 0.5,
specularIntensity: 1,
clearcoat: 1,
clearcoatRoughness: 0.03,
envMapIntensity: 1.2,
});
const bubbleGeo = new THREE.SphereGeometry(1, 48, 32);
const floaters = new THREE.InstancedMesh(bubbleGeo, glassMat, MAXB);
floaters.frustumCulled = false;
scene.add(floaters);
const droplets = new THREE.InstancedMesh(bubbleGeo, glassMat, MAXD);
droplets.frustumCulled = false;
spin.add(droplets);
const dummy = new THREE.Object3D();
// droplets hang from the underside of a few bars
for (let i = 0; i < MAXD; i++) {
const pr = PAIR_LIST[Math.floor(hash(i * 3.1 + 1) * PAIRS)];
const side = hash(i * 5.7) < 0.5 ? 1 : -1;
const along = 0.2 + 0.6 * hash(i * 9.3);
const rr = 0.028 + 0.03 * hash(i * 2.2);
const rad = (0.03 + along * (R - 0.06)) * side;
dummy.position.set(Math.cos(-pr.a) * rad, pr.y - 0.036 - rr * 0.55, Math.sin(-pr.a) * rad);
dummy.scale.set(rr, rr * 0.92, rr);
dummy.updateMatrix();
droplets.setMatrixAt(i, dummy.matrix);
}
droplets.instanceMatrix.needsUpdate = true;
type Bubble = { p: THREE.Vector3; v: THREE.Vector3; r: number; ph: number };
const rnd = (a: number, b: number) => a + Math.random() * (b - a);
const bub: Bubble[] = Array.from({ length: MAXB }, () => ({
p: new THREE.Vector3(rnd(-2.4, 2.4), rnd(-3, 3), rnd(-1.6, 2.2)),
v: new THREE.Vector3(),
r: Math.random() < 0.75 ? rnd(0.025, 0.06) : rnd(0.065, 0.1),
ph: Math.random() * 6.28,
}));
const fragMat = helixMat.clone();
fragMat.onBeforeCompile = () => {};
const fragGeo = fragmentGeo();
const frags = new THREE.InstancedMesh(fragGeo, fragMat, MAXF);
frags.frustumCulled = false;
scene.add(frags);
const frag = Array.from({ length: MAXF }, () => ({
p: new THREE.Vector3(rnd(-2.2, 2.2), rnd(-3, 3), rnd(-1.4, 1.8)),
r: rnd(0.008, 0.03),
rot: new THREE.Euler(rnd(0, 6), rnd(0, 6), rnd(0, 6)),
w: rnd(-0.6, 0.6),
}));
// ---- render: supersampled, multisampled HDR, soft bloom, ACES ----
const rt = new THREE.WebGLRenderTarget(1, 1, { type: THREE.HalfFloatType, samples: 4 });
const composer = new EffectComposer(renderer, rt);
composer.addPass(new RenderPass(scene, camera));
const bloom = new UnrealBloomPass(new THREE.Vector2(1, 1), 0.2, 0.35, 1.0);
composer.addPass(bloom);
composer.addPass(new OutputPass());
let w = 1, h = 1;
const resize = () => {
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
// render above screen resolution so thin highlights stay clean, within a pixel budget
let pr = Math.min(2, (window.devicePixelRatio || 1) * 1.5);
pr = Math.min(pr, Math.sqrt(5.5e6 / (w * h)));
renderer.setPixelRatio(pr);
renderer.setSize(w, h, false);
composer.setPixelRatio(pr);
composer.setSize(w, h);
camera.aspect = w / h;
const halfH = Math.max(2.0, 1.08 / camera.aspect);
camera.fov = (2 * Math.atan(halfH / 7) * 180) / Math.PI;
camera.updateProjectionMatrix();
};
resize();
// ---- motion state ----
const s = { intro: still ? 1 : 0, dist: still ? 7 : 9.6, light: still ? 1 : 0, hover: 0, cx: 0, cy: 0, lx: 0, ly: 0 };
let theta = 0.4, omega = 0, time = 0;
let lastST = 0;
const idle = () => 0.22 * Math.max(0, props.current.speed);
const ptr = { x: 0, y: 0, in: false, down: false, dragging: false, sx: 0, sy: 0, lx: 0, lt: 0, vel: 0, t0: 0 };
const pulseAge = Array(MAXP).fill(-1);
let pulseNext = 0;
const tmpV = new THREE.Vector3();
const ray = new THREE.Raycaster();
const ndc = new THREE.Vector2();
const camTo = { x: gsap.quickTo(s, "cx", { duration: 1.1, ease: "power3.out" }), y: gsap.quickTo(s, "cy", { duration: 1.1, ease: "power3.out" }) };
const lightTo = { x: gsap.quickTo(s, "lx", { duration: 0.45, ease: "power3.out" }), y: gsap.quickTo(s, "ly", { duration: 0.45, ease: "power3.out" }) };
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.6, ease: "sine.out" });
const place = () => {
const p = props.current;
camera.position.set(s.cx, s.cy, s.dist);
camera.lookAt(0, 0, 0);
tilt.rotation.set(0, 0, (-p.angle * Math.PI) / 180);
const halfW = Math.tan((camera.fov * Math.PI) / 360) * 7 * camera.aspect;
tilt.position.set(Math.max(-1, Math.min(1, p.offset)) * halfW * 0.55, 0, 0);
spin.rotation.set(0, theta, 0);
cursorLight.position.set(s.lx, s.ly, 1.7);
};
const bgCol = new THREE.Color();
const rimCol = new THREE.Color();
const draw = () => {
const p = props.current;
place();
bgCol.set(p.background);
(scene.background as THREE.Color).copy(bgCol);
(scene.fog as THREE.Fog).color.copy(bgCol);
helixMat.color.set(p.body);
fragMat.color.set(p.body);
rimCol.set(p.color);
rimA.color.copy(rimCol);
rimB.color.copy(rimCol);
cursorLight.color.copy(rimCol);
pulseCol.copy(rimCol);
rimA.intensity = lightBase.rimA * s.light;
rimB.intensity = lightBase.rimB * s.light;
key.intensity = lightBase.key * s.light;
scene.environmentIntensity = 1.0 * s.light;
cursorLight.intensity = 4 * s.hover * s.light;
bloom.strength = Math.max(0, p.glow);
for (let i = 0; i < MAXP; i++) uPulse[i].w = pulseAge[i];
const k = Math.max(0, Math.min(1.8, p.bubbles));
floaters.count = Math.min(MAXB, Math.round(32 * k));
for (let i = 0; i < floaters.count; i++) {
const b = bub[i];
dummy.position.copy(b.p);
dummy.rotation.set(0, 0, 0);
dummy.scale.setScalar(b.r * Math.min(1, s.intro * 1.4));
dummy.updateMatrix();
floaters.setMatrixAt(i, dummy.matrix);
}
floaters.instanceMatrix.needsUpdate = true;
droplets.count = Math.min(MAXD, Math.round(12 * k));
frags.count = Math.min(MAXF, Math.round(26 * k));
for (let i = 0; i < frags.count; i++) {
const f = frag[i];
dummy.position.copy(f.p);
dummy.rotation.copy(f.rot);
dummy.scale.setScalar(f.r);
dummy.updateMatrix();
frags.setMatrixAt(i, dummy.matrix);
}
frags.instanceMatrix.needsUpdate = true;
composer.render();
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
// ---- pointer: the cursor is a light; grab to turn it; a tap sends a pulse ----
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const aimLight = (x: number, y: number) => {
// the light sits on a plane just in front of the helix, under the cursor
ndc.set((x / w) * 2 - 1, 1 - (y / h) * 2);
ray.setFromCamera(ndc, camera);
const t = (1.7 - ray.ray.origin.z) / ray.ray.direction.z;
tmpV.copy(ray.ray.direction).multiplyScalar(t).add(ray.ray.origin);
lightTo.x(tmpV.x);
lightTo.y(tmpV.y);
};
const move = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const l = local(e);
const t = performance.now();
if (ptr.down) {
if (!ptr.dragging && Math.hypot(l.x - ptr.sx, l.y - ptr.sy) > 5) ptr.dragging = true;
if (ptr.dragging) {
// grabbed: it turns with your hand
const dx = l.x - ptr.lx;
const d = (dx / Math.max(320, w * 0.45)) * Math.PI;
theta += d;
const dt = Math.max(8, t - ptr.lt) / 1000;
ptr.vel += (d / dt - ptr.vel) * 0.5;
}
}
ptr.lx = l.x;
ptr.lt = t;
ptr.x = l.x;
ptr.y = l.y;
ptr.in = true;
camTo.x(((l.x / w) * 2 - 1) * 0.5);
camTo.y((1 - (l.y / h) * 2) * 0.35);
aimLight(l.x, l.y);
hoverTo(1);
};
const leave = () => {
ptr.in = false;
ptr.down = false;
ptr.dragging = false;
camTo.x(0);
camTo.y(0);
hoverTo(0);
};
const down = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const tg = e.target as HTMLElement | null;
if (e.pointerType === "mouse" && tg && (tg === host || tg === canvas || tg.dataset.helixLayer !== undefined)) e.preventDefault();
const l = local(e);
ptr.down = true;
ptr.dragging = false;
ptr.sx = ptr.lx = l.x;
ptr.sy = l.y;
ptr.lt = ptr.t0 = performance.now();
ptr.vel = 0;
};
const up = () => {
if (!ptr.down) return;
const wasDrag = ptr.dragging;
const tap = !wasDrag && performance.now() - ptr.t0 < 400;
ptr.down = false;
ptr.dragging = false;
if (wasDrag) {
// released: it keeps the spin you gave it
omega = Math.max(-6, Math.min(6, ptr.vel));
return;
}
if (!tap) return;
place();
scene.updateMatrixWorld(true);
ndc.set((ptr.x / w) * 2 - 1, 1 - (ptr.y / h) * 2);
ray.setFromCamera(ndc, camera);
const hit = ray.intersectObject(helix, false)[0];
let lp: THREE.Vector3 | null = hit ? helix.worldToLocal(hit.point.clone()) : null;
if (!lp) {
// between the bars: take the point of the ray closest to the helix's axis, if it passes inside
const inv = helix.matrixWorld.clone().invert();
const o = ray.ray.origin.clone().applyMatrix4(inv);
const d = ray.ray.direction.clone().transformDirection(inv);
const den = d.x * d.x + d.z * d.z;
if (den > 1e-6) {
const t = -(o.x * d.x + o.z * d.z) / den;
const q = o.clone().addScaledVector(d, t);
if (Math.hypot(q.x, q.z) < R * 1.3) lp = q;
}
}
if (lp) {
const i = pulseNext++ % MAXP;
uPulse[i].set(lp.x, lp.y, lp.z, 0);
pulseAge[i] = 0;
}
// nearby bubbles are pushed gently aside
for (const b of bub) {
tmpV.copy(b.p).project(camera);
const dx = (tmpV.x * 0.5 + 0.5) * w - ptr.x, dy = (0.5 - tmpV.y * 0.5) * h - ptr.y;
const d = Math.hypot(dx, dy);
if (d < 240 && d > 1) {
const kk = (1 - d / 240) * 0.9;
b.v.x += (dx / d) * kk;
b.v.y -= (dy / d) * kk;
}
}
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
window.addEventListener("pointerup", up);
// ---- scroll spins it with momentum ----
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;
lastST = performance.now();
if (!props.current.interactive || Math.abs(dy) > 2000) return;
omega = Math.max(-5, Math.min(5, omega + dy * 0.004));
},
});
if (st) lastScroll = st.scroll();
const wheel = (e: WheelEvent) => {
if (still || !props.current.interactive) return;
if (performance.now() - lastST < 80) return;
const dy = e.deltaMode === 1 ? e.deltaY * 16 : e.deltaY;
omega = Math.max(-5, Math.min(5, omega + Math.max(-200, Math.min(200, dy)) * 0.004));
};
host.addEventListener("wheel", wheel, { passive: true });
// ---- loop ----
let visible = true;
let prev = performance.now();
let intro: gsap.core.Timeline | null = null;
const tick = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt;
const p = props.current;
// a real object turning in air: grabbed it follows the hand; released it coasts, then settles to its idle turn
if (!ptr.dragging) {
omega += (idle() - omega) * (1 - Math.exp(-dt * 1.4));
theta += omega * dt;
}
if (theta > 1e4) theta -= Math.PI * 2 * 1000;
for (let i = 0; i < MAXP; i++) if (pulseAge[i] >= 0) pulseAge[i] = pulseAge[i] > 6 ? -1 : pulseAge[i] + dt;
// bubbles rise, sway, and drift aside from the cursor
const drag = Math.exp(-dt * 1.6);
for (const b of bub) {
if (ptr.in && p.interactive) {
tmpV.copy(b.p).project(camera);
const dx = (tmpV.x * 0.5 + 0.5) * w - ptr.x, dy = (0.5 - tmpV.y * 0.5) * h - ptr.y;
const d = Math.hypot(dx, dy);
if (d < 150 && d > 1) {
const kk = (1 - d / 150) ** 2 * 2.4 * dt;
b.v.x += (dx / d) * kk;
b.v.y -= (dy / d) * kk;
}
}
b.v.multiplyScalar(drag);
b.p.x += (b.v.x + Math.sin(time * 0.7 + b.ph) * 0.05) * dt;
b.p.y += (b.v.y + 0.1 + b.r * 0.6) * dt;
if (b.p.y > 3.4) b.p.y -= 6.8;
if (b.p.x > 2.8) b.p.x -= 5.6;
if (b.p.x < -2.8) b.p.x += 5.6;
}
for (const f of frag) {
f.rot.x += f.w * dt;
f.rot.y += f.w * 0.7 * dt;
f.p.y += 0.05 * dt;
if (f.p.y > 3.3) f.p.y -= 6.6;
}
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
if (still) {
draw();
redraw.current = draw;
} else {
omega = 1.6; // it turns into view and settles
intro = gsap
.timeline({ delay: 0.05 })
.to(s, { dist: 7, duration: 2.6, ease: "expo.out" }, 0)
.to(s, { light: 1, duration: 1.8, ease: "power2.out" }, 0)
.to(s, { intro: 1, duration: 2.2, ease: "power2.out" }, 0.2);
io.observe(host);
gsap.ticker.add(tick);
}
return () => {
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);
window.removeEventListener("pointerup", up);
host.removeEventListener("wheel", wheel);
gsap.killTweensOf(s);
helixGeo.dispose();
bubbleGeo.dispose();
fragGeo.dispose();
helixMat.dispose();
fragMat.dispose();
glassMat.dispose();
floaters.dispose();
droplets.dispose();
frags.dispose();
envTex.dispose();
pmrem.dispose();
composer.dispose();
rt.dispose();
renderer.dispose();
renderer.forceContextLoss();
canvas.remove();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && (
<div data-helix-layer="" className="relative z-10 h-full">
{children}
</div>
)}
</div>
);
}
export default HelixDrift;
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
12 propscolorstringColour of the light catching the edges, the cursor light and the pulse.default "#dfe8f2"default "#dfe8f2"bodystringColour of the glossy body.default "#22252b"default "#22252b"backgroundstringBackground colour.default "#000000"default "#000000"anglenumberTilt of the helix, degrees.default 12default 12offsetnumberHorizontal placement, -1 left to 1 right.default 0default 0speednumberSpeed of the idle turn.default 1default 1bubblesnumberHow many bubbles drift around it.default 1default 1glownumberStrength of the bloom on highlights.default 0.35default 0.35interactivebooleanGrab to spin, scroll to spin, cursor light, click pulse.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the helix.classNamestringSize it, e.g. h-screen w-full.