Prompt specification
Build or customize the Three.js 3D scene "Multiple-counter queue simulation" 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: Multiple-counter queue simulation
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/multiple-counter-queue-simulation-x0456
Scene Description Prompt:
Multiple-counter queue simulation. Build a shared service queue feeding three counters; configurable service durations change waiting patterns while each ticket is served once and the queue order remains explicit. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (multiple-counter-queue-simulation-x0456):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Flow / 03 — Multiple-Counter Queue</title>
<style>
:root {
color-scheme: dark;
--bg: #071117;
--panel: #0d1b23;
--panel-2: #12232d;
--line: rgba(185, 224, 218, 0.13);
--text: #edf7f4;
--muted: #8ea8aa;
--mint: #55d6be;
--amber: #f2b85b;
--coral: #f27f73;
--blue: #6fa8ff;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 3px;
}
#app {
height: 100vh;
min-height: 650px;
display: flex;
flex-direction: column;
}
header {
height: 86px;
flex: 0 0 86px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 26px;
border-bottom: 1px solid var(--line);
background:
linear-gradient(90deg, rgba(85, 214, 190, 0.055), transparent 30%),
#09151c;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 260px;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border: 1px solid rgba(85, 214, 190, 0.42);
border-radius: 12px;
background: rgba(85, 214, 190, 0.08);
color: var(--mint);
font-size: 12px;
font-weight: 800;
letter-spacing: -0.04em;
box-shadow: inset 0 0 20px rgba(85, 214, 190, 0.04);
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: 0.02em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
}
.stats {
display: grid;
grid-template-columns: repeat(4, minmax(90px, 1fr));
gap: 10px;
width: min(620px, 58vw);
}
.stat {
min-width: 0;
padding: 9px 13px;
border-left: 1px solid var(--line);
}
.stat-label {
display: block;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.stat-value {
display: block;
margin-top: 3px;
font-size: 23px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.stat-value.mint {
color: var(--mint);
}
.stat-value.amber {
color: var(--amber);
}
.layout {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1fr) 355px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #0b1720;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-top {
position: absolute;
top: 20px;
left: 22px;
pointer-events: none;
display: flex;
flex-direction: column;
gap: 9px;
}
.eyebrow {
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.scene-title {
font-size: clamp(19px, 2.1vw, 29px);
font-weight: 750;
letter-spacing: -0.025em;
}
.scene-subtitle {
max-width: 350px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
margin-top: 4px;
color: #b8c9c9;
font-size: 11px;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 8px;
height: 8px;
display: inline-block;
border-radius: 50%;
background: var(--mint);
}
.legend i.amber {
background: var(--amber);
}
.legend i.coral {
background: var(--coral);
}
.transport,
.camera-tools {
position: absolute;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(8, 20, 27, 0.84);
backdrop-filter: blur(14px);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.22);
}
.transport {
left: 20px;
}
.camera-tools {
right: 20px;
}
.transport button,
.camera-tools button {
height: 36px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: #b9cccd;
cursor: pointer;
font-size: 12px;
font-weight: 650;
transition: 150ms ease;
}
.transport button:hover,
.camera-tools button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.06);
}
.transport button.primary {
padding: 0 14px;
color: #062019;
background: var(--mint);
}
.transport button.primary:hover {
background: #72e4cf;
transform: translateY(-1px);
}
.transport button.square,
.camera-tools button {
padding: 0 11px;
}
.separator {
width: 1px;
height: 23px;
margin: 0 2px;
background: var(--line);
}
.speed-group {
display: flex;
gap: 3px;
}
.speed-group button {
min-width: 35px;
padding: 0 8px;
}
.speed-group button.active {
color: var(--mint);
background: rgba(85, 214, 190, 0.1);
}
aside {
min-height: 0;
overflow-y: auto;
padding: 18px;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(85, 214, 190, 0.025), transparent 160px),
#09151c;
scrollbar-width: thin;
scrollbar-color: #29414b transparent;
}
.panel-card {
margin-bottom: 14px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(16, 31, 40, 0.78);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.card-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.card-heading span {
color: var(--muted);
font-size: 10px;
}
.counter-row {
padding: 12px 0;
border-top: 1px solid var(--line);
}
.counter-row:first-child {
padding-top: 0;
border-top: 0;
}
.counter-head {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
}
.counter-head strong {
font-size: 12px;
}
.counter-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 55%, transparent);
}
.counter-state {
margin-left: auto;
color: var(--accent);
font-size: 10px;
font-weight: 750;
text-transform: uppercase;
}
.counter-ticket {
min-height: 16px;
margin: 6px 0 10px 17px;
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.range-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: #a9bebf;
font-size: 11px;
}
.range-label output {
color: var(--text);
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 10px;
appearance: none;
background: #263a43;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #10232c;
border-radius: 50%;
background: var(--accent, var(--mint));
box-shadow: 0 0 0 1px var(--accent, var(--mint));
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #10232c;
border-radius: 50%;
background: var(--accent, var(--mint));
}
.hint {
margin: 9px 0 0;
color: #728c90;
font-size: 10px;
line-height: 1.45;
}
.arrival-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.arrival-row strong {
display: block;
font-size: 12px;
}
.arrival-row small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.switch {
position: relative;
width: 42px;
height: 23px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 20px;
background: #263a43;
cursor: pointer;
transition: 180ms ease;
}
.switch span::after {
content: "";
position: absolute;
width: 17px;
height: 17px;
top: 3px;
left: 3px;
border-radius: 50%;
background: #90a5a8;
transition: 180ms ease;
}
.switch input:checked + span {
background: rgba(85, 214, 190, 0.28);
}
.switch input:checked + span::after {
left: 22px;
background: var(--mint);
}
.arrival-range {
margin-top: 15px;
}
.queue-list {
display: flex;
flex-direction: column;
gap: 7px;
}
.queue-row {
display: grid;
grid-template-columns: 34px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
min-height: 48px;
padding: 7px 9px;
border: 1px solid rgba(185, 224, 218, 0.08);
border-radius: 10px;
background: rgba(6, 17, 23, 0.36);
}
.queue-position {
width: 29px;
height: 29px;
display: grid;
place-items: center;
border-radius: 8px;
color: var(--mint);
background: rgba(85, 214, 190, 0.08);
font-size: 11px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.queue-ticket strong {
display: block;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.queue-ticket small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.queue-wait {
color: #c9d8d8;
font-size: 11px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.empty {
padding: 16px 10px;
border: 1px dashed rgba(185, 224, 218, 0.12);
border-radius: 10px;
color: var(--muted);
text-align: center;
font-size: 11px;
line-height: 1.5;
}
.event-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.event {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: start;
gap: 9px;
color: #b9cbcb;
font-size: 10px;
line-height: 1.4;
}
.event i {
width: 6px;
height: 6px;
margin-top: 4px;
border-radius: 50%;
background: #637d82;
}
.event.dispatch i {
background: var(--blue);
}
.event.service i {
background: var(--amber);
}
.event.complete i {
background: var(--mint);
}
.event time {
color: #668086;
font-variant-numeric: tabular-nums;
}
.side-footer {
padding: 0 5px 15px;
color: #617b80;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 920px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
header {
height: auto;
min-height: 86px;
padding: 14px 18px;
align-items: flex-start;
}
.brand {
min-width: 0;
}
.stats {
grid-template-columns: repeat(2, 1fr);
width: 280px;
}
.layout {
display: block;
}
#stage {
height: 62vh;
min-height: 480px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.camera-tools {
display: none;
}
}
@media (max-width: 590px) {
header {
display: block;
}
.brand {
margin-bottom: 13px;
}
.stats {
width: 100%;
}
.stat {
padding: 7px 10px;
}
.stat-value {
font-size: 19px;
}
#stage {
min-height: 450px;
}
.scene-top {
top: 15px;
left: 16px;
}
.scene-subtitle,
.legend {
display: none;
}
.transport {
left: 12px;
right: 12px;
bottom: 12px;
justify-content: center;
}
.transport button {
padding: 0 8px;
}
aside {
padding: 12px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark">F/03</div>
<div>
<h1>Flow Laboratory</h1>
<p>Multiple-counter queue simulation</p>
</div>
</div>
<div class="stats">
<div class="stat">
<span class="stat-label">In queue</span>
<strong class="stat-value mint" id="statQueue">0</strong>
</div>
<div class="stat">
<span class="stat-label">At counters</span>
<strong class="stat-value amber" id="statServing">0</strong>
</div>
<div class="stat">
<span class="stat-label">Average wait</span>
<strong class="stat-value" id="statWait">—</strong>
</div>
<div class="stat">
<span class="stat-label">Completed</span>
<strong class="stat-value" id="statCompleted">0</strong>
</div>
</div>
</header>
<main class="layout">
<section id="stage" aria-label="Interactive 3D queue simulation">
<div id="viewport"></div>
<div class="scene-top">
<div class="eyebrow">Live operations</div>
<div class="scene-title">One line. Three destinations.</div>
<div class="scene-subtitle">
Tickets are dispatched in explicit FIFO order. Adjust each counter’s
service time to see the queue reorganize.
</div>
<div class="legend">
<span><i></i>Counter A</span>
<span><i class="amber"></i>Counter B</span>
<span><i class="coral"></i>Counter C</span>
</div>
</div>
<div class="transport" aria-label="Simulation controls">
<button id="addBtn" class="primary" title="Add a ticket">+ New ticket</button>
<button id="pauseBtn" class="square" title="Pause or resume">Ⅱ Pause</button>
<div class="separator"></div>
<div class="speed-group" aria-label="Simulation speed">
<button class="speed active" data-speed="1">1×</button>
<button class="speed" data-speed="2">2×</button>
<button class="speed" data-speed="4">4×</button>
</div>
<div class="separator"></div>
<button id="resetBtn" class="square" title="Reset simulation">Reset</button>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button id="cameraReset" title="Reset camera">↺ View</button>
<button id="cameraTop" title="Top-down camera">Top</button>
</div>
</section>
<aside>
<section class="panel-card">
<div class="card-heading">
<h2>Counter pace</h2>
<span>Seconds per ticket</span>
</div>
<div id="counterConfigs"></div>
<p class="hint">
Changes apply immediately, including to the customer currently at that counter.
</p>
</section>
<section class="panel-card">
<div class="card-heading">
<h2>Arrival rhythm</h2>
<span id="arrivalState">Automatic</span>
</div>
<div class="arrival-row">
<div>
<strong>Automatic arrivals</strong>
<small>Add a new ticket at a fixed interval</small>
</div>
<label class="switch">
<input id="autoToggle" type="checkbox" checked />
<span aria-hidden="true"></span>
</label>
</div>
<div class="arrival-range">
<div class="range-label">
<label for="autoInterval">Arrival interval</label>
<output id="autoIntervalOut">4.0s</output>
</div>
<input
id="autoInterval"
type="range"
min="2"
max="10"
step="0.5"
value="4"
style="--accent: var(--mint)"
/>
</div>
</section>
<section class="panel-card">
<div class="card-heading">
<h2>Shared queue</h2>
<span>FIFO dispatch order</span>
</div>
<div id="queueList" class="queue-list"></div>
</section>
<section class="panel-card">
<div class="card-heading">
<h2>Activity</h2>
<span>Latest events</span>
</div>
<div id="eventList" class="event-list"></div>
</section>
<div class="side-footer">
Drag to orbit · Scroll to zoom · Space to pause · N to add a ticket
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// DOM
// ---------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const queueList = document.getElementById("queueList");
const eventList = document.getElementById("eventList");
const counterConfigs = document.getElementById("counterConfigs");
const addBtn = document.getElementById("addBtn");
const pauseBtn = document.getElementById("pauseBtn");
const resetBtn = document.getElementById("resetBtn");
const autoToggle = document.getElementById("autoToggle");
const autoInterval = document.getElementById("autoInterval");
const autoIntervalOut = document.getElementById("autoIntervalOut");
const arrivalState = document.getElementById("arrivalState");
const statQueue = document.getElementById("statQueue");
const statServing = document.getElementById("statServing");
const statWait = document.getElementById("statWait");
const statCompleted = document.getElementById("statCompleted");
// ---------------------------------------------------------------------
// Simulation state
// ---------------------------------------------------------------------
const HEAD_Z = 2.65;
const colors = {
mint: 0x55d6be,
amber: 0xf2b85b,
coral: 0xf27f73
};
const ticketColors = [
0x55d6be,
0xf2b85b,
0xf27f73,
0x6fa8ff,
0xb79cff,
0x8fd66f
];
const counterNames = ["A", "B", "C"];
const counterXs = [-4.2, 0, 4.2];
const counterDurations = [5, 7, 9];
let tickets = [];
let nextTicketId = 1;
let simulationTime = 0;
let simulationSpeed = 1;
let paused = false;
let autoArrivals = true;
let arrivalInterval = 4;
let autoElapsed = 0;
let events = [];
let particles = [];
// ---------------------------------------------------------------------
// Three.js setup
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1720);
scene.fog = new THREE.Fog(0x0b1720, 28, 54);
const camera = new THREE.PerspectiveCamera(
40,
viewport.clientWidth / viewport.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xbde8ef, 0x10202b, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3df, 3.1);
sun.position.set(8, 16, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0003;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x5fd4c4, 1.15);
rim.position.set(-10, 7, -9);
scene.add(rim);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.05,
flatShading: true,
...options
});
}
const darkMaterial = standardMaterial(0x142832);
const deepMaterial = standardMaterial(0x0c1b23);
const floorMaterial = standardMaterial(0x19313b);
const laneMaterial = standardMaterial(0x223b43);
const metalMaterial = standardMaterial(0x789094, {
metalness: 0.35,
roughness: 0.48
});
function addBox(parent, width, height, depth, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Octagonal low-poly operating platform.
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(10.8, 11.2, 0.72, 8),
floorMaterial
);
platform.position.set(0, -0.48, 2.5);
platform.scale.z = 1.38;
platform.rotation.y = Math.PI / 8;
platform.receiveShadow = true;
scene.add(platform);
const platformInset = new THREE.Mesh(
new THREE.CylinderGeometry(10.35, 10.5, 0.08, 8),
standardMaterial(0x1c343d)
);
platformInset.position.set(0, -0.08, 2.5);
platformInset.scale.z = 1.38;
platformInset.rotation.y = Math.PI / 8;
platformInset.receiveShadow = true;
scene.add(platformInset);
// Shared queue lane.
addBox(scene, 2.5, 0.055, 12.1, laneMaterial, 0, -0.005, 7.35, false);
addBox(scene, 0.055, 0.10, 12.1, metalMaterial, -1.29, 0.045, 7.35, false);
addBox(scene, 0.055, 0.10, 12.1, metalMaterial, 1.29, 0.045, 7.35, false);
// Back wall and framing.
addBox(scene, 13.4, 4.25, 0.28, deepMaterial, 0, 2.02, -5.75);
addBox(scene, 13.6, 0.12, 0.42, metalMaterial, 0, 4.17, -5.72, false);
addBox(scene, 0.18, 4.25, 0.42, metalMaterial, -6.65, 2.02, -5.72, false);
addBox(scene, 0.18, 4.25, 0.42, metalMaterial, 6.65, 2.02, -5.72, false);
// Direction arrows.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 0.46);
arrowShape.lineTo(0.34, -0.28);
arrowShape.lineTo(0, -0.10);
arrowShape.lineTo(-0.34, -0.28);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
function addFloorArrow(x, z, color = 0x55d6be, scale = 1) {
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.46
})
);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(x, 0.032, z);
arrow.scale.setScalar(scale);
scene.add(arrow);
}
addFloorArrow(0, 1.32);
addFloorArrow(-2.65, 0.55, colors.amber, 0.78);
addFloorArrow(0, 0.55, colors.mint, 0.78);
addFloorArrow(2.65, 0.55, colors.coral, 0.78);
// ---------------------------------------------------------------------
// Text and sprite 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.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabelSprite(
text,
foreground = "#eaf8f5",
background = "#10242c",
worldWidth = 1.25,
worldHeight = 0.34,
fontSize = 50
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
if (background) {
roundedRect(ctx, 8, 12, 496, 104, 28);
ctx.fillStyle = background;
ctx.fill();
}
ctx.fillStyle = foreground;
ctx.font = `800 ${fontSize}px Arial, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 10;
return sprite;
}
const mainSign = makeLabelSprite(
"SHARED QUEUE",
"#bff9ed",
null,
3.7,
0.74,
62
);
mainSign.position.set(0, 4.55, -5.52);
scene.add(mainSign);
// ---------------------------------------------------------------------
// Low-poly people
// ---------------------------------------------------------------------
function createPerson(shirtColor, ticketId = null) {
const group = new THREE.Group();
const rig = new THREE.Group();
group.add(rig);
const skinColors = [0xe2ad82, 0xb87956, 0xf1c49e, 0x8d583e];
const hairColors = [0x2b2020, 0x49362c, 0x17191d, 0x72513c];
const skin = skinColors[ticketId !== null ? ticketId % skinColors.length : 0];
const hair = hairColors[ticketId !== null ? ticketId % hairColors.length : 1];
const shirtMat = standardMaterial(shirtColor);
const pantsMat = standardMaterial(0x243944);
const skinMat = standardMaterial(skin);
const hairMat = standardMaterial(hair);
const legLeft = addBox(rig, 0.17, 0.34, 0.19, pantsMat, -0.14, 0.19, 0);
const legRight = addBox(rig, 0.17, 0.34, 0.19, pantsMat, 0.14, 0.19, 0);
legLeft.rotation.z = 0.025;
legRight.rotation.z = -0.025;
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.34, 0.70, 6),
shirtMat
);
body.position.y = 0.79;
body.castShadow = true;
rig.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.255, 0),
skinMat
);
head.position.y = 1.39;
head.castShadow = true;
rig.add(head);
const hairCap = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.255, 0),
hairMat
);
hairCap.position.set(0, 1.50, -0.015);
hairCap.scale.set(1.02, 0.42, 1.02);
hairCap.castShadow = true;
rig.add(hairCap);
function createArm(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.34, 1.04, 0);
const arm = addBox(
pivot,
0.115,
0.48,
0.13,
shirtMat,
0,
-0.20,
0
);
const hand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.09, 0),
skinMat
);
hand.position.set(0, -0.47, 0);
hand.castShadow = true;
pivot.add(hand);
rig.add(pivot);
return pivot;
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
if (ticketId !== null) {
const label = makeLabelSprite(
`T-${String(ticketId).padStart(3, "0")}`,
"#e8faf5",
"#10242c",
0.94,
0.25,
45
);
label.position.set(0, 1.92, 0);
rig.add(label);
}
group.position.y = -0.06;
scene.add(group);
return {
group,
rig,
leftArm,
rightArm,
state: "waiting",
removed: false
};
}
// ---------------------------------------------------------------------
// Counters
// ---------------------------------------------------------------------
const counters = [];
function createCounterPanel(index, color) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 200;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.65, 0.83, 1);
sprite.position.set(counterXs[index], 3.55, -3.65);
sprite.renderOrder = 12;
scene.add(sprite);
return { canvas, ctx, texture };
}
function updateCounterPanel(counter) {
const { ctx, texture } = counter.panel;
const css = "#" + counter.color.toString(16).padStart(6, "0");
ctx.clearRect(0, 0, 640, 200);
roundedRect(ctx, 6, 6, 628, 188, 28);
ctx.fillStyle = "#0b1b23";
ctx.fill();
roundedRect(ctx, 6, 6, 14, 188, 7);
ctx.fillStyle = css;
ctx.fill();
ctx.fillStyle = "#8fa9aa";
ctx.font = "700 25px Arial, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "alphabetic";
ctx.fillText(`COUNTER ${counter.name}`, 44, 48);
let status = "READY";
let detail = "Waiting for a ticket";
if (counter.phase === "walking") {
status = "TICKET CALLED";
detail = `Walking to counter ${counter.name}`;
} else if (counter.phase === "service") {
status = "SERVING";
const remaining = Math.max(0, counter.duration - counter.elapsed);
detail = `T-${String(counter.ticket).padStart(3, "0")} · ${remaining.toFixed(1)}s`;
}
ctx.fillStyle = css;
ctx.font = "800 42px Arial, sans-serif";
ctx.fillText(status, 44, 111);
ctx.fillStyle = "#b7c9ca";
ctx.font = "500 27px Arial, sans-serif";
ctx.fillText(detail, 44, 158);
texture.needsUpdate = true;
}
function createCounter(index) {
const color = [colors.mint, colors.amber, colors.coral][index];
const group = new THREE.Group();
group.position.set(counterXs[index], 0, -3.55);
scene.add(group);
const accentMat = standardMaterial(color);
const deskMat = standardMaterial(0x233a43);
const darkMat = standardMaterial(0x10232c);
const trimMat = standardMaterial(0x789094, {
metalness: 0.4,
roughness: 0.4
});
addBox(group, 3.15, 1.12, 1.45, deskMat, 0, 0.48, 0);
addBox(group, 3.38, 0.18, 1.65, accentMat, 0, 1.13, 0);
addBox(group, 2.68, 0.69, 0.055, darkMat, 0, 0.47, 0.755, false);
addBox(group, 2.35, 0.055, 0.07, accentMat, 0, 0.49, 0.795, false);
addBox(group, 0.13, 2.45, 0.13, trimMat, -1.42, 1.63, -0.69);
addBox(group, 0.13, 2.45, 0.13, trimMat, 1.42, 1.63, -0.69);
addBox(group, 3.18, 0.18, 1.48, deskMat, 0, 2.91, -0.12);
addBox(group, 2.8, 0.055, 0.06, accentMat, 0, 2.89, 0.63, false);
const counterLabel = makeLabelSprite(
counterNames[index],
"#f2fbf9",
null,
0.6,
0.42,
80
);
counterLabel.position.set(0, 2.45, 0.74);
group.add(counterLabel);
const staff = createPerson(0x425c65);
staff.group.position.set(0, -0.06, -0.94);
staff.group.scale.setScalar(0.92);
staff.leftArm.rotation.x = -0.5;
staff.rightArm.rotation.x = -0.5;
const beaconMaterial = standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.45
});
const beacon = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.12, 0),
beaconMaterial
);
beacon.position.set(1.28, 1.48, 0.61);
group.add(beacon);
const counter = {
index,
name: counterNames[index],
x: counterXs[index],
serviceZ: -1.65,
color,
duration: counterDurations[index],
phase: "idle",
ticket: null,
elapsed: 0,
group,
beacon,
beaconMaterial,
panel: createCounterPanel(index, color)
};
counters.push(counter);
return counter;
}
for (let i = 0; i < 3; i++) {
createCounter(i);
}
// Numbered floor positions make queue order visible in the 3D scene.
const queueSlots = [];
for (let i = 0; i < 11; i++) {
const z = HEAD_Z + i * 1.25;
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x4c696d,
transparent: true,
opacity: 0.55
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.025, 6, 24),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(0, 0.037, z);
scene.add(ring);
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 128;
labelCanvas.height = 128;
const labelCtx = labelCanvas.getContext("2d");
labelCtx.fillStyle = "#8da9aa";
labelCtx.font = "800 52px Arial, sans-serif";
labelCtx.textAlign = "center";
labelCtx.textBaseline = "middle";
labelCtx.fillText(String(i + 1).padStart(2, "0"), 64, 67);
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.48, 0.48),
new THREE.MeshBasicMaterial({
map: labelTexture,
transparent: true,
opacity: 0.75,
depthWrite: false
})
);
label.rotation.x = -Math.PI / 2;
label.position.set(0, 0.042, z);
scene.add(label);
queueSlots.push({ ring, ringMaterial, label });
}
// ---------------------------------------------------------------------
// Camera controls implemented directly, without add-ons
// ---------------------------------------------------------------------
const cameraState = {
yaw: 0.34,
phi: 0.88,
radius: 26,
target: new THREE.Vector3(0, 0.45, 2.55)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.yaw = 0.34;
cameraState.phi = 0.88;
cameraState.radius = 26;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.004,
0.12,
1.25
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
15,
34
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("cameraReset").addEventListener("click", resetCamera);
document.getElementById("cameraTop").addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.phi = 0.16;
cameraState.radius = 25;
updateCamera();
});
const resizeObserver = new ResizeObserver(() => {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resizeObserver.observe(viewport);
updateCamera();
// ---------------------------------------------------------------------
// Ticket and event logic
// ---------------------------------------------------------------------
function waitingTickets() {
return tickets.filter((ticket) => ticket.state === "waiting");
}
function activeTickets() {
return tickets.filter(
(ticket) =>
ticket.state === "waiting" ||
ticket.state === "assigned" ||
ticket.state === "service"
);
}
function addEvent(message, type = "info") {
events.unshift({
time: simulationTime,
message,
type
});
if (events.length > 40) events.length = 40;
}
function addTicket(logEvent = true) {
const id = nextTicketId++;
const shirt = ticketColors[(id - 1) % ticketColors.length];
const person = createPerson(shirt, id);
const currentWaiting = waitingTickets();
const rearZ = currentWaiting.reduce(
(max, ticket) => Math.max(max, ticket.person.group.position.z),
12.4
);
person.group.position.set(0, -0.06, Math.min(15.8, rearZ + 1.05));
const ticket = {
id,
joinedAt: simulationTime,
state: "waiting",
counter: null,
serviceStartedAt: null,
completedAt: null,
waitDuration: null,
serviceDuration: null,
person
};
tickets.push(ticket);
if (logEvent) {
addEvent(`T-${String(id).padStart(3, "0")} joined the shared queue`);
}
tryDispatch();
return ticket;
}
function assignTicket(counter, ticket) {
counter.phase = "walking";
counter.ticket = ticket.id;
counter.elapsed = 0;
ticket.state = "assigned";
ticket.counter = counter.index;
ticket.person.state = "assigned";
addEvent(
`T-${String(ticket.id).padStart(3, "0")} called to Counter ${counter.name}`,
"dispatch"
);
}
function tryDispatch() {
const line = waitingTickets();
if (!line.length) return;
const head = line[0];
const distance = Math.hypot(
head.person.group.position.x,
head.person.group.position.z - HEAD_Z
);
// A ticket must reach the front of the shared line before dispatch.
if (distance > 0.26) return;
for (const counter of counters) {
if (counter.phase === "idle") {
assignTicket(counter, head);
break;
}
}
}
function startService(counter) {
counter.phase = "service";
counter.elapsed = 0;
const ticket = tickets.find((item) => item.id === counter.ticket);
if (!ticket) return;
ticket.state = "service";
ticket.serviceStartedAt = simulationTime;
ticket.waitDuration = ticket.serviceStartedAt - ticket.joinedAt;
ticket.person.state = "service";
addEvent(
`T-${String(ticket.id).padStart(3, "0")} started at Counter ${counter.name}`,
"service"
);
}
function completeService(counter) {
const ticket = tickets.find((item) => item.id === counter.ticket);
if (!ticket) return;
ticket.state = "completed";
ticket.completedAt = simulationTime;
ticket.serviceDuration = counter.duration;
ticket.person.state = "exiting";
ticket.person.exitX = 8.6;
ticket.person.exitZ = -2.2 + (counter.index - 1) * 0.55;
addEvent(
`T-${String(ticket.id).padStart(3, "0")} completed · waited ${ticket.waitDuration.toFixed(1)}s`,
"complete"
);
spawnConfetti(
new THREE.Vector3(counter.x, 1.4, counter.serviceZ + 0.8),
counter.color
);
counter.phase = "idle";
counter.ticket = null;
counter.elapsed = 0;
}
function moveTicket(ticket, dt) {
const person = ticket.person;
if (!person || person.removed) return;
let targetX = 0;
let targetZ = HEAD_Z;
if (ticket.state === "waiting") {
const line = waitingTickets();
const index = line.indexOf(ticket);
const baseZ = HEAD_Z + index * 1.25;
if (index > 0) {
const previous = line[index - 1];
targetZ = Math.max(
baseZ,
previous.person.group.position.z + 0.92
);
} else {
targetZ = HEAD_Z;
}
} else if (ticket.state === "assigned" || ticket.state === "service") {
const counter = counters[ticket.counter];
targetX = counter.x;
targetZ = counter.serviceZ;
} else if (ticket.state === "exiting") {
targetX = person.exitX;
targetZ = person.exitZ;
}
const alpha = 1 - Math.exp(-dt * 5.2);
person.group.position.x += (targetX - person.group.position.x) * alpha;
person.group.position.z += (targetZ - person.group.position.z) * alpha;
if (ticket.state === "waiting") {
const line = waitingTickets();
const index = line.indexOf(ticket);
if (index > 0) {
const previous = line[index - 1];
person.group.position.z = Math.max(
person.group.position.z,
previous.person.group.position.z + 0.86
);
}
}
if (ticket.state === "exiting") {
const distance = Math.hypot(
person.group.position.x - targetX,
person.group.position.z - targetZ
);
if (distance < 0.16) {
scene.remove(person.group);
person.removed = true;
return;
}
}
const phase = simulationTime * 2.1 + ticket.id;
const bob =
ticket.state === "waiting"
? Math.sin(phase) * 0.018
: ticket.state === "assigned"
? Math.abs(Math.sin(phase * 1.5)) * 0.025
: 0;
person.rig.position.y = bob;
if (ticket.state === "service") {
person.rightArm.rotation.x = -0.58 + Math.sin(phase) * 0.12;
person.leftArm.rotation.x = -0.25;
} else if (ticket.state === "assigned") {
person.rightArm.rotation.x = Math.sin(phase) * 0.35 - 0.25;
person.leftArm.rotation.x = -Math.sin(phase) * 0.35 - 0.25;
} else {
person.rightArm.rotation.x = 0.08;
person.leftArm.rotation.x = -0.08;
}
}
function simulate(dt) {
simulationTime += dt;
if (autoArrivals) {
autoElapsed += dt;
if (autoElapsed >= arrivalInterval) {
autoElapsed %= arrivalInterval;
addTicket();
}
}
for (const ticket of tickets) {
moveTicket(ticket, dt);
}
for (const counter of counters) {
if (counter.phase === "walking") {
const ticket = tickets.find((item) => item.id === counter.ticket);
if (ticket) {
const distance = Math.hypot(
ticket.person.group.position.x - counter.x,
ticket.person.group.position.z - counter.serviceZ
);
if (distance < 0.18) {
startService(counter);
}
}
} else if (counter.phase === "service") {
counter.elapsed += dt;
if (counter.elapsed >= counter.duration) {
completeService(counter);
}
}
}
tryDispatch();
}
// ---------------------------------------------------------------------
// Completion particles
// ---------------------------------------------------------------------
function spawnConfetti(position, color) {
for (let i = 0; i < 9; i++) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.09),
standardMaterial(i % 2 ? color : 0xf2f7e8, {
emissive: i % 2 ? color : 0x000000,
emissiveIntensity: 0.2
})
);
mesh.position.copy(position);
scene.add(mesh);
particles.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 2.2,
1.8 + Math.random() * 1.7,
(Math.random() - 0.5) * 2.2
),
life: 0.8 + Math.random() * 0.5
});
}
}
function updateParticles(dt) {
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.life -= dt;
if (particle.life <= 0) {
scene.remove(particle.mesh);
particles.splice(i, 1);
continue;
}
particle.velocity.y -= dt * 4.8;
particle.mesh.position.addScaledVector(particle.velocity, dt);
particle.mesh.rotation.x += dt * 4;
particle.mesh.rotation.y += dt * 5;
particle.mesh.scale.setScalar(Math.min(1, particle.life * 2));
}
}
// ---------------------------------------------------------------------
// Counter configuration UI
// ---------------------------------------------------------------------
counterConfigs.innerHTML = counters
.map((counter, index) => {
const css = "#" + counter.color.toString(16).padStart(6, "0");
return `
<div class="counter-row" style="--accent:${css}">
<div class="counter-head">
<span class="counter-dot"></span>
<strong>Counter ${counter.name}</strong>
<span class="counter-state" id="counterState${index}">Ready</span>
</div>
<div class="counter-ticket" id="counterTicket${index}">No active ticket</div>
<div class="range-label">
<label for="duration${index}">Service time</label>
<output id="durationOut${index}">${counter.duration.toFixed(1)}s</output>
</div>
<input
id="duration${index}"
data-counter="${index}"
type="range"
min="2"
max="30"
step="0.5"
value="${counter.duration}"
style="--accent:${css}"
aria-label="Counter ${counter.name} service duration"
/>
</div>
`;
})
.join("");
document.querySelectorAll("[data-counter]").forEach((input) => {
const index = Number(input.dataset.counter);
const counter = counters[index];
const output = document.getElementById(`durationOut${index}`);
input.addEventListener("input", () => {
counter.duration = Number(input.value);
output.textContent = `${counter.duration.toFixed(1)}s`;
});
input.addEventListener("change", () => {
addEvent(
`Counter ${counter.name} duration set to ${counter.duration.toFixed(1)}s`
);
renderUI();
});
});
// ---------------------------------------------------------------------
// Interface controls
// ---------------------------------------------------------------------
function setPaused(value) {
paused = value;
pauseBtn.textContent = paused ? "▶ Resume" : "Ⅱ Pause";
pauseBtn.setAttribute("aria-pressed", String(paused));
}
addBtn.addEventListener("click", () => addTicket());
pauseBtn.addEventListener("click", () => setPaused(!paused));
resetBtn.addEventListener("click", () => {
for (const ticket of tickets) {
if (ticket.person && !ticket.person.removed) {
scene.remove(ticket.person.group);
}
}
for (const particle of particles) {
scene.remove(particle.mesh);
}
tickets = [];
particles = [];
events = [];
nextTicketId = 1;
simulationTime = 0;
autoElapsed = 0;
for (const counter of counters) {
counter.phase = "idle";
counter.ticket = null;
counter.elapsed = 0;
}
setPaused(false);
renderUI();
});
document.querySelectorAll(".speed").forEach((button) => {
button.addEventListener("click", () => {
simulationSpeed = Number(button.dataset.speed);
document.querySelectorAll(".speed").forEach((item) => {
item.classList.toggle("active", item === button);
});
});
});
autoToggle.addEventListener("change", () => {
autoArrivals = autoToggle.checked;
autoElapsed = 0;
arrivalState.textContent = autoArrivals ? "Automatic" : "Manual";
renderUI();
});
autoInterval.addEventListener("input", () => {
arrivalInterval = Number(autoInterval.value);
autoIntervalOut.textContent = `${arrivalInterval.toFixed(1)}s`;
});
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (tag === "INPUT" || tag === "TEXTAREA") return;
if (event.code === "Space") {
event.preventDefault();
setPaused(!paused);
} else if (event.key.toLowerCase() === "n") {
addTicket();
}
});
// ---------------------------------------------------------------------
// UI rendering
// ---------------------------------------------------------------------
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainder = Math.floor(seconds % 60);
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
function renderUI() {
const waiting = waitingTickets();
const active = activeTickets();
const completed = tickets.filter((ticket) => ticket.state === "completed");
statQueue.textContent = waiting.length;
statServing.textContent = active.filter(
(ticket) => ticket.state === "service" || ticket.state === "assigned"
).length;
statCompleted.textContent = completed.length;
const completedWaits = completed
.map((ticket) => ticket.waitDuration)
.filter((value) => value !== null);
statWait.textContent = completedWaits.length
? `${(
completedWaits.reduce((sum, value) => sum + value, 0) /
completedWaits.length
).toFixed(1)}s`
: "—";
counters.forEach((counter, index) => {
const state = document.getElementById(`counterState${index}`);
const ticketLine = document.getElementById(`counterTicket${index}`);
if (counter.phase === "service") {
state.textContent = "Serving";
const remaining = Math.max(0, counter.duration - counter.elapsed);
ticketLine.textContent =
`T-${String(counter.ticket).padStart(3, "0")} · ${remaining.toFixed(1)}s remaining`;
} else if (counter.phase === "walking") {
state.textContent = "Called";
ticketLine.textContent =
`T-${String(counter.ticket).padStart(3, "0")} is walking to the counter`;
} else {
state.textContent = "Ready";
ticketLine.textContent = waiting.length
? `Next: T-${String(waiting[0].id).padStart(3, "0")}`
: "No active ticket";
}
updateCounterPanel(counter);
});
if (waiting.length) {
queueList.innerHTML = waiting
.map((ticket, index) => {
const wait = Math.max(0, simulationTime - ticket.joinedAt);
return `
<div class="queue-row">
<span class="queue-position">${String(index + 1).padStart(2, "0")}</span>
<div class="queue-ticket">
<strong>T-${String(ticket.id).padStart(3, "0")}</strong>
<small>Joined ${formatTime(ticket.joinedAt)}</small>
</div>
<span class="queue-wait">${wait.toFixed(1)}s</span>
</div>
`;
})
.join("");
} else {
queueList.innerHTML = `
<div class="empty">
The shared line is empty.<br />
Add a ticket or enable automatic arrivals.
</div>
`;
}
if (events.length) {
eventList.innerHTML = events
.slice(0, 8)
.map(
(event) => `
<div class="event ${event.type}">
<i></i>
<span>${event.message}</span>
<time>${formatTime(event.time)}</time>
</div>
`
)
.join("");
} else {
eventList.innerHTML = `<div class="empty">No activity yet.</div>`;
}
const activeSlotCount = Math.min(waiting.length, queueSlots.length);
queueSlots.forEach((slot, index) => {
const active = index < activeSlotCount;
slot.ringMaterial.color.setHex(
active ? (index === 0 ? colors.mint : 0x66898b) : 0x3e555a
);
slot.ringMaterial.opacity = active ? 0.72 : 0.22;
slot.label.material.opacity = active ? 0.82 : 0.16;
});
}
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let uiElapsed = 0;
function animate() {
requestAnimationFrame(animate);
const realDt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulate(realDt * simulationSpeed);
}
updateParticles(realDt);
for (const counter of counters) {
const active = counter.phase !== "idle";
const pulse = active
? 0.9 + Math.sin(simulationTime * 5 + counter.index) * 0.14
: 0.72;
counter.beacon.scale.setScalar(pulse);
counter.beaconMaterial.emissiveIntensity = active ? 0.9 : 0.25;
}
uiElapsed += realDt;
if (uiElapsed >= 0.12) {
uiElapsed = 0;
renderUI();
}
renderer.render(scene, camera);
}
// Seed a readable starting queue.
for (let i = 0; i < 5; i++) {
addTicket(false);
}
tickets.forEach((ticket, index) => {
ticket.person.group.position.set(0, -0.06, HEAD_Z + index * 1.25);
});
renderUI();
animate();
</script>
</body>
</html>
```