Prompt specification
Build or customize the Three.js 3D scene "Catalyst reuse token sequence" 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: Catalyst reuse token sequence
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/catalyst-reuse-token-sequence-x1926
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring an animation of a symbolic catalyst binding reactants, enabling a transformation, and being released unchanged overall; track atom tokens and distinguish intermediate changes from net consumption. A 3D cutaway view.
Working Three.js Starter (catalyst-reuse-token-sequence-x1926):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Catalyst Turnover — Atom-Token Reactor</title>
<style>
:root {
color-scheme: dark;
--bg: #050a12;
--panel: rgba(9, 18, 31, 0.82);
--panel-strong: rgba(12, 24, 39, 0.94);
--line: rgba(153, 192, 216, 0.18);
--text: #e9f3f8;
--muted: #8da5b5;
--cyan: #56e2c4;
--coral: #ff776d;
--blue: #66a8ff;
--white: #eef6fb;
--amber: #ffc86a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, rgba(27, 75, 94, 0.23), transparent 38%),
radial-gradient(circle at 15% 85%, rgba(32, 51, 97, 0.18), transparent 35%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#scene-container {
position: fixed;
inset: 0;
}
#scene-container canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.brand {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.02em;
}
.toolbar {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(8, 16, 27, 0.78);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
}
.tool-button {
min-width: 38px;
height: 36px;
padding: 0 10px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: #b9cbd6;
cursor: pointer;
transition:
color 150ms ease,
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.tool-button:hover,
.tool-button:focus-visible {
border-color: rgba(86, 226, 196, 0.24);
background: rgba(86, 226, 196, 0.08);
color: white;
outline: none;
}
.tool-button:active {
transform: translateY(1px);
}
.tool-button.active {
border-color: rgba(86, 226, 196, 0.34);
background: rgba(86, 226, 196, 0.12);
color: var(--cyan);
}
.tool-icon {
display: inline-block;
min-width: 18px;
font-size: 14px;
font-weight: 750;
text-align: center;
}
.tool-label {
margin-left: 6px;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.04em;
}
.panel {
border: 1px solid var(--line);
border-radius: 17px;
background:
linear-gradient(145deg, rgba(20, 36, 52, 0.58), rgba(5, 13, 24, 0.88)),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.30),
inset 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(18px);
}
.ledger {
position: fixed;
z-index: 6;
top: 84px;
right: 24px;
width: 340px;
max-height: calc(100vh - 108px);
overflow: auto;
padding: 17px;
scrollbar-width: thin;
scrollbar-color: rgba(86, 226, 196, 0.25) transparent;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 15px;
}
.panel-heading h2 {
margin: 0;
font-size: 11px;
font-weight: 760;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
}
.live::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
.equation {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 10px;
margin-bottom: 14px;
padding: 14px 12px;
border: 1px solid rgba(133, 183, 205, 0.13);
border-radius: 12px;
background: rgba(1, 7, 14, 0.38);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 650;
text-align: center;
}
.equation .side {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 4px;
}
.arrow {
position: relative;
color: var(--cyan);
font-size: 20px;
}
.arrow .over {
position: absolute;
top: -11px;
left: 50%;
color: var(--cyan);
font-size: 9px;
transform: translateX(-50%);
}
.table-head,
.token-row {
display: grid;
grid-template-columns: 58px minmax(0, 1fr) 48px;
align-items: center;
gap: 9px;
}
.table-head {
padding: 0 9px 7px;
color: #698090;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.table-head span:last-child {
text-align: right;
}
#tokenRows {
display: grid;
gap: 4px;
}
.token-row {
width: 100%;
padding: 9px;
border: 1px solid transparent;
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
color: var(--text);
cursor: pointer;
text-align: left;
transition: 150ms ease;
}
.token-row:hover,
.token-row:focus-visible {
border-color: rgba(86, 226, 196, 0.2);
background: rgba(86, 226, 196, 0.055);
outline: none;
}
.token-row.selected {
border-color: rgba(86, 226, 196, 0.42);
background: rgba(86, 226, 196, 0.09);
}
.token-id {
display: inline-flex;
align-items: center;
gap: 7px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
}
.token-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--token-color);
box-shadow: 0 0 9px color-mix(in srgb, var(--token-color), transparent 25%);
}
.token-state {
overflow: hidden;
color: #a8bac6;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.token-delta {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
text-align: right;
}
.balance-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
.balance-card {
min-width: 0;
padding: 11px;
border: 1px solid rgba(133, 183, 205, 0.12);
border-radius: 11px;
background: rgba(0, 5, 12, 0.28);
}
.balance-label {
margin-bottom: 7px;
color: #718896;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.balance-value {
overflow: hidden;
color: #d8e8f0;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.balance-note {
margin-top: 5px;
color: #708997;
font-size: 9px;
line-height: 1.35;
}
.integrity {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 9px;
padding: 11px;
border: 1px solid rgba(86, 226, 196, 0.22);
border-radius: 11px;
background: linear-gradient(90deg, rgba(86, 226, 196, 0.1), rgba(86, 226, 196, 0.035));
}
.integrity strong {
display: block;
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.03em;
}
.integrity span {
display: block;
margin-top: 3px;
color: #91a8b5;
font-size: 9px;
}
.intact-badge {
flex: 0 0 auto;
padding: 5px 7px;
border-radius: 999px;
background: rgba(86, 226, 196, 0.14);
color: var(--cyan);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
}
.selected-detail {
margin-top: 9px;
padding: 10px 11px;
border-left: 2px solid var(--cyan);
border-radius: 0 8px 8px 0;
background: rgba(86, 226, 196, 0.055);
color: #9fb5c1;
font-size: 10px;
line-height: 1.45;
}
.phase-card {
position: fixed;
z-index: 6;
bottom: 24px;
left: 24px;
width: min(470px, calc(100vw - 48px));
padding: 17px 18px 15px;
}
.phase-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.phase-number {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
}
.phase-card h2 {
margin: 5px 0 0;
font-size: 21px;
font-weight: 650;
letter-spacing: -0.025em;
}
.phase-card p {
min-height: 34px;
margin: 9px 0 14px;
color: #98adb9;
font-size: 11px;
line-height: 1.5;
}
.cycle-track {
position: relative;
height: 4px;
overflow: hidden;
border-radius: 999px;
background: rgba(143, 180, 200, 0.13);
}
#cycleProgress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #3fc7ff, var(--cyan));
box-shadow: 0 0 16px rgba(86, 226, 196, 0.45);
}
.phase-segments {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 6px;
margin-top: 8px;
}
.phase-segment {
color: #627987;
font-size: 7px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
transition: color 180ms ease;
}
.phase-segment.active {
color: var(--cyan);
}
.orbit-hint {
position: fixed;
z-index: 4;
right: 25px;
bottom: 24px;
color: rgba(164, 190, 204, 0.64);
font-size: 9px;
letter-spacing: 0.06em;
pointer-events: none;
}
@media (max-width: 900px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.toolbar {
top: 14px;
right: 14px;
}
.ledger {
top: 67px;
right: 14px;
width: min(330px, calc(100vw - 28px));
max-height: 43vh;
}
.phase-card {
bottom: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.orbit-hint {
display: none;
}
}
@media (max-width: 580px) {
.brand h1 {
font-size: 24px;
}
.brand .eyebrow {
font-size: 8px;
}
.toolbar {
top: 68px;
left: 14px;
right: auto;
}
.ledger {
top: 116px;
}
.tool-label {
display: none;
}
.phase-card {
padding: 14px;
}
.phase-card h2 {
font-size: 18px;
}
.phase-card p {
min-height: 48px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="scene-container" aria-label="Interactive 3D cutaway catalyst reaction"></div>
<header class="brand">
<div class="eyebrow">Molecular dynamics / token tracking</div>
<h1>Catalyst turnover</h1>
<p>A–H + B–H → A–B + H–H, mediated by unchanged X</p>
</header>
<nav class="toolbar" aria-label="Scene controls">
<button class="tool-button" id="playButton" title="Pause or resume animation">
<span class="tool-icon" id="playIcon">Ⅱ</span>
<span class="tool-label" id="playLabel">Pause</span>
</button>
<button class="tool-button" id="speedButton" title="Change simulation speed">
<span class="tool-icon">×</span>
<span class="tool-label" id="speedLabel">1.0</span>
</button>
<button class="tool-button active" id="cutawayButton" title="Toggle reactor cutaway">
<span class="tool-icon">◐</span>
<span class="tool-label">Cutaway</span>
</button>
<button class="tool-button" id="resetButton" title="Restart reaction cycle">
<span class="tool-icon">↺</span>
<span class="tool-label">Reset</span>
</button>
</nav>
<aside class="ledger panel" aria-label="Atom conservation ledger">
<div class="panel-heading">
<h2>Conservation ledger</h2>
<span class="live">Live</span>
</div>
<div class="equation" aria-label="Net reaction equation">
<div class="side">
<span style="color:var(--coral)">A</span>–H
<span>+</span>
<span style="color:var(--blue)">B</span>–H
</div>
<div class="arrow">
<span class="over">X</span>⟶
</div>
<div class="side">
<span style="color:var(--coral)">A</span>–<span style="color:var(--blue)">B</span>
<span>+</span>
H–H
</div>
</div>
<div class="table-head">
<span>Token</span>
<span>Current state</span>
<span>Δ count</span>
</div>
<div id="tokenRows"></div>
<div class="balance-grid">
<div class="balance-card">
<div class="balance-label">Transient intermediate</div>
<div class="balance-value" id="intermediateValue">None</div>
<div class="balance-note" id="intermediateNote">Free catalyst X</div>
</div>
<div class="balance-card">
<div class="balance-label">Net consumption</div>
<div class="balance-value" id="consumptionValue">X: 0</div>
<div class="balance-note">Atom counts are conserved globally.</div>
</div>
</div>
<div class="integrity">
<div>
<strong>Same catalyst token X throughout</strong>
<span>Its bonds change temporarily, but X is not consumed.</span>
</div>
<span class="intact-badge">Intact</span>
</div>
<div class="selected-detail" id="selectedDetail" aria-live="polite"></div>
</aside>
<section class="phase-card panel" aria-live="polite">
<div class="phase-top">
<div>
<div class="phase-number" id="phaseNumber">01 / 05</div>
<h2 id="phaseTitle">Approach</h2>
</div>
</div>
<p id="phaseDescription">
The two reactants approach the active site while retaining their original bonds.
</p>
<div class="cycle-track" aria-hidden="true">
<div id="cycleProgress"></div>
</div>
<div class="phase-segments" aria-hidden="true">
<span class="phase-segment active">Approach</span>
<span class="phase-segment">Bind</span>
<span class="phase-segment">Transform</span>
<span class="phase-segment">Release</span>
<span class="phase-segment">Regenerated</span>
</div>
</section>
<div class="orbit-hint">DRAG TO ORBIT · SHIFT/right-drag to pan · wheel to zoom · click a token</div>
</main>
<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 container = document.getElementById("scene-container");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x06101b, 0.026);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.localClippingEnabled = true;
renderer.domElement.setAttribute("aria-label", "3D cutaway molecular catalyst simulation");
renderer.domElement.tabIndex = 0;
container.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0x9edcff, 0x07101b, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.8);
keyLight.position.set(4, 7, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x4fc9ff, 30, 18, 2);
rimLight.position.set(-4, 2, -3);
scene.add(rimLight);
const catalystLight = new THREE.PointLight(0x55f0ca, 14, 7, 2);
catalystLight.position.set(0, 0.1, 1.2);
scene.add(catalystLight);
// Camera controls are implemented locally; no Three.js addons are used.
const cameraTarget = new THREE.Vector3(0, 0.25, 0);
let cameraTheta = 0.34;
let cameraPhi = 1.18;
let cameraRadius = 11.3;
let dragging = false;
let dragButton = 0;
let pointerX = 0;
let pointerY = 0;
let pointerTravel = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const forward = new THREE.Vector3();
const right = new THREE.Vector3();
const up = new THREE.Vector3();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragButton = event.button;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
if (event.shiftKey || dragButton === 2) {
camera.getWorldDirection(forward);
right.crossVectors(forward, camera.up).normalize();
up.crossVectors(right, forward).normalize();
const panScale = cameraRadius * 0.0015;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(up, dy * panScale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -2.4, 2.4);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, -1.8, 2.4);
} else {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.006, 0.38, 2.65);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (pointerTravel < 5) {
selectFromPointer(event.clientX, event.clientY);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
7.2,
17.5
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Reactor cutaway and stage
// -------------------------------------------------------------------------
const cutawayPlane = new THREE.Plane(new THREE.Vector3(0, 0, -1), 0);
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0x8ec9df,
transparent: true,
opacity: 0.105,
roughness: 0.28,
metalness: 0.18,
side: THREE.DoubleSide,
depthWrite: false,
clippingPlanes: [cutawayPlane]
});
const reactorShell = new THREE.Mesh(
new THREE.SphereGeometry(4.15, 72, 40),
shellMaterial
);
scene.add(reactorShell);
const shellEdgeMaterial = new THREE.MeshBasicMaterial({
color: 0x6ccfe4,
transparent: true,
opacity: 0.34,
depthWrite: false
});
const shellEdge = new THREE.Mesh(
new THREE.TorusGeometry(4.15, 0.022, 8, 180),
shellEdgeMaterial
);
scene.add(shellEdge);
const outerHalo = new THREE.Mesh(
new THREE.TorusGeometry(4.28, 0.008, 6, 180),
new THREE.MeshBasicMaterial({
color: 0x56e2c4,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
scene.add(outerHalo);
const floor = new THREE.Mesh(
new THREE.CircleGeometry(3.9, 96),
new THREE.MeshStandardMaterial({
color: 0x0b1c29,
transparent: true,
opacity: 0.36,
roughness: 0.9,
side: THREE.DoubleSide
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.02;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(7.7, 18, 0x2d8fa7, 0x173747);
grid.position.y = -1.995;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
const floorRings = [];
for (const radius of [1.05, 2.1, 3.15]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.009, 6, 100),
new THREE.MeshBasicMaterial({
color: 0x2d8094,
transparent: true,
opacity: 0.23,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -1.98;
scene.add(ring);
floorRings.push(ring);
}
const activeSite = new THREE.Group();
scene.add(activeSite);
const siteRingA = new THREE.Mesh(
new THREE.TorusGeometry(0.92, 0.012, 8, 100),
new THREE.MeshBasicMaterial({
color: 0x56e2c4,
transparent: true,
opacity: 0.26,
depthWrite: false
})
);
siteRingA.rotation.x = Math.PI / 2;
activeSite.add(siteRingA);
const siteRingB = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.008, 8, 100),
new THREE.MeshBasicMaterial({
color: 0x65bfff,
transparent: true,
opacity: 0.2,
depthWrite: false
})
);
siteRingB.rotation.y = Math.PI / 2;
activeSite.add(siteRingB);
const catalystHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.49, 0.035, 10, 72),
new THREE.MeshBasicMaterial({
color: 0x56e2c4,
transparent: true,
opacity: 0.25,
depthWrite: false
})
);
activeSite.add(catalystHalo);
// Deterministic suspended particles give the chamber depth.
let randomSeed = 3817;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const particleCount = 220;
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i++) {
const radius = 0.4 + random() * 3.5;
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
particlePositions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
particlePositions[i * 3 + 1] = radius * Math.cos(phi);
particlePositions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x80c6df,
size: 0.025,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
scene.add(particles);
// -------------------------------------------------------------------------
// Atom tokens and labels
// -------------------------------------------------------------------------
const tokenColors = {
A: 0xff776d,
B: 0x66a8ff,
H1: 0xeef6fb,
H2: 0xeef6fb,
X: 0x56e2c4
};
function createLabelTexture(text, background, foreground) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 256, 128);
const x = 25;
const y = 20;
const width = 206;
const height = 88;
const radius = 28;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = background;
context.fill();
context.strokeStyle = foreground;
context.globalAlpha = 0.55;
context.lineWidth = 3;
context.stroke();
context.globalAlpha = 1;
context.fillStyle = foreground;
context.font = "700 54px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createAtom(id, label, radius, position, emissive = 0.45) {
const color = tokenColors[id];
const root = new THREE.Group();
root.position.copy(position);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: emissive,
roughness: 0.27,
metalness: 0.16,
transparent: true,
opacity: 1
});
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 32, 24),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.token = id;
root.add(mesh);
const glow = new THREE.Mesh(
new THREE.SphereGeometry(radius * 1.12, 24, 18),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.08,
side: THREE.BackSide,
depthWrite: false
})
);
root.add(glow);
const labelSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createLabelTexture(
label,
id === "X" ? "rgba(5,35,39,0.92)" : "rgba(8,17,28,0.9)",
id === "H1" || id === "H2" ? "#dceaf2" : `#${color.toString(16).padStart(6, "0")}`
),
transparent: true,
depthTest: false,
depthWrite: false
})
);
labelSprite.position.set(0, radius + 0.42, 0);
labelSprite.scale.set(0.72, 0.36, 1);
labelSprite.renderOrder = 30;
root.add(labelSprite);
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(radius * 1.55, 0.018, 8, 72),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.85,
depthTest: false,
depthWrite: false
})
);
selectionRing.visible = false;
selectionRing.renderOrder = 29;
root.add(selectionRing);
scene.add(root);
return {
id,
label,
root,
mesh,
glow,
labelSprite,
selectionRing,
material,
radius
};
}
const atoms = {
A: createAtom(
"A",
"A₁",
0.27,
new THREE.Vector3(-3.2, 2.2, 1.0)
),
B: createAtom(
"B",
"B₁",
0.27,
new THREE.Vector3(3.1, 2.0, -0.9)
),
H1: createAtom(
"H1",
"H₁",
0.19,
new THREE.Vector3(-4.05, 1.6, 0.7)
),
H2: createAtom(
"H2",
"H₂",
0.19,
new THREE.Vector3(3.95, 1.45, -0.55)
),
X: createAtom(
"X",
"X•",
0.34,
new THREE.Vector3(0, 0.05, 0),
0.7
)
};
const atomMeshes = Object.values(atoms).map((atom) => atom.mesh);
// -------------------------------------------------------------------------
// Dynamic bonds
// -------------------------------------------------------------------------
function createBond(color, radius = 0.045) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 18, 1, true),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false
})
);
mesh.userData.radius = radius;
scene.add(mesh);
return mesh;
}
const bonds = {
AH: createBond(0xb9d0dc, 0.047),
BH: createBond(0xb9d0dc, 0.047),
XH1: createBond(0x56e2c4, 0.038),
XH2: createBond(0x56e2c4, 0.038),
AB: createBond(0xff9a85, 0.065),
HH: createBond(0xd9e7ee, 0.05)
};
const bondDirection = new THREE.Vector3();
const bondMidpoint = new THREE.Vector3();
const upAxis = new THREE.Vector3(0, 1, 0);
function updateBond(mesh, start, end, opacity) {
mesh.visible = opacity > 0.005;
if (!mesh.visible) return;
bondDirection.subVectors(end, start);
const length = Math.max(bondDirection.length(), 0.001);
bondMidpoint.addVectors(start, end).multiplyScalar(0.5);
mesh.position.copy(bondMidpoint);
mesh.quaternion.setFromUnitVectors(upAxis, bondDirection.normalize());
mesh.scale.set(mesh.userData.radius, length, mesh.userData.radius);
mesh.material.opacity = opacity;
}
// -------------------------------------------------------------------------
// Reaction tracks
// -------------------------------------------------------------------------
const tracks = {
A: [
{ t: 0.0, p: [-3.2, 2.2, 1.0] },
{ t: 2.0, p: [-1.35, 1.45, 0.35] },
{ t: 5.0, p: [-1.2, 1.28, 0.22] },
{ t: 7.0, p: [-0.45, 1.15, 0.02] },
{ t: 9.2, p: [-0.45, 1.15, 0.02] },
{ t: 11.5, p: [-1.1, 1.25, 0.18] },
{ t: 14.0, p: [-1.8, 1.45, 0.35] }
],
B: [
{ t: 0.0, p: [3.1, 2.0, -0.9] },
{ t: 2.0, p: [1.3, 1.35, -0.15] },
{ t: 5.0, p: [1.2, 1.25, -0.08] },
{ t: 7.0, p: [0.45, 1.15, -0.02] },
{ t: 9.2, p: [0.45, 1.15, -0.02] },
{ t: 11.5, p: [-0.25, 1.25, 0.05] },
{ t: 14.0, p: [-0.9, 1.45, 0.2] }
],
H1: [
{ t: 0.0, p: [-4.05, 1.6, 0.7] },
{ t: 2.0, p: [-2.1, 0.9, 0.2] },
{ t: 3.4, p: [-2.0, 0.82, 0.18] },
{ t: 5.0, p: [-0.58, 0.78, 0.18] },
{ t: 8.5, p: [-0.58, 0.78, 0.18] },
{ t: 9.2, p: [-0.25, -0.52, 0.14] },
{ t: 11.5, p: [0.55, -1.15, -0.12] },
{ t: 14.0, p: [1.0, -1.55, -0.25] }
],
H2: [
{ t: 0.0, p: [3.95, 1.45, -0.55] },
{ t: 2.0, p: [2.05, 0.85, -0.35] },
{ t: 3.4, p: [1.95, 0.78, -0.3] },
{ t: 5.0, p: [0.58, 0.78, -0.18] },
{ t: 8.5, p: [0.58, 0.78, -0.18] },
{ t: 9.2, p: [0.25, -0.52, 0.06] },
{ t: 11.5, p: [0.95, -1.05, -0.22] },
{ t: 14.0, p: [1.5, -1.45, -0.38] }
]
};
function smoothstep(min, max, value) {
const x = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return x * x * (3 - 2 * x);
}
function sampleTrack(track, time, target) {
for (let i = 0; i < track.length - 1; i++) {
const a = track[i];
const b = track[i + 1];
if (time >= a.t && time <= b.t) {
const u = smoothstep(a.t, b.t, time);
target.set(
THREE.MathUtils.lerp(a.p[0], b.p[0], u),
THREE.MathUtils.lerp(a.p[1], b.p[1], u),
THREE.MathUtils.lerp(a.p[2], b.p[2], u)
);
return target;
}
}
const last = track[track.length - 1].p;
target.set(last[0], last[1], last[2]);
return target;
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const phases = [
{
number: "01 / 05",
title: "Approach",
description:
"The two reactants approach the active site while retaining their original bonds."
},
{
number: "02 / 05",
title: "Bind / activate",
description:
"X temporarily coordinates both hydrogen tokens. The A–H and B–H bonds are cleaved."
},
{
number: "03 / 05",
title: "Transform",
description:
"Inside the X(H₁)(H₂) intermediate, the A–B product bond forms. No atom is consumed."
},
{
number: "04 / 05",
title: "Release products",
description:
"The hydrogen tokens recombine as H–H and detach from X, allowing the product to leave."
},
{
number: "05 / 05",
title: "Catalyst regenerated",
description:
"X is released in its original state. Its coordination changed, but its net atom count did not."
}
];
const phaseStates = [
{
A: "A–H",
B: "B–H",
H1: "H–A",
H2: "H–B",
X: "X free",
intermediate: "None",
note: "Free catalyst X"
},
{
A: "A detached",
B: "B detached",
H1: "X···H",
H2: "X···H",
X: "X coordinated",
intermediate: "X(H₁)(H₂)",
note: "Temporary coordination only"
},
{
A: "A···B",
B: "A···B",
H1: "X···H",
H2: "X···H",
X: "X coordinated",
intermediate: "X(H₁)(H₂) + A···B",
note: "Bond-making intermediate"
},
{
A: "A–B",
B: "A–B",
H1: "H···H",
H2: "H···H",
X: "X releasing",
intermediate: "A–B + X···H···H",
note: "Products detach from active site"
},
{
A: "A–B",
B: "A–B",
H1: "H–H",
H2: "H–H",
X: "X free",
intermediate: "A–B + H–H",
note: "Only the final products remain"
}
];
const tokenDescriptions = {
A: "A₁ is conserved: A–H → A–B. Only the bonding partner changes.",
B: "B₁ is conserved: B–H → A–B. Only the bonding partner changes.",
H1: "H₁ is conserved: H–A → H–H. The token is temporarily held by X.",
H2: "H₂ is conserved: H–B → H–H. The token is temporarily held by X.",
X: "X• is the same catalyst token throughout: X → X(H₁)(H₂) → X. Δn(X) = 0."
};
const tokenRows = document.getElementById("tokenRows");
const tokenOrder = ["A", "B", "H1", "H2", "X"];
const tokenLabels = {
A: "A₁",
B: "B₁",
H1: "H₁",
H2: "H₂",
X: "X•"
};
let selectedToken = "X";
for (const id of tokenOrder) {
const row = document.createElement("button");
row.className = "token-row";
row.dataset.token = id;
row.setAttribute("aria-pressed", String(id === selectedToken));
row.style.setProperty(
"--token-color",
`#${tokenColors[id].toString(16).padStart(6, "0")}`
);
row.innerHTML = `
<span class="token-id">
<span class="token-dot"></span>
${tokenLabels[id]}
</span>
<span class="token-state"></span>
<span class="token-delta">0</span>
`;
row.addEventListener("click", () => selectToken(id));
tokenRows.appendChild(row);
}
function selectToken(id) {
selectedToken = id;
for (const row of tokenRows.children) {
const selected = row.dataset.token === id;
row.classList.toggle("selected", selected);
row.setAttribute("aria-pressed", String(selected));
}
for (const atom of Object.values(atoms)) {
atom.selectionRing.visible = atom.id === id;
}
document.getElementById("selectedDetail").textContent =
tokenDescriptions[id];
}
selectToken("X");
const phaseNumber = document.getElementById("phaseNumber");
const phaseTitle = document.getElementById("phaseTitle");
const phaseDescription = document.getElementById("phaseDescription");
const phaseSegments = [...document.querySelectorAll(".phase-segment")];
const cycleProgress = document.getElementById("cycleProgress");
const intermediateValue = document.getElementById("intermediateValue");
const intermediateNote = document.getElementById("intermediateNote");
const consumptionValue = document.getElementById("consumptionValue");
let previousPhase = -1;
function getPhaseIndex(time) {
if (time < 2.0) return 0;
if (time < 4.2) return 1;
if (time < 7.6) return 2;
if (time < 10.6) return 3;
return 4;
}
function updateUI(time) {
const phaseIndex = getPhaseIndex(time);
cycleProgress.style.width = `${(time / DURATION) * 100}%`;
if (phaseIndex !== previousPhase) {
const phase = phases[phaseIndex];
const states = phaseStates[phaseIndex];
phaseNumber.textContent = phase.number;
phaseTitle.textContent = phase.title;
phaseDescription.textContent = phase.description;
intermediateValue.textContent = states.intermediate;
intermediateNote.textContent = states.note;
consumptionValue.textContent = "X: 0";
for (const row of tokenRows.children) {
row.querySelector(".token-state").textContent =
states[row.dataset.token];
}
phaseSegments.forEach((segment, index) => {
segment.classList.toggle("active", index === phaseIndex);
});
previousPhase = phaseIndex;
}
}
// -------------------------------------------------------------------------
// Raycast token selection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectFromPointer(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(atomMeshes, false);
if (intersections.length) {
selectToken(intersections[0].object.userData.token);
}
}
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
const playButton = document.getElementById("playButton");
const playIcon = document.getElementById("playIcon");
const playLabel = document.getElementById("playLabel");
const speedButton = document.getElementById("speedButton");
const speedLabel = document.getElementById("speedLabel");
const cutawayButton = document.getElementById("cutawayButton");
const resetButton = document.getElementById("resetButton");
let playing = true;
let speed = 1;
let speedIndex = 1;
const speeds = [0.5, 1, 1.5, 2];
let cutawayEnabled = true;
function togglePlayback() {
playing = !playing;
playIcon.textContent = playing ? "Ⅱ" : "▶";
playLabel.textContent = playing ? "Pause" : "Play";
playButton.classList.toggle("active", !playing);
}
function cycleSpeed() {
speedIndex = (speedIndex + 1) % speeds.length;
speed = speeds[speedIndex];
speedLabel.textContent = speed.toFixed(1);
}
function toggleCutaway() {
cutawayEnabled = !cutawayEnabled;
shellMaterial.clippingPlanes = cutawayEnabled ? [cutawayPlane] : [];
shellMaterial.needsUpdate = true;
shellEdge.visible = cutawayEnabled;
outerHalo.visible = cutawayEnabled;
cutawayButton.classList.toggle("active", cutawayEnabled);
}
playButton.addEventListener("click", togglePlayback);
speedButton.addEventListener("click", cycleSpeed);
cutawayButton.addEventListener("click", toggleCutaway);
resetButton.addEventListener("click", () => {
simulationTime = 0;
previousPhase = -1;
});
addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
togglePlayback();
} else if (event.key.toLowerCase() === "c") {
toggleCutaway();
} else if (event.key.toLowerCase() === "r") {
simulationTime = 0;
previousPhase = -1;
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const DURATION = 14;
let simulationTime = 0;
const clock = new THREE.Clock();
const sampledPosition = new THREE.Vector3();
function updateScene(time) {
const cycleFade =
smoothstep(0.0, 0.5, time) *
(1 - smoothstep(13.25, DURATION, time));
for (const id of ["A", "B", "H1", "H2"]) {
const atom = atoms[id];
sampleTrack(tracks[id], time, sampledPosition);
atom.root.position.copy(sampledPosition);
const opacity = cycleFade;
atom.root.visible = opacity > 0.005;
atom.material.opacity = opacity;
atom.glow.material.opacity = opacity * 0.08;
atom.labelSprite.material.opacity = opacity;
}
// X is one continuously tracked token. It never leaves the scene.
atoms.X.root.position.set(0, 0.05, 0);
atoms.X.material.opacity = 1;
atoms.X.glow.material.opacity = 0.12;
atoms.X.labelSprite.material.opacity = 1;
for (const atom of Object.values(atoms)) {
atom.selectionRing.quaternion.copy(camera.quaternion);
atom.material.emissiveIntensity =
atom.id === selectedToken ? 1.0 : atom.id === "X" ? 0.68 : 0.38;
}
const ahOpacity = 1 - smoothstep(3.2, 4.4, time);
const bhOpacity = 1 - smoothstep(3.2, 4.4, time);
const xh1Opacity =
smoothstep(3.2, 4.4, time) *
(1 - smoothstep(8.55, 9.45, time));
const xh2Opacity =
smoothstep(3.2, 4.4, time) *
(1 - smoothstep(8.55, 9.45, time));
const abOpacity = smoothstep(5.8, 7.15, time);
const hhOpacity = smoothstep(8.2, 9.3, time);
updateBond(
bonds.AH,
atoms.A.root.position,
atoms.H1.root.position,
ahOpacity * cycleFade
);
updateBond(
bonds.BH,
atoms.B.root.position,
atoms.H2.root.position,
bhOpacity * cycleFade
);
updateBond(
bonds.XH1,
atoms.X.root.position,
atoms.H1.root.position,
xh1Opacity * cycleFade
);
updateBond(
bonds.XH2,
atoms.X.root.position,
atoms.H2.root.position,
xh2Opacity * cycleFade
);
updateBond(
bonds.AB,
atoms.A.root.position,
atoms.B.root.position,
abOpacity * cycleFade
);
updateBond(
bonds.HH,
atoms.H1.root.position,
atoms.H2.root.position,
hhOpacity * cycleFade
);
const boundAmount = xh1Opacity * xh2Opacity;
catalystHalo.material.opacity = 0.17 + boundAmount * 0.58;
catalystHalo.scale.setScalar(
1 + 0.07 * Math.sin(time * 5.2) + boundAmount * 0.16
);
catalystLight.intensity = 12 + boundAmount * 16;
siteRingA.rotation.z = time * 0.22;
siteRingB.rotation.x = time * 0.17;
particles.rotation.y = time * 0.012;
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationTime += delta * speed;
}
const time = simulationTime % DURATION;
updateCamera();
updateScene(time);
updateUI(time);
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
animate();
</script>
</body>
</html>
```