Prompt specification
Build or customize the Three.js 3D scene "Periodic Arrival Beads on a Clock Ring" 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: Periodic Arrival Beads on a Clock Ring
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/periodic-arrival-beads-on-a-clock-ring-x2141
Scene Description Prompt:
Place service-arrival markers around a clock ring with explicit intervals. Show headway and phase separately so equal frequency does not imply synchronized arrivals. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (periodic-arrival-beads-on-a-clock-ring-x2141):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Clock — Service Arrivals</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 21, 38, 0.88);
--panel-border: rgba(148, 163, 184, 0.22);
--text: #e8f1ff;
--muted: #91a4bd;
--accent: #65e7ff;
}
* {
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,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.35),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
#hero {
position: fixed;
z-index: 3;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 20px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #75e7ff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#hero p {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.headline-note {
display: flex;
align-items: center;
gap: 9px;
margin-top: 15px;
padding: 10px 12px;
border: 1px solid rgba(101, 231, 255, 0.18);
border-radius: 10px;
background: rgba(101, 231, 255, 0.07);
color: #c9f7ff;
font-size: 12px;
}
.headline-note b {
color: #ffffff;
}
.note-mark {
flex: 0 0 auto;
width: 8px;
height: 8px;
border-radius: 2px;
background: #65e7ff;
box-shadow: 0 0 14px #65e7ff;
}
#panel {
position: fixed;
z-index: 4;
top: 20px;
right: 20px;
width: 380px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 17px;
border-radius: 18px;
scrollbar-width: thin;
scrollbar-color: #34465e transparent;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-title h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.01em;
}
.panel-title span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.preset-label {
margin: 0 0 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-bottom: 14px;
}
.preset,
.small-button,
#playButton {
border: 1px solid rgba(148, 163, 184, 0.2);
border-radius: 9px;
background: rgba(148, 163, 184, 0.07);
color: var(--text);
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.preset {
padding: 9px 8px;
font-size: 11px;
font-weight: 700;
}
.preset:hover,
.small-button:hover,
#playButton:hover {
border-color: rgba(101, 231, 255, 0.55);
background: rgba(101, 231, 255, 0.1);
}
.preset.active {
border-color: rgba(101, 231, 255, 0.6);
background: rgba(101, 231, 255, 0.14);
color: #d8faff;
}
#services {
display: grid;
gap: 10px;
}
.service-card {
--accent: #65e7ff;
position: relative;
overflow: hidden;
padding: 12px 12px 11px;
border: 1px solid rgba(148, 163, 184, 0.16);
border-radius: 12px;
background: rgba(2, 10, 22, 0.3);
}
.service-card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
background: var(--accent);
content: "";
box-shadow: 0 0 15px color-mix(in srgb, var(--accent), transparent 40%);
}
.service-head {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 11px;
}
.service-dot {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
.service-head strong {
font-size: 13px;
}
.service-badge {
margin-left: auto;
padding: 3px 6px;
border-radius: 5px;
background: rgba(148, 163, 184, 0.08);
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.remove-button {
width: 23px;
height: 23px;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
color: #70849d;
cursor: pointer;
}
.remove-button:hover {
background: rgba(255, 107, 122, 0.12);
color: #ff8794;
}
.control-row {
display: grid;
grid-template-columns: 61px 48px 28px 1fr;
align-items: center;
gap: 7px;
min-height: 31px;
color: var(--muted);
font-size: 11px;
}
.control-row label {
font-weight: 700;
}
.number-input {
width: 48px;
padding: 5px 5px;
border: 1px solid rgba(148, 163, 184, 0.22);
border-radius: 6px;
outline: none;
background: rgba(3, 10, 20, 0.72);
color: #f2f7ff;
text-align: center;
font-size: 11px;
}
.number-input:focus {
border-color: var(--accent);
}
.unit {
color: #647991;
font-size: 10px;
}
.meter {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(148, 163, 184, 0.12);
}
.headway-fill {
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), transparent);
opacity: 0.85;
transition: width 160ms ease;
}
.phase-track {
position: relative;
height: 7px;
border-radius: 999px;
background:
repeating-linear-gradient(
90deg,
rgba(148, 163, 184, 0.12) 0,
rgba(148, 163, 184, 0.12) 1px,
transparent 1px,
transparent 25%
);
}
.phase-track::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 2px;
border-radius: 2px;
background: rgba(148, 163, 184, 0.5);
content: "";
}
.phase-dot {
position: absolute;
z-index: 2;
top: 50%;
width: 9px;
height: 9px;
border: 2px solid #07111f;
border-radius: 2px;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
transform: translate(-50%, -50%);
transition: left 120ms ease;
}
input[type="range"] {
grid-column: 1 / -1;
width: 100%;
height: 4px;
margin: 0 0 7px;
accent-color: var(--accent);
cursor: pointer;
}
.arrival-row {
display: grid;
grid-template-columns: 52px 1fr;
align-items: start;
gap: 7px;
margin-top: 5px;
padding-top: 9px;
border-top: 1px solid rgba(148, 163, 184, 0.1);
color: var(--muted);
font-size: 10px;
}
.arrival-chips {
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.arrival-chip {
min-width: 26px;
padding: 3px 4px;
border: 1px solid color-mix(in srgb, var(--accent), transparent 70%);
border-radius: 4px;
background: color-mix(in srgb, var(--accent), transparent 92%);
color: var(--accent);
text-align: center;
font-variant-numeric: tabular-nums;
}
.panel-actions {
display: flex;
gap: 8px;
margin-top: 12px;
}
.small-button,
#playButton {
padding: 8px 11px;
font-size: 11px;
font-weight: 700;
}
#playButton {
min-width: 82px;
color: #bff8ff;
}
.transport {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
gap: 9px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.transport input {
width: 100%;
accent-color: #65e7ff;
}
.clock-readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
.readout-box {
padding: 10px;
border: 1px solid rgba(148, 163, 184, 0.13);
border-radius: 9px;
background: rgba(2, 10, 22, 0.3);
}
.readout-box small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#currentTime {
color: #f4fbff;
font-size: 21px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
#arrivalsNow {
color: #a8f4ff;
font-size: 12px;
font-weight: 700;
}
.formula {
margin-top: 12px;
padding: 10px;
border-left: 2px solid #65e7ff;
border-radius: 0 8px 8px 0;
background: rgba(101, 231, 255, 0.06);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.formula code {
color: #d9f9ff;
font-size: 11px;
}
#legend {
position: fixed;
z-index: 3;
bottom: 20px;
left: 20px;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 15px;
max-width: calc(100vw - 40px);
padding: 11px 14px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-symbol {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 2px;
background: #65e7ff;
box-shadow: 0 0 9px rgba(101, 231, 255, 0.55);
}
.legend-symbol.arrival {
width: 10px;
height: 10px;
border-radius: 1px;
background: #ff7381;
}
.legend-symbol.phase {
width: 15px;
height: 12px;
border: 2px solid #ffc857;
border-top-width: 4px;
border-radius: 1px;
background: transparent;
box-shadow: none;
}
.legend-symbol.lane {
width: 16px;
height: 3px;
border-radius: 2px;
background: #3d5978;
box-shadow: none;
}
#tooltip {
position: fixed;
z-index: 8;
display: none;
padding: 7px 9px;
border: 1px solid rgba(101, 231, 255, 0.35);
border-radius: 7px;
background: rgba(4, 13, 26, 0.95);
color: #eafaff;
font-size: 11px;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #07111f;
color: #8deaff;
font-size: 13px;
letter-spacing: 0.08em;
}
@media (max-width: 760px) {
#hero {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
#hero p,
.headline-note {
display: none;
}
#panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 54vh;
padding: 13px;
}
#legend {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="loading">LOADING VOXEL CLOCK…</div>
<header id="hero" class="glass">
<div class="eyebrow">Temporal systems / voxel visualization</div>
<h1>Service arrival clock</h1>
<p>
Each lane shows recurring arrivals over a 60-minute cycle. The tall outer
gates show phase; the solid blocks show arrival events.
</p>
<div class="headline-note">
<span class="note-mark"></span>
<span><b>Equal headway</b> does not mean synchronized arrivals.</span>
</div>
</header>
<aside id="panel" class="glass">
<div class="panel-title">
<h2>Timing controls</h2>
<span>Headway ≠ phase</span>
</div>
<p class="preset-label">Comparison preset</p>
<div class="presets">
<button class="preset active" data-preset="staggered">
Equal / staggered
</button>
<button class="preset" data-preset="synchronized">
Equal / synchronized
</button>
</div>
<div id="services"></div>
<div class="panel-actions">
<button id="addService" class="small-button">+ Add service</button>
<button id="playButton" class="small-button">Pause</button>
</div>
<div class="transport">
<span>Animation speed</span>
<input
id="speed"
type="range"
min="1"
max="20"
step="1"
value="5"
aria-label="Animation speed"
/>
</div>
<div class="clock-readout">
<div class="readout-box">
<small>Clock minute</small>
<div id="currentTime">00 min</div>
</div>
<div class="readout-box">
<small>Arriving now</small>
<div id="arrivalsNow">A, C</div>
</div>
</div>
<div class="formula">
<strong>Headway</strong> is the spacing between consecutive arrivals.
<strong>Phase</strong> is the offset from the 00-minute reference.<br />
<code>arrival(n) = (phase + n × headway) mod 60</code>
</div>
</aside>
<div id="legend" class="glass">
<div class="legend-item">
<span class="legend-symbol arrival"></span>
Arrival marker
</div>
<div class="legend-item">
<span class="legend-symbol phase"></span>
Phase gate
</div>
<div class="legend-item">
<span class="legend-symbol lane"></span>
Service lane
</div>
<div class="legend-item">00 at top · minutes increase clockwise</div>
</div>
<div id="tooltip"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const sceneHost = $("#scene");
const tooltip = $("#tooltip");
const palette = [0x55e4ff, 0xff6f80, 0xffc857, 0xb58cff];
const services = [
{ id: "A", name: "Route A", h: 10, p: 0, color: palette[0] },
{ id: "B", name: "Route B", h: 10, p: 5, color: palette[1] },
{ id: "C", name: "Route C", h: 20, p: 0, color: palette[2] }
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 32, 58);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls: drag to orbit, wheel to zoom.
const controls = {
azimuth: 0,
elevation: 0.68,
distance: 31,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const horizontal = Math.sin(controls.elevation) * controls.distance;
camera.position.set(
Math.sin(controls.azimuth) * horizontal,
Math.cos(controls.elevation) * controls.distance,
Math.cos(controls.azimuth) * horizontal
);
camera.lookAt(0, 0, 0);
}
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
tooltip.style.display = "none";
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (controls.dragging) {
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.azimuth -= dx * 0.006;
controls.elevation = THREE.MathUtils.clamp(
controls.elevation + dy * 0.005,
0.24,
1.38
);
updateCamera();
return;
}
updateTooltip(event);
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch {
// Pointer capture may already have been released.
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
tooltip.style.display = "none";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance + event.deltaY * 0.018,
18,
48
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// Lighting.
scene.add(new THREE.HemisphereLight(0xbcdcff, 0x07101d, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(8, 18, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -17;
keyLight.shadow.camera.right = 17;
keyLight.shadow.camera.top = 17;
keyLight.shadow.camera.bottom = -17;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x328dff, 30, 45, 2);
rimLight.position.set(-12, 8, -12);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addBox(
parent,
x,
y,
z,
sx,
sy,
sz,
material,
rotationY = 0
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
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, accent = "#dceaff", width = 1.4, height = 0.55) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 18, 496, 124, 24);
ctx.fillStyle = "rgba(5, 14, 28, 0.90)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 5;
ctx.stroke();
const fontSize = text.length > 9 ? 38 : text.length > 6 ? 46 : 58;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = accent;
ctx.fillText(text, 256, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
function hex(color) {
return `#${color.toString(16).padStart(6, "0")}`;
}
// A tiled voxel floor.
const floorGeometry = new THREE.BoxGeometry(0.96, 0.14, 0.96);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
metalness: 0.02
});
const floor = new THREE.InstancedMesh(floorGeometry, floorMaterial, 31 * 31);
floor.receiveShadow = true;
const dummy = new THREE.Object3D();
const floorColor = new THREE.Color();
let floorIndex = 0;
for (let x = -15; x <= 15; x++) {
for (let z = -15; z <= 15; z++) {
dummy.position.set(x, -0.25, z);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
floor.setMatrixAt(floorIndex, dummy.matrix);
const variation = 0.5 + 0.5 * Math.sin(x * 13.7 + z * 7.1);
floorColor.setHSL(
0.58,
0.35,
0.045 + variation * 0.025
);
floor.setColorAt(floorIndex, floorColor);
floorIndex++;
}
}
floor.instanceMatrix.needsUpdate = true;
if (floor.instanceColor) floor.instanceColor.needsUpdate = true;
scene.add(floor);
// Main voxel clock ring.
const tickMaterial = new THREE.MeshStandardMaterial({
color: 0x37526f,
roughness: 0.72,
metalness: 0.12
});
const majorTickMaterial = new THREE.MeshStandardMaterial({
color: 0x91a8c4,
emissive: 0x203a55,
emissiveIntensity: 0.35,
roughness: 0.55
});
const hourPipMaterial = new THREE.MeshStandardMaterial({
color: 0x466986,
emissive: 0x10263b,
emissiveIntensity: 0.4,
roughness: 0.55
});
const minuteAngle = (minute) => (minute / 60) * Math.PI * 2;
for (let minute = 0; minute < 60; minute++) {
const theta = minuteAngle(minute);
const isMajor = minute % 5 === 0;
const radius = isMajor ? 11.05 : 11.05;
addBox(
scene,
Math.sin(theta) * radius,
0.03,
-Math.cos(theta) * radius,
isMajor ? 0.25 : 0.13,
isMajor ? 0.25 : 0.15,
isMajor ? 0.9 : 0.46,
isMajor ? majorTickMaterial : tickMaterial,
-theta
);
}
// Twelve larger pips form the inner clock face.
for (let hour = 0; hour < 12; hour++) {
const theta = (hour / 12) * Math.PI * 2;
addBox(
scene,
Math.sin(theta) * 4.72,
0.1,
-Math.cos(theta) * 4.72,
0.62,
0.32,
0.62,
hour % 3 === 0 ? majorTickMaterial : hourPipMaterial,
-theta
);
}
[
["00", 0],
["15", 15],
["30", 30],
["45", 45]
].forEach(([label, minute]) => {
const theta = minuteAngle(minute);
const sprite = makeTextSprite(label, "#bcd4ec", 1.3, 0.52);
sprite.position.set(
Math.sin(theta) * 12.1,
0.55,
-Math.cos(theta) * 12.1
);
scene.add(sprite);
});
// Voxel center hub and sweeping minute hand.
const hubMaterial = new THREE.MeshStandardMaterial({
color: 0x1f3953,
emissive: 0x0b2136,
emissiveIntensity: 0.6,
roughness: 0.45,
metalness: 0.3
});
addBox(scene, 0, 0.22, 0, 1.25, 0.48, 1.25, hubMaterial);
addBox(scene, 0, 0.57, 0, 0.72, 0.34, 0.72, majorTickMaterial);
const sweep = new THREE.Group();
sweep.position.y = 1.05;
scene.add(sweep);
const handMaterial = new THREE.MeshStandardMaterial({
color: 0xff7183,
emissive: 0xff254c,
emissiveIntensity: 0.85,
roughness: 0.38,
metalness: 0.16
});
addBox(sweep, 0, 0, -2.03, 0.13, 0.13, 4.06, handMaterial);
addBox(sweep, 0, 0, -4.14, 0.27, 0.27, 0.27, handMaterial);
addBox(sweep, 0, 0, 0.5, 0.2, 0.2, 0.75, handMaterial);
const minLabel = makeTextSprite("MIN", "#8fa8c3", 0.95, 0.38);
minLabel.position.set(0, 1.25, 1.25);
scene.add(minLabel);
const serviceRoot = new THREE.Group();
scene.add(serviceRoot);
let markerGroups = [];
let pickMeshes = [];
function clearServiceScene() {
const materials = new Set();
const textures = new Set();
serviceRoot.traverse((object) => {
if (object.material) {
const list = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of list) {
if (material.map) textures.add(material.map);
materials.add(material);
}
}
});
for (const texture of textures) texture.dispose();
for (const material of materials) material.dispose();
serviceRoot.clear();
markerGroups = [];
pickMeshes = [];
}
function arrivalsFor(service) {
const result = [];
for (let minute = service.p; minute < 60; minute += service.h) {
result.push(minute);
}
return result;
}
function buildServiceScene() {
clearServiceScene();
services.forEach((service, index) => {
const laneRadius = 7.2 - index * 0.62;
const phaseRadius = 9.45 - index * 0.62;
service.laneRadius = laneRadius;
service.phaseRadius = phaseRadius;
const laneColor = new THREE.Color(service.color).multiplyScalar(0.24);
const laneMaterial = new THREE.MeshStandardMaterial({
color: laneColor,
roughness: 0.85,
metalness: 0.05
});
// Dim voxel ticks define each service lane.
for (let minute = 0; minute < 60; minute++) {
const theta = minuteAngle(minute);
const tick = addBox(
serviceRoot,
Math.sin(theta) * laneRadius,
0.01,
-Math.cos(theta) * laneRadius,
0.16,
0.065,
0.24,
laneMaterial,
-theta
);
tick.castShadow = false;
}
// The phase gate is deliberately different from an arrival marker.
const phaseMaterial = new THREE.MeshStandardMaterial({
color: service.color,
emissive: service.color,
emissiveIntensity: 0.24,
roughness: 0.42,
metalness: 0.12
});
const phaseTheta = minuteAngle(service.p);
const phaseGate = new THREE.Group();
phaseGate.position.set(
Math.sin(phaseTheta) * phaseRadius,
0,
-Math.cos(phaseTheta) * phaseRadius
);
phaseGate.rotation.y = -phaseTheta;
serviceRoot.add(phaseGate);
addBox(phaseGate, -0.3, 0.5, 0, 0.18, 1.0, 0.24, phaseMaterial);
addBox(phaseGate, 0.3, 0.5, 0, 0.18, 1.0, 0.24, phaseMaterial);
addBox(phaseGate, 0, 0.98, 0, 0.82, 0.18, 0.28, phaseMaterial);
const phaseLabel = makeTextSprite(
`${service.id} P`,
hex(service.color),
1.02,
0.38
);
phaseLabel.position.set(0, 1.6, 0);
phaseGate.add(phaseLabel);
// A faint radial connector links phase to its first arrival.
const connectorMaterial = new THREE.MeshBasicMaterial({
color: service.color,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const connectorLength = phaseRadius - laneRadius;
const connectorRadius = (phaseRadius + laneRadius) / 2;
addBox(
serviceRoot,
Math.sin(phaseTheta) * connectorRadius,
0.025,
-Math.cos(phaseTheta) * connectorRadius,
0.035,
0.035,
connectorLength,
connectorMaterial,
-phaseTheta
);
// Solid voxel pins represent actual service arrivals.
arrivalsFor(service).forEach((minute) => {
const theta = minuteAngle(minute);
const markerMaterial = new THREE.MeshStandardMaterial({
color: service.color,
emissive: service.color,
emissiveIntensity: 0.08,
roughness: 0.34,
metalness: 0.18
});
const marker = new THREE.Group();
marker.position.set(
Math.sin(theta) * laneRadius,
0,
-Math.cos(theta) * laneRadius
);
marker.rotation.y = -theta;
marker.userData.minute = minute;
marker.userData.service = service;
marker.userData.material = markerMaterial;
addBox(marker, 0, 0.18, 0, 0.52, 0.26, 0.52, markerMaterial);
addBox(marker, 0, 0.47, 0, 0.37, 0.33, 0.37, markerMaterial);
const cap = addBox(
marker,
0,
0.75,
0,
0.2,
0.2,
0.2,
markerMaterial
);
cap.userData.arrivalInfo = {
service,
minute
};
pickMeshes.push(cap);
markerGroups.push(marker);
serviceRoot.add(marker);
});
});
}
function serviceCardHTML(service) {
const accent = hex(service.color);
return `
<article class="service-card" data-id="${service.id}" style="--accent:${accent}">
<div class="service-head">
<span class="service-dot"></span>
<strong>${service.name}</strong>
<span class="service-badge"></span>
<button class="remove-button" title="Remove service" aria-label="Remove ${service.name}">×</button>
</div>
<div class="control-row">
<label for="h-${service.id}">Headway</label>
<input
id="h-${service.id}"
class="number-input headway-input"
type="number"
min="5"
max="60"
step="1"
value="${service.h}"
aria-label="${service.name} headway"
/>
<span class="unit">min</span>
<div class="meter" title="Headway relative to a 60-minute cycle">
<div class="headway-fill"></div>
</div>
</div>
<div class="control-row">
<label for="p-${service.id}">Phase</label>
<input
id="p-${service.id}"
class="number-input phase-input"
type="number"
min="0"
max="${service.h - 1}"
step="1"
value="${service.p}"
aria-label="${service.name} phase"
/>
<span class="unit">min</span>
<div class="phase-track" title="Phase within one headway interval">
<div class="phase-dot"></div>
</div>
</div>
<input
class="phase-range"
type="range"
min="0"
max="${service.h - 1}"
step="1"
value="${service.p}"
aria-label="${service.name} phase slider"
/>
<div class="arrival-row">
<span>Arrivals</span>
<div class="arrival-chips"></div>
</div>
</article>
`;
}
function buildControls() {
$("#services").innerHTML = services
.map(serviceCardHTML)
.join("");
services.forEach((service) => {
const card = $(`.service-card[data-id="${service.id}"]`);
const headwayInput = card.querySelector(".headway-input");
const phaseInput = card.querySelector(".phase-input");
const phaseRange = card.querySelector(".phase-range");
const removeButton = card.querySelector(".remove-button");
headwayInput.addEventListener("change", () => {
const value = Number(headwayInput.value);
if (!Number.isFinite(value)) return;
service.h = THREE.MathUtils.clamp(Math.round(value), 5, 60);
service.p = Math.min(service.p, service.h - 1);
phaseInput.max = service.h - 1;
phaseRange.max = service.h - 1;
rebuildAll();
});
phaseInput.addEventListener("change", () => {
const value = Number(phaseInput.value);
if (!Number.isFinite(value)) return;
service.p = THREE.MathUtils.clamp(
Math.round(value),
0,
service.h - 1
);
rebuildAll();
});
phaseRange.addEventListener("input", () => {
service.p = Number(phaseRange.value);
rebuildAll();
});
removeButton.addEventListener("click", () => {
if (services.length <= 2) return;
const index = services.indexOf(service);
services.splice(index, 1);
buildControls();
rebuildAll();
});
});
syncControls();
}
function syncControls() {
services.forEach((service) => {
const card = $(`.service-card[data-id="${service.id}"]`);
if (!card) return;
const headwayInput = card.querySelector(".headway-input");
const phaseInput = card.querySelector(".phase-input");
const phaseRange = card.querySelector(".phase-range");
const phaseDot = card.querySelector(".phase-dot");
const headwayFill = card.querySelector(".headway-fill");
const arrivalChips = card.querySelector(".arrival-chips");
const badge = card.querySelector(".service-badge");
headwayInput.value = service.h;
phaseInput.value = service.p;
phaseInput.max = service.h - 1;
phaseRange.value = service.p;
phaseRange.max = service.h - 1;
phaseDot.style.left = `${(service.p / service.h) * 100}%`;
headwayFill.style.width = `${(service.h / 60) * 100}%`;
arrivalChips.innerHTML = arrivalsFor(service)
.map(
(minute) =>
`<span class="arrival-chip">${String(minute).padStart(2, "0")}</span>`
)
.join("");
const sameHeadway = services.some(
(other) => other !== service && other.h === service.h
);
badge.textContent = sameHeadway
? `${60 / service.h}/h · same headway`
: `${60 / service.h}/h`;
});
}
function rebuildAll() {
buildServiceScene();
syncControls();
clearPresetSelection();
}
function clearPresetSelection() {
document.querySelectorAll(".preset").forEach((button) => {
button.classList.remove("active");
});
}
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
clearPresetSelection();
button.classList.add("active");
if (button.dataset.preset === "staggered") {
services[0].h = 10;
services[0].p = 0;
services[1].h = 10;
services[1].p = 5;
services[2].h = 20;
services[2].p = 0;
} else {
services[0].h = 10;
services[0].p = 0;
services[1].h = 10;
services[1].p = 0;
services[2].h = 20;
services[2].p = 0;
}
rebuildAll();
button.classList.add("active");
});
});
$("#addService").addEventListener("click", () => {
if (services.length >= 4) return;
const index = services.length;
const h = [10, 10, 20, 15][index];
const p = [0, 5, 0, 3][index];
services.push({
id: String.fromCharCode(65 + index),
name: `Route ${String.fromCharCode(65 + index)}`,
h,
p,
color: palette[index]
});
buildControls();
rebuildAll();
});
let playing = true;
let simulationMinute = 0;
let lastDisplayedMinute = -1;
$("#playButton").addEventListener("click", () => {
playing = !playing;
$("#playButton").textContent = playing ? "Pause" : "Play";
});
$("#speed").addEventListener("input", (event) => {
animationSpeed = Number(event.target.value);
});
let animationSpeed = 5;
function updateClockReadout() {
const minute = Math.floor(simulationMinute) % 60;
$("#currentTime").textContent = `${String(minute).padStart(2, "0")} min`;
const arriving = services
.filter((service) => arrivalsFor(service).includes(minute))
.map((service) => service.id);
$("#arrivalsNow").textContent = arriving.length
? arriving.join(", ")
: "—";
}
// Hover information for the 3D arrival markers.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function updateTooltip(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (!hits.length) {
tooltip.style.display = "none";
return;
}
const info = hits[0].object.userData.arrivalInfo;
tooltip.textContent =
`${info.service.name} · arrival ${String(info.minute).padStart(2, "0")} min`;
tooltip.style.display = "block";
tooltip.style.left = `${event.clientX + 13}px`;
tooltip.style.top = `${event.clientY + 13}px`;
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
buildControls();
buildServiceScene();
updateClockReadout();
let previousTime = performance.now();
renderer.setAnimationLoop((now) => {
const delta = Math.min((now - previousTime) / 1000, 0.1);
previousTime = now;
if (playing) {
simulationMinute += delta * animationSpeed;
if (simulationMinute >= 60) {
simulationMinute %= 60;
}
}
const theta = minuteAngle(simulationMinute);
sweep.rotation.y = -theta;
for (const marker of markerGroups) {
const minute = marker.userData.minute;
let distance = Math.abs(simulationMinute - minute);
distance = Math.min(distance, 60 - distance);
const pulse = Math.exp(-distance * 7);
const horizontalScale = 1 + pulse * 0.24;
const verticalScale = 1 + pulse * 0.38;
marker.scale.set(
horizontalScale,
verticalScale,
horizontalScale
);
marker.userData.material.emissiveIntensity = 0.08 + pulse * 1.7;
}
const displayedMinute = Math.floor(simulationMinute) % 60;
if (displayedMinute !== lastDisplayedMinute) {
lastDisplayedMinute = displayedMinute;
updateClockReadout();
}
renderer.render(scene, camera);
});
$("#loading").remove();
</script>
</body>
</html>
```