Prompt specification
Build or customize the Three.js 3D scene "Token Message Through a Mail Slot" 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: Token Message Through a Mail Slot
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/token-message-through-a-mail-slot-x3438
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows written symbol order and reading direction. Animate symbols entering a narrow slot one at a time and reappearing in the same order. Separate transmission order from their later spatial layout. Stylized solid forms.
Working Three.js Starter (token-message-through-a-mail-slot-x3438):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Order / Direction — Three.js Visualization</title>
<style>
:root {
--ink: #07151c;
--panel: rgba(8, 26, 34, 0.82);
--line: rgba(171, 222, 220, 0.18);
--text: #eef7f3;
--muted: #91aaa9;
--accent: #58ddca;
--warm: #ff7868;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
padding: 22px 24px;
pointer-events: none;
}
.brand {
max-width: 510px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--accent);
box-shadow: 0 0 14px rgba(88, 221, 202, 0.7);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 720;
line-height: 1;
letter-spacing: -0.055em;
}
.intro {
max-width: 500px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
.segmented {
display: flex;
padding: 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(14px);
}
.segmented button,
.control-button {
min-height: 36px;
padding: 0 13px;
border: 0;
border-radius: 8px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.06em;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.segmented button:hover,
.control-button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.06);
}
.segmented button:active,
.control-button:active {
transform: translateY(1px);
}
.segmented button.active {
color: #06221f;
background: var(--accent);
box-shadow: 0 5px 16px rgba(88, 221, 202, 0.22);
}
.control-button {
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(14px);
}
.world-label {
position: fixed;
z-index: 5;
left: 0;
top: 0;
padding: 7px 10px;
border: 1px solid rgba(151, 213, 207, 0.2);
border-radius: 7px;
color: #d6ebe6;
background: rgba(5, 20, 27, 0.78);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.world-label::after {
position: absolute;
left: 50%;
bottom: -10px;
width: 1px;
height: 9px;
content: "";
background: rgba(151, 213, 207, 0.32);
}
.world-label.accent {
color: var(--accent);
border-color: rgba(88, 221, 202, 0.3);
}
.bottom {
position: fixed;
z-index: 10;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
padding: 20px 24px;
pointer-events: none;
}
.status-card {
width: min(440px, calc(100vw - 48px));
padding: 15px 16px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.status-main {
color: var(--text);
font-size: 12px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-side {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-detail {
min-height: 17px;
margin-top: 6px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.progress {
height: 3px;
margin-top: 13px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.08);
}
.progress > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #43cbb9, #8bf2df);
box-shadow: 0 0 12px rgba(88, 221, 202, 0.65);
transition: width 100ms linear;
}
.sequence {
display: flex;
gap: 5px;
margin-top: 10px;
}
.sequence i {
width: 19px;
height: 4px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.11);
transition:
background 180ms ease,
box-shadow 180ms ease,
transform 180ms ease;
}
.sequence i.done {
background: rgba(88, 221, 202, 0.54);
}
.sequence i.active {
background: var(--accent);
box-shadow: 0 0 12px rgba(88, 221, 202, 0.8);
transform: scaleY(1.8);
}
.hint {
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--muted);
background: rgba(6, 22, 29, 0.66);
font-size: 10px;
line-height: 1.5;
text-align: right;
backdrop-filter: blur(12px);
}
.hint strong {
color: #d7eae7;
font-weight: 700;
}
@media (max-width: 760px) {
.topbar {
flex-direction: column;
gap: 14px;
padding: 16px;
}
.controls {
justify-content: flex-start;
}
.intro {
max-width: 92vw;
}
.bottom {
padding: 14px 16px;
}
.hint {
display: none;
}
.status-card {
width: calc(100vw - 32px);
}
.world-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="A three-dimensional visualization of symbols passing through a narrow gate and being arranged according to reading direction."
></canvas>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Serial form / spatial reading</div>
<h1>ORDER → DIRECTION</h1>
<p class="intro">
Symbols enter one at a time in a fixed transmission order. After passing
through the narrow gate, they reappear as a written layout.
</p>
</div>
<div class="controls">
<div class="segmented" role="group" aria-label="Reading direction">
<button class="active" data-direction="ltr" aria-pressed="true">
Read L → R
</button>
<button data-direction="rtl" aria-pressed="false">
Read R → L
</button>
</div>
<button class="control-button" id="replay">↻ Replay</button>
<button class="control-button" id="reset-camera">⌖ Reset view</button>
</div>
</header>
<div class="world-label" id="source-label">Serial order · 01 → 06</div>
<div class="world-label accent" id="gate-label">One-way narrow gate</div>
<div class="world-label" id="page-label">Written page · L → R</div>
<section class="bottom">
<div class="status-card" aria-live="polite">
<div class="status-row">
<div class="status-main" id="status-main">Preparing serial queue</div>
<div class="status-side" id="status-side">LTR</div>
</div>
<div class="status-detail" id="status-detail">
The transmission order remains fixed in both reading directions.
</div>
<div class="progress"><span id="progress-bar"></span></div>
<div class="sequence" id="sequence" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i>
</div>
</div>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom<br />
Double-click the scene to reset the camera
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07151c);
scene.fog = new THREE.FogExp2(0x07151c, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100,
);
// Custom camera controls: no addon modules are used.
const cameraState = {
target: new THREE.Vector3(0, 0.75, 0),
theta: -0.06,
phi: 1.16,
radius: 19,
desiredTheta: -0.06,
desiredPhi: 1.16,
desiredRadius: 19,
dragging: false,
pointerX: 0,
pointerY: 0,
};
const defaultCamera = {
theta: -0.06,
phi: 1.16,
radius: 19,
};
function updateCamera(dt) {
const smoothing = 1 - Math.pow(0.0008, dt);
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * smoothing;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * smoothing;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * smoothing;
const aspectCompensation = Math.max(
1,
1.18 / camera.aspect,
);
const spherical = new THREE.Spherical(
cameraState.radius * aspectCompensation,
cameraState.phi,
cameraState.theta,
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.desiredTheta = defaultCamera.theta;
cameraState.desiredPhi = defaultCamera.phi;
cameraState.desiredRadius = defaultCamera.radius;
}
canvas.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.pointerX;
const dy = event.clientY - cameraState.pointerY;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
cameraState.desiredTheta -= dx * 0.0055;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi + dy * 0.0045,
0.58,
1.46,
);
});
function endPointerDrag(event) {
cameraState.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointerDrag);
canvas.addEventListener("pointercancel", endPointerDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
12,
27,
);
},
{ passive: false },
);
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Lighting and ground
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbcebe8, 0x10212a, 1.6));
const keyLight = new THREE.DirectionalLight(0xfff1d6, 3.2);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x55d9dc, 1.35);
rimLight.position.set(9, 5, -7);
scene.add(rimLight);
const gateLight = new THREE.PointLight(0x62ffe2, 1.6, 6, 2);
gateLight.position.set(0, 1.25, 0.3);
scene.add(gateLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x081820,
roughness: 0.94,
metalness: 0.04,
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
groundMaterial,
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x17343c, 0x102830);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.45;
scene.add(grid);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function roundedRectangleShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height,
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function roundedGeometry(
width,
height,
depth,
radius,
bevelSize = 0.025,
) {
const geometry = new THREE.ExtrudeGeometry(
roundedRectangleShape(width, height, radius),
{
depth,
steps: 1,
curveSegments: 8,
bevelEnabled: true,
bevelSegments: 2,
bevelSize,
bevelThickness: bevelSize,
},
);
geometry.translate(0, 0, -depth / 2);
return geometry;
}
function makeMesh(
geometry,
material,
position = [0, 0, 0],
parent = scene,
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const darkSolid = new THREE.MeshStandardMaterial({
color: 0x10262d,
roughness: 0.58,
metalness: 0.16,
});
const ivorySolid = new THREE.MeshStandardMaterial({
color: 0xf0eadc,
roughness: 0.64,
metalness: 0.02,
});
const gateSolid = new THREE.MeshStandardMaterial({
color: 0x29464c,
roughness: 0.38,
metalness: 0.56,
});
const cyanSolid = new THREE.MeshStandardMaterial({
color: 0x57ddc8,
emissive: 0x0b776d,
emissiveIntensity: 0.75,
roughness: 0.35,
metalness: 0.12,
});
// -------------------------------------------------------------------------
// Source queue
// -------------------------------------------------------------------------
const tokenColors = [
0xff7463,
0xf2b84b,
0x4ed4c1,
0x8a7df2,
0xef79aa,
0x70afff,
];
const queuePositions = Array.from({ length: 6 }, (_, index) =>
new THREE.Vector3(
-7.0 + index * 0.45,
1.15,
0.6 + index * 0.65,
),
);
const conveyor = makeMesh(
new THREE.BoxGeometry(1.34, 0.28, 6.05),
new THREE.MeshStandardMaterial({
color: 0x102a32,
roughness: 0.48,
metalness: 0.34,
}),
[-5.875, 0.45, 2.225],
);
conveyor.rotation.y = 0.605;
const conveyorEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x2b5c61,
emissive: 0x0b3538,
emissiveIntensity: 0.45,
roughness: 0.38,
metalness: 0.42,
});
for (const side of [-1, 1]) {
const rail = makeMesh(
new THREE.BoxGeometry(0.055, 0.12, 5.95),
conveyorEdgeMaterial,
[-5.875, 0.68, 2.225],
);
rail.rotation.y = 0.605;
rail.translateX(side * 0.67);
}
queuePositions.forEach((position, index) => {
const padMaterial = new THREE.MeshStandardMaterial({
color: tokenColors[index],
emissive: tokenColors[index],
emissiveIntensity: 0.16,
roughness: 0.5,
});
makeMesh(
new THREE.BoxGeometry(0.78, 0.055, 0.78),
padMaterial,
[position.x, 0.615, position.z],
);
});
// -------------------------------------------------------------------------
// Narrow gate
// -------------------------------------------------------------------------
const gate = new THREE.Group();
scene.add(gate);
makeMesh(
roundedGeometry(1.08, 4.35, 0.36, 0.18),
gateSolid,
[-0.74, 1.18, 0],
gate,
);
makeMesh(
roundedGeometry(1.08, 4.35, 0.36, 0.18),
gateSolid,
[0.74, 1.18, 0],
gate,
);
makeMesh(
roundedGeometry(2.56, 1.35, 0.36, 0.18),
gateSolid,
[0, 3.08, 0],
gate,
);
makeMesh(
roundedGeometry(2.56, 0.72, 0.36, 0.18),
gateSolid,
[0, -0.28, 0],
gate,
);
for (const side of [-1, 1]) {
makeMesh(
new THREE.BoxGeometry(0.025, 2.3, 0.39),
cyanSolid,
[side * 0.205, 1.28, 0],
gate,
);
}
const gateInner = new THREE.Mesh(
new THREE.PlaneGeometry(0.39, 2.3),
new THREE.MeshBasicMaterial({
color: 0x51ddc9,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
}),
);
gateInner.position.set(0, 1.28, 0);
gate.add(gateInner);
// -------------------------------------------------------------------------
// Written page
// -------------------------------------------------------------------------
const pageMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d0bd,
roughness: 0.86,
metalness: 0.01,
});
makeMesh(
roundedGeometry(5.45, 4.5, 0.18, 0.27, 0.035),
pageMaterial,
[5.2, 1.1, -2.12],
);
const pageFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x9b917d,
roughness: 0.82,
metalness: 0.02,
});
makeMesh(
new THREE.BoxGeometry(4.95, 0.025, 0.025),
pageFrameMaterial,
[5.2, 3.1, -2.015],
);
makeMesh(
new THREE.BoxGeometry(4.95, 0.025, 0.025),
pageFrameMaterial,
[5.2, -0.91, -2.015],
);
makeMesh(
new THREE.BoxGeometry(0.025, 3.98, 0.025),
pageFrameMaterial,
[2.75, 1.1, -2.015],
);
makeMesh(
new THREE.BoxGeometry(0.025, 3.98, 0.025),
pageFrameMaterial,
[7.65, 1.1, -2.015],
);
function makeDirectionArrow(y) {
const group = new THREE.Group();
makeMesh(
new THREE.BoxGeometry(2.62, 0.055, 0.065),
cyanSolid,
[0, 0, 0],
group,
);
const tip = makeMesh(
new THREE.ConeGeometry(0.13, 0.3, 4),
cyanSolid,
[1.43, 0, 0],
group,
);
tip.rotation.z = -Math.PI / 2;
for (const x of [-0.92, 0, 0.92]) {
makeMesh(
new THREE.SphereGeometry(0.045, 10, 8),
cyanSolid,
[x, 0, 0.04],
group,
);
}
group.position.set(5.2, y, -1.59);
scene.add(group);
return group;
}
const pageArrows = [makeDirectionArrow(1.08), makeDirectionArrow(-0.7)];
function destinationFor(index) {
const row = Math.floor(index / 3);
const column = index % 3;
const ltrX = [3.72, 5.2, 6.68][column];
const x = direction === "ltr" ? ltrX : 10.4 - ltrX;
const y = row === 0 ? 2.05 : 0.15;
return new THREE.Vector3(x, y, -1.73);
}
// -------------------------------------------------------------------------
// Solid symbol tokens
// -------------------------------------------------------------------------
const symbolMaterial = new THREE.MeshStandardMaterial({
color: 0x09212a,
roughness: 0.48,
metalness: 0.12,
});
const digitMaterial = new THREE.MeshStandardMaterial({
color: 0xf6f1e5,
emissive: 0x433b2d,
emissiveIntensity: 0.08,
roughness: 0.6,
});
const digitSegments = {
1: ["b", "c"],
2: ["a", "b", "g", "e", "d"],
3: ["a", "b", "g", "c", "d"],
4: ["f", "g", "b", "c"],
5: ["a", "f", "g", "c", "d"],
6: ["a", "f", "g", "e", "c", "d"],
};
function makeSevenSegmentNumber(digit) {
const group = new THREE.Group();
const horizontal = new THREE.BoxGeometry(0.13, 0.027, 0.025);
const vertical = new THREE.BoxGeometry(0.027, 0.105, 0.025);
const definitions = {
a: [horizontal, 0, 0.072],
b: [vertical, 0.067, 0.036],
c: [vertical, 0.067, -0.036],
d: [horizontal, 0, -0.072],
e: [vertical, -0.067, -0.036],
f: [vertical, -0.067, 0.036],
g: [horizontal, 0, 0],
};
for (const name of digitSegments[digit]) {
const [geometry, x, y] = definitions[name];
makeMesh(geometry, digitMaterial, [x, y, 0], group);
}
group.scale.setScalar(0.92);
return group;
}
function addSymbolDesign(group, index) {
const z = 0.19;
if (index === 0) {
const ring = makeMesh(
new THREE.TorusGeometry(0.255, 0.075, 12, 32),
symbolMaterial,
[0, 0.12, z],
group,
);
ring.castShadow = true;
}
if (index === 1) {
const triangle = new THREE.Shape();
triangle.moveTo(0, 0.29);
triangle.lineTo(-0.3, -0.19);
triangle.lineTo(0.3, -0.19);
triangle.closePath();
const geometry = new THREE.ExtrudeGeometry(triangle, {
depth: 0.11,
bevelEnabled: true,
bevelSize: 0.025,
bevelThickness: 0.025,
bevelSegments: 2,
});
geometry.translate(0, 0, -0.055);
makeMesh(
geometry,
symbolMaterial,
[0, 0.12, z],
group,
);
}
if (index === 2) {
makeMesh(
new THREE.BoxGeometry(0.51, 0.13, 0.12),
symbolMaterial,
[0, 0.12, z],
group,
);
makeMesh(
new THREE.BoxGeometry(0.13, 0.51, 0.12),
symbolMaterial,
[0, 0.12, z],
group,
);
}
if (index === 3) {
for (const side of [-1, 1]) {
makeMesh(
new THREE.BoxGeometry(0.075, 0.48, 0.12),
symbolMaterial,
[side * 0.22, 0.12, z],
group,
);
makeMesh(
new THREE.BoxGeometry(0.48, 0.075, 0.12),
symbolMaterial,
[0, 0.12 + side * 0.2, z],
group,
);
}
}
if (index === 4) {
const points = [];
const pointCount = 28;
for (let i = 0; i <= pointCount; i++) {
const x = -0.34 + (i / pointCount) * 0.68;
const y = Math.sin((i / pointCount) * Math.PI * 2) * 0.13;
points.push(new THREE.Vector2(x, y));
}
const wave = new THREE.Shape();
wave.moveTo(points[0].x, points[0].y + 0.055);
points.slice(1).forEach((point) =>
wave.lineTo(point.x, point.y + 0.055),
);
[...points].reverse().forEach((point) =>
wave.lineTo(point.x, point.y - 0.055),
);
wave.closePath();
const geometry = new THREE.ExtrudeGeometry(wave, {
depth: 0.1,
bevelEnabled: true,
bevelSize: 0.018,
bevelThickness: 0.018,
bevelSegments: 2,
});
geometry.translate(0, 0, -0.05);
makeMesh(
geometry,
symbolMaterial,
[0, 0.12, z],
group,
);
}
if (index === 5) {
for (const x of [-0.21, 0, 0.21]) {
makeMesh(
new THREE.BoxGeometry(0.105, 0.46, 0.12),
symbolMaterial,
[x, 0.12, z],
group,
);
}
}
}
const tokenBaseGeometry = roundedGeometry(1.12, 1.12, 0.24, 0.16);
const badgeGeometry = roundedGeometry(0.39, 0.29, 0.035, 0.05, 0.01);
const tokens = tokenColors.map((color, index) => {
const group = new THREE.Group();
const tokenMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.42,
metalness: 0.09,
});
makeMesh(tokenBaseGeometry, tokenMaterial, [0, 0, 0], group);
addSymbolDesign(group, index);
makeMesh(
badgeGeometry,
darkSolid,
[-0.34, -0.37, 0.145],
group,
);
const number = makeSevenSegmentNumber(index + 1);
number.position.set(-0.34, -0.37, 0.18);
group.add(number);
group.position.copy(queuePositions[index]);
group.scale.setScalar(0);
group.userData.index = index;
group.userData.state = "queued";
group.userData.queuePosition = queuePositions[index].clone();
scene.add(group);
return group;
});
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
let direction = "ltr";
const durations = {
approach: 0.78,
insert: 0.5,
place: 0.82,
gap: 0.14,
};
let mode = "grow";
let modeTime = 0;
let symbolIndex = 0;
let phase = "approach";
let phaseTime = 0;
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function easeInOut(value) {
const t = clamp01(value);
return t * t * (3 - 2 * t);
}
function setPhase(nextPhase) {
phase = nextPhase;
phaseTime = 0;
}
function resetFlow() {
mode = "grow";
modeTime = 0;
symbolIndex = 0;
phase = "approach";
phaseTime = 0;
tokens.forEach((token) => {
token.userData.state = "queued";
token.position.copy(token.userData.queuePosition);
token.rotation.set(0, 0, 0);
token.scale.setScalar(0);
});
}
function updateGrow(dt) {
modeTime += dt;
tokens.forEach((token, index) => {
const localTime = modeTime - index * 0.14;
const amount = easeInOut(localTime / 0.26);
token.userData.state = "queued";
token.position.copy(token.userData.queuePosition);
token.rotation.set(0, 0, 0);
token.scale.setScalar(amount);
});
if (modeTime > 0.26 + 5 * 0.14 + 0.12) {
mode = "run";
modeTime = 0;
symbolIndex = 0;
setPhase("approach");
}
}
function updateQueuedTokens(time) {
tokens.forEach((token) => {
if (token.userData.state !== "queued") return;
token.position.copy(token.userData.queuePosition);
token.position.y += Math.sin(time * 2.1 + token.userData.index * 0.8) * 0.018;
token.rotation.y =
Math.sin(time * 1.25 + token.userData.index * 0.55) * 0.018;
});
}
function updateRun(dt) {
phaseTime += dt;
const token = tokens[symbolIndex];
if (phase === "approach") {
const amount = clamp01(phaseTime / durations.approach);
const eased = easeInOut(amount);
const start = token.userData.queuePosition;
token.userData.state = "moving";
token.position.set(
THREE.MathUtils.lerp(start.x, 0, eased),
THREE.MathUtils.lerp(
start.y,
start.y,
eased,
) + Math.sin(amount * Math.PI) * 0.45,
THREE.MathUtils.lerp(start.z, 1.0, eased),
);
token.rotation.y = eased * Math.PI * 0.5;
token.scale.setScalar(THREE.MathUtils.lerp(1, 0.76, eased));
if (amount >= 1) {
token.position.set(0, 1.15, 1.0);
token.rotation.y = Math.PI * 0.5;
token.scale.setScalar(0.76);
setPhase("insert");
}
} else if (phase === "insert") {
const amount = clamp01(phaseTime / durations.insert);
token.userData.state = "moving";
token.position.set(
0,
1.15,
THREE.MathUtils.lerp(1.0, -0.98, amount),
);
token.rotation.y = Math.PI * 0.5;
token.scale.setScalar(0.76);
if (amount >= 1) {
setPhase("place");
}
} else if (phase === "place") {
const amount = clamp01(phaseTime / durations.place);
const eased = easeInOut(amount);
const destination = destinationFor(symbolIndex);
token.userData.state = "moving";
token.position.set(
THREE.MathUtils.lerp(0, destination.x, eased),
THREE.MathUtils.lerp(1.15, destination.y, eased) +
Math.sin(amount * Math.PI) * 0.62,
THREE.MathUtils.lerp(-0.98, destination.z, eased),
);
token.rotation.y = (1 - eased) * Math.PI * 0.5;
token.scale.setScalar(THREE.MathUtils.lerp(0.76, 1, eased));
if (amount >= 1) {
token.position.copy(destination);
token.rotation.y = 0;
token.scale.setScalar(1);
token.userData.state = "placed";
setPhase("gap");
}
} else if (phase === "gap") {
if (phaseTime >= durations.gap) {
symbolIndex += 1;
if (symbolIndex >= tokens.length) {
mode = "hold";
modeTime = 0;
} else {
setPhase("approach");
}
}
}
}
function updateHold(dt) {
modeTime += dt;
if (modeTime >= 1.05) {
mode = "rewind";
modeTime = 0;
}
}
function updateRewind(dt) {
modeTime += dt;
tokens.forEach((token, index) => {
const localTime = modeTime - index * 0.14;
const destination = destinationFor(index);
if (localTime <= 0) {
token.position.copy(destination);
token.scale.setScalar(1);
token.userData.state = "placed";
} else if (localTime < 0.26) {
const amount = easeInOut(localTime / 0.26);
token.position.copy(destination);
token.scale.setScalar(1 - amount);
token.userData.state = "rewinding";
} else if (localTime < 0.68) {
token.position.copy(token.userData.queuePosition);
token.scale.setScalar(0);
token.userData.state = "rewinding";
} else if (localTime < 0.98) {
const amount = easeInOut((localTime - 0.68) / 0.3);
token.position.copy(token.userData.queuePosition);
token.rotation.y = 0;
token.scale.setScalar(amount);
token.userData.state = "queued";
} else {
token.position.copy(token.userData.queuePosition);
token.rotation.y = 0;
token.scale.setScalar(1);
token.userData.state = "queued";
}
});
if (modeTime > 0.98 + 5 * 0.14 + 0.1) {
mode = "run";
modeTime = 0;
symbolIndex = 0;
setPhase("approach");
}
}
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
const statusMain = document.querySelector("#status-main");
const statusDetail = document.querySelector("#status-detail");
const statusSide = document.querySelector("#status-side");
const progressBar = document.querySelector("#progress-bar");
const sequenceBars = [
...document.querySelectorAll("#sequence i"),
];
const pageLabel = document.querySelector("#page-label");
function updateDirectionUI() {
const isLTR = direction === "ltr";
pageArrows.forEach((arrow) => {
arrow.scale.x = isLTR ? 1 : -1;
});
pageLabel.textContent = isLTR
? "Written page · L → R"
: "Written page · R → L";
statusSide.textContent = isLTR ? "LTR" : "RTL";
document
.querySelectorAll("[data-direction]")
.forEach((button) => {
const active = button.dataset.direction === direction;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
document
.querySelectorAll("[data-direction]")
.forEach((button) => {
button.addEventListener("click", () => {
direction = button.dataset.direction;
updateDirectionUI();
resetFlow();
});
});
document.querySelector("#replay").addEventListener("click", resetFlow);
document
.querySelector("#reset-camera")
.addEventListener("click", resetCamera);
updateDirectionUI();
function updateInterface() {
let progress = 0;
let activeIndex = symbolIndex;
if (mode === "grow") {
statusMain.textContent = "Preparing serial queue";
statusDetail.textContent =
"The same six symbols are loaded in transmission order: 01 → 06.";
activeIndex = Math.min(5, Math.floor(modeTime / 0.14));
} else if (mode === "run") {
const number = String(symbolIndex + 1).padStart(2, "0");
if (phase === "approach") {
const amount = clamp01(phaseTime / durations.approach);
statusMain.textContent = `Transmitting ${number} / 06`;
statusDetail.textContent =
"One symbol leaves the serial queue and approaches the gate.";
progress = (symbolIndex + amount) / 6;
} else if (phase === "insert") {
const amount = clamp01(phaseTime / durations.insert);
statusMain.textContent = `Passing ${number} / 06`;
statusDetail.textContent =
"The symbol rotates edge-on to fit through the narrow opening.";
progress = (symbolIndex + 0.8 + amount * 0.1) / 6;
} else if (phase === "place") {
const amount = clamp01(phaseTime / durations.place);
statusMain.textContent = `Reappearing ${number} / 06`;
statusDetail.textContent =
direction === "ltr"
? "The symbol returns facing forward and is placed left to right."
: "The symbol returns facing forward and is placed right to left.";
progress = (symbolIndex + 0.9 + amount * 0.1) / 6;
} else {
statusMain.textContent = "Next symbol";
statusDetail.textContent =
"Transmission order stays fixed while spatial order follows direction.";
progress = (symbolIndex + 1) / 6;
}
} else if (mode === "hold") {
statusMain.textContent = "Written layout complete";
statusDetail.textContent =
"Follow the solid arrow to read the page in the selected direction.";
progress = 1;
activeIndex = 5;
} else if (mode === "rewind") {
statusMain.textContent = "Replaying the same order";
statusDetail.textContent =
"The symbols disappear in serial order and return to the source queue in that same order.";
progress = Math.max(0, 1 - modeTime / 1.7);
activeIndex = Math.min(5, Math.floor(modeTime / 0.14));
}
progressBar.style.width = `${Math.max(0, Math.min(1, progress)) * 100}%`;
sequenceBars.forEach((bar, index) => {
const tokenState = tokens[index].userData.state;
const done =
tokenState === "placed" ||
tokenState === "rewinding" ||
(mode === "hold" && index <= 5);
bar.classList.toggle("done", done && index !== activeIndex);
bar.classList.toggle("active", index === activeIndex);
});
}
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#source-label"),
position: new THREE.Vector3(-5.7, 2.55, 2.25),
},
{
element: document.querySelector("#gate-label"),
position: new THREE.Vector3(0, 4.05, 0),
},
{
element: document.querySelector("#page-label"),
position: new THREE.Vector3(5.2, 3.75, -2),
},
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible = projected.z > -1 && projected.z < 1;
label.element.style.visibility = visible ? "visible" : "hidden";
label.element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
});
}
// -------------------------------------------------------------------------
// Resize and main loop
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(dt);
updateQueuedTokens(elapsed);
if (mode === "grow") {
updateGrow(dt);
} else if (mode === "run") {
updateRun(dt);
} else if (mode === "hold") {
updateHold(dt);
} else if (mode === "rewind") {
updateRewind(dt);
}
const gatePulse =
mode === "run" && phase === "insert"
? Math.sin(
clamp01(phaseTime / durations.insert) * Math.PI,
) * 4
: 0;
gateLight.intensity = 1.55 + gatePulse;
gateInner.material.opacity = 0.1 + gatePulse * 0.035;
updateInterface();
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```