Prompt specification
Build or customize the Three.js 3D scene "Queue Simulation at Two Playback Speeds" 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: Queue Simulation at Two Playback Speeds
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/queue-simulation-at-two-playback-speeds-x3574
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the same tiny service queue at two playback speeds. Build two matching low-poly counters with numbered customer tokens and a visible simulated clock above each. Use one fixed list of arrival and service times for both copies; one plays slowly and the other quickly. When each reaches the same simulated timestamp, the completed customers and waiting-time totals must match, even though the animations reached that point at different real times. Add a pause-at-time control so the two states can be compared directly. Keep the event schedule visible as a short strip beside the counters.
Working Three.js Starter (queue-simulation-at-two-playback-speeds-x3574):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Two Speeds, One Service Queue</title>
<style>
:root {
--ink: #243247;
--muted: #647184;
--paper: #f7f3ea;
--panel: rgba(255, 255, 255, 0.88);
--line: #d9d4c8;
--slow: #e76f51;
--fast: #277da1;
--teal: #2a9d8f;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
color: var(--ink);
background:
radial-gradient(circle at 15% 0%, #fffaf1, transparent 35%),
#e9e4d8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
header {
max-width: 1480px;
margin: 0 auto;
padding: 18px 18px 10px;
}
.heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
margin-bottom: 12px;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
letter-spacing: -0.035em;
}
.subtitle {
margin: 5px 0 0;
color: var(--muted);
font-size: 13px;
}
.live-status {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.65);
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.live-status::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(42, 157, 143, 0.13);
}
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 9px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 8px 28px rgba(45, 55, 66, 0.06);
}
button,
select,
input[type="number"] {
min-height: 36px;
border: 1px solid #cbc6ba;
border-radius: 9px;
background: #fffdf8;
color: var(--ink);
font: inherit;
}
button {
padding: 0 13px;
cursor: pointer;
font-size: 13px;
font-weight: 700;
}
button:hover {
border-color: #8f9aaa;
transform: translateY(-1px);
}
button.primary {
border-color: var(--teal);
background: var(--teal);
color: white;
}
select {
padding: 0 30px 0 9px;
font-size: 13px;
cursor: pointer;
}
input[type="number"] {
width: 72px;
padding: 0 8px;
text-align: center;
}
.rate-control {
display: flex;
align-items: center;
gap: 7px;
padding: 0 6px;
color: var(--muted);
font-size: 12px;
font-weight: 700;
}
.rate-control strong {
min-width: 28px;
color: var(--ink);
text-align: center;
}
.compare-control {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 7px;
margin-left: auto;
padding-left: 10px;
border-left: 1px solid var(--line);
}
.compare-control label {
color: var(--muted);
font-size: 12px;
font-weight: 700;
}
#timeRange {
width: 155px;
accent-color: var(--teal);
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 300px;
gap: 12px;
max-width: 1480px;
margin: 0 auto;
padding: 0 18px 18px;
}
#viewport {
position: relative;
min-width: 0;
height: calc(100vh - 165px);
min-height: 570px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 18px;
background: #e9e4d8;
box-shadow: 0 14px 40px rgba(45, 55, 66, 0.08);
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.scene-hint {
position: absolute;
right: 13px;
bottom: 12px;
padding: 7px 10px;
border: 1px solid rgba(36, 50, 71, 0.12);
border-radius: 9px;
background: rgba(255, 255, 255, 0.72);
color: var(--muted);
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(7px);
}
.view-button {
position: absolute;
left: 13px;
bottom: 12px;
min-height: 31px;
background: rgba(255, 255, 255, 0.78);
backdrop-filter: blur(7px);
}
aside {
min-width: 0;
padding: 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(45, 55, 66, 0.08);
}
aside h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.aside-note {
margin: 5px 0 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.event {
--c: #888;
display: grid;
grid-template-columns: 29px minmax(0, 1fr) auto;
grid-template-rows: auto 9px;
column-gap: 8px;
align-items: center;
padding: 8px 7px;
border-top: 1px solid #ece7dc;
transition: opacity 160ms ease, background 160ms ease;
}
.event:first-of-type {
border-top: 0;
}
.event-number {
display: grid;
place-items: center;
width: 27px;
height: 27px;
border: 2px solid var(--c);
border-radius: 50%;
background: #fffdf8;
color: var(--c);
font-size: 11px;
font-weight: 800;
}
.event-copy {
display: flex;
flex-wrap: wrap;
gap: 4px 9px;
min-width: 0;
}
.event-copy span {
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.event-copy b {
color: var(--ink);
font-size: 10px;
letter-spacing: 0.02em;
}
.state {
min-width: 51px;
text-align: right;
color: #969daa;
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
}
.event-track {
position: relative;
grid-column: 2 / 4;
height: 5px;
margin-top: 6px;
overflow: visible;
border-radius: 5px;
background: #e9e5dc;
}
.service-bar {
position: absolute;
top: 0;
height: 5px;
min-width: 5px;
border-radius: 5px;
background: var(--c);
opacity: 0.75;
}
.arrival-dot {
position: absolute;
top: -3px;
width: 7px;
height: 7px;
margin-left: -3px;
border: 1px solid #fffdf8;
border-radius: 50%;
background: var(--ink);
}
.event.done .state {
color: var(--teal);
}
.event.serving {
background: rgba(39, 125, 161, 0.08);
}
.event.serving .state {
color: var(--fast);
}
.event.waiting .state {
color: #b76e00;
}
.event.future {
opacity: 0.48;
}
.compare-badge {
margin-top: 13px;
padding: 11px;
border: 1px solid #d4dedb;
border-radius: 11px;
background: #eef7f3;
color: #35655d;
font-size: 11px;
line-height: 1.45;
}
.legend {
margin-top: 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
@media (max-width: 960px) {
main {
grid-template-columns: 1fr;
}
#viewport {
height: 62vh;
min-height: 480px;
}
.compare-control {
margin-left: 0;
padding-left: 0;
border-left: 0;
}
}
@media (max-width: 600px) {
header,
main {
padding-left: 10px;
padding-right: 10px;
}
.heading {
align-items: flex-start;
flex-direction: column;
}
.live-status {
display: none;
}
.toolbar {
align-items: stretch;
}
.compare-control {
width: 100%;
}
#timeRange {
flex: 1;
min-width: 100px;
}
}
</style>
</head>
<body>
<header>
<div class="heading">
<div>
<h1>Two speeds. One queue.</h1>
<p class="subtitle">
The same fixed customer schedule is evaluated by two independent simulated clocks.
</p>
</div>
<div class="live-status" id="liveStatus">Running independently</div>
</div>
<div class="toolbar">
<button class="primary" id="playButton">Pause both</button>
<button id="resetButton">Reset</button>
<label class="rate-control">
Slow
<select id="slowRate">
<option value="0.25">0.25×</option>
<option value="0.5" selected>0.50×</option>
<option value="1">1.00×</option>
</select>
</label>
<label class="rate-control">
Fast
<select id="fastRate">
<option value="1.5">1.50×</option>
<option value="2" selected>2.00×</option>
<option value="3">3.00×</option>
</select>
</label>
<div class="compare-control">
<label for="targetTime">Compare / pause at</label>
<input id="targetTime" type="number" min="0" max="14" step="0.1" value="8.0">
<button id="compareButton">Set both clocks</button>
<input id="timeRange" type="range" min="0" max="14" step="0.1" value="8"
aria-label="Scrub and pause both queues at the same simulated time">
</div>
</div>
</header>
<main>
<section id="viewport" aria-label="Interactive Three.js service queue scene">
<canvas id="scene" aria-label="Two matching low-poly service queues"></canvas>
<button class="view-button" id="resetViewButton">Reset view</button>
<div class="scene-hint">Drag to orbit · Wheel to zoom</div>
</section>
<aside>
<h2>Fixed event schedule</h2>
<p class="aside-note">
This strip is the single source of truth for both copies.
Each service window is shown as a colored bar; the dot marks arrival.
</p>
<div id="scheduleStrip"></div>
<div class="compare-badge" id="compareBadge">
The clocks advance at different real-time rates. Use
<strong>Set both clocks</strong> to lock both views to one simulated timestamp.
</div>
<div class="legend">
<strong>WAIT TOTAL</strong> means completed waiting time for customers whose
service has started, plus elapsed waiting time for customers still queued.
Both calculations use exactly the same schedule.
</div>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// One immutable schedule drives both scenes.
// Service windows are fixed, valid, non-overlapping FIFO service times.
// ---------------------------------------------------------------------
const CUSTOMERS = [
{ id: 1, arrival: 0.0, serviceStart: 0.0, serviceEnd: 3.0, color: 0xef8354 },
{ id: 2, arrival: 1.0, serviceStart: 3.0, serviceEnd: 5.0, color: 0x4d96ff },
{ id: 3, arrival: 2.0, serviceStart: 5.0, serviceEnd: 7.0, color: 0x6bcb77 },
{ id: 4, arrival: 4.0, serviceStart: 7.0, serviceEnd: 9.0, color: 0xf9c74f },
{ id: 5, arrival: 6.0, serviceStart: 9.0, serviceEnd: 11.0, color: 0x9b5de5 },
{ id: 6, arrival: 9.0, serviceStart: 11.0, serviceEnd: 13.0, color: 0x00bbf9 },
{ id: 7, arrival: 12.0, serviceStart: 13.0, serviceEnd: 14.0, color: 0xff6b6b }
];
const TOTAL_TIME = 14;
const sceneCanvas = document.querySelector("#scene");
const viewport = document.querySelector("#viewport");
let slowTime = 0;
let fastTime = 0;
let paused = false;
let comparisonLocked = false;
let comparisonTime = 0;
// ---------------------------------------------------------------------
// DOM schedule strip
// ---------------------------------------------------------------------
const scheduleStrip = document.querySelector("#scheduleStrip");
scheduleStrip.innerHTML = CUSTOMERS.map(customer => {
const color = "#" + customer.color.toString(16).padStart(6, "0");
const left = customer.serviceStart / TOTAL_TIME * 100;
const width = (customer.serviceEnd - customer.serviceStart) / TOTAL_TIME * 100;
const arrival = customer.arrival / TOTAL_TIME * 100;
return `
<div class="event" data-id="${customer.id}" style="--c:${color}">
<div class="event-number">${customer.id}</div>
<div class="event-copy">
<span><b>ARR ${customer.arrival.toFixed(1)}s</b></span>
<span><b>SVC ${customer.serviceStart.toFixed(1)}–${customer.serviceEnd.toFixed(1)}s</b></span>
</div>
<div class="state">future</div>
<div class="event-track">
<div class="service-bar"
style="left:${left}%;width:${width}%"></div>
<div class="arrival-dot" style="left:${arrival}%"></div>
</div>
</div>
`;
}).join("");
const scheduleRows = [...document.querySelectorAll(".event")];
// ---------------------------------------------------------------------
// Renderer, camera, lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas: sceneCanvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0xe9e4d8, 1);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe9e4d8, 28, 52);
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);
const cameraTarget = new THREE.Vector3(-1.25, 1.35, 1.05);
// Custom camera controls, implemented without Three.js addons.
let orbitTheta = 0.10;
let orbitPhi = 0.92;
let cameraZoom = 1;
function updateCamera() {
const radius = 22;
const horizontal = radius * Math.sin(orbitPhi);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(orbitTheta),
cameraTarget.y + radius * Math.cos(orbitPhi),
cameraTarget.z + horizontal * Math.cos(orbitTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xfff8e8, 0x87929d, 2.15));
const sun = new THREE.DirectionalLight(0xfff3da, 3.2);
sun.position.set(-2, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d9ff, 1.15);
fill.position.set(8, 5, -7);
scene.add(fill);
const materials = {
cabinet: new THREE.MeshStandardMaterial({
color: 0xf5efe4, roughness: 0.8, flatShading: true
}),
cabinetSide: new THREE.MeshStandardMaterial({
color: 0xe5ded1, roughness: 0.86, flatShading: true
}),
top: new THREE.MeshStandardMaterial({
color: 0x29384a, roughness: 0.62, flatShading: true
}),
accent: new THREE.MeshStandardMaterial({
color: 0x2a9d8f, roughness: 0.7, flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x1e2938, roughness: 0.7, flatShading: true
}),
screen: new THREE.MeshStandardMaterial({
color: 0x88d8cf,
emissive: 0x245d59,
emissiveIntensity: 0.55,
roughness: 0.45
}),
platform: new THREE.MeshStandardMaterial({
color: 0xf2ede3, roughness: 0.95, flatShading: true
}),
ground: new THREE.MeshStandardMaterial({
color: 0xe1ddd2, roughness: 1
}),
rope: new THREE.MeshStandardMaterial({
color: 0xc76d4f, roughness: 0.8
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Diorama platform and ground.
addBox(
scene,
[13.4, 0.18, 7.1],
[-1.2, -0.09, 1.1],
materials.platform
);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.19;
ground.receiveShadow = true;
scene.add(ground);
// Low-poly decorative border strips on the platform.
addBox(
scene,
[13.4, 0.025, 0.08],
[-1.2, 0.015, 4.56],
materials.accent,
false
);
addBox(
scene,
[13.4, 0.025, 0.08],
[-1.2, 0.015, -2.36],
materials.accent,
false
);
// ---------------------------------------------------------------------
// Canvas helpers
// ---------------------------------------------------------------------
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 makeNumberTexture(customer) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const color = "#" + customer.color.toString(16).padStart(6, "0");
ctx.clearRect(0, 0, 256, 256);
ctx.beginPath();
ctx.arc(128, 128, 110, 0, Math.PI * 2);
ctx.fillStyle = "#fffaf0";
ctx.fill();
ctx.lineWidth = 15;
ctx.strokeStyle = color;
ctx.stroke();
ctx.fillStyle = "#243247";
ctx.font = "800 112px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(customer.id), 128, 136);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function formatClock(time) {
const minutes = Math.floor(time / 60);
const seconds = time - minutes * 60;
return `${String(minutes).padStart(2, "0")}:${seconds.toFixed(1).padStart(4, "0")}`;
}
function createDisplay(station) {
const canvas = document.createElement("canvas");
canvas.width = 896;
canvas.height = 280;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(0, 3.55, -0.42);
sprite.scale.set(3.25, 1.02, 1);
sprite.renderOrder = 20;
station.group.add(sprite);
station.display = { canvas, ctx, texture, sprite, lastKey: "" };
}
function updateDisplay(station, time, rate) {
const state = computeState(time);
const key = [
time.toFixed(1),
state.done,
state.wait.toFixed(1),
state.current,
state.waiting.length,
rate
].join("|");
if (station.display.lastKey === key) return;
station.display.lastKey = key;
const { ctx, texture } = station.display;
const accent = station.kind === "SLOW" ? "#e76f51" : "#277da1";
ctx.clearRect(0, 0, 896, 280);
ctx.fillStyle = "rgba(26, 36, 49, 0.95)";
roundedRect(ctx, 5, 5, 886, 270, 25);
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 5, 5, 886, 18, 12);
ctx.fill();
ctx.textAlign = "left";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = accent;
ctx.font = "800 31px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(station.kind, 34, 58);
ctx.textAlign = "right";
ctx.fillStyle = "#d9e1eb";
ctx.font = "700 29px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(`${rate.toFixed(2)}×`, 860, 57);
ctx.textAlign = "left";
ctx.fillStyle = "#ffffff";
ctx.font = "800 62px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(`SIM ${formatClock(time)}`, 34, 135);
ctx.fillStyle = "#dce5ef";
ctx.font = "700 37px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(
`DONE ${state.done}/${CUSTOMERS.length} WAIT ${state.wait.toFixed(1)}s`,
34,
196
);
let status;
if (state.done === CUSTOMERS.length) {
status = "ALL CUSTOMERS COMPLETED";
} else if (state.current !== null) {
status = `SERVING C${state.current} • QUEUE ${state.waiting.length}`;
} else {
status = `WAITING • QUEUE ${state.waiting.length}`;
}
ctx.fillStyle = accent;
ctx.font = "700 24px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(status, 34, 244);
texture.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Queue token construction
// ---------------------------------------------------------------------
function createToken(customer) {
const group = new THREE.Group();
const sideMaterial = new THREE.MeshStandardMaterial({
color: customer.color,
roughness: 0.62,
flatShading: true
});
const puck = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.29, 0.14, 10),
sideMaterial
);
puck.castShadow = true;
puck.receiveShadow = true;
group.add(puck);
const face = new THREE.Mesh(
new THREE.CircleGeometry(0.235, 20),
new THREE.MeshBasicMaterial({
map: makeNumberTexture(customer),
transparent: true,
side: THREE.DoubleSide
})
);
face.rotation.x = -Math.PI / 2;
face.position.y = 0.076;
group.add(face);
return group;
}
// ---------------------------------------------------------------------
// Matching service counters
// ---------------------------------------------------------------------
function buildStation(x, kind, accentColor) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const station = { group, kind, accentColor, tokens: [] };
// Counter body, plinth, and worktop.
addBox(group, [3.08, 0.18, 1.32], [0, 0.09, 0], materials.dark);
addBox(group, [2.92, 0.80, 1.16], [0, 0.58, 0], materials.cabinet);
addBox(group, [3.22, 0.16, 1.48], [0, 1.04, 0], materials.top);
addBox(group, [2.62, 0.42, 0.025], [0, 0.56, 0.592], materials.accent);
// Customer terminal.
addBox(group, [0.36, 0.08, 0.30], [0.62, 1.16, -0.20], materials.dark);
addBox(group, [0.09, 0.34, 0.09], [0.62, 1.35, -0.22], materials.dark);
addBox(group, [0.68, 0.44, 0.09], [0.62, 1.63, -0.20], materials.dark);
addBox(group, [0.57, 0.32, 0.018], [0.62, 1.63, -0.146], materials.screen);
// Small service bell.
const bellBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.14, 0.05, 10),
materials.dark
);
bellBase.position.set(-0.62, 1.15, 0.17);
bellBase.castShadow = true;
group.add(bellBase);
const bellTop = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.18, 10),
materials.accent
);
bellTop.position.set(-0.62, 1.25, 0.17);
bellTop.castShadow = true;
group.add(bellTop);
// Queue-side rope barrier.
for (const z of [0.88, 2.54]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.065, 0.85, 8),
materials.dark
);
post.position.set(-2.07, 0.43, z);
post.castShadow = true;
group.add(post);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 8, 6),
materials.accent
);
cap.position.set(-2.07, 0.89, z);
group.add(cap);
}
const rope = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.026, 1.66, 8),
materials.rope
);
rope.rotation.x = Math.PI / 2;
rope.position.set(-2.07, 0.72, 1.71);
rope.castShadow = true;
group.add(rope);
// Queue lane markings.
for (let i = 0; i < 5; i++) {
addBox(
group,
[0.52, 0.014, 0.055],
[-1.70, 0.012, 0.98 + i * 0.82],
materials.accent,
false
);
}
// Tray where completed customer tokens accumulate.
addBox(
group,
[1.05, 0.045, 0.62],
[1.10, 1.145, 0.24],
materials.cabinetSide
);
// Display support.
addBox(
group,
[0.065, 1.88, 0.065],
[0, 2.12, -0.43],
materials.dark
);
createDisplay(station);
for (const customer of CUSTOMERS) {
const token = createToken(customer);
group.add(token);
station.tokens.push(token);
}
return station;
}
const slowStation = buildStation(-3.25, "SLOW", "#e76f51");
const fastStation = buildStation(0.25, "FAST", "#277da1");
// ---------------------------------------------------------------------
// Deterministic queue evaluation
// ---------------------------------------------------------------------
function computeState(time) {
let done = 0;
let wait = 0;
let current = null;
const completed = [];
const waiting = [];
for (const customer of CUSTOMERS) {
if (customer.arrival > time) continue;
if (customer.serviceEnd <= time) {
done++;
completed.push(customer);
wait += customer.serviceStart - customer.arrival;
} else if (customer.serviceStart <= time) {
current = customer.id;
wait += customer.serviceStart - customer.arrival;
} else {
waiting.push(customer);
wait += time - customer.arrival;
}
}
return { done, wait, current, completed, waiting };
}
const SERVICE_POSITION = new THREE.Vector3(0, 1.20, -0.08);
const FRONT_QUEUE_POSITION = new THREE.Vector3(-1.70, 0.08, 1.02);
function smoothStep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function setTokenPosition(token, position) {
token.position.copy(position);
}
function interpolateToken(token, from, to, amount, arc = 0) {
const t = smoothStep(amount);
token.position.lerpVectors(from, to, t);
token.position.y += Math.sin(t * Math.PI) * arc;
}
function completedTokenTarget(customer, rank) {
const column = rank % 3;
const layer = Math.floor(rank / 3);
return new THREE.Vector3(
0.84 + column * 0.27,
1.24 + layer * 0.14,
0.12 + layer * 0.17
);
}
function updateStation(station, time, rate) {
const state = computeState(time);
for (let index = 0; index < CUSTOMERS.length; index++) {
const customer = CUSTOMERS[index];
const token = station.tokens[index];
token.visible = customer.arrival <= time;
if (!token.visible) continue;
if (customer.serviceEnd <= time) {
// Completed tokens move to the output tray and remain there.
const rank = state.completed.findIndex(item => item.id === customer.id);
const target = completedTokenTarget(customer, rank);
const elapsed = time - customer.serviceEnd;
if (elapsed < 0.75) {
interpolateToken(
token,
SERVICE_POSITION,
target,
elapsed / 0.75,
0.42
);
} else {
setTokenPosition(token, target);
}
} else if (customer.serviceStart <= time) {
// Active customer moves from the queue to the counter.
const elapsed = time - customer.serviceStart;
interpolateToken(
token,
FRONT_QUEUE_POSITION,
SERVICE_POSITION,
elapsed / 0.45,
0.32
);
} else {
// Waiting customer position is determined entirely by simulated time.
const queueIndex = state.waiting.findIndex(item => item.id === customer.id);
const bob = Math.sin(time * 3.2 + customer.id) * 0.018;
token.position.set(
-1.70,
0.08 + bob,
1.02 + queueIndex * 0.82
);
}
}
updateDisplay(station, time, rate);
}
// ---------------------------------------------------------------------
// Playback and exact-time comparison
// ---------------------------------------------------------------------
const slowRateSelect = document.querySelector("#slowRate");
const fastRateSelect = document.querySelector("#fastRate");
const playButton = document.querySelector("#playButton");
const resetButton = document.querySelector("#resetButton");
const compareButton = document.querySelector("#compareButton");
const targetTimeInput = document.querySelector("#targetTime");
const timeRange = document.querySelector("#timeRange");
const liveStatus = document.querySelector("#liveStatus");
const compareBadge = document.querySelector("#compareBadge");
function slowRate() {
return Number(slowRateSelect.value);
}
function fastRate() {
return Number(fastRateSelect.value);
}
function updateScheduleHighlight(time) {
for (const row of scheduleRows) {
const id = Number(row.dataset.id);
const customer = CUSTOMERS.find(item => item.id === id);
let state = "future";
let label = "future";
if (customer.serviceEnd <= time) {
state = "done";
label = "done";
} else if (customer.serviceStart <= time) {
state = "serving";
label = "serving";
} else if (customer.arrival <= time) {
state = "waiting";
label = "waiting";
}
row.className = `event ${state}`;
row.querySelector(".state").textContent = label;
}
}
function clearScheduleHighlight() {
for (const row of scheduleRows) {
row.className = "event";
row.querySelector(".state").textContent = "future";
}
}
function updatePlaybackUI() {
playButton.textContent = paused ? "Play both" : "Pause both";
if (comparisonLocked) {
liveStatus.textContent = `Comparison locked at ${comparisonTime.toFixed(1)}s`;
} else if (paused) {
liveStatus.textContent = "Paused at independent clock positions";
} else {
liveStatus.textContent =
`Running independently • ${slowRate().toFixed(2)}× / ${fastRate().toFixed(2)}×`;
}
if (comparisonLocked) {
const state = computeState(comparisonTime);
compareBadge.innerHTML = `
<strong>Both clocks = ${comparisonTime.toFixed(1)}s</strong><br>
DONE ${state.done}/${CUSTOMERS.length}
•
TOTAL WAIT ${state.wait.toFixed(1)}s
`;
} else {
compareBadge.innerHTML = `
The clocks advance at different real-time rates. Use
<strong>Set both clocks</strong> to lock both views to one simulated timestamp.
`;
}
}
function pauseBothAt(time) {
const clamped = THREE.MathUtils.clamp(Number(time) || 0, 0, TOTAL_TIME);
slowTime = clamped;
fastTime = clamped;
comparisonTime = clamped;
comparisonLocked = true;
paused = true;
targetTimeInput.value = clamped.toFixed(1);
timeRange.value = clamped.toFixed(1);
updateScheduleHighlight(clamped);
updatePlaybackUI();
}
playButton.addEventListener("click", () => {
if (paused && slowTime >= TOTAL_TIME && fastTime >= TOTAL_TIME) {
slowTime = 0;
fastTime = 0;
}
paused = !paused;
comparisonLocked = false;
clearScheduleHighlight();
updatePlaybackUI();
});
resetButton.addEventListener("click", () => {
slowTime = 0;
fastTime = 0;
paused = true;
comparisonLocked = false;
comparisonTime = 0;
targetTimeInput.value = "8.0";
timeRange.value = "8";
clearScheduleHighlight();
updatePlaybackUI();
});
compareButton.addEventListener("click", () => {
pauseBothAt(targetTimeInput.value);
});
targetTimeInput.addEventListener("keydown", event => {
if (event.key === "Enter") pauseBothAt(targetTimeInput.value);
});
timeRange.addEventListener("input", () => {
pauseBothAt(timeRange.value);
});
slowRateSelect.addEventListener("change", updatePlaybackUI);
fastRateSelect.addEventListener("change", updatePlaybackUI);
// ---------------------------------------------------------------------
// Custom pointer camera controls
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
sceneCanvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
sceneCanvas.setPointerCapture(event.pointerId);
});
sceneCanvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbitTheta -= dx * 0.006;
orbitPhi = THREE.MathUtils.clamp(orbitPhi - dy * 0.005, 0.52, 1.28);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && sceneCanvas.hasPointerCapture(event.pointerId)) {
sceneCanvas.releasePointerCapture(event.pointerId);
}
}
sceneCanvas.addEventListener("pointerup", endDrag);
sceneCanvas.addEventListener("pointercancel", endDrag);
sceneCanvas.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
updateCamera();
}, { passive: false });
document.querySelector("#resetViewButton").addEventListener("click", () => {
orbitTheta = 0.10;
orbitPhi = 0.92;
cameraZoom = 1;
updateCamera();
});
// ---------------------------------------------------------------------
// Responsive renderer sizing
// ---------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const frustumHeight = Math.max(9.2, 14 / aspect);
camera.left = -frustumHeight * aspect / 2;
camera.right = frustumHeight * aspect / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(viewport);
resize();
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
let previousFrame = performance.now();
function animate(now) {
const realDelta = Math.min(0.1, (now - previousFrame) / 1000);
previousFrame = now;
if (!paused) {
slowTime = Math.min(TOTAL_TIME, slowTime + realDelta * slowRate());
fastTime = Math.min(TOTAL_TIME, fastTime + realDelta * fastRate());
if (slowTime >= TOTAL_TIME && fastTime >= TOTAL_TIME) {
paused = true;
comparisonLocked = false;
updatePlaybackUI();
}
}
updateStation(slowStation, slowTime, slowRate());
updateStation(fastStation, fastTime, fastRate());
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updatePlaybackUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```