Prompt specification
Build or customize the Three.js 3D scene "Migration cue comparison chamber" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Migration cue comparison chamber
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/migration-cue-comparison-chamber-x0820
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring cell migration. Provide a uniform environment and a directional cue in adjacent toy cell tracks; compare prescribed trajectories while stating that real migration depends on many interacting mechanisms. Low-poly.
Working Three.js Starter (migration-cue-comparison-chamber-x0820):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cell Migration — Prescribed Trajectory Comparison</title>
<style>
:root {
--ink: #172333;
--muted: #607083;
--panel: rgba(249, 251, 253, 0.88);
--border: rgba(36, 56, 76, 0.15);
--coral: #ed6a5a;
--amber: #e9aa3f;
--teal: #178f91;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dde5ec;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow:
0 16px 45px rgba(31, 48, 65, 0.11),
0 2px 8px rgba(31, 48, 65, 0.05);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
top: 18px;
left: 18px;
right: 18px;
min-height: 74px;
border-radius: 17px;
padding: 14px 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 4px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2.2vw, 28px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
}
.header-meta {
display: flex;
align-items: center;
gap: 9px;
flex-wrap: wrap;
justify-content: flex-end;
}
.chip,
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(255, 255, 255, 0.65);
color: #435267;
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
.chip {
color: var(--teal);
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.a {
background: var(--coral);
}
.swatch.b {
background: var(--amber);
}
.info {
top: 110px;
right: 18px;
width: min(355px, calc(100vw - 36px));
border-radius: 17px;
padding: 17px 18px;
font-size: 12px;
line-height: 1.55;
}
.info h2 {
margin: 0 0 8px;
font-size: 14px;
letter-spacing: -0.015em;
}
.info p {
margin: 0 0 10px;
color: #536276;
}
.info p:last-child {
margin-bottom: 0;
}
.info strong {
color: var(--ink);
}
.caveat {
padding-top: 10px;
border-top: 1px solid var(--border);
}
.controls {
left: 18px;
bottom: 18px;
width: min(365px, calc(100vw - 36px));
border-radius: 17px;
padding: 13px 14px;
display: grid;
grid-template-columns: auto auto auto 1fr;
align-items: center;
gap: 9px;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 10px;
padding: 9px 11px;
background: rgba(255, 255, 255, 0.86);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#play {
min-width: 66px;
border-color: transparent;
background: var(--ink);
color: white;
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
padding-left: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.07em;
}
input[type="range"] {
width: 100%;
min-width: 45px;
accent-color: var(--teal);
}
.check {
grid-column: 1 / -1;
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.check input {
accent-color: var(--teal);
}
.status-row {
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
padding-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
#status {
color: var(--teal);
}
.hint {
right: 18px;
bottom: 18px;
padding: 9px 12px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.world-label {
position: fixed;
top: 0;
left: 0;
z-index: 5;
min-width: 118px;
padding: 8px 10px;
border: 1px solid rgba(32, 48, 64, 0.13);
border-radius: 11px;
background: rgba(250, 252, 254, 0.82);
box-shadow: 0 8px 24px rgba(32, 48, 64, 0.08);
backdrop-filter: blur(8px);
pointer-events: none;
will-change: transform;
}
.world-label b {
display: block;
color: var(--ink);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.world-label span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
#label-a {
border-left: 3px solid var(--coral);
}
#label-b {
border-left: 3px solid var(--amber);
}
#label-cue {
min-width: 0;
border-left: 3px solid var(--teal);
}
@media (max-width: 780px) {
header {
top: 10px;
left: 10px;
right: 10px;
min-height: 68px;
padding: 12px 13px;
}
.header-meta {
display: none;
}
.subtitle {
font-size: 10px;
}
.info {
top: auto;
right: 10px;
bottom: 106px;
left: 10px;
width: auto;
max-height: 31vh;
overflow: auto;
padding: 13px 14px;
font-size: 11px;
}
.info h2 {
font-size: 12px;
}
.controls {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
grid-template-columns: auto auto auto 1fr;
padding: 10px;
}
.hint {
display: none;
}
.world-label {
transform-origin: center;
scale: 0.88;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive cell migration trajectory comparison"></canvas>
<header class="hud">
<div>
<div class="eyebrow">Cell migration · toy comparison</div>
<h1>Prescribed trajectories, common environment</h1>
<div class="subtitle">
Adjacent low-poly tracks share identical substrate, lighting, and a synthetic directional cue.
</div>
</div>
<div class="header-meta">
<div class="chip">Uniform substrate</div>
<div class="legend-item"><span class="swatch a"></span>A · Smooth</div>
<div class="legend-item"><span class="swatch b"></span>B · Zig-zag</div>
</div>
</header>
<aside class="info hud">
<h2>What is being compared?</h2>
<p>
The lanes differ only in their <strong>prescribed paths</strong>.
Both cells move through the same uniform environment toward the same
rightward synthetic cue.
</p>
<p class="caveat">
<strong>This is not a biological simulation.</strong>
Real cell migration depends on many interacting mechanisms, including
receptor signaling, adhesion, cytoskeletal dynamics, cell polarity,
mechanics, and interactions with the extracellular matrix and neighboring cells.
</p>
</aside>
<section class="controls hud" aria-label="Animation controls">
<button id="play" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<button id="view" type="button">Top view</button>
<label class="speed-control" for="speed">
Speed
<input id="speed" type="range" min="0.5" max="2" step="0.1" value="1" />
</label>
<label class="check">
<input id="show-paths" type="checkbox" checked />
Show prescribed paths
</label>
<div class="status-row">
<span id="status" aria-live="polite">Running</span>
<span id="progress-text">0%</span>
</div>
</section>
<div class="hint hud">Drag to orbit · wheel to zoom · double-click to reset</div>
<div id="label-a" class="world-label">
<b>A · Smooth</b>
<span>directed prescription</span>
</div>
<div id="label-b" class="world-label">
<b>B · Zig-zag</b>
<span>biased prescription</span>
</div>
<div id="label-cue" class="world-label">
<b>→ Synthetic cue</b>
<span>identical in both tracks</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdde5ec);
scene.fog = new THREE.Fog(0xdde5ec, 34, 62);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100,
);
const target = new THREE.Vector3(0, 0, 0);
let yaw = 0.52;
let polar = 1.05;
let cameraRadius = 23;
let fitScale = 1;
let topView = false;
function updateCamera() {
const r = cameraRadius * fitScale;
const horizontal = Math.sin(polar) * r;
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + Math.cos(polar) * r,
target.z + horizontal * Math.cos(yaw),
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
// -------------------------------------------------------------------------
// Uniform environment and lighting
// -------------------------------------------------------------------------
const hemiLight = new THREE.HemisphereLight(0xf4f8ff, 0x8593a3, 2.0);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xfff6e8, 3.0);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcde8ff, 1.0);
fillLight.position.set(10, 6, -8);
scene.add(fillLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xd3dde5,
roughness: 1,
metalness: 0,
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 60),
groundMaterial,
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.46;
ground.receiveShadow = true;
scene.add(ground);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xcbd6df,
roughness: 0.92,
metalness: 0,
});
const platform = new THREE.Mesh(
new THREE.BoxGeometry(23, 0.44, 11.4),
platformMaterial,
);
platform.position.y = -0.22;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const laneMaterial = new THREE.MeshStandardMaterial({
color: 0xe9eff3,
roughness: 0.98,
metalness: 0,
});
const laneEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x9baab7,
transparent: true,
opacity: 0.48,
});
const laneZ = [-3.15, 3.15];
function makeLane(z) {
const lane = new THREE.Mesh(
new THREE.BoxGeometry(21, 0.08, 3.35),
laneMaterial,
);
lane.position.set(0, 0.04, z);
lane.receiveShadow = true;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(lane.geometry),
laneEdgeMaterial,
);
lane.add(edges);
scene.add(lane);
return lane;
}
laneZ.forEach(makeLane);
// -------------------------------------------------------------------------
// Prescribed trajectories
// -------------------------------------------------------------------------
const pathHeight = 0.11;
const smoothPath = new THREE.CatmullRomCurve3(
[
[-8.8, pathHeight, -3.15],
[-7.6, pathHeight, -3.05],
[-6.1, pathHeight, -3.25],
[-4.5, pathHeight, -3.08],
[-2.8, pathHeight, -3.22],
[-1.0, pathHeight, -3.04],
[0.9, pathHeight, -3.18],
[2.7, pathHeight, -3.08],
[4.4, pathHeight, -3.22],
[6.1, pathHeight, -3.10],
[7.6, pathHeight, -3.18],
[8.8, pathHeight, -3.15],
].map((p) => new THREE.Vector3(...p)),
false,
"centripetal",
);
const zigzagPath = new THREE.CatmullRomCurve3(
[
[-8.8, pathHeight, 3.15],
[-7.4, pathHeight, 3.65],
[-6.0, pathHeight, 2.75],
[-4.3, pathHeight, 3.55],
[-2.7, pathHeight, 2.70],
[-1.0, pathHeight, 3.55],
[0.8, pathHeight, 2.75],
[2.5, pathHeight, 3.60],
[4.1, pathHeight, 2.78],
[5.8, pathHeight, 3.48],
[7.2, pathHeight, 2.95],
[8.8, pathHeight, 3.15],
].map((p) => new THREE.Vector3(...p)),
false,
"centripetal",
);
function makeTrail(curve, color) {
const points = curve.getPoints(180);
const guide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: 0x7b8997,
transparent: true,
opacity: 0.42,
dashSize: 0.13,
gapSize: 0.1,
}),
);
guide.computeLineDistances();
scene.add(guide);
const activeGeometry = new THREE.BufferGeometry().setFromPoints(points);
activeGeometry.setDrawRange(0, 0);
const active = new THREE.Line(
activeGeometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
}),
);
scene.add(active);
return {
guide,
active,
sampleCount: points.length - 1,
};
}
const smoothTrail = makeTrail(smoothPath, 0xed6a5a);
const zigzagTrail = makeTrail(zigzagPath, 0xe9aa3f);
// -------------------------------------------------------------------------
// Shared start/end markers and synthetic directional cues
// -------------------------------------------------------------------------
const markerGeometry = new THREE.TorusGeometry(0.27, 0.045, 6, 20);
const startMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x8c99a6,
roughness: 0.75,
});
const endMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x178f91,
roughness: 0.62,
});
const cueMaterial = new THREE.MeshStandardMaterial({
color: 0x178f91,
emissive: 0x0b4545,
emissiveIntensity: 0.22,
roughness: 0.55,
});
function makeCueAndMarkers(z) {
const start = new THREE.Mesh(markerGeometry, startMarkerMaterial);
start.rotation.x = -Math.PI / 2;
start.position.set(-9.05, 0.095, z);
scene.add(start);
const end = new THREE.Mesh(markerGeometry, endMarkerMaterial);
end.rotation.x = -Math.PI / 2;
end.position.set(8.98, 0.095, z);
scene.add(end);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.95, 6),
cueMaterial,
);
shaft.rotation.z = -Math.PI / 2;
shaft.position.set(9.62, 0.14, z);
scene.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.38, 5),
cueMaterial,
);
head.rotation.z = -Math.PI / 2;
head.position.set(10.28, 0.14, z);
scene.add(head);
}
laneZ.forEach(makeCueAndMarkers);
// -------------------------------------------------------------------------
// Low-poly toy cells
// -------------------------------------------------------------------------
function makeCell(bodyColor) {
const group = new THREE.Group();
const membraneMaterial = new THREE.MeshStandardMaterial({
color: bodyColor,
roughness: 0.67,
metalness: 0.02,
flatShading: true,
});
const nucleusMaterial = new THREE.MeshStandardMaterial({
color: 0x36325f,
roughness: 0.58,
flatShading: true,
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.45, 1),
membraneMaterial,
);
body.scale.set(1.18, 0.72, 0.9);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const nucleus = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.19, 0),
nucleusMaterial,
);
nucleus.position.set(0.05, 0.21, 0.02);
nucleus.rotation.set(0.3, 0.4, 0.2);
nucleus.castShadow = true;
group.add(nucleus);
const bumpGeometry = new THREE.IcosahedronGeometry(0.11, 0);
const bumpPositions = [
[-0.27, 0.11, 0.24],
[0.19, 0.04, -0.29],
[-0.10, 0.16, -0.28],
[0.27, 0.12, 0.17],
];
for (const position of bumpPositions) {
const bump = new THREE.Mesh(bumpGeometry, membraneMaterial);
bump.position.set(...position);
bump.castShadow = true;
group.add(bump);
}
scene.add(group);
return {
group,
body,
nucleus,
};
}
const cellA = makeCell(0xed6a5a);
const cellB = makeCell(0xe9aa3f);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const playButton = document.getElementById("play");
const restartButton = document.getElementById("restart");
const viewButton = document.getElementById("view");
const speedInput = document.getElementById("speed");
const pathsInput = document.getElementById("show-paths");
const statusElement = document.getElementById("status");
const progressText = document.getElementById("progress-text");
let progress = 0;
let speed = 1;
let playing = true;
let elapsed = 0;
function updatePlayButton() {
if (progress >= 1) {
playButton.textContent = "Replay";
} else {
playButton.textContent = playing ? "Pause" : "Play";
}
statusElement.textContent =
progress >= 1 ? "Complete" : playing ? "Running" : "Paused";
}
function togglePlay() {
if (progress >= 1) {
progress = 0;
playing = true;
} else {
playing = !playing;
}
updatePlayButton();
}
playButton.addEventListener("click", togglePlay);
restartButton.addEventListener("click", () => {
progress = 0;
playing = true;
updatePlayButton();
});
speedInput.addEventListener("input", () => {
speed = Number(speedInput.value);
});
pathsInput.addEventListener("change", () => {
const visible = pathsInput.checked;
smoothTrail.guide.visible = visible;
smoothTrail.active.visible = visible;
zigzagTrail.guide.visible = visible;
zigzagTrail.active.visible = visible;
});
function resetView() {
yaw = 0.52;
polar = 1.05;
cameraRadius = 23;
topView = false;
viewButton.textContent = "Top view";
updateCamera();
}
viewButton.addEventListener("click", () => {
topView = !topView;
if (topView) {
yaw = 0;
polar = 0.035;
cameraRadius = 25;
viewButton.textContent = "Perspective";
} else {
resetView();
viewButton.textContent = "Top view";
}
updateCamera();
});
// Keyboard shortcut.
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (
event.code === "Space" &&
tag !== "BUTTON" &&
tag !== "INPUT"
) {
event.preventDefault();
togglePlay();
}
});
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
yaw -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar + dy * 0.005, 0.025, 1.42);
if (topView && polar > 0.05) {
topView = false;
viewButton.textContent = "Top view";
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
14,
38,
);
updateCamera();
},
{ passive: false },
);
canvas.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// World-space HTML labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-a"),
position: new THREE.Vector3(-8.7, 1.05, -3.15),
},
{
element: document.getElementById("label-b"),
position: new THREE.Vector3(-8.7, 1.05, 3.15),
},
{
element: document.getElementById("label-cue"),
position: new THREE.Vector3(9.85, 0.72, -3.15),
},
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
if (projected.z < -1 || projected.z > 1) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.opacity = "1";
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
}
// -------------------------------------------------------------------------
// Responsive sizing
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = aspect;
camera.updateProjectionMatrix();
// Pull the camera back on portrait screens so both tracks remain visible.
fitScale = Math.max(1, 0.9 / aspect);
updateCamera();
}
window.addEventListener("resize", onResize);
onResize();
// -------------------------------------------------------------------------
// Scene updates
// -------------------------------------------------------------------------
function updateTrail(trail, t) {
const count =
t <= 0 ? 0 : Math.min(trail.sampleCount + 1, Math.floor(t * trail.sampleCount) + 1);
trail.active.geometry.setDrawRange(0, count);
}
function updateCell(cell, curve, t, bobOffset) {
const point = curve.getPointAt(THREE.MathUtils.clamp(t, 0, 1));
const tangent = curve.getTangentAt(THREE.MathUtils.clamp(t, 0, 1));
cell.group.position.set(
point.x,
0.47 + Math.sin(elapsed * 3 + bobOffset) * 0.022,
point.z,
);
// Align the cell's local +X direction with the prescribed tangent.
cell.group.rotation.y = Math.atan2(-tangent.z, tangent.x);
cell.body.rotation.y = Math.sin(elapsed * 1.8 + bobOffset) * 0.08;
cell.nucleus.rotation.y += 0.008;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
if (playing) {
progress += dt * 0.055 * speed;
if (progress >= 1) {
progress = 1;
playing = false;
updatePlayButton();
}
}
updateTrail(smoothTrail, progress);
updateTrail(zigzagTrail, progress);
updateCell(cellA, smoothPath, progress, 0);
updateCell(cellB, zigzagPath, progress, Math.PI);
progressText.textContent = `${Math.round(progress * 100)}%`;
renderer.render(scene, camera);
updateLabels();
}
updatePlayButton();
animate();
</script>
</body>
</html>
```