Prompt specification
Build or customize the Three.js 3D scene "Missed-versus-made-connection story" 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: Missed-versus-made-connection story
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/missed-versus-made-connection-story-x3916
Scene Description Prompt:
Missed-versus-made-connection story. Create two timeline branches with identical starting positions but different delays; compare whether a traveler reaches boarding before a fictional cutoff using explicit clocks and continuous routes. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (missed-versus-made-connection-story-x3916):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Missed vs. Made Connection — Three.js Story</title>
<style>
:root {
color-scheme: dark;
--bg: #08111e;
--panel: rgba(12, 24, 40, 0.88);
--panel-solid: #0d1a2b;
--line: rgba(180, 211, 239, 0.16);
--text: #eef7ff;
--muted: #91a8bd;
--made: #4be3cf;
--missed: #ff747c;
--cutoff: #ffc857;
}
* {
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,
select,
input {
font: inherit;
}
button,
select {
color: var(--text);
background: #14263a;
border: 1px solid rgba(180, 211, 239, 0.2);
border-radius: 9px;
padding: 9px 13px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover,
select:hover {
background: #1b3149;
border-color: rgba(180, 211, 239, 0.38);
}
button:active {
transform: translateY(1px);
}
button:focus-visible,
select:focus-visible,
input:focus-visible {
outline: 2px solid var(--made);
outline-offset: 3px;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.hero {
position: absolute;
top: 24px;
left: 28px;
max-width: 570px;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
padding: 6px 10px;
border: 1px solid rgba(75, 227, 207, 0.32);
border-radius: 999px;
color: #b8fff7;
background: rgba(10, 28, 42, 0.72);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--made);
box-shadow: 0 0 12px var(--made);
}
h1 {
margin: 0;
font-size: clamp(27px, 3.3vw, 48px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.hero p {
max-width: 540px;
margin: 12px 0 0;
color: #b6c8d8;
font-size: 14px;
line-height: 1.55;
}
.top-tools {
position: absolute;
top: 24px;
right: 28px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.legend {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: 400px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 20, 34, 0.8);
color: #b7c7d6;
font-size: 11px;
font-weight: 700;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.made-color {
color: var(--made);
}
.missed-color {
color: var(--missed);
}
.cutoff-color {
color: var(--cutoff);
}
#event {
position: absolute;
top: 126px;
left: 50%;
width: min(620px, calc(100vw - 40px));
transform: translateX(-50%);
padding: 11px 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(8, 19, 32, 0.82);
color: #dceaf5;
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
font-size: 13px;
font-weight: 650;
text-align: center;
backdrop-filter: blur(12px);
transition: border-color 180ms ease;
}
.dashboard {
position: absolute;
left: 50%;
bottom: 18px;
width: min(1120px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 16px;
border: 1px solid rgba(173, 207, 234, 0.2);
border-radius: 18px;
background:
linear-gradient(135deg, rgba(20, 39, 59, 0.72), rgba(8, 20, 34, 0.9)),
var(--panel);
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.45);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.dashboard-head,
.controls,
.branch-grid,
.timeline-head {
display: flex;
align-items: center;
}
.dashboard-head {
justify-content: space-between;
gap: 14px;
margin-bottom: 12px;
}
.dashboard-head strong {
font-size: 13px;
letter-spacing: 0.015em;
}
.dashboard-head span {
color: var(--muted);
font-size: 11px;
}
.controls {
gap: 8px;
flex-wrap: wrap;
padding-bottom: 13px;
border-bottom: 1px solid var(--line);
}
.controls button {
min-width: 84px;
font-size: 12px;
font-weight: 750;
}
#play {
color: #06201d;
background: var(--made);
border-color: transparent;
}
#play:hover {
background: #7af0df;
}
.speed-label {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.speed-label select {
padding: 8px 25px 8px 10px;
font-size: 11px;
}
.sim-clock {
display: flex;
align-items: center;
gap: 10px;
margin-left: auto;
}
.sim-clock span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.sim-clock strong {
min-width: 91px;
color: #fff;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 19px;
letter-spacing: 0.045em;
}
.branch-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 12px 0;
}
.branch-card {
position: relative;
overflow: hidden;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(5, 14, 25, 0.48);
transition:
border-color 180ms ease,
background 180ms ease;
}
.branch-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: currentColor;
box-shadow: 0 0 14px currentColor;
}
.branch-card.active {
border-color: rgba(180, 211, 239, 0.32);
background: rgba(18, 36, 55, 0.64);
}
.branch-card.made {
color: var(--made);
}
.branch-card.missed {
color: var(--missed);
}
.branch-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.branch-title {
display: flex;
align-items: center;
gap: 8px;
color: var(--text);
font-size: 13px;
font-weight: 850;
}
.branch-title .dot {
flex: 0 0 auto;
}
.delay-badge {
padding: 4px 7px;
border: 1px solid currentColor;
border-radius: 999px;
color: inherit;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.branch-main {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
}
.branch-clock {
color: var(--text);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 23px;
font-weight: 760;
letter-spacing: 0.03em;
}
.branch-state {
margin-bottom: 3px;
color: #b8c8d6;
font-size: 11px;
text-align: right;
}
.progress-track {
height: 4px;
margin: 9px 0 8px;
overflow: hidden;
border-radius: 999px;
background: rgba(177, 203, 226, 0.12);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.branch-result {
color: #91a8bd;
font-size: 10px;
}
.branch-result b {
color: var(--text);
}
.timeline {
padding-top: 3px;
}
.timeline-head {
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-body {
display: grid;
gap: 6px;
}
.timeline-row {
display: grid;
grid-template-columns: 104px 1fr;
align-items: center;
gap: 10px;
}
.timeline-label {
color: var(--text);
font-size: 10px;
font-weight: 800;
}
.track {
position: relative;
height: 15px;
border-radius: 5px;
background:
linear-gradient(
90deg,
rgba(255, 255, 255, 0.04),
rgba(255, 255, 255, 0.015)
),
#091522;
box-shadow: inset 0 0 0 1px rgba(177, 203, 226, 0.07);
}
.route-window {
position: absolute;
top: 3px;
height: 9px;
border-radius: 4px;
opacity: 0.92;
}
.route-window.made {
background: var(--made);
box-shadow: 0 0 10px rgba(75, 227, 207, 0.32);
}
.route-window.missed {
background: var(--missed);
box-shadow: 0 0 10px rgba(255, 116, 124, 0.32);
}
.cutoff-line {
position: absolute;
z-index: 4;
top: -4px;
bottom: -4px;
width: 2px;
background: var(--cutoff);
box-shadow: 0 0 9px rgba(255, 200, 87, 0.65);
}
.cutoff-line::after {
content: "";
position: absolute;
top: -3px;
left: -3px;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cutoff);
}
.event-pin,
.branch-pin {
position: absolute;
z-index: 5;
top: 50%;
width: 9px;
height: 9px;
transform: translate(-50%, -50%);
border: 2px solid #dceaf5;
border-radius: 50%;
background: #15283c;
}
.event-pin {
width: 7px;
height: 7px;
border-color: #8196a9;
}
.branch-pin {
width: 10px;
height: 10px;
}
.branch-pin.made {
border-color: #dffffb;
background: var(--made);
box-shadow: 0 0 10px var(--made);
}
.branch-pin.missed {
border-color: #ffe8ea;
background: var(--missed);
box-shadow: 0 0 10px var(--missed);
}
.current-cursor {
position: absolute;
z-index: 3;
top: -3px;
bottom: -3px;
width: 1px;
background: rgba(255, 255, 255, 0.45);
pointer-events: none;
}
.axis {
position: relative;
height: 18px;
margin: 4px 0 0 114px;
color: #73899d;
font-size: 9px;
}
.axis span {
position: absolute;
transform: translateX(-50%);
}
.axis span:first-child {
transform: none;
}
.axis span:last-child {
transform: translateX(-100%);
}
.scrub-row {
display: flex;
align-items: center;
gap: 12px;
margin-top: 5px;
}
.scrub-row label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#scrubber {
width: 100%;
height: 4px;
accent-color: var(--made);
cursor: pointer;
}
.fineprint {
margin-top: 9px;
color: #71879b;
font-size: 9px;
line-height: 1.4;
text-align: center;
}
.camera-tip {
position: absolute;
right: 28px;
bottom: 326px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 19, 32, 0.72);
color: #8fa5b9;
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(10px);
}
@media (max-width: 760px) {
.hero {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.hero p {
max-width: 390px;
font-size: 11px;
}
.top-tools {
top: auto;
right: 12px;
bottom: 332px;
}
.legend {
display: none;
}
#viewReset {
padding: 7px 10px;
font-size: 10px;
}
#event {
top: 111px;
padding: 9px 11px;
font-size: 11px;
}
.dashboard {
bottom: 8px;
width: calc(100vw - 16px);
padding: 11px;
border-radius: 14px;
}
.dashboard-head {
margin-bottom: 8px;
}
.dashboard-head span {
display: none;
}
.controls {
gap: 6px;
padding-bottom: 9px;
}
.controls button,
.speed-label select {
padding: 7px 9px;
font-size: 10px;
}
.controls button {
min-width: 68px;
}
.sim-clock span {
display: none;
}
.sim-clock strong {
min-width: 80px;
font-size: 15px;
}
.branch-grid {
gap: 7px;
margin: 9px 0;
}
.branch-card {
padding: 9px;
}
.branch-title {
font-size: 10px;
}
.delay-badge {
padding: 3px 5px;
font-size: 7px;
}
.branch-clock {
font-size: 17px;
}
.branch-state {
max-width: 100px;
font-size: 9px;
}
.branch-result {
font-size: 8px;
}
.timeline-row {
grid-template-columns: 72px 1fr;
gap: 7px;
}
.axis {
margin-left: 79px;
}
.camera-tip {
display: none;
}
}
@media (max-width: 440px) {
.branch-title {
align-items: flex-start;
flex-direction: column;
gap: 4px;
}
.branch-main {
align-items: flex-start;
flex-direction: column;
gap: 3px;
}
.branch-state {
max-width: none;
text-align: left;
}
.timeline-head span:last-child {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly transportation diorama"></div>
<div id="hud">
<header class="hero">
<div class="eyebrow">Fictional connection study</div>
<h1>One arrival.<br>Two outcomes.</h1>
<p>
Both branches begin at the exact same Hub A coordinate at 12:00.
Only the connection delay changes. Each then follows a continuous
10-minute route to the same B10 boarding point.
</p>
</header>
<div class="top-tools">
<div class="legend" aria-label="Legend">
<div class="legend-item made-color">
<span class="dot"></span> Made branch
</div>
<div class="legend-item missed-color">
<span class="dot"></span> Missed branch
</div>
<div class="legend-item cutoff-color">
<span class="dot"></span> 12:15 cutoff
</div>
</div>
<button id="viewReset" type="button">Reset view</button>
</div>
<div id="event" role="status" aria-live="polite">
Both branches wait together at Hub A.
</div>
<section class="dashboard" aria-label="Connection timeline controls">
<div class="dashboard-head">
<strong>Missed-versus-made connection</strong>
<span>Same start · same 10-minute route · same boarding point</span>
</div>
<div class="controls">
<button id="play" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<label class="speed-label">
Speed
<select id="speed" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="2">2×</option>
<option value="4">4×</option>
</select>
</label>
<div class="sim-clock">
<span>Simulation clock</span>
<strong id="simClock">12:00:00</strong>
</div>
</div>
<div class="branch-grid">
<article class="branch-card made" id="madeCard">
<div class="branch-top">
<div class="branch-title">
<span class="dot"></span>
Made connection
</div>
<span class="delay-badge">2 min delay</span>
</div>
<div class="branch-main">
<strong class="branch-clock" id="madeClock">12:00:00</strong>
<span class="branch-state" id="madeState">
Waiting at Hub A
</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="madeProgress"></div>
</div>
<div class="branch-result">
Arrives B10 at <b>12:12</b> · boards
<b>3 min before</b> cutoff
</div>
</article>
<article class="branch-card missed" id="missedCard">
<div class="branch-top">
<div class="branch-title">
<span class="dot"></span>
Missed connection
</div>
<span class="delay-badge">7 min delay</span>
</div>
<div class="branch-main">
<strong class="branch-clock" id="missedClock">12:00:00</strong>
<span class="branch-state" id="missedState">
Waiting at Hub A
</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="missedProgress"></div>
</div>
<div class="branch-result">
Arrives B10 at <b>12:17</b> · misses
<b>2 min after</b> cutoff
</div>
</article>
</div>
<div class="timeline">
<div class="timeline-head">
<span>Continuous timeline</span>
<span>Colored bar = time moving toward B10</span>
</div>
<div class="timeline-body">
<div class="timeline-row">
<div class="timeline-label made-color">Made · 12:02–12:12</div>
<div class="track">
<div class="route-window made"
id="madeWindow"
style="left:11.7647%; width:58.8235%;"></div>
<i class="event-pin" style="left:11.7647%;"></i>
<i class="event-pin" style="left:70.5882%;"></i>
<i class="branch-pin made" id="madePin" style="left:0%;"></i>
<i class="current-cursor" id="madeCursor" style="left:0%;"></i>
</div>
</div>
<div class="timeline-row">
<div class="timeline-label missed-color">Missed · 12:07–12:17</div>
<div class="track">
<div class="route-window missed"
id="missedWindow"
style="left:41.1765%; width:58.8235%;"></div>
<i class="event-pin" style="left:41.1765%;"></i>
<i class="event-pin" style="left:100%;"></i>
<i class="branch-pin missed" id="missedPin" style="left:0%;"></i>
<i class="current-cursor" id="missedCursor" style="left:0%;"></i>
</div>
</div>
</div>
<div class="axis">
<span style="left:0%;">12:00</span>
<span style="left:88.2353%;">12:15 cutoff</span>
<span style="left:100%;">12:17</span>
</div>
<div class="scrub-row">
<label for="scrubber">Scrub story</label>
<input id="scrubber" type="range" min="0" max="17" step="0.01" value="0">
</div>
</div>
<div class="fineprint">
Fictional schedule and geometry for storytelling only.
Playback speed 1× equals one simulated minute per second.
</div>
</section>
<div class="camera-tip">
Drag to orbit · wheel to zoom · Shift-drag to pan
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Story data
// -------------------------------------------------------------------------
const START_MINUTE = 0;
const END_MINUTE = 17;
const CUTOFF_MINUTE = 15;
const ROUTE_DURATION = 10;
const branchData = [
{
id: "made",
delay: 2,
arrival: 12,
color: 0x4be3cf,
css: "#4be3cf",
zSign: -1
},
{
id: "missed",
delay: 7,
arrival: 17,
color: 0xff747c,
css: "#ff747c",
zSign: 1
}
];
const ui = {
scene: document.querySelector("#scene"),
play: document.querySelector("#play"),
restart: document.querySelector("#restart"),
speed: document.querySelector("#speed"),
scrubber: document.querySelector("#scrubber"),
simClock: document.querySelector("#simClock"),
event: document.querySelector("#event"),
viewReset: document.querySelector("#viewReset"),
madeCard: document.querySelector("#madeCard"),
missedCard: document.querySelector("#missedCard"),
madeClock: document.querySelector("#madeClock"),
missedClock: document.querySelector("#missedClock"),
madeState: document.querySelector("#madeState"),
missedState: document.querySelector("#missedState"),
madeProgress: document.querySelector("#madeProgress"),
missedProgress: document.querySelector("#missedProgress"),
madePin: document.querySelector("#madePin"),
missedPin: document.querySelector("#missedPin"),
madeCursor: document.querySelector("#madeCursor"),
missedCursor: document.querySelector("#missedCursor")
};
let simMinute = 0;
let playing = true;
let playbackSpeed = 1;
let lastFrame = performance.now();
function formatClock(minutes, includeSeconds = true) {
const totalSeconds = Math.floor((12 * 60 + minutes) * 60);
const hours = Math.floor(totalSeconds / 3600) % 24;
const mins = Math.floor(totalSeconds / 60) % 60;
const secs = totalSeconds % 60;
const base = `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
return includeSeconds ? `${base}:${String(secs).padStart(2, "0")}` : base;
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111e);
scene.fog = new THREE.Fog(0x08111e, 22, 43);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
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;
ui.scene.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbadfff, 0x182133, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-7, 14, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 45;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x36d9d0, 20, 22, 2);
rimLight.position.set(-5, 5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb75f, 15, 18, 2);
warmLight.position.set(8, 4, 4);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Low-poly helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function standardMaterial(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.08,
flatShading: true,
...options
})
);
}
return materialCache.get(key);
}
function addBox(
width,
height,
depth,
x,
y,
z,
color,
options = {},
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
color,
segments = 6,
options = {},
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
standardMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCone(
radius,
height,
x,
y,
z,
color,
segments = 6,
options = {},
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, segments),
standardMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = 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 colorToCss(color) {
return `#${color.toString(16).padStart(6, "0")}`;
}
function makeLabel(title, subtitle, accent = "#4be3cf", width = 4) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 4, 4, 760, 172, 28);
ctx.fillStyle = "rgba(8, 19, 32, 0.94)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(28, 31, 8, 116);
ctx.fillStyle = "#f1f8ff";
ctx.font = "800 43px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(title, 58, 66);
ctx.fillStyle = "#9fb4c8";
ctx.font = "650 27px system-ui, sans-serif";
ctx.fillText(subtitle, 58, 119);
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(width, width * 180 / 768, 1);
sprite.renderOrder = 30;
return sprite;
}
// -------------------------------------------------------------------------
// Diorama base, station, train, gate, and scenery
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
standardMaterial(0x07101b, { roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.72;
ground.receiveShadow = true;
scene.add(ground);
addBox(20, 0.5, 9, 0, -0.43, 0, 0x172a3c);
addBox(18.8, 0.16, 8.35, 0, -0.1, 0, 0x243a4d);
// Subtle platform tiles.
for (let x = -9; x <= 9; x += 1.5) {
addBox(0.025, 0.015, 8.15, x, 0.002, 0, 0x385064);
}
// Track bed.
addBox(18.5, 0.1, 1.65, 0, 0.02, -3.62, 0x111d2a);
for (let x = -9; x <= 9; x += 0.75) {
addBox(0.28, 0.06, 1.35, x, 0.1, -3.62, 0x3b332d);
}
addBox(18.4, 0.08, 0.1, 0, 0.17, -3.94, 0x9aa7b0, {
metalness: 0.7
});
addBox(18.4, 0.08, 0.1, 0, 0.17, -3.3, 0x9aa7b0, {
metalness: 0.7
});
// Low-poly inbound train.
const train = new THREE.Group();
train.position.set(-7.1, 0, -3.62);
scene.add(train);
addBox(4.4, 1.08, 1.28, 0, 0.76, 0, 0xdce8ec, {}, train);
addBox(4.15, 0.22, 1.2, 0, 1.36, 0, 0x367b96, {}, train);
addBox(4.5, 0.16, 1.34, 0, 0.32, 0, 0x263849, {}, train);
for (let i = -1.55; i <= 1.55; i += 0.78) {
addBox(0.54, 0.44, 0.035, i, 0.9, 0.66, 0x164c68, {
emissive: 0x0b3047,
emissiveIntensity: 0.55
}, train);
}
addBox(0.09, 0.22, 0.42, -2.23, 0.64, 0, 0xffd56a, {
emissive: 0xffad22,
emissiveIntensity: 1.2
}, train);
addBox(0.09, 0.22, 0.42, 2.23, 0.64, 0, 0xffd56a, {
emissive: 0xffad22,
emissiveIntensity: 1.2
}, train);
// Hub A: shared exact starting coordinate.
const origin = new THREE.Vector3(-7, 0.14, 0);
const destination = new THREE.Vector3(7, 0.14, 0);
addCylinder(1.25, 1.35, 0.12, -7, 0.07, 0, 0x35566b, 8);
addCylinder(0.9, 0.9, 0.05, -7, 0.16, 0, 0x5c8396, 8);
for (const dx of [-0.88, 0.88]) {
for (const dz of [-0.72, 0.72]) {
addCylinder(
0.075,
0.09,
1.9,
-7 + dx,
1.05,
dz,
0xa9c2ce,
6
);
}
}
addCone(1.62, 0.58, -7, 2.25, 0, 0x2c7280, 6);
addCylinder(0.13, 0.13, 0.3, -7, 2.68, 0, 0x91e9df, 6);
const hubLabel = makeLabel(
"HUB A",
"EXACT SHARED START",
"#b8fff7",
3.6
);
hubLabel.position.set(-7, 3.45, 0);
scene.add(hubLabel);
// Dynamic world clock.
const clockCanvas = document.createElement("canvas");
clockCanvas.width = 640;
clockCanvas.height = 190;
const clockCtx = clockCanvas.getContext("2d");
const clockTexture = new THREE.CanvasTexture(clockCanvas);
clockTexture.colorSpace = THREE.SRGBColorSpace;
const worldClock = new THREE.Sprite(
new THREE.SpriteMaterial({
map: clockTexture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
worldClock.position.set(-7, 3.45, 0.9);
worldClock.scale.set(3.7, 1.1, 1);
worldClock.renderOrder = 31;
scene.add(worldClock);
let lastClockSecond = -1;
function updateWorldClock(time) {
const second = Math.floor(time * 60);
if (second === lastClockSecond) return;
lastClockSecond = second;
clockCtx.clearRect(0, 0, clockCanvas.width, clockCanvas.height);
roundedRect(clockCtx, 4, 4, 632, 182, 28);
clockCtx.fillStyle = "rgba(5, 14, 25, 0.96)";
clockCtx.fill();
clockCtx.lineWidth = 4;
clockCtx.strokeStyle = "#4be3cf";
clockCtx.stroke();
clockCtx.fillStyle = "#8ba2b6";
clockCtx.font = "800 27px system-ui, sans-serif";
clockCtx.textBaseline = "middle";
clockCtx.fillText("HUB A • SIMULATION CLOCK", 34, 48);
clockCtx.fillStyle = "#f4fbff";
clockCtx.font = "800 73px monospace";
clockCtx.fillText(formatClock(time), 32, 116);
clockTexture.needsUpdate = true;
}
// Boarding gate B10.
addBox(0.28, 2.25, 0.28, 7, 1.12, -0.88, 0xb8cad2);
addBox(0.28, 2.25, 0.28, 7, 1.12, 0.88, 0xb8cad2);
addBox(0.34, 0.34, 2.15, 7, 2.24, 0, 0xd6e3e9);
const gatePanelMaterial = standardMaterial(0xffc857, {
emissive: 0xffa62c,
emissiveIntensity: 0.7
});
const gatePanel = addBox(
0.15,
0.58,
1.25,
7.18,
1.36,
0,
0xffc857,
{
emissive: 0xffa62c,
emissiveIntensity: 0.7
}
);
const gateLabel = makeLabel(
"GATE B10",
"BOARDING",
"#ffc857",
3.25
);
gateLabel.position.set(7, 3.15, 0);
scene.add(gateLabel);
// Cutoff beacon.
addCylinder(0.055, 0.075, 1.8, 8.05, 0.9, 1.72, 0x9fadb8, 6);
const cutoffBeaconMaterial = standardMaterial(0xffc857, {
emissive: 0xffa62c,
emissiveIntensity: 1.2
});
const cutoffBeacon = new THREE.Mesh(
new THREE.OctahedronGeometry(0.22, 0),
cutoffBeaconMaterial
);
cutoffBeacon.position.set(8.05, 1.92, 1.72);
scene.add(cutoffBeacon);
const cutoffLabel = makeLabel(
"12:15",
"BOARDING CUTOFF",
"#ffc857",
3.1
);
cutoffLabel.position.set(8.05, 2.65, 1.72);
scene.add(cutoffLabel);
// Small low-poly environment pieces.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
addCylinder(
0.08,
0.11,
0.75,
0,
0.38,
0,
0x72523c,
6,
{},
tree
);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.55, 0),
standardMaterial(0x2b705a, { flatShading: true })
);
crown.position.y = 1.04;
crown.castShadow = true;
tree.add(crown);
addCone(
0.42,
0.72,
0,
1.25,
0,
0x347f63,
6,
{},
tree
);
}
[
[-8.8, 3.65, 0.9],
[-6.8, 3.85, 0.72],
[-4.5, 3.7, 0.85],
[1.8, 3.7, 0.75],
[3.8, 3.8, 0.95],
[6.1, 3.65, 0.72],
[8.7, 3.7, 0.9]
].forEach(([x, z, s]) => addTree(x, z, s));
// Distant simple buildings.
addBox(2.2, 1.15, 1.1, -0.8, 0.58, 4.45, 0x31465a);
addBox(1.4, 0.9, 1.0, 1.7, 0.45, 4.55, 0x3d5266);
addBox(1.9, 0.6, 0.9, 5.2, 0.3, 4.55, 0x2b4053);
// -------------------------------------------------------------------------
// Continuous route curves and travelers
// -------------------------------------------------------------------------
function createRouteCurve(zSign) {
const points = [
origin.clone(),
new THREE.Vector3(-5.4, 0.14, zSign * 0.9),
new THREE.Vector3(-3.0, 0.14, zSign * 2.15),
new THREE.Vector3(-0.2, 0.14, zSign * 1.35),
new THREE.Vector3(2.45, 0.14, zSign * 2.3),
new THREE.Vector3(4.8, 0.14, zSign * 0.95),
destination.clone()
];
return new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.25
);
}
function addRouteArrows(curve, color) {
for (const u of [0.22, 0.47, 0.72]) {
const arrow = addCone(
0.13,
0.36,
0,
0,
0,
color,
6,
{
emissive: color,
emissiveIntensity: 0.45
}
);
const point = curve.getPointAt(u);
const tangent = curve.getTangentAt(u).normalize();
arrow.position.copy(point);
arrow.position.y += 0.04;
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
}
}
function createAvatar(color) {
const root = new THREE.Group();
scene.add(root);
const upper = new THREE.Group();
root.add(upper);
const bodyMaterial = standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.12
});
addCylinder(
0.22,
0.25,
0.56,
0,
0.65,
0,
color,
6,
{
emissive: color,
emissiveIntensity: 0.12
},
upper
);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 8, 6),
standardMaterial(0xf1c7a7)
);
head.position.y = 1.08;
head.castShadow = true;
upper.add(head);
addBox(
0.28,
0.32,
0.16,
0,
0.72,
-0.24,
0x324559,
{},
upper
);
addCylinder(
0.075,
0.08,
0.34,
-0.11,
0.19,
0,
0x172438,
6,
{},
root
);
addCylinder(
0.075,
0.08,
0.34,
0.11,
0.19,
0,
0x172438,
6,
{},
root
);
const haloMaterial = standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.9,
transparent: true,
opacity: 0.9
});
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.035, 5, 18),
haloMaterial
);
halo.rotation.x = Math.PI / 2;
halo.position.y = 0.035;
root.add(halo);
return {
root,
upper,
halo,
haloMaterial
};
}
const branches = branchData.map((data) => {
const curve = createRouteCurve(data.zSign);
const walkway = new THREE.Mesh(
new THREE.TubeGeometry(curve, 96, 0.16, 6, false),
standardMaterial(0x314a5e, {
transparent: true,
opacity: 0.9,
roughness: 0.9
})
);
walkway.receiveShadow = true;
scene.add(walkway);
const routeMaterial = standardMaterial(data.color, {
emissive: data.color,
emissiveIntensity: 0.65,
roughness: 0.55
});
const route = new THREE.Mesh(
new THREE.TubeGeometry(curve, 96, 0.052, 6, false),
routeMaterial
);
scene.add(route);
addRouteArrows(curve, data.color);
const labelPoint = curve.getPointAt(0.43);
const routeLabel = makeLabel(
data.id === "made" ? "MADE" : "MISSED",
data.id === "made"
? "12:02 DEPARTURE"
: "12:07 DEPARTURE",
data.css,
3.8
);
routeLabel.position.copy(labelPoint);
routeLabel.position.y = 1.35;
scene.add(routeLabel);
const avatar = createAvatar(data.color);
return {
...data,
curve,
route,
routeMaterial,
routeLabel,
avatar
};
});
const madeResult = makeLabel(
"BOARDED 12:12",
"MADE CONNECTION",
"#4be3cf",
3.8
);
madeResult.position.set(6.4, 1.5, -1.35);
madeResult.visible = false;
scene.add(madeResult);
const missedResult = makeLabel(
"TOO LATE 12:17",
"MISSED CONNECTION",
"#ff747c",
3.8
);
missedResult.position.set(6.4, 1.5, 1.35);
missedResult.visible = false;
scene.add(missedResult);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.53,
phi: 0.68,
radius: 22,
target: new THREE.Vector3(0, 0.2, 0),
dragging: false,
panning: false,
previousX: 0,
previousY: 0
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.53;
cameraState.phi = 0.68;
cameraState.radius = window.innerWidth < 700 ? 38 : 22;
cameraState.target.set(0, 0.2, 0);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.panning =
event.shiftKey || event.button === 2 || event.pointerType === "touch";
cameraState.previousX = event.clientX;
cameraState.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.previousX;
const dy = event.clientY - cameraState.previousY;
cameraState.previousX = event.clientX;
cameraState.previousY = event.clientY;
if (cameraState.panning) {
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.theta),
0,
-Math.cos(cameraState.theta)
);
const panScale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(forward, dy * panScale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.34,
1.34
);
}
updateCamera();
});
function endPointerDrag(event) {
cameraState.dragging = false;
cameraState.panning = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
11,
48
);
updateCamera();
},
{ passive: false }
);
ui.viewReset.addEventListener("click", resetCamera);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Simulation state and DOM updates
// -------------------------------------------------------------------------
function branchProgress(branch, time) {
return THREE.MathUtils.clamp(
(time - branch.delay) / ROUTE_DURATION,
0,
1
);
}
function updateBranchUI(branch, time) {
const progress = branchProgress(branch, time);
const prefix = branch.id;
document.querySelector(`#${prefix}Clock`).textContent =
formatClock(time);
document.querySelector(`#${prefix}Progress`).style.width =
`${progress * 100}%`;
let stateText;
if (time < branch.delay) {
const remaining = Math.max(
0,
Math.ceil(branch.delay - time)
);
stateText = `Waiting at Hub A · departs in ${remaining} min`;
} else if (time < branch.arrival) {
const remaining = Math.max(
0,
Math.ceil(branch.arrival - time)
);
stateText = `Moving toward B10 · ${remaining} min left`;
} else if (branch.id === "made") {
stateText = "At B10 · boarded before cutoff";
} else {
stateText = "At B10 · boarding already closed";
}
document.querySelector(`#${prefix}State`).textContent = stateText;
const card = document.querySelector(`#${prefix}Card`);
card.classList.toggle(
"active",
time >= branch.delay && time < branch.arrival
);
const pin = document.querySelector(`#${prefix}Pin`);
pin.style.left = `${(Math.min(time, branch.arrival) / END_MINUTE) * 100}%`;
const cursor = document.querySelector(`#${prefix}Cursor`);
cursor.style.left = `${(time / END_MINUTE) * 100}%`;
}
function updateEventMessage(time) {
let message;
let border = "rgba(180, 211, 239, 0.16)";
if (time < 2) {
message = "12:00 — Both branches wait at the exact same Hub A start.";
} else if (time < 7) {
message =
"12:02 — The made branch departs and follows its continuous route. The missed branch is still waiting.";
border = "rgba(75, 227, 207, 0.45)";
} else if (time < 12) {
message =
"12:07 — The missed branch departs. Both travelers now move along separate 10-minute routes toward B10.";
border = "rgba(255, 116, 124, 0.42)";
} else if (time < CUTOFF_MINUTE) {
message =
"12:12 — The made branch reaches B10 and boards, with 3 minutes remaining before the 12:15 cutoff.";
border = "rgba(75, 227, 207, 0.65)";
} else if (time < 17) {
message =
"12:15 — Boarding is now closed. The missed branch is still moving toward B10.";
border = "rgba(255, 200, 87, 0.62)";
} else {
message =
"12:17 — The missed branch reaches B10, exactly 2 minutes after the fictional cutoff.";
border = "rgba(255, 116, 124, 0.68)";
}
ui.event.textContent = message;
ui.event.style.borderColor = border;
}
function updateScene(time) {
ui.simClock.textContent = formatClock(time);
updateWorldClock(time);
updateEventMessage(time);
for (const branch of branches) {
updateBranchUI(branch, time);
const progress = branchProgress(branch, time);
const avatar = branch.avatar;
let position;
let tangent;
if (time < branch.delay) {
position = origin.clone();
tangent = new THREE.Vector3(1, 0, 0);
} else if (time < branch.arrival) {
position = branch.curve.getPointAt(progress);
tangent = branch.curve.getTangentAt(progress).normalize();
} else {
position = destination.clone();
tangent = branch.curve.getTangentAt(1).normalize();
}
avatar.root.position.copy(position);
avatar.root.rotation.y = Math.atan2(tangent.x, tangent.z);
const isMoving =
time >= branch.delay && time < branch.arrival;
const bob = isMoving
? Math.abs(Math.sin(time * 9.5)) * 0.07
: Math.sin(time * 2.2) * 0.012;
avatar.upper.position.y = bob;
if (branch.id === "made") {
const fade =
time <= 12.5
? 1
: Math.max(0, 1 - (time - 12.5) / 0.5);
avatar.root.visible = fade > 0.01;
avatar.root.scale.setScalar(0.86 * fade);
madeResult.visible = time >= branch.arrival;
} else {
avatar.root.visible = true;
avatar.root.scale.setScalar(0.86);
missedResult.visible = time >= branch.arrival;
}
const isClosed = time >= CUTOFF_MINUTE;
if (branch.id === "made" && time >= branch.arrival) {
avatar.haloMaterial.color.setHex(0x65f0a6);
avatar.haloMaterial.emissive.setHex(0x38d978);
} else if (branch.id === "missed" && isClosed) {
avatar.haloMaterial.color.setHex(0xff5364);
avatar.haloMaterial.emissive.setHex(0xff3048);
} else {
avatar.haloMaterial.color.setHex(branch.color);
avatar.haloMaterial.emissive.setHex(branch.color);
}
const glow =
0.65 +
Math.sin(time * 3.2 + (branch.id === "made" ? 0 : 1.4)) *
0.12;
branch.routeMaterial.emissiveIntensity = glow;
}
// Gate panel reflects the fictional boarding state.
if (time < 12) {
gatePanel.material.color.setHex(0xffc857);
gatePanel.material.emissive.setHex(0xffa62c);
gatePanel.material.emissiveIntensity = 0.65;
} else if (time < CUTOFF_MINUTE) {
gatePanel.material.color.setHex(0x58e6a6);
gatePanel.material.emissive.setHex(0x29d879);
gatePanel.material.emissiveIntensity = 0.9;
} else {
gatePanel.material.color.setHex(0xff5968);
gatePanel.material.emissive.setHex(0xff3048);
gatePanel.material.emissiveIntensity = 0.9;
}
const nearCutoff =
1 - Math.min(1, Math.abs(time - CUTOFF_MINUTE) / 1.8);
cutoffBeaconMaterial.emissiveIntensity =
0.8 + nearCutoff * 1.2;
cutoffBeacon.rotation.y = time * 1.3;
cutoffBeacon.position.y =
1.92 + Math.sin(time * 2.2) * 0.06;
}
// -------------------------------------------------------------------------
// Playback controls
// -------------------------------------------------------------------------
function updatePlayButton() {
ui.play.textContent = playing ? "Pause" : "Play";
}
ui.play.addEventListener("click", () => {
if (simMinute >= END_MINUTE && !playing) {
simMinute = 0;
}
playing = !playing;
updatePlayButton();
});
ui.restart.addEventListener("click", () => {
simMinute = 0;
playing = true;
ui.scrubber.value = "0";
updatePlayButton();
});
ui.speed.addEventListener("change", () => {
playbackSpeed = Number(ui.speed.value);
});
ui.scrubber.addEventListener("input", () => {
simMinute = Number(ui.scrubber.value);
updateScene(simMinute);
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLSelectElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
ui.play.click();
}
if (event.key.toLowerCase() === "r") {
ui.restart.click();
}
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
function animate(now) {
const delta = Math.min((now - lastFrame) / 1000, 0.1);
lastFrame = now;
if (playing) {
simMinute += delta * playbackSpeed;
if (simMinute >= END_MINUTE) {
simMinute = END_MINUTE;
playing = false;
updatePlayButton();
}
}
ui.scrubber.value = simMinute.toFixed(2);
updateScene(simMinute);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resetCamera();
updatePlayButton();
updateScene(0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```