Prompt specification
Build or customize the Three.js 3D scene "Arrival Departure Connection Clock" 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: Arrival Departure Connection Clock
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/arrival-departure-connection-clock-x2150
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing an animation of one arrival and one departure with a visible transfer walking time. Show missed and successful connections from explicit timestamps rather than visual proximity. Voxel style.
Working Three.js Starter (arrival-departure-connection-clock-x2150):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Transfer — Timestamp-Based Connection</title>
<style>
:root {
--ink: #13242b;
--panel: rgba(15, 31, 38, 0.94);
--panel-2: #203740;
--line: rgba(255, 255, 255, 0.13);
--muted: #9eb4ba;
--text: #f5f1e8;
--amber: #ffc857;
--green: #65e6a6;
--red: #ff6b6b;
--accent: var(--green);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fc9cd;
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
button {
font: inherit;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
outline: none;
}
#stage canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
z-index: 5;
pointer-events: none;
}
.brand {
top: 20px;
left: 20px;
max-width: min(540px, calc(100vw - 410px));
padding: 13px 16px 14px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-left: 6px solid var(--amber);
background: rgba(15, 31, 38, 0.9);
box-shadow: 0 12px 35px rgba(12, 30, 36, 0.2);
backdrop-filter: blur(8px);
}
.brand h1 {
margin: 0 0 5px;
font-size: clamp(18px, 2.1vw, 27px);
line-height: 1;
letter-spacing: -0.045em;
}
.brand p {
margin: 0;
color: #c5d5d8;
font-size: 11px;
line-height: 1.5;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#control-panel {
top: 20px;
right: 20px;
width: 350px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.17);
background: var(--panel);
box-shadow: 0 18px 50px rgba(10, 25, 30, 0.28);
backdrop-filter: blur(12px);
pointer-events: auto;
scrollbar-width: thin;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.panel-title strong {
font-size: 12px;
letter-spacing: 0.13em;
}
.timestamp-badge {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid rgba(101, 230, 166, 0.4);
background: rgba(101, 230, 166, 0.09);
color: var(--green);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.panel-copy {
margin: 0 0 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.result-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 13px;
}
.result-card {
min-width: 0;
padding: 11px;
border: 1px solid var(--line);
color: var(--text);
background: #182c34;
text-align: left;
cursor: pointer;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.result-card:hover {
transform: translateY(-2px);
border-color: rgba(255, 255, 255, 0.35);
}
.result-card.active {
border-color: currentColor;
background: #223b43;
box-shadow: inset 0 -4px 0 currentColor;
}
.result-card.success {
color: var(--green);
}
.result-card.missed {
color: var(--red);
}
.result-card small,
.result-card b,
.result-card span {
display: block;
}
.result-card small {
margin-bottom: 7px;
color: currentColor;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
}
.result-card b {
color: var(--text);
font-size: 14px;
}
.result-card span {
margin-top: 5px;
color: #b9c9cd;
font-size: 9px;
line-height: 1.35;
}
.equation {
padding: 12px;
border: 1px solid var(--line);
background: rgba(0, 0, 0, 0.13);
}
.equation-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
padding: 5px 0;
color: #c9d6d9;
font-size: 11px;
}
.equation-row strong {
color: var(--text);
}
.equation-row.ready {
margin-top: 3px;
padding-top: 9px;
border-top: 1px dashed rgba(255, 255, 255, 0.18);
}
.verdict {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
padding: 12px;
border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.verdict strong {
color: var(--accent);
font-size: 16px;
letter-spacing: 0.04em;
}
.verdict span {
color: #c2d0d3;
font-size: 9px;
text-align: right;
line-height: 1.45;
}
.rule-note {
margin: 12px 0 0;
padding: 10px;
border-left: 3px solid var(--amber);
background: rgba(255, 200, 87, 0.08);
color: #d7dfe0;
font-size: 9px;
line-height: 1.55;
}
.rule-note b {
color: var(--amber);
}
#timeline-panel {
left: 20px;
right: 390px;
bottom: 20px;
min-width: 420px;
padding: 14px 16px 12px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(15, 31, 38, 0.92);
box-shadow: 0 14px 35px rgba(10, 25, 30, 0.24);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.timeline-header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
margin-bottom: 14px;
}
.clock {
display: flex;
align-items: baseline;
gap: 10px;
}
.clock span,
.transfer-time span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.11em;
}
.clock strong {
color: var(--amber);
font-size: 24px;
letter-spacing: -0.04em;
}
.transfer-time {
text-align: right;
}
.transfer-time strong {
display: block;
margin-top: 2px;
color: var(--text);
font-size: 15px;
}
.timeline-track {
position: relative;
height: 6px;
margin: 0 4px 10px;
background: #314850;
}
#timeline-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
background: var(--amber);
}
#timeline-walk {
position: absolute;
top: 0;
bottom: 0;
left: 25%;
width: 44.44%;
background: rgba(255, 200, 87, 0.24);
border-left: 1px solid rgba(255, 200, 87, 0.55);
border-right: 1px solid rgba(255, 200, 87, 0.55);
}
#timeline-dot {
position: absolute;
top: 50%;
left: 0;
width: 13px;
height: 13px;
border: 3px solid var(--panel);
background: var(--amber);
transform: translate(-50%, -50%);
box-shadow: 0 0 0 1px var(--amber);
}
.timeline-marker {
position: absolute;
top: -4px;
width: 2px;
height: 14px;
background: rgba(255, 255, 255, 0.5);
}
.timeline-marker span {
position: absolute;
left: 50%;
width: max-content;
max-width: 130px;
color: #b9c9cd;
font-size: 8px;
line-height: 1.25;
transform: translateX(-50%);
}
.timeline-marker.above span {
bottom: 19px;
}
.timeline-marker.below span {
top: 19px;
}
#arrival-marker {
left: 25%;
}
#ready-marker {
left: 69.44%;
background: var(--amber);
}
#departure-marker {
background: var(--accent);
}
.timeline-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.progress-copy {
flex: 1;
min-width: 120px;
}
.progress-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
}
.progress-track {
height: 5px;
background: #314850;
}
#transfer-progress {
width: 0;
height: 100%;
background: var(--amber);
}
.button-row {
display: flex;
gap: 7px;
}
.control-button {
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.22);
background: #263e46;
color: var(--text);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
cursor: pointer;
}
.control-button:hover {
background: #34515b;
}
.control-button.primary {
border-color: var(--amber);
background: var(--amber);
color: var(--ink);
}
#result-banner {
top: 112px;
left: 50%;
min-width: 310px;
max-width: calc(100vw - 40px);
padding: 12px 18px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-left: 6px solid #9bb0b6;
background: rgba(15, 31, 38, 0.93);
text-align: center;
transform: translateX(-50%);
box-shadow: 0 10px 30px rgba(10, 25, 30, 0.2);
}
#result-banner.success {
border-left-color: var(--green);
}
#result-banner.missed {
border-left-color: var(--red);
}
#result-banner b,
#result-banner span {
display: block;
}
#result-banner b {
margin-bottom: 4px;
font-size: 14px;
letter-spacing: 0.08em;
}
#result-banner span {
color: #c4d1d4;
font-size: 9px;
line-height: 1.4;
}
.world-label {
position: fixed;
z-index: 4;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.42);
background: rgba(15, 31, 38, 0.84);
color: #fff;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 0 5px 14px rgba(0, 0, 0, 0.15);
}
.world-label.walk {
border-color: var(--amber);
color: var(--amber);
}
.world-label.departure {
border-color: var(--accent);
color: var(--accent);
}
.camera-hint {
right: 390px;
bottom: 173px;
color: rgba(19, 36, 43, 0.76);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
@media (max-width: 850px) {
#control-panel {
width: 315px;
}
#timeline-panel {
right: 355px;
min-width: 380px;
}
.camera-hint {
right: 355px;
}
.brand {
max-width: calc(100vw - 365px);
}
}
@media (max-width: 700px) {
.brand {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
}
#control-panel {
top: 102px;
right: 10px;
width: min(330px, calc(100vw - 20px));
max-height: 42vh;
padding: 12px;
}
#timeline-panel {
left: 10px;
right: 10px;
bottom: 10px;
min-width: 0;
padding: 11px;
}
.timeline-header {
gap: 8px;
}
.clock strong {
font-size: 19px;
}
.timeline-footer {
align-items: flex-end;
}
.camera-hint {
display: none;
}
#result-banner {
top: 92px;
min-width: 0;
width: calc(100vw - 20px);
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="brand overlay">
<h1>VOXEL TRANSFER</h1>
<p>Central interchange · Platform 2 → Platform 4</p>
</header>
<aside id="control-panel" class="overlay">
<div class="panel-title">
<strong>CONNECTION ENGINE</strong>
<span class="timestamp-badge">TIMESTAMP-BASED</span>
</div>
<p class="panel-copy">
Select a departure timestamp. The result is calculated by comparing
<b>arrival + walking time</b> with that timestamp.
</p>
<div class="result-grid">
<button
id="success-scenario"
class="result-card success active"
type="button"
aria-pressed="true"
>
<small>SUCCESS</small>
<b>08:21:00</b>
<span>Ready 08:20 ≤ departure</span>
<span>Buffer +00:01:00</span>
</button>
<button
id="missed-scenario"
class="result-card missed"
type="button"
aria-pressed="false"
>
<small>MISSED</small>
<b>08:19:00</b>
<span>Ready 08:20 > departure</span>
<span>Late by 00:01:00</span>
</button>
</div>
<div class="equation" aria-live="polite">
<div class="equation-row">
<span>Arrival timestamp</span>
<strong>08:12:00</strong>
</div>
<div class="equation-row">
<span>Transfer walking time</span>
<strong>+ 00:08:00</strong>
</div>
<div class="equation-row ready">
<span>Ready at departure point</span>
<strong>08:20:00</strong>
</div>
<div class="equation-row">
<span id="comparison-label">Compared with departure</span>
<strong id="selected-departure">08:21:00</strong>
</div>
</div>
<div class="verdict">
<strong id="verdict">SUCCESS</strong>
<span id="verdict-detail">
Ready at 08:20:00.<br>
00:01:00 before departure.
</span>
</div>
<p class="rule-note">
<b>NO VISUAL PROXIMITY TEST.</b><br>
A connection succeeds only when
<code>arrival + walk ≤ departure</code>.
Train distance never changes the result.
</p>
</aside>
<section id="timeline-panel" class="overlay">
<div class="timeline-header">
<div class="clock">
<span>SIM CLOCK</span>
<strong id="current-time">08:11:30</strong>
</div>
<div class="transfer-time">
<span>VISIBLE TRANSFER WALK</span>
<strong>00:08:00</strong>
</div>
</div>
<div class="timeline-track">
<div id="timeline-walk"></div>
<div id="timeline-fill"></div>
<div id="timeline-dot"></div>
<div id="arrival-marker" class="timeline-marker below">
<span>ARRIVAL<br>08:12:00</span>
</div>
<div id="ready-marker" class="timeline-marker above">
<span>WALK COMPLETE<br>08:20:00</span>
</div>
<div id="departure-marker" class="timeline-marker below">
<span id="departure-marker-text">DEPARTURE<br>08:21:00</span>
</div>
</div>
<div class="timeline-footer">
<div class="progress-copy">
<div class="progress-label">
<span>TRANSFER PROGRESS</span>
<span id="transfer-elapsed">00:00:00 / 00:08:00</span>
</div>
<div class="progress-track">
<div id="transfer-progress"></div>
</div>
</div>
<div class="button-row">
<button id="pause-button" class="control-button" type="button">PAUSE</button>
<button id="replay-button" class="control-button primary" type="button">
REPLAY
</button>
</div>
</div>
</section>
<div id="result-banner" class="overlay" aria-live="assertive">
<b id="result-title">CONNECTION CHECK</b>
<span id="result-detail">08:12:00 + 00:08:00 = ready at 08:20:00</span>
</div>
<div id="arrival-label" class="world-label">ARRIVAL · 08:12:00</div>
<div id="departure-label" class="world-label departure">DEPARTURE · 08:21:00</div>
<div id="walk-label" class="world-label walk">TRANSFER WALK · 8 MIN</div>
<div class="camera-hint overlay">
DRAG TO ORBIT · SCROLL TO ZOOM · ARROW KEYS TO ROTATE
</div>
<noscript>This demonstration requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Timestamp model. Connection status is NEVER derived from 3D proximity.
// -------------------------------------------------------------------------
const toSeconds = (h, m, s = 0) => h * 3600 + m * 60 + s;
function formatClock(totalSeconds) {
const value = Math.max(0, Math.round(totalSeconds));
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = value % 60;
return [h, m, s].map(n => String(n).padStart(2, "0")).join(":");
}
function formatDuration(totalSeconds) {
const value = Math.max(0, Math.round(Math.abs(totalSeconds)));
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = value % 60;
return [h, m, s].map(n => String(n).padStart(2, "0")).join(":");
}
const ARRIVAL_SECONDS = toSeconds(8, 12, 0);
const WALK_SECONDS = toSeconds(0, 8, 0);
const READY_SECONDS = ARRIVAL_SECONDS + WALK_SECONDS;
const SCENARIOS = {
success: {
departure: toSeconds(8, 21, 0),
eventTime: 12.5
},
missed: {
departure: toSeconds(8, 19, 0),
eventTime: 11.5
}
};
function evaluateConnection(departureSeconds) {
const difference = departureSeconds - READY_SECONDS;
return {
success: difference >= 0,
difference,
buffer: Math.abs(difference)
};
}
let selectedScenario = "success";
let animationTime = 0;
let paused = false;
let ended = false;
let resultShown = false;
const TOTAL_ANIMATION_SECONDS = 18;
const ARRIVAL_EVENT_TIME = 4.5;
const WALK_START_TIME = 4.5;
const WALK_END_TIME = 12.5;
// -------------------------------------------------------------------------
// Renderer, camera and direct camera controls (no addons).
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fc9cd);
scene.fog = new THREE.Fog(0x9fc9cd, 40, 78);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraTarget = new THREE.Vector3(0, 1.1, 0);
const cameraState = {
yaw: 0.56,
pitch: 0.79,
radius: 36
};
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
const horizontal = radius * Math.sin(pitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(yaw),
cameraTarget.y + radius * Math.cos(pitch),
cameraTarget.z + horizontal * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
let dragging = false;
let dragX = 0;
let dragY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.42,
1.22
);
dragX = event.clientX;
dragY = event.clientY;
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
20,
56
);
}, { passive: false });
renderer.domElement.addEventListener("keydown", event => {
const step = 0.08;
if (event.key === "ArrowLeft") cameraState.yaw += step;
if (event.key === "ArrowRight") cameraState.yaw -= step;
if (event.key === "ArrowUp") cameraState.pitch -= step * 0.5;
if (event.key === "ArrowDown") cameraState.pitch += step * 0.5;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch,
0.42,
1.22
);
});
// -------------------------------------------------------------------------
// Lighting and voxel construction helpers.
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xeafcff, 0x53675d, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cc, 3.1);
sun.position.set(-16, 28, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00035;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.04,
flatShading: true,
...options
});
}
const mat = {
ground: material(0x43585a),
platform: material(0xb8b8ad),
tileA: material(0xd7d4c8),
tileB: material(0xc6c8bf),
yellow: material(0xf4c34f),
path: material(0xffc857, { emissive: 0x6b4100, emissiveIntensity: 0.28 }),
ballast: material(0x35464a),
rail: material(0x758486, { metalness: 0.55, roughness: 0.42 }),
sleeper: material(0x554d43),
cream: material(0xf0eadb),
dark: material(0x24373e),
black: material(0x17262c),
steel: material(0x92a6aa, { metalness: 0.45, roughness: 0.4 }),
glass: material(0x244d62, { metalness: 0.25, roughness: 0.28 }),
green: material(0x4aa982),
red: material(0xd85555),
blue: material(0x3b7893),
buildingA: material(0x68858a),
buildingB: material(0x769497),
buildingC: material(0x526e75)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addTrack(z) {
box(42, 0.24, 3.0, mat.ballast, 0, 0.03, z);
for (let x = -20; x <= 20; x += 1.45) {
box(0.42, 0.16, 2.55, mat.sleeper, x, 0.22, z);
}
box(42, 0.18, 0.14, mat.rail, 0, 0.42, z - 0.72);
box(42, 0.18, 0.14, mat.rail, 0, 0.42, z + 0.72);
}
function addPlatform(z) {
box(26, 0.9, 4.5, mat.platform, 0, 0.45, z);
const columns = 13;
const rows = 6;
const tileGeometry = new THREE.BoxGeometry(1.84, 0.13, 0.66);
const tileMaterial = material(0xffffff);
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let index = 0;
for (let ix = 0; ix < columns; ix++) {
for (let iz = 0; iz < rows; iz++) {
const x = -12 + ix * 2;
const tileZ = z - 1.44 + iz * 0.72;
matrix.makeTranslation(x, 1.01, tileZ);
tiles.setMatrixAt(index, matrix);
const alternate = (ix + iz) % 3 === 0;
color.set(alternate ? 0xc9cbc2 : 0xd9d6ca);
tiles.setColorAt(index, color);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
const outerEdge = z < 0 ? z - 2.2 : z + 2.2;
for (let x = -12.5; x <= 12.5; x += 1.25) {
box(0.72, 0.055, 0.28, mat.yellow, x, 1.10, outerEdge);
}
}
function addLamp(x, z, facing = 1) {
box(0.16, 3.8, 0.16, mat.dark, x, 2.8, z);
box(0.8, 0.16, 0.8, mat.cream, x, 4.72, z);
box(0.62, 0.08, 0.62, material(0xffe7a8, {
emissive: 0xffd36a,
emissiveIntensity: 0.55
}), x, 4.61, z);
box(0.16, 0.16, 0.75, mat.dark, x, 4.55, z + facing * 0.25);
}
function addBench(x, z) {
box(2.4, 0.18, 0.65, mat.cream, x, 1.72, z);
box(2.4, 0.8, 0.16, mat.cream, x, 2.18, z + 0.28);
box(0.18, 0.75, 0.55, mat.dark, x - 0.85, 1.35, z);
box(0.18, 0.75, 0.55, mat.dark, x + 0.85, 1.35, z);
}
function addArrow(x, z, direction) {
const arrow = new THREE.Group();
arrow.position.set(x, 1.16, z);
if (direction === "x") {
box(0.72, 0.07, 0.17, mat.path, 0, 0, 0, arrow);
const a = box(0.27, 0.07, 0.27, mat.path, 0.25, 0, 0.09, arrow);
const b = box(0.27, 0.07, 0.27, mat.path, 0.25, 0, -0.09, arrow);
a.rotation.y = Math.PI / 4;
b.rotation.y = -Math.PI / 4;
} else {
box(0.17, 0.07, 0.72, mat.path, 0, 0, 0, arrow);
const a = box(0.27, 0.07, 0.27, mat.path, 0.09, 0, 0.25, arrow);
const b = box(0.27, 0.07, 0.27, mat.path, -0.09, 0, 0.25, arrow);
a.rotation.y = Math.PI / 4;
b.rotation.y = -Math.PI / 4;
}
scene.add(arrow);
}
function makeSignSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = "#19323a";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#ffc857";
context.lineWidth = 12;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
context.fillStyle = "#fff4d5";
context.font = "bold 54px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(5.2, 1.62, 1);
scene.add(sprite);
return sprite;
}
// -------------------------------------------------------------------------
// Station, tracks and transfer route.
// -------------------------------------------------------------------------
box(46, 0.6, 28, mat.ground, 0, -0.48, 0);
addTrack(-6.45);
addTrack(6.45);
addPlatform(-3.3);
addPlatform(3.3);
// Transfer bridge over the central service gap.
box(2.35, 0.35, 2.8, mat.steel, 3, 0.83, 0);
box(0.25, 1.0, 0.25, mat.dark, 2.05, 0.35, 0);
box(0.25, 1.0, 0.25, mat.dark, 3.95, 0.35, 0);
for (const z of [-1.05, 1.05]) {
for (const x of [1.95, 4.05]) {
box(0.12, 1.2, 0.12, mat.dark, x, 1.55, z);
}
box(2.2, 0.12, 0.12, mat.dark, 3, 2.12, z);
}
// Golden voxel walking route.
box(0.42, 0.07, 1.95, mat.path, -4, 1.12, -4.18);
box(7.42, 0.07, 0.42, mat.path, -0.5, 1.12, -3.2);
box(0.42, 0.07, 6.82, mat.path, 3, 1.12, 0);
box(1.42, 0.07, 0.42, mat.path, 3.5, 1.12, 3.2);
box(0.42, 0.07, 1.95, mat.path, 4, 1.12, 4.18);
addArrow(-1.7, -3.2, "x");
addArrow(3, 0.2, "z");
addArrow(3.72, 3.2, "x");
addArrow(4, 4.25, "z");
for (const x of [-10, -2, 6, 11]) {
addLamp(x, -1.65, -1);
addLamp(x, 1.65, 1);
}
addBench(-8, -2.0);
addBench(8, 2.0);
addBench(8, 4.5);
const walkSign = makeSignSprite("TRANSFER 8 MIN");
walkSign.position.set(3, 3.25, 0);
// Blocky background city.
const cityColors = [mat.buildingA, mat.buildingB, mat.buildingC];
for (let i = 0; i < 13; i++) {
const x = -24 + i * 4;
const height = 3 + (i % 4) * 1.25;
const z = -13 - (i % 2) * 1.5;
box(3.1, height, 3.0, cityColors[i % 3], x, height / 2, z);
for (let y = 1.4; y < height - 0.4; y += 1.35) {
box(0.48, 0.48, 0.08, mat.glass, x - 0.7, y, z + 1.54);
box(0.48, 0.48, 0.08, mat.glass, x + 0.7, y, z + 1.54);
}
}
// -------------------------------------------------------------------------
// Voxel trains.
// -------------------------------------------------------------------------
function createTrain(bodyColor, accentColor, platformSide) {
const group = new THREE.Group();
const bodyMaterial = material(bodyColor);
const accentMaterial = material(accentColor);
box(12, 1.9, 1.7, bodyMaterial, 0, 2.0, 0, group);
box(12.25, 0.28, 1.85, accentMaterial, 0, 3.04, 0, group);
box(12.1, 0.25, 1.78, mat.dark, 0, 0.97, 0, group);
// Front and rear caps.
box(0.38, 1.55, 1.55, accentMaterial, 6.02, 2.05, 0, group);
box(0.38, 1.55, 1.55, accentMaterial, -6.02, 2.05, 0, group);
// Voxel bogies.
for (const x of [-4.2, 0, 4.2]) {
box(1.2, 0.65, 2.0, mat.black, x, 0.52, 0, group);
box(0.7, 0.72, 2.15, mat.steel, x, 0.52, 0, group);
}
const sideZ = platformSide * 0.88;
for (const x of [-2.1, 0, 2.1, 4.2]) {
box(1.48, 0.76, 0.08, mat.glass, x, 2.38, sideZ, group);
box(1.6, 0.09, 0.11, accentMaterial, x, 1.93, sideZ, group);
}
const door = box(
1.05,
1.68,
0.09,
mat.dark,
-4,
1.95,
platformSide * 0.9,
group
);
box(0.72, 0.17, 0.08, mat.yellow, -4, 2.82, platformSide * 0.95, group);
// Small destination sign.
box(1.3, 0.34, 0.08, mat.black, 2.4, 2.83, platformSide * 0.95, group);
group.userData.door = door;
group.userData.doorClosedX = -4;
group.userData.doorOpenX = -2.95;
group.userData.platformSide = platformSide;
return group;
}
const arrivalTrain = createTrain(0x3d7890, 0xf0b94d, 1);
arrivalTrain.position.set(-31, 0, -6.45);
scene.add(arrivalTrain);
const departureTrain = createTrain(0x458b69, 0xf2d36c, -1);
departureTrain.position.set(8, 0, 6.45);
scene.add(departureTrain);
// -------------------------------------------------------------------------
// Voxel passenger.
// -------------------------------------------------------------------------
const passenger = new THREE.Group();
const passengerBody = material(0xf4a340);
const passengerPants = material(0x293d4d);
const passengerSkin = material(0xe8aa78);
box(0.48, 0.72, 0.34, passengerBody, 0, 0.88, 0, passenger);
box(0.4, 0.4, 0.38, passengerSkin, 0, 1.43, 0, passenger);
box(0.44, 0.16, 0.42, mat.dark, 0, 1.65, 0, passenger);
box(0.36, 0.48, 0.22, mat.blue, 0, 0.94, -0.25, passenger);
const leftArmPivot = new THREE.Group();
const rightArmPivot = new THREE.Group();
leftArmPivot.position.set(-0.34, 1.17, 0);
rightArmPivot.position.set(0.34, 1.17, 0);
box(0.16, 0.58, 0.18, passengerBody, 0, -0.22, 0, leftArmPivot);
box(0.16, 0.58, 0.18, passengerBody, 0, -0.22, 0, rightArmPivot);
passenger.add(leftArmPivot, rightArmPivot);
const leftLegPivot = new THREE.Group();
const rightLegPivot = new THREE.Group();
leftLegPivot.position.set(-0.13, 0.58, 0);
rightLegPivot.position.set(0.13, 0.58, 0);
box(0.19, 0.56, 0.22, passengerPants, 0, -0.24, 0, leftLegPivot);
box(0.19, 0.56, 0.22, passengerPants, 0, -0.24, 0, rightLegPivot);
box(0.21, 0.13, 0.34, mat.black, 0, -0.51, 0.07, leftLegPivot);
box(0.21, 0.13, 0.34, mat.black, 0, -0.51, 0.07, rightLegPivot);
passenger.add(leftLegPivot, rightLegPivot);
passenger.visible = false;
scene.add(passenger);
// -------------------------------------------------------------------------
// Walking path interpolation.
// -------------------------------------------------------------------------
const pathPoints = [
new THREE.Vector3(-4, 1.14, -5.08),
new THREE.Vector3(-4, 1.14, -3.2),
new THREE.Vector3(3, 1.14, -3.2),
new THREE.Vector3(3, 1.14, 3.2),
new THREE.Vector3(4, 1.14, 5.08)
];
const segmentLengths = [];
let totalPathLength = 0;
for (let i = 0; i < pathPoints.length - 1; i++) {
const length = pathPoints[i].distanceTo(pathPoints[i + 1]);
segmentLengths.push(length);
totalPathLength += length;
}
function pointOnPath(progress) {
const target = THREE.MathUtils.clamp(progress, 0, 1) * totalPathLength;
let traversed = 0;
for (let i = 0; i < segmentLengths.length; i++) {
if (target <= traversed + segmentLengths[i] || i === segmentLengths.length - 1) {
const local = (target - traversed) / segmentLengths[i];
const position = new THREE.Vector3().lerpVectors(
pathPoints[i],
pathPoints[i + 1],
THREE.MathUtils.clamp(local, 0, 1)
);
const direction = new THREE.Vector3().subVectors(
pathPoints[i + 1],
pathPoints[i]
).normalize();
return { position, direction };
}
traversed += segmentLengths[i];
}
return {
position: pathPoints[pathPoints.length - 1].clone(),
direction: new THREE.Vector3(0, 0, 1)
};
}
function orientPassenger(direction) {
passenger.rotation.y = Math.atan2(direction.x, direction.z);
}
// -------------------------------------------------------------------------
// UI references and scenario controls.
// -------------------------------------------------------------------------
const currentTimeElement = document.getElementById("current-time");
const transferProgressElement = document.getElementById("transfer-progress");
const transferElapsedElement = document.getElementById("transfer-elapsed");
const timelineFill = document.getElementById("timeline-fill");
const timelineDot = document.getElementById("timeline-dot");
const departureMarker = document.getElementById("departure-marker");
const departureMarkerText = document.getElementById("departure-marker-text");
const departureLabel = document.getElementById("departure-label");
const selectedDeparture = document.getElementById("selected-departure");
const comparisonLabel = document.getElementById("comparison-label");
const verdict = document.getElementById("verdict");
const verdictDetail = document.getElementById("verdict-detail");
const resultBanner = document.getElementById("result-banner");
const resultTitle = document.getElementById("result-title");
const resultDetail = document.getElementById("result-detail");
const pauseButton = document.getElementById("pause-button");
const successButton = document.getElementById("success-scenario");
const missedButton = document.getElementById("missed-scenario");
function showBanner(type, title, detail) {
resultBanner.className = `overlay ${type}`;
resultTitle.textContent = title;
resultDetail.textContent = detail;
}
function updateScenarioUI() {
const scenario = SCENARIOS[selectedScenario];
const result = evaluateConnection(scenario.departure);
const departureText = formatClock(scenario.departure);
const readyText = formatClock(READY_SECONDS);
successButton.classList.toggle("active", selectedScenario === "success");
missedButton.classList.toggle("active", selectedScenario === "missed");
successButton.setAttribute("aria-pressed", String(selectedScenario === "success"));
missedButton.setAttribute("aria-pressed", String(selectedScenario === "missed"));
selectedDeparture.textContent = departureText;
comparisonLabel.textContent = result.success
? "Ready time ≤ departure time"
: "Ready time > departure time";
verdict.textContent = result.success ? "SUCCESS" : "MISSED";
verdictDetail.innerHTML = result.success
? `Ready at ${readyText}.<br>${formatDuration(result.buffer)} before departure.`
: `Ready at ${readyText}.<br>${formatDuration(result.buffer)} after departure.`;
document.documentElement.style.setProperty(
"--accent",
result.success ? "var(--green)" : "var(--red)"
);
departureMarkerText.innerHTML = `DEPARTURE<br>${departureText}`;
departureLabel.textContent = `DEPARTURE · ${departureText}`;
showBanner(
"",
"CONNECTION CHECK",
"08:12:00 + 00:08:00 = ready at 08:20:00"
);
}
function resetAnimation() {
animationTime = 0;
paused = false;
ended = false;
resultShown = false;
pauseButton.textContent = "PAUSE";
updateScenarioUI();
}
successButton.addEventListener("click", () => {
selectedScenario = "success";
resetAnimation();
});
missedButton.addEventListener("click", () => {
selectedScenario = "missed";
resetAnimation();
});
document.getElementById("replay-button").addEventListener("click", resetAnimation);
pauseButton.addEventListener("click", () => {
if (ended) {
resetAnimation();
return;
}
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
});
// -------------------------------------------------------------------------
// Animation and timestamp display.
// -------------------------------------------------------------------------
function currentSimulationSeconds() {
if (animationTime < ARRIVAL_EVENT_TIME) {
const approach = animationTime / ARRIVAL_EVENT_TIME;
return ARRIVAL_SECONDS - 30 + approach * 30;
}
if (animationTime < WALK_END_TIME) {
const walkingProgress = (animationTime - WALK_START_TIME) /
(WALK_END_TIME - WALK_START_TIME);
return ARRIVAL_SECONDS + walkingProgress * WALK_SECONDS;
}
if (
selectedScenario === "success" &&
animationTime >= SCENARIOS.success.departure - ARRIVAL_SECONDS
) {
return SCENARIOS.success.departure;
}
return READY_SECONDS;
}
function updateTrainDoors() {
const arrivalOpen = THREE.MathUtils.smoothstep(
animationTime,
ARRIVAL_EVENT_TIME,
ARRIVAL_EVENT_TIME + 0.55
);
const departureOpen = selectedScenario === "success"
? THREE.MathUtils.smoothstep(animationTime, 12.35, 12.85) *
(1 - THREE.MathUtils.smoothstep(animationTime, 13.1, 13.45))
: 0;
const arrivalDoor = arrivalTrain.userData.door;
arrivalDoor.position.x = THREE.MathUtils.lerp(
arrivalTrain.userData.doorClosedX,
arrivalTrain.userData.doorOpenX,
arrivalOpen
);
const departureDoor = departureTrain.userData.door;
departureDoor.position.x = THREE.MathUtils.lerp(
departureTrain.userData.doorClosedX,
departureTrain.userData.doorOpenX,
departureOpen
);
}
function updateScene() {
const scenario = SCENARIOS[selectedScenario];
// Arrival train decelerates into the platform.
if (animationTime < ARRIVAL_EVENT_TIME) {
const p = THREE.MathUtils.clamp(animationTime / ARRIVAL_EVENT_TIME, 0, 1);
const eased = 1 - Math.pow(1 - p, 3);
arrivalTrain.position.x = THREE.MathUtils.lerp(-31, 0, eased);
} else {
arrivalTrain.position.x = 0;
}
// The departure train leaves exactly at the selected timestamp.
const departureAnimationTime = selectedScenario === "success" ? 13.5 : 11.5;
if (animationTime >= departureAnimationTime) {
const dt = animationTime - departureAnimationTime;
departureTrain.position.x = 8 + dt * 1.25 + dt * dt * 0.42;
} else {
departureTrain.position.x = 8;
}
updateTrainDoors();
// Passenger exits and walks the visible transfer route.
const walkProgress = THREE.MathUtils.clamp(
(animationTime - WALK_START_TIME) /
(WALK_END_TIME - WALK_START_TIME),
0,
1
);
if (animationTime < WALK_START_TIME) {
passenger.visible = false;
} else if (animationTime < WALK_END_TIME) {
passenger.visible = true;
const pathState = pointOnPath(walkProgress);
passenger.position.copy(pathState.position);
orientPassenger(pathState.direction);
const stride = Math.sin(animationTime * 13) * 0.55;
leftLegPivot.rotation.x = stride;
rightLegPivot.rotation.x = -stride;
leftArmPivot.rotation.x = -stride * 0.8;
rightArmPivot.rotation.x = stride * 0.8;
passenger.position.y += Math.abs(Math.sin(animationTime * 13)) * 0.045;
} else if (selectedScenario === "success" && animationTime < 13.2) {
// Board the departure train.
passenger.visible = true;
const boardingProgress = THREE.MathUtils.clamp(
(animationTime - WALK_END_TIME) / 0.7,
0,
1
);
passenger.position.set(
4,
1.14,
THREE.MathUtils.lerp(5.08, 5.5, boardingProgress)
);
passenger.rotation.y = 0;
leftLegPivot.rotation.x = 0;
rightLegPivot.rotation.x = 0;
leftArmPivot.rotation.x = 0;
rightArmPivot.rotation.x = 0;
} else if (selectedScenario === "missed") {
// The passenger reaches the gate after the train has gone.
passenger.visible = true;
passenger.position.set(4, 1.14, 5.08);
passenger.rotation.y = 0;
leftLegPivot.rotation.x = 0;
rightLegPivot.rotation.x = 0;
leftArmPivot.rotation.x = 0;
rightArmPivot.rotation.x = 0;
} else {
passenger.visible = false;
}
// The visible result event is driven by the timestamp comparison.
if (!resultShown && animationTime >= scenario.eventTime) {
resultShown = true;
const result = evaluateConnection(scenario.departure);
if (result.success) {
showBanner(
"success",
"CONNECTION SUCCESSFUL",
`Ready 08:20:00 ≤ departure ${formatClock(scenario.departure)} · buffer ${formatDuration(result.buffer)}`
);
} else {
showBanner(
"missed",
"CONNECTION MISSED",
`Departure ${formatClock(scenario.departure)} < ready 08:20:00 · late by ${formatDuration(result.buffer)}`
);
}
}
// Clock, transfer progress and timeline.
const currentSeconds = currentSimulationSeconds();
const transferElapsed = Math.min(
WALK_SECONDS,
Math.max(0, (animationTime - WALK_START_TIME) * 60)
);
currentTimeElement.textContent = formatClock(currentSeconds);
transferElapsedElement.textContent =
`${formatDuration(transferElapsed)} / 00:08:00`;
const progressPercent = walkProgress * 100;
transferProgressElement.style.width = `${progressPercent}%`;
const timelinePercent = THREE.MathUtils.clamp(
animationTime / TOTAL_ANIMATION_SECONDS,
0,
1
) * 100;
timelineFill.style.width = `${timelinePercent}%`;
timelineDot.style.left = `${timelinePercent}%`;
if (animationTime >= TOTAL_ANIMATION_SECONDS && !ended) {
ended = true;
pauseButton.textContent = "REPLAY";
}
}
// -------------------------------------------------------------------------
// World-space DOM labels.
// -------------------------------------------------------------------------
const arrivalLabelPosition = new THREE.Vector3(-4, 4.25, -6.45);
const departureLabelPosition = new THREE.Vector3(8, 4.25, 6.45);
const walkLabelPosition = new THREE.Vector3(3, 4.55, 0);
function positionWorldLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateWorldLabels() {
positionWorldLabel(
document.getElementById("arrival-label"),
arrivalLabelPosition
);
positionWorldLabel(departureLabel, departureLabelPosition);
positionWorldLabel(
document.getElementById("walk-label"),
walkLabelPosition
);
}
// -------------------------------------------------------------------------
// Resize and render loop.
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateScenarioUI();
updateScene();
let previousTime = performance.now();
function animate(now) {
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (!paused && !ended) {
animationTime = Math.min(
TOTAL_ANIMATION_SECONDS,
animationTime + delta
);
}
updateScene();
updateCamera();
updateWorldLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```