Prompt specification
Build or customize the Three.js 3D scene "Run-Length Conveyor Decoder" 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: Run-Length Conveyor Decoder
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/run-length-conveyor-decoder-x3370
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Animate a conveyor reconstructing a colored block sequence from run-length pairs. Compare encoded and decoded lengths and verify every output position against the original.
Working Three.js Starter (run-length-conveyor-decoder-x3370):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Run-Length Conveyor</title>
<style>
:root {
color-scheme: dark;
--bg: #08101d;
--panel: rgba(13, 23, 40, 0.9);
--line: rgba(148, 163, 184, 0.16);
--text: #eef6ff;
--muted: #8fa1b9;
--cyan: #38bdf8;
--green: #6ee7b7;
--red: #fb7185;
--amber: #fbbf24;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0 352px 0 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #14243b 0, #08101d 58%, #050a12 100%);
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#loading {
position: absolute;
inset: 0;
display: grid;
place-items: center;
z-index: 10;
color: var(--muted);
font: 600 12px/1.4 ui-monospace, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
background: #08101d;
transition: opacity 0.35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
#hud {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
width: min(430px, calc(100vw - 400px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: #b9c9dc;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 16px rgba(56, 189, 248, 0.9);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 44px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 760;
}
.subtitle {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
#phaseBadge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 8px 11px;
border: 1px solid rgba(56, 189, 248, 0.2);
border-radius: 999px;
color: #b9ddff;
background: rgba(11, 25, 42, 0.76);
backdrop-filter: blur(12px);
font: 700 10px/1 ui-monospace, monospace;
letter-spacing: 0.08em;
}
#phaseBadge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px currentColor;
}
#phaseBadge.success {
color: var(--green);
border-color: rgba(110, 231, 183, 0.25);
}
#phaseBadge.success::before {
background: var(--green);
}
#controls {
position: fixed;
z-index: 6;
left: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.control {
height: 38px;
padding: 0 13px;
border: 1px solid rgba(148, 163, 184, 0.18);
border-radius: 10px;
color: #dbeafe;
background: rgba(13, 23, 40, 0.84);
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(14px);
cursor: pointer;
transition:
border-color 0.2s ease,
background 0.2s ease,
transform 0.2s ease;
}
.control:hover {
border-color: rgba(56, 189, 248, 0.42);
background: rgba(20, 36, 59, 0.94);
transform: translateY(-1px);
}
.control.primary {
color: #06111e;
border-color: transparent;
background: #7dd3fc;
font-weight: 750;
}
.control.primary:hover {
background: #a5e3ff;
}
.camera-hint {
margin-left: 7px;
color: #71839c;
font: 500 10px/1.4 ui-monospace, monospace;
letter-spacing: 0.04em;
}
#sidebar {
position: fixed;
z-index: 8;
top: 16px;
right: 16px;
bottom: 16px;
width: 320px;
padding: 18px;
overflow: hidden;
border: 1px solid rgba(148, 163, 184, 0.16);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(24, 39, 62, 0.92), rgba(9, 18, 32, 0.94));
box-shadow:
0 28px 80px rgba(0, 0, 0, 0.42),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(20px);
}
.sidebar-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
padding-bottom: 15px;
border-bottom: 1px solid var(--line);
}
.sidebar-title {
margin: 0 0 4px;
font-size: 13px;
letter-spacing: -0.01em;
}
.sidebar-sub {
color: var(--muted);
font: 500 10px/1.4 ui-monospace, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: #a5f3d0;
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: 0.12em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #34d399;
box-shadow: 0 0 10px rgba(52, 211, 153, 0.8);
}
.length-compare {
display: grid;
grid-template-columns: 1fr 22px 1fr;
align-items: center;
gap: 7px;
margin-top: 16px;
}
.length-card {
min-width: 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(4, 10, 20, 0.36);
}
.length-label {
color: var(--muted);
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.length-value {
display: block;
margin-top: 7px;
font-size: 25px;
font-weight: 760;
line-height: 1;
letter-spacing: -0.045em;
}
.length-detail {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.length-arrow {
color: #5d7797;
text-align: center;
font-size: 18px;
}
.encoded-strip {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 10px;
}
.token-chip {
padding: 5px 7px;
border: 1px solid var(--token-border);
border-radius: 7px;
color: var(--token-color);
background: var(--token-bg);
font: 750 10px/1 ui-monospace, monospace;
}
.progress-head {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 17px;
color: var(--muted);
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#progressText {
color: #dbeafe;
}
.progress-track {
height: 6px;
margin-top: 8px;
overflow: hidden;
border-radius: 999px;
background: rgba(148, 163, 184, 0.11);
}
#progressFill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #38bdf8, #6ee7b7);
box-shadow: 0 0 14px rgba(56, 189, 248, 0.45);
transition: width 0.25s ease;
}
#lengthState {
margin-top: 7px;
color: #71839c;
font: 600 9px/1.4 ui-monospace, monospace;
}
#lengthState.match {
color: var(--green);
}
.section-title {
display: flex;
justify-content: space-between;
align-items: center;
margin: 17px 0 9px;
color: #b8c7d9;
font: 700 9px/1 ui-monospace, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span:last-child {
color: #60748e;
font-weight: 500;
letter-spacing: 0.05em;
}
#checks {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 6px;
max-height: calc(100vh - 398px);
overflow-y: auto;
padding-right: 3px;
scrollbar-width: thin;
scrollbar-color: #29415e transparent;
}
.check {
display: grid;
grid-template-columns: 23px 1fr 10px 1fr 14px;
align-items: center;
gap: 4px;
min-width: 0;
padding: 8px 6px;
border: 1px solid rgba(148, 163, 184, 0.11);
border-radius: 9px;
background: rgba(2, 8, 17, 0.3);
transition:
border-color 0.2s ease,
background 0.2s ease;
}
.check.pass {
border-color: rgba(110, 231, 183, 0.25);
background: rgba(16, 185, 129, 0.065);
}
.check.fail {
border-color: rgba(251, 113, 133, 0.4);
background: rgba(244, 63, 94, 0.08);
}
.check-id {
color: #657991;
font: 700 9px/1 ui-monospace, monospace;
}
.swatch {
width: 100%;
height: 10px;
min-width: 0;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 3px;
}
.swatch.output {
background:
repeating-linear-gradient(
135deg,
rgba(255, 255, 255, 0.055) 0 3px,
rgba(255, 255, 255, 0.1) 3px 5px
);
}
.mini-arrow {
color: #4f627a;
text-align: center;
font-size: 9px;
}
.result {
color: #52657e;
text-align: center;
font-size: 12px;
font-weight: 900;
}
.check.pass .result {
color: var(--green);
}
.check.fail .result {
color: var(--red);
}
.legend {
display: flex;
align-items: center;
gap: 13px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #71839c;
font: 500 9px/1 ui-monospace, monospace;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
}
.legend .green {
background: var(--green);
}
.legend .red {
background: var(--red);
}
@media (max-width: 900px) {
#stage {
inset: 0 0 282px 0;
}
#hud {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
}
.subtitle {
max-width: 320px;
font-size: 11px;
}
#sidebar {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
height: 262px;
padding: 13px;
border-radius: 15px;
}
.length-compare {
margin-top: 10px;
}
.length-card {
padding: 8px 10px;
}
.length-value {
font-size: 20px;
}
#checks {
grid-template-columns: repeat(4, minmax(0, 1fr));
max-height: 94px;
}
.section-title {
margin-top: 11px;
}
.legend {
display: none;
}
#controls {
left: 15px;
bottom: 294px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 560px) {
#checks {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.control {
height: 34px;
padding: 0 10px;
font-size: 11px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive three-dimensional run-length encoding conveyor">
<div id="loading">Initializing conveyor…</div>
</main>
<header id="hud">
<div class="eyebrow">Algorithm 01 / Run-length encoding</div>
<h1>Run-length<br />conveyor.</h1>
<p class="subtitle">
Compact color pairs enter the decoder. Each run is rebuilt, scanned,
and checked position-by-position against the original sequence.
</p>
<div id="phaseBadge">FEEDING · 0 / 5 PAIRS</div>
</header>
<div id="controls">
<button class="control primary" id="replay">↻ Replay</button>
<button class="control" id="pause">Ⅱ Pause</button>
<button class="control" id="speed">1.0×</button>
<button class="control" id="resetCamera">Reset view</button>
<span class="camera-hint">Drag to orbit · Shift-drag to pan · Wheel to zoom</span>
</div>
<aside id="sidebar">
<div class="sidebar-head">
<div>
<h2 class="sidebar-title">Length comparison</h2>
<div class="sidebar-sub">Compact pairs → expanded blocks</div>
</div>
<div class="live">LIVE</div>
</div>
<div class="length-compare">
<div class="length-card">
<span class="length-label">Encoded</span>
<strong class="length-value" id="encodedLength">5</strong>
<span class="length-detail" id="encodedDetail">pairs · 10 symbols</span>
</div>
<div class="length-arrow">→</div>
<div class="length-card">
<span class="length-label">Decoded</span>
<strong class="length-value" id="decodedLength">14</strong>
<span class="length-detail" id="decodedDetail">blocks expected</span>
</div>
</div>
<div class="encoded-strip" id="encodedStrip"></div>
<div class="progress-head">
<span>Position verification</span>
<span id="progressText">0 / 14</span>
</div>
<div class="progress-track"><div id="progressFill"></div></div>
<div id="lengthState">Length check pending · decoded 0 / 14</div>
<div class="section-title">
<span>Original → Output</span>
<span>position by position</span>
</div>
<div id="checks"></div>
<div class="legend">
<span><i></i> source color</span>
<span><i class="green"></i> verified</span>
<span><i class="red"></i> mismatch</span>
</div>
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Data
// -------------------------------------------------------------------------
const RUNS = [
{ key: "CYAN", code: "C", count: 4, color: 0x38bdf8 },
{ key: "CORAL", code: "R", count: 3, color: 0xff6b6b },
{ key: "AMBER", code: "Y", count: 2, color: 0xfacc15 },
{ key: "VIOLET", code: "V", count: 2, color: 0xa78bfa },
{ key: "MINT", code: "M", count: 3, color: 0x34d399 }
];
const ORIGINAL = RUNS.flatMap(run =>
Array.from({ length: run.count }, () => run)
);
const TOTAL = ORIGINAL.length;
const ENCODED_TOKENS = RUNS.map(run => `${run.count}${run.code}`);
const ENCODED_SYMBOL_COUNT = ENCODED_TOKENS.join("").length;
const SOURCE_X = -5.45;
const SOURCE_STEP = 0.79;
const $ = id => document.getElementById(id);
const stage = $("stage");
$("encodedLength").textContent = String(RUNS.length);
$("encodedDetail").textContent =
`pairs · ${ENCODED_SYMBOL_COUNT} symbols`;
$("decodedLength").textContent = String(TOTAL);
$("encodedStrip").innerHTML = ENCODED_TOKENS.map((token, index) => {
const run = RUNS[index];
const color = `#${run.color.toString(16).padStart(6, "0")}`;
return `
<span class="token-chip"
style="
--token-color:${color};
--token-border:${color}44;
--token-bg:${color}12;
">${token}</span>`;
}).join("");
// -------------------------------------------------------------------------
// Renderer, camera, scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08101d);
scene.fog = new THREE.Fog(0x08101d, 15, 31);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const cameraGoal = {
yaw: 0.025,
pitch: 0.5,
radius: 16.5,
target: new THREE.Vector3(-0.25, 1.05, -0.35)
};
const cameraCurrent = {
yaw: cameraGoal.yaw,
pitch: cameraGoal.pitch,
radius: cameraGoal.radius,
target: cameraGoal.target.clone()
};
function updateCamera(dt) {
const ease = 1 - Math.exp(-dt * 8);
cameraCurrent.yaw +=
(cameraGoal.yaw - cameraCurrent.yaw) * ease;
cameraCurrent.pitch +=
(cameraGoal.pitch - cameraCurrent.pitch) * ease;
cameraCurrent.radius +=
(cameraGoal.radius - cameraCurrent.radius) * ease;
cameraCurrent.target.lerp(cameraGoal.target, ease);
const { yaw, pitch, radius, target } = cameraCurrent;
camera.position.set(
target.x + radius * Math.sin(pitch) * Math.sin(yaw),
target.y + radius * Math.cos(pitch),
target.z + radius * Math.sin(pitch) * Math.cos(yaw)
);
camera.lookAt(target);
}
function defaultRadius() {
const aspect = stage.clientWidth / Math.max(stage.clientHeight, 1);
if (aspect < 0.8) return 27;
if (aspect < 1.15) return 20;
if (aspect < 1.4) return 17.8;
return 16.5;
}
cameraGoal.radius = defaultRadius();
cameraCurrent.radius = cameraGoal.radius;
function resize() {
const width = Math.max(stage.clientWidth, 1);
const height = Math.max(stage.clientHeight, 1);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
// -------------------------------------------------------------------------
// Lights and environment
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9d7ff, 0x07101b, 1.9));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8b5cf6, 1.6);
rimLight.position.set(8, 5, -8);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(0x38bdf8, 7, 6, 2);
cyanLight.position.set(-0.25, 2.1, 1.1);
scene.add(cyanLight);
// Floor and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(38, 24),
new THREE.MeshStandardMaterial({
color: 0x0a1322,
roughness: 0.92,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x29405f, 0x182840);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
// -------------------------------------------------------------------------
// Canvas-generated labels and badges (no external assets or addons)
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeTextSprite(text, options = {}) {
const {
color = "#eef6ff",
bg = null,
border = null,
height = 0.28,
fontSize = 42,
weight = 750
} = options;
const measureCanvas = document.createElement("canvas");
const measureContext = measureCanvas.getContext("2d");
measureContext.font = `${weight} ${fontSize}px ui-monospace, monospace`;
const width = Math.min(
1000,
Math.max(72, Math.ceil(measureContext.measureText(text).width + 48))
);
const canvasHeight = 92;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = canvasHeight;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, canvasHeight);
if (bg) {
roundedRect(ctx, 2, 2, width - 4, canvasHeight - 4, 18);
ctx.fillStyle = bg;
ctx.fill();
if (border) {
ctx.lineWidth = 2;
ctx.strokeStyle = border;
ctx.stroke();
}
}
ctx.font = `${weight} ${fontSize}px ui-monospace, monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.fillText(text, width / 2, canvasHeight / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(height * (width / canvasHeight), height, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeBadgeTexture(pass) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(64, 64, 54, 0, Math.PI * 2);
ctx.fillStyle = pass ? "#6ee7b7" : "#fb7185";
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.8)";
ctx.lineWidth = 7;
ctx.stroke();
ctx.fillStyle = "#07121e";
ctx.font = "900 67px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(pass ? "✓" : "×", 64, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const passBadgeTexture = makeBadgeTexture(true);
const failBadgeTexture = makeBadgeTexture(false);
function makeBadge(pass) {
const badge = new THREE.Sprite(
new THREE.SpriteMaterial({
map: pass ? passBadgeTexture : failBadgeTexture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
badge.scale.set(0.27, 0.27, 1);
badge.renderOrder = 25;
return badge;
}
// -------------------------------------------------------------------------
// Reusable 3D pieces
// -------------------------------------------------------------------------
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x17263b,
metalness: 0.72,
roughness: 0.28
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1320,
metalness: 0.38,
roughness: 0.55
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x334963,
metalness: 0.78,
roughness: 0.24
});
function makeBlock(color, dimensions = {}, dimmed = false) {
const width = dimensions.width ?? 0.48;
const height = dimensions.height ?? 0.55;
const depth = dimensions.depth ?? 0.55;
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({
color,
emissive: new THREE.Color(color),
emissiveIntensity: dimmed ? 0.07 : 0.13,
roughness: 0.34,
metalness: 0.07,
transparent: true,
opacity: dimmed ? 0.52 : 1
})
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
new THREE.LineBasicMaterial({
color: dimmed ? 0x8394ad : 0xffffff,
transparent: true,
opacity: dimmed ? 0.32 : 0.62
})
);
group.add(edges);
const top = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.8, 0.025, depth * 0.78),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.16
})
);
top.position.y = height / 2 + 0.014;
group.add(top);
group.userData.body = body;
group.userData.edges = edges;
return group;
}
function addLabel(text, position, options = {}) {
const label = makeTextSprite(text, options);
label.position.copy(position);
scene.add(label);
return label;
}
function createConveyor(start, end, topY, width = 1.35) {
const length = end - start;
const middle = (start + end) / 2;
const base = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.28, width + 0.22),
metalMaterial
);
base.position.set(middle, topY - 0.2, 0);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const belt = new THREE.Mesh(
new THREE.BoxGeometry(length - 0.05, 0.095, width),
darkMaterial
);
belt.position.set(middle, topY - 0.04, 0);
belt.receiveShadow = true;
scene.add(belt);
for (const side of [-1, 1]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(length + 0.08, 0.14, 0.09),
railMaterial
);
rail.position.set(middle, topY + 0.055, side * (width / 2 + 0.075));
rail.castShadow = true;
scene.add(rail);
}
const slatCount = Math.max(10, Math.floor(length / 0.3));
const spacing = length / slatCount;
const slats = [];
for (let i = 0; i < slatCount; i++) {
const slat = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.018, width * 0.83),
new THREE.MeshStandardMaterial({
color: 0x33465e,
metalness: 0.42,
roughness: 0.52
})
);
slat.position.set(start + i * spacing, topY + 0.018, 0);
scene.add(slat);
slats.push(slat);
}
for (const x of [start + 0.15, end - 0.15]) {
const roller = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, width + 0.12, 24),
railMaterial
);
roller.rotation.x = Math.PI / 2;
roller.position.set(x, topY - 0.08, 0);
roller.castShadow = true;
scene.add(roller);
}
const legCount = Math.max(2, Math.floor(length / 2.3));
for (let i = 0; i < legCount; i++) {
const x = start + 0.45 +
i * ((length - 0.9) / Math.max(1, legCount - 1));
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.13, topY - 0.3, 0.13),
metalMaterial
);
leg.position.set(x, (topY - 0.3) / 2, side * width * 0.33);
leg.castShadow = true;
scene.add(leg);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.4, 0.07, 0.28),
darkMaterial
);
foot.position.set(x, 0.035, side * width * 0.33);
scene.add(foot);
}
}
return { start, end, length, spacing, slats, topY };
}
const inputBelt = createConveyor(-6.8, -0.35, 1.25);
const outputBelt = createConveyor(0.25, 4.15, 0.62);
// -------------------------------------------------------------------------
// Source and reconstructed racks
// -------------------------------------------------------------------------
const sourcePlatform = new THREE.Mesh(
new THREE.BoxGeometry(11.6, 0.12, 0.88),
new THREE.MeshStandardMaterial({
color: 0x15243a,
metalness: 0.62,
roughness: 0.38
})
);
sourcePlatform.position.set(-0.28, 1.53, -3);
sourcePlatform.receiveShadow = true;
scene.add(sourcePlatform);
const outputPlatform = new THREE.Mesh(
new THREE.BoxGeometry(11.6, 0.12, 0.88),
new THREE.MeshStandardMaterial({
color: 0x15243a,
metalness: 0.62,
roughness: 0.38
})
);
outputPlatform.position.set(-0.28, 0.43, 2.2);
outputPlatform.receiveShadow = true;
scene.add(outputPlatform);
for (const z of [-3.43, -2.57, 1.77, 2.63]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(11.65, 0.055, 0.055),
railMaterial
);
rail.position.set(-0.28, z === 1.77 || z === 2.63 ? 0.53 : 1.63, z);
scene.add(rail);
}
const sourceBlocks = [];
for (let i = 0; i < TOTAL; i++) {
const run = ORIGINAL[i];
const x = SOURCE_X + i * SOURCE_STEP;
const block = makeBlock(
run.color,
{ width: 0.48, height: 0.55, depth: 0.55 },
true
);
block.position.set(x, 1.91, -3);
scene.add(block);
const indexLabel = makeTextSprite(
String(i + 1).padStart(2, "0"),
{
color: "#91a4bb",
height: 0.16,
fontSize: 37,
weight: 700
}
);
indexLabel.position.set(x, 1.64, -3.36);
scene.add(indexLabel);
sourceBlocks.push({
group: block,
body: block.userData.body,
edges: block.userData.edges,
badge: null
});
}
addLabel(
"ORIGINAL / SOURCE",
new THREE.Vector3(-5.45, 2.62, -3),
{
color: "#9fb2c9",
height: 0.25,
fontSize: 36
}
);
addLabel(
"RECONSTRUCTED / VERIFIED",
new THREE.Vector3(-5.45, 1.35, 2.2),
{
color: "#b9d8ef",
height: 0.25,
fontSize: 36
}
);
// -------------------------------------------------------------------------
// Decoder machine and verification gate
// -------------------------------------------------------------------------
const machine = new THREE.Group();
scene.add(machine);
for (const z of [-0.72, 0.72]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 2.45, 0.22),
metalMaterial
);
post.position.set(-0.25, 1.48, z);
post.castShadow = true;
machine.add(post);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.1, 0.65),
darkMaterial
);
foot.position.set(-0.25, 0.05, z);
machine.add(foot);
}
const topBeam = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.24, 1.65),
railMaterial
);
topBeam.position.set(-0.25, 2.72, 0);
topBeam.castShadow = true;
machine.add(topBeam);
const scannerMaterial = new THREE.MeshBasicMaterial({
color: 0x38bdf8,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
});
const scannerDisc = new THREE.Mesh(
new THREE.CircleGeometry(0.49, 64),
scannerMaterial
);
scannerDisc.position.set(-0.25, 1.64, -0.035);
machine.add(scannerDisc);
const scannerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.65, 0.065, 16, 72),
new THREE.MeshStandardMaterial({
color: 0x38bdf8,
emissive: 0x38bdf8,
emissiveIntensity: 1.3,
metalness: 0.35,
roughness: 0.25
})
);
scannerRing.position.set(-0.25, 1.64, 0);
machine.add(scannerRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.5, 0.015, 8, 64),
new THREE.MeshBasicMaterial({
color: 0xa5f3fc,
transparent: true,
opacity: 0.55
})
);
innerRing.position.set(-0.25, 1.64, 0.035);
machine.add(innerRing);
const rotor = new THREE.Group();
rotor.position.set(-0.25, 1.64, 0.05);
machine.add(rotor);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
const notch = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.19, 0.07),
new THREE.MeshBasicMaterial({ color: 0xbae6fd })
);
notch.position.set(
Math.cos(angle) * 0.52,
Math.sin(angle) * 0.52,
0
);
notch.rotation.z = angle;
rotor.add(notch);
}
addLabel(
"RLE DECODER",
new THREE.Vector3(-0.25, 2.98, 0),
{
color: "#d7efff",
bg: "rgba(8,18,32,0.78)",
border: "rgba(56,189,248,0.28)",
height: 0.25,
fontSize: 36
}
);
addLabel(
"RUN-LENGTH PAIRS",
new THREE.Vector3(-4.45, 1.77, 0.72),
{
color: "#a7bbd0",
height: 0.23,
fontSize: 36
}
);
addLabel(
"EXPANDED OUTPUT",
new THREE.Vector3(2.65, 1.15, 0.72),
{
color: "#a7bbd0",
height: 0.23,
fontSize: 36
}
);
// Verification gate at the end of the output belt.
const gate = new THREE.Group();
gate.position.x = 1.1;
scene.add(gate);
for (const z of [-0.59, 0.59]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 1.18, 0.1),
railMaterial
);
post.position.set(0, 0.75, z);
post.castShadow = true;
gate.add(post);
}
const gateTop = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.1, 1.28),
railMaterial
);
gateTop.position.set(0, 1.35, 0);
gate.add(gateTop);
const gateLight = new THREE.Mesh(
new THREE.BoxGeometry(0.145, 0.055, 0.66),
new THREE.MeshBasicMaterial({ color: 0x6ee7b7 })
);
gateLight.position.set(0, 1.39, 0);
gate.add(gateLight);
addLabel(
"VERIFY",
new THREE.Vector3(1.1, 1.65, 0),
{
color: "#b9f8dd",
height: 0.19,
fontSize: 38
}
);
// -------------------------------------------------------------------------
// Encoded pair packets
// -------------------------------------------------------------------------
const packets = RUNS.map((run, index) => {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.02, 0.62, 0.78),
new THREE.MeshStandardMaterial({
color: 0x17263b,
metalness: 0.65,
roughness: 0.3
})
);
body.castShadow = true;
group.add(body);
const band = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.65, 0.82),
new THREE.MeshStandardMaterial({
color: run.color,
emissive: run.color,
emissiveIntensity: 0.28,
metalness: 0.2,
roughness: 0.3
})
);
band.position.x = -0.43;
group.add(band);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
new THREE.LineBasicMaterial({
color: 0x8fa9c5,
transparent: true,
opacity: 0.48
})
);
group.add(edges);
const count = makeTextSprite(`${run.count}× ${run.code}`, {
color: "#eff8ff",
bg: "rgba(5,12,22,0.76)",
border: "rgba(148,163,184,0.22)",
height: 0.2,
fontSize: 38
});
count.position.set(0.12, 0, 0.43);
group.add(count);
group.position.set(-6.35, 1.66, 0);
group.visible = false;
scene.add(group);
return {
group,
run,
index,
arrivalTime: 3.2 + index * 1.32,
spawnTime: 3.2 + index * 1.32 - 2.35,
arrived: false
};
});
// -------------------------------------------------------------------------
// UI position checks
// -------------------------------------------------------------------------
const checkElements = [];
for (let i = 0; i < TOTAL; i++) {
const run = ORIGINAL[i];
const sourceColor = `#${run.color.toString(16).padStart(6, "0")}`;
const element = document.createElement("div");
element.className = "check";
element.innerHTML = `
<span class="check-id">${String(i + 1).padStart(2, "0")}</span>
<span class="swatch source" style="background:${sourceColor}"></span>
<span class="mini-arrow">→</span>
<span class="swatch output"></span>
<span class="result">…</span>
`;
$("checks").appendChild(element);
checkElements.push({
element,
outputSwatch: element.querySelector(".output"),
result: element.querySelector(".result")
});
}
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
let timeline = 0;
let paused = false;
let playbackSpeed = 1;
let decodedCount = 0;
let verifiedCount = 0;
let arrivedPairCount = 0;
let activeDecodeRun = -1;
let decodeCursor = 0;
let nextDecodeTime = Infinity;
const outputBlocks = [];
const pulses = [];
const VERIFY_X = 1.1;
const TRANSFER_DURATION = 0.95;
function setScannerColor(color) {
scannerMaterial.color.setHex(color);
scannerRing.material.color.setHex(color);
scannerRing.material.emissive.setHex(color);
cyanLight.color.setHex(color);
}
function createPulse(color) {
const pulse = new THREE.Mesh(
new THREE.TorusGeometry(0.65, 0.022, 8, 64),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.75,
depthWrite: false
})
);
pulse.position.set(-0.25, 1.64, 0.08);
pulse.userData.startedAt = timeline;
scene.add(pulse);
pulses.push(pulse);
}
function beginDecode(runIndex) {
activeDecodeRun = runIndex;
decodeCursor = 0;
nextDecodeTime = timeline + 0.08;
setScannerColor(RUNS[runIndex].color);
}
function spawnDecodedBlock(run) {
const index = decodedCount;
const block = makeBlock(
run.color,
{ width: 0.43, height: 0.55, depth: 0.52 },
false
);
block.position.set(0.28, 0.95, 0);
block.scale.setScalar(0.15);
block.userData.mode = "belt";
block.userData.index = index;
block.userData.bornAt = timeline;
block.userData.transferProgress = 0;
block.userData.target = new THREE.Vector3(
SOURCE_X + index * SOURCE_STEP,
0.79,
2.2
);
scene.add(block);
outputBlocks.push(block);
decodedCount++;
$("decodedDetail").textContent =
`${decodedCount} emitted · ${verifiedCount} checked`;
}
function updateDecoder() {
if (activeDecodeRun < 0) return;
while (
decodeCursor < RUNS[activeDecodeRun].count &&
timeline >= nextDecodeTime
) {
spawnDecodedBlock(RUNS[activeDecodeRun]);
decodeCursor++;
nextDecodeTime += 0.27;
}
if (decodeCursor >= RUNS[activeDecodeRun].count) {
activeDecodeRun = -1;
nextDecodeTime = Infinity;
if (decodedCount === TOTAL) {
$("lengthState").textContent =
`Length match · ${decodedCount} blocks = expected`;
$("lengthState").classList.add("match");
}
}
}
function verifyPosition(index, outputColor) {
const expected = ORIGINAL[index];
const pass = expected.key === outputColor.key;
const output = outputBlocks.find(
block => block.userData.index === index
);
if (output) {
const edges = output.userData.edges;
edges.material.color.setHex(pass ? 0x6ee7b7 : 0xfb7185);
edges.material.opacity = 1;
output.userData.body.material.emissiveIntensity = pass ? 0.55 : 0.8;
const badge = makeBadge(pass);
badge.position.set(0, 0.43, 0);
output.add(badge);
}
const source = sourceBlocks[index];
source.edges.material.color.setHex(pass ? 0x6ee7b7 : 0xfb7185);
source.edges.material.opacity = 1;
source.body.material.opacity = 1;
source.body.material.emissiveIntensity = pass ? 0.35 : 0.65;
const sourceBadge = makeBadge(pass);
sourceBadge.position.set(0, 0.43, 0);
source.group.add(sourceBadge);
source.badge = sourceBadge;
const ui = checkElements[index];
ui.element.classList.toggle("pass", pass);
ui.element.classList.toggle("fail", !pass);
ui.outputSwatch.style.background =
`#${outputColor.color.toString(16).padStart(6, "0")}`;
ui.result.textContent = pass ? "✓" : "×";
verifiedCount++;
$("progressText").textContent = `${verifiedCount} / ${TOTAL}`;
$("progressFill").style.width = `${verifiedCount / TOTAL * 100}%`;
$("decodedDetail").textContent =
`${decodedCount} emitted · ${verifiedCount} checked`;
}
function updatePackets() {
for (const packet of packets) {
if (packet.arrived) continue;
if (timeline >= packet.spawnTime) {
packet.group.visible = true;
const progress = THREE.MathUtils.clamp(
(timeline - packet.spawnTime) / 2.35,
0,
1
);
packet.group.position.x =
THREE.MathUtils.lerp(-6.35, -0.25, progress);
packet.group.position.y =
1.66 + Math.sin(progress * Math.PI * 8) * 0.015;
}
if (timeline >= packet.arrivalTime) {
packet.arrived = true;
packet.group.visible = false;
arrivedPairCount++;
createPulse(packet.run.color);
beginDecode(packet.index);
}
}
}
function updateOutputBlocks(dt) {
for (const block of outputBlocks) {
const bornAge = timeline - block.userData.bornAt;
const scale = THREE.MathUtils.clamp(bornAge / 0.2, 0.15, 1);
block.scale.setScalar(scale);
if (block.userData.mode === "belt") {
block.position.x += 2.35 * dt;
if (block.position.x >= VERIFY_X) {
block.position.x = VERIFY_X;
block.userData.mode = "transfer";
block.userData.transferProgress = 0;
const index = block.userData.index;
verifyPosition(index, ORIGINAL[index]);
}
} else if (block.userData.mode === "transfer") {
block.userData.transferProgress +=
dt / TRANSFER_DURATION;
const raw = THREE.MathUtils.clamp(
block.userData.transferProgress,
0,
1
);
const eased = raw * raw * (3 - 2 * raw);
const target = block.userData.target;
block.position.x = THREE.MathUtils.lerp(
VERIFY_X,
target.x,
eased
);
block.position.y = THREE.MathUtils.lerp(
0.95,
target.y,
eased
) + Math.sin(eased * Math.PI) * 1.25;
block.position.z = THREE.MathUtils.lerp(
0,
target.z,
eased
);
block.rotation.y = (1 - eased) * -0.65;
if (raw >= 1) {
block.userData.mode = "rack";
block.position.copy(target);
block.rotation.y = 0;
}
}
}
}
function updateBelts() {
for (const belt of [inputBelt, outputBelt]) {
const travel = (timeline * 1.35) % belt.length;
belt.slats.forEach((slat, index) => {
slat.position.x =
belt.end - ((index * belt.spacing + travel) % belt.length);
});
}
}
function updatePulses() {
for (let i = pulses.length - 1; i >= 0; i--) {
const pulse = pulses[i];
const age = timeline - pulse.userData.startedAt;
if (age > 0.75) {
scene.remove(pulse);
pulse.geometry.dispose();
pulse.material.dispose();
pulses.splice(i, 1);
continue;
}
const progress = age / 0.75;
pulse.scale.setScalar(1 + progress * 0.7);
pulse.material.opacity = (1 - progress) * 0.7;
}
}
let previousPhase = "";
function updateStatus() {
let phase;
let success = false;
if (verifiedCount === TOTAL) {
phase = `COMPLETE · ${TOTAL} / ${TOTAL} VERIFIED`;
success = true;
} else if (decodedCount === TOTAL) {
phase = `VERIFYING · ${verifiedCount} / ${TOTAL} POSITIONS`;
} else if (activeDecodeRun >= 0) {
const run = RUNS[activeDecodeRun];
phase =
`DECODING · ${run.count}× ${run.key} ` +
`(${activeDecodeRun + 1} / ${RUNS.length})`;
} else {
phase = `FEEDING · ${arrivedPairCount} / ${RUNS.length} PAIRS`;
}
if (phase !== previousPhase) {
$("phaseBadge").textContent = phase;
$("phaseBadge").classList.toggle("success", success);
previousPhase = phase;
}
}
// -------------------------------------------------------------------------
// Replay
// -------------------------------------------------------------------------
function disposeObject(object) {
object.traverse(child => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material)
? child.material
: [child.material];
materials.forEach(material => material.dispose());
}
});
}
function replay() {
timeline = 0;
decodedCount = 0;
verifiedCount = 0;
arrivedPairCount = 0;
activeDecodeRun = -1;
decodeCursor = 0;
nextDecodeTime = Infinity;
previousPhase = "";
for (const packet of packets) {
packet.arrived = false;
packet.group.visible = false;
packet.group.position.set(-6.35, 1.66, 0);
}
for (const block of outputBlocks) {
scene.remove(block);
disposeObject(block);
}
outputBlocks.length = 0;
for (const pulse of pulses) {
scene.remove(pulse);
disposeObject(pulse);
}
pulses.length = 0;
for (let i = 0; i < TOTAL; i++) {
const source = sourceBlocks[i];
if (source.badge) {
source.group.remove(source.badge);
source.badge.material.dispose();
source.badge = null;
}
source.body.material.opacity = 0.52;
source.body.material.emissiveIntensity = 0.07;
source.edges.material.color.setHex(0x8394ad);
source.edges.material.opacity = 0.32;
const ui = checkElements[i];
ui.element.classList.remove("pass", "fail");
ui.outputSwatch.style.background =
"repeating-linear-gradient(135deg," +
"rgba(255,255,255,0.055) 0 3px," +
"rgba(255,255,255,0.1) 3px 5px)";
ui.result.textContent = "…";
}
$("progressText").textContent = `0 / ${TOTAL}`;
$("progressFill").style.width = "0%";
$("decodedDetail").textContent = "blocks expected";
$("lengthState").textContent =
`Length check pending · decoded 0 / ${TOTAL}`;
$("lengthState").classList.remove("match");
setScannerColor(0x38bdf8);
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, double-click reset
// -------------------------------------------------------------------------
let dragging = false;
let previousPointer = { x: 0, y: 0 };
let activePointer = null;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
activePointer = event.pointerId;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (event.shiftKey || event.buttons === 2) {
const scale = cameraCurrent.radius * 0.0011;
const right = new THREE.Vector3(
Math.cos(cameraCurrent.yaw),
0,
-Math.sin(cameraCurrent.yaw)
);
cameraGoal.target.addScaledVector(right, -dx * scale);
cameraGoal.target.y += dy * scale;
cameraGoal.target.y = THREE.MathUtils.clamp(
cameraGoal.target.y,
-0.2,
3.2
);
} else {
cameraGoal.yaw -= dx * 0.005;
cameraGoal.pitch = THREE.MathUtils.clamp(
cameraGoal.pitch + dy * 0.004,
0.18,
1.08
);
}
});
function stopDragging(event) {
if (event && event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius * Math.exp(event.deltaY * 0.001),
9,
31
);
}, { passive: false });
function resetCamera() {
cameraGoal.yaw = 0.025;
cameraGoal.pitch = 0.5;
cameraGoal.radius = defaultRadius();
cameraGoal.target.set(-0.25, 1.05, -0.35);
}
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Ambient dust
// -------------------------------------------------------------------------
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(150 * 3);
for (let i = 0; i < 150; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 17;
dustPositions[i * 3 + 1] = Math.random() * 5 + 0.15;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 11;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x93c5fd,
size: 0.027,
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
$("replay").addEventListener("click", replay);
$("resetCamera").addEventListener("click", resetCamera);
$("pause").addEventListener("click", () => {
paused = !paused;
$("pause").textContent = paused ? "▶ Resume" : "Ⅱ Pause";
});
const speeds = [0.75, 1, 1.5, 2];
let speedIndex = 1;
$("speed").addEventListener("click", () => {
speedIndex = (speedIndex + 1) % speeds.length;
playbackSpeed = speeds[speedIndex];
$("speed").textContent = `${playbackSpeed.toFixed(2).replace(/0$/, "")}×`;
});
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const rawDt = Math.min(clock.getDelta(), 0.05);
const dt = paused ? 0 : rawDt * playbackSpeed;
if (!paused) {
timeline += dt;
updatePackets();
updateDecoder();
updateOutputBlocks(dt);
updatePulses();
}
updateBelts();
updateCamera(rawDt);
updateStatus();
rotor.rotation.z = timeline * 0.9;
innerRing.rotation.z = -timeline * 1.4;
scannerDisc.material.opacity =
0.055 + Math.sin(timeline * 3.5) * 0.018;
gateLight.material.color.setHex(
verifiedCount === TOTAL ? 0x6ee7b7 : 0x38bdf8
);
dust.rotation.y = timeline * 0.012;
dust.position.y = Math.sin(timeline * 0.22) * 0.06;
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```