Prompt specification
Build or customize the Three.js 3D scene "Commute decision timeline sandbox" 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: Commute decision timeline sandbox
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/commute-decision-timeline-sandbox-x3856
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a delayed bus and alternative commute choices. Create a toy transport map with declared travel and waiting times; users respond to a delay event and compare arrival outcomes through visible clocks and route traces. Low-poly.
Working Three.js Starter (commute-decision-timeline-sandbox-x3856):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Route 17 — Delay Planner</title>
<style>
:root {
--ink: #17333b;
--muted: #68797d;
--paper: #f8f5ec;
--paper-strong: #fffdf8;
--line: #d9ded8;
--bus: #ef6b52;
--tram: #148e88;
--rail: #6a63c7;
--yellow: #f4c95d;
--green: #3d8b68;
--shadow: 0 16px 44px rgba(26, 51, 58, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
min-height: 100%;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
button:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(20, 142, 136, 0.42);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
#app {
min-height: 100vh;
}
.topbar {
height: 74px;
display: flex;
align-items: center;
gap: 22px;
padding: 0 24px;
background: var(--paper-strong);
border-bottom: 1px solid var(--line);
position: relative;
z-index: 30;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 42px;
height: 42px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 13px;
color: #fff;
background: var(--ink);
font-weight: 850;
letter-spacing: -0.06em;
box-shadow: 0 5px 14px rgba(23, 51, 59, 0.18);
}
.brand-copy {
line-height: 1.05;
}
.brand-copy strong {
display: block;
font-size: 15px;
letter-spacing: -0.02em;
}
.brand-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.delay-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
color: #9b3e2f;
background: #fde4db;
border: 1px solid #f3b6a7;
border-radius: 999px;
font-size: 12px;
font-weight: 800;
white-space: nowrap;
}
.delay-pill::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--bus);
box-shadow: 0 0 0 4px rgba(239, 107, 82, 0.15);
}
.top-spacer {
flex: 1;
}
.header-clock {
display: flex;
align-items: center;
gap: 10px;
padding-right: 4px;
}
.header-clock small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.header-clock strong {
display: block;
margin-top: 2px;
font-size: 18px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.03em;
}
.clock-face-icon {
width: 37px;
height: 37px;
display: grid;
place-items: center;
border-radius: 50%;
color: var(--ink);
background: #edf0e9;
border: 1px solid #d7ddd5;
font-size: 18px;
}
.compare-button {
min-height: 40px;
padding: 0 15px;
border: 1px solid var(--ink);
border-radius: 11px;
color: var(--ink);
background: transparent;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: 160ms ease;
}
.compare-button:hover,
.compare-button.active {
color: #fff;
background: var(--ink);
transform: translateY(-1px);
}
.layout {
height: calc(100vh - 74px);
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dbe6e1;
isolation: isolate;
}
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
.event-card {
position: absolute;
z-index: 10;
top: 20px;
left: 20px;
width: min(370px, calc(100% - 40px));
padding: 17px 18px 15px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 18px;
background: rgba(255, 253, 248, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: none;
}
.event-kicker {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #a74836;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.event-kicker::before {
content: "";
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--bus);
transform: rotate(45deg);
}
.event-card h1 {
margin: 0;
max-width: 320px;
font-size: 22px;
line-height: 1.08;
letter-spacing: -0.045em;
}
.event-card p {
margin: 9px 0 13px;
color: #5f7074;
font-size: 12px;
line-height: 1.55;
}
.event-meta {
display: flex;
gap: 17px;
padding-top: 11px;
border-top: 1px solid rgba(23, 51, 59, 0.1);
}
.event-meta span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.event-meta strong {
display: block;
margin-top: 3px;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.map-legend {
position: absolute;
z-index: 9;
left: 20px;
bottom: 91px;
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: calc(100% - 40px);
}
.legend-chip {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
background: rgba(255, 253, 248, 0.87);
box-shadow: 0 5px 16px rgba(23, 51, 59, 0.09);
color: #52656a;
font-size: 10px;
font-weight: 800;
backdrop-filter: blur(10px);
}
.legend-line {
width: 18px;
height: 4px;
border-radius: 3px;
background: currentColor;
}
.timeline {
position: absolute;
z-index: 12;
left: 20px;
right: 20px;
bottom: 18px;
min-height: 58px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 17px;
background: rgba(255, 253, 248, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.timeline-clock {
min-width: 88px;
padding-right: 11px;
border-right: 1px solid var(--line);
}
.timeline-clock span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.timeline-clock strong {
display: block;
margin-top: 2px;
font-size: 20px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.timeline-buttons {
display: flex;
gap: 5px;
}
.time-button {
min-width: 34px;
height: 34px;
padding: 0 9px;
border: 1px solid #d7ded8;
border-radius: 9px;
color: var(--ink);
background: #fff;
font-size: 11px;
font-weight: 850;
cursor: pointer;
}
.time-button:hover:not(:disabled) {
border-color: var(--ink);
}
.time-button:disabled {
opacity: 0.38;
cursor: not-allowed;
}
.time-button.play {
min-width: 40px;
color: #fff;
background: var(--ink);
border-color: var(--ink);
}
.timeline-hint {
margin-left: auto;
color: var(--muted);
font-size: 10px;
font-weight: 700;
text-align: right;
}
.camera-controls {
position: absolute;
z-index: 11;
top: 20px;
right: 18px;
display: grid;
gap: 6px;
}
.camera-controls button {
width: 36px;
height: 36px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 11px;
color: var(--ink);
background: rgba(255, 253, 248, 0.88);
box-shadow: 0 5px 16px rgba(23, 51, 59, 0.1);
font-size: 16px;
font-weight: 850;
cursor: pointer;
backdrop-filter: blur(10px);
}
.camera-controls button:hover {
background: #fff;
}
.camera-help {
position: absolute;
z-index: 8;
right: 18px;
bottom: 90px;
padding: 7px 9px;
border-radius: 9px;
color: rgba(23, 51, 59, 0.68);
background: rgba(255, 253, 248, 0.67);
font-size: 9px;
font-weight: 750;
pointer-events: none;
}
.side-panel {
min-height: 0;
overflow-y: auto;
padding: 24px 20px 28px;
background: var(--paper);
border-left: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c4cec8 transparent;
}
.panel-heading {
margin-bottom: 15px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel-heading h2 {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.05em;
}
.panel-heading p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.comparison-panel {
margin-bottom: 15px;
padding: 13px;
border: 1px solid #cbdad4;
border-radius: 15px;
background: #eef4ee;
}
.comparison-panel h3 {
margin: 0 0 9px;
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
.comparison-table th {
padding: 5px 3px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.08em;
text-align: left;
text-transform: uppercase;
}
.comparison-table td {
padding: 7px 3px;
border-top: 1px solid rgba(23, 51, 59, 0.09);
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.comparison-table td:last-child {
text-align: right;
}
.table-route {
display: flex;
align-items: center;
gap: 6px;
}
.route-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
}
.route-cards {
display: grid;
gap: 11px;
}
.route-card {
position: relative;
padding: 15px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--paper-strong);
transition: 170ms ease;
}
.route-card::before {
content: "";
position: absolute;
top: 18px;
bottom: 18px;
left: -1px;
width: 4px;
border-radius: 0 5px 5px 0;
background: var(--route-color);
opacity: 0.8;
}
.route-card:hover,
.route-card.preview {
border-color: var(--route-color);
box-shadow: 0 8px 24px rgba(23, 51, 59, 0.08);
transform: translateY(-1px);
}
.route-card.selected {
border: 2px solid var(--route-color);
padding: 14px;
box-shadow: 0 10px 27px rgba(23, 51, 59, 0.1);
}
.route-card-header {
display: flex;
align-items: flex-start;
gap: 11px;
}
.mode-badge {
width: 38px;
height: 38px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 11px;
color: #fff;
background: var(--route-color);
font-size: 11px;
font-weight: 950;
letter-spacing: -0.04em;
}
.route-title {
min-width: 0;
flex: 1;
}
.route-title h3 {
margin: 0;
font-size: 14px;
letter-spacing: -0.02em;
}
.route-title p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.status-badge {
padding: 5px 7px;
border-radius: 999px;
color: #9b4735;
background: #fde8e1;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.05em;
text-transform: uppercase;
white-space: nowrap;
}
.status-badge.good {
color: #28705a;
background: #dff1e9;
}
.segment-list {
display: grid;
gap: 5px;
margin: 13px 0 12px;
padding: 10px 0;
border-top: 1px dashed #d9dfda;
border-bottom: 1px dashed #d9dfda;
}
.segment-row {
display: grid;
grid-template-columns: 42px 1fr auto;
align-items: center;
gap: 6px;
color: #52666b;
font-size: 9px;
}
.segment-row strong {
color: var(--ink);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.segment-kind {
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.route-outcome {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 10px;
}
.arrival-block span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.arrival-block strong {
display: block;
margin-top: 2px;
font-size: 26px;
line-height: 1;
font-variant-numeric: tabular-nums;
letter-spacing: -0.055em;
}
.route-outcome-copy {
padding-bottom: 2px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
text-align: right;
}
.route-outcome-copy strong {
display: block;
color: var(--ink);
font-size: 10px;
}
.choose-route {
width: 100%;
height: 36px;
margin-top: 12px;
border: 1px solid var(--route-color);
border-radius: 10px;
color: var(--route-color);
background: transparent;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.03em;
cursor: pointer;
transition: 140ms ease;
}
.choose-route:hover {
color: #fff;
background: var(--route-color);
}
.route-card.selected .choose-route {
color: #fff;
background: var(--route-color);
}
.trip-clock-card {
margin-top: 15px;
padding: 17px;
border-radius: 18px;
color: #f9f6ee;
background: var(--ink);
box-shadow: 0 13px 30px rgba(23, 51, 59, 0.16);
}
.trip-clock-card .eyebrow {
color: #a8bec1;
}
.trip-clock-main {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
margin-top: 9px;
}
.trip-clock-main span {
display: block;
color: #a8bec1;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.trip-clock-main strong {
display: block;
margin-top: 3px;
font-size: 25px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.05em;
}
.trip-status {
min-height: 29px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.14);
color: #bdd0d1;
font-size: 10px;
line-height: 1.4;
}
.reset-button {
width: 100%;
height: 37px;
margin-top: 11px;
border: 1px solid #cfd8d2;
border-radius: 10px;
color: var(--ink);
background: transparent;
font-size: 10px;
font-weight: 850;
cursor: pointer;
}
.reset-button:hover {
background: #fff;
}
.webgl-error {
position: absolute;
inset: 0;
display: grid;
place-items: center;
padding: 30px;
color: var(--ink);
background: #dbe6e1;
text-align: center;
}
@media (max-width: 980px) {
.layout {
grid-template-columns: minmax(0, 1fr) 350px;
}
.side-panel {
padding: 21px 16px 24px;
}
.brand-copy span {
display: none;
}
.delay-pill {
display: none;
}
.timeline-hint {
display: none;
}
}
@media (max-width: 740px) {
body {
overflow: auto;
}
.topbar {
height: auto;
min-height: 68px;
padding: 11px 14px;
gap: 10px;
}
.brand-mark {
width: 37px;
height: 37px;
border-radius: 11px;
}
.brand-copy strong {
font-size: 13px;
}
.header-clock {
margin-left: auto;
}
.header-clock small,
.clock-face-icon {
display: none;
}
.compare-button {
padding: 0 10px;
font-size: 10px;
}
.layout {
display: block;
height: auto;
}
#stage {
height: 62vh;
min-height: 470px;
}
.side-panel {
height: auto;
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.event-card {
top: 13px;
left: 13px;
width: min(330px, calc(100% - 68px));
padding: 14px;
}
.event-card h1 {
font-size: 19px;
}
.event-card p {
display: none;
}
.event-meta {
padding-top: 8px;
}
.timeline {
left: 12px;
right: 12px;
bottom: 12px;
}
.map-legend {
left: 12px;
bottom: 82px;
}
.camera-help {
display: none;
}
.camera-controls {
top: 13px;
right: 12px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark">17</div>
<div class="brand-copy">
<strong>Wayfinder</strong>
<span>Commute response lab</span>
</div>
</div>
<div class="delay-pill">Delay reported · Route 17</div>
<div class="top-spacer"></div>
<div class="header-clock">
<div class="clock-face-icon" aria-hidden="true">◷</div>
<div>
<small id="clockLabel">Decision time</small>
<strong id="headerClock">08:00</strong>
</div>
</div>
<button id="compareButton" class="compare-button" aria-pressed="false">
Compare outcomes
</button>
</header>
<main class="layout">
<section id="stage" aria-label="Interactive low-poly transport map">
<div class="event-card">
<div class="event-kicker">Live service alert</div>
<h1 id="eventTitle">Route 17 is running 12 minutes late.</h1>
<p id="eventCopy">
A stalled coach near Civic Center is blocking the usual path.
Compare the declared walking, waiting, and riding times.
</p>
<div class="event-meta">
<div>
<span>Reported</span>
<strong>08:00</strong>
</div>
<div>
<span>Delay</span>
<strong>+12 min</strong>
</div>
<div>
<span>Affected</span>
<strong>Route 17</strong>
</div>
</div>
</div>
<div class="camera-controls" aria-label="Map camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="resetCamera" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<div class="map-legend" aria-label="Route trace legend">
<div class="legend-chip" style="color: var(--bus)">
<span class="legend-line"></span><span>Delayed bus</span>
</div>
<div class="legend-chip" style="color: var(--tram)">
<span class="legend-line"></span><span>Tram</span>
</div>
<div class="legend-chip" style="color: var(--rail)">
<span class="legend-line"></span><span>Bike + rail</span>
</div>
</div>
<div class="timeline" aria-label="Journey clock controls">
<div class="timeline-clock">
<span>Journey clock</span>
<strong id="timelineClock">08:00</strong>
</div>
<div class="timeline-buttons">
<button id="stepBack" class="time-button" title="Back one minute" aria-label="Back one minute">−1</button>
<button id="playButton" class="time-button play" title="Play or pause" aria-label="Play or pause">▶</button>
<button id="stepForward" class="time-button" title="Forward one minute" aria-label="Forward one minute">+1</button>
<button id="stepFive" class="time-button" title="Forward five minutes" aria-label="Forward five minutes">+5</button>
</div>
<div class="timeline-hint">Choose a route to start the journey clock</div>
</div>
<div class="camera-help">Drag to rotate · Scroll to zoom · R to reset</div>
</section>
<aside class="side-panel">
<div class="panel-heading">
<p class="eyebrow">Your response</p>
<h2>How will you get there?</h2>
<p>
Every arrival time includes the full declared journey, not just the ride.
</p>
</div>
<section id="comparisonPanel" class="comparison-panel" hidden>
<h3>Arrival comparison</h3>
<table class="comparison-table">
<thead>
<tr>
<th>Route</th>
<th>Leave</th>
<th>Arrive</th>
<th>Total</th>
</tr>
</thead>
<tbody id="comparisonRows"></tbody>
</table>
</section>
<div id="routeCards" class="route-cards"></div>
<section class="trip-clock-card">
<p class="eyebrow">Your trip clock</p>
<div class="trip-clock-main">
<div>
<span>Current</span>
<strong id="tripCurrent">08:00</strong>
</div>
<div>
<span>Arrival</span>
<strong id="tripArrival">—</strong>
</div>
</div>
<div id="tripStatus" class="trip-status" aria-live="polite">
Pick a response below to start the clock.
</div>
<button id="resetButton" class="reset-button">Reset scenario</button>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const POINTS = {
start: [-3, 2.5],
busStop: [-7, 4],
busEnd: [3, -4],
destination: [7, -4],
tramStop: [-1, 0],
tramEnd: [7, -6],
bikeDock: [-4, 2.5],
station: [1, -7]
};
const ROUTES = {
bus: {
id: "bus",
name: "Route 17 bus",
subtitle: "Stay on the delayed bus",
badge: "BUS",
color: "#ef6b52",
threeColor: 0xef6b52,
scheduledTotal: 31,
delay: 12,
segments: [
{
kind: "walk",
duration: 4,
points: [POINTS.start, POINTS.busStop],
label: "Walk to Cedar Avenue"
},
{
kind: "wait",
duration: 6,
point: POINTS.busStop,
label: "Wait for Route 17"
},
{
kind: "ride",
mode: "bus",
duration: 30,
points: [
POINTS.busStop,
[-8, 1],
[-8, -2],
[-5, -4],
[0, -4],
POINTS.busEnd
],
label: "Ride Route 17 · 18 min + 12 min delay"
},
{
kind: "walk",
duration: 3,
points: [POINTS.busEnd, POINTS.destination],
label: "Walk to Clocktower Square"
}
]
},
tram: {
id: "tram",
name: "Green Line tram",
subtitle: "Walk to the tram and transfer north",
badge: "T",
color: "#148e88",
threeColor: 0x148e88,
segments: [
{
kind: "walk",
duration: 5,
points: [POINTS.start, POINTS.tramStop],
label: "Walk to Willow Tram"
},
{
kind: "wait",
duration: 9,
point: POINTS.tramStop,
label: "Wait for the Green Line"
},
{
kind: "ride",
mode: "tram",
duration: 11,
points: [
POINTS.tramStop,
[1, -3],
[4, -6],
POINTS.tramEnd
],
label: "Ride the Green Line"
},
{
kind: "walk",
duration: 2,
points: [POINTS.tramEnd, POINTS.destination],
label: "Walk to Clocktower Square"
}
]
},
rail: {
id: "rail",
name: "Bike + city rail",
subtitle: "Take a bike to Union Station",
badge: "BR",
color: "#6a63c7",
threeColor: 0x6a63c7,
segments: [
{
kind: "walk",
duration: 1,
points: [POINTS.start, POINTS.bikeDock],
label: "Walk to the bike dock"
},
{
kind: "wait",
duration: 3,
point: POINTS.bikeDock,
label: "Unlock a shared bike"
},
{
kind: "ride",
mode: "bike",
duration: 12,
points: [
POINTS.bikeDock,
[-7, 0],
[-8, -4],
[-5, -7],
POINTS.station
],
label: "Cycle to Union Station"
},
{
kind: "wait",
duration: 5,
point: POINTS.station,
label: "Wait for the city rail"
},
{
kind: "ride",
mode: "train",
duration: 7,
points: [
POINTS.station,
[4, -5],
[6, -5]
],
label: "Ride the city rail"
},
{
kind: "walk",
duration: 2,
points: [[6, -5], POINTS.destination],
label: "Walk to Clocktower Square"
}
]
}
};
for (const route of Object.values(ROUTES)) {
route.total = route.segments.reduce((sum, segment) => sum + segment.duration, 0);
route.arrival = 8 * 60 + route.total;
let offset = 0;
for (const segment of route.segments) {
segment.start = offset;
segment.end = offset + segment.duration;
offset = segment.end;
}
}
const state = {
selectedRoute: null,
previewRoute: null,
compareMode: false,
simMinutes: 0,
playing: false
};
const stage = $("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe6e1);
scene.fog = new THREE.Fog(0xdbe6e1, 38, 72);
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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;
renderer.domElement.setAttribute("aria-label", "Three-dimensional transport map. Drag to rotate and scroll to zoom.");
stage.prepend(renderer.domElement);
const cameraState = {
target: new THREE.Vector3(0, 0, -0.6),
radius: 30,
theta: 0.72,
phi: 0.77
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf7fbf4, 0x6b8079, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d3, 3.2);
sun.position.set(-12, 22, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const routeTraceRecords = [];
const waitRingRecords = [];
const destinationRing = new THREE.Group();
let dynamicClockSprite;
let analogClock;
const material = {
ground: new THREE.MeshStandardMaterial({ color: 0xb9cbb6, roughness: 1, flatShading: true }),
groundEdge: new THREE.MeshStandardMaterial({ color: 0x91aa9a, roughness: 1, flatShading: true }),
sidewalk: new THREE.MeshStandardMaterial({ color: 0xd8d2c0, roughness: 1, flatShading: true }),
road: new THREE.MeshStandardMaterial({ color: 0x506166, roughness: 0.95, flatShading: true }),
lane: new THREE.MeshBasicMaterial({ color: 0xe8ddad }),
dark: new THREE.MeshStandardMaterial({ color: 0x263d45, roughness: 0.8, flatShading: true }),
cream: new THREE.MeshStandardMaterial({ color: 0xf5f0dc, roughness: 0.85, flatShading: true }),
glass: new THREE.MeshStandardMaterial({ color: 0x2f5e6b, roughness: 0.3, metalness: 0.1, flatShading: true }),
trunk: new THREE.MeshStandardMaterial({ color: 0x6d5543, roughness: 1, flatShading: true }),
leaf: new THREE.MeshStandardMaterial({ color: 0x4d8968, roughness: 1, flatShading: true }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x76a879, roughness: 1, flatShading: true }),
grass: new THREE.MeshStandardMaterial({ color: 0x8fb590, roughness: 1, flatShading: true }),
water: new THREE.MeshStandardMaterial({ color: 0x70b8c0, roughness: 0.35, metalness: 0.05, flatShading: true })
};
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function createLabelSprite(text, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
function draw(value) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 7, 7, 498, 98, 23);
ctx.fillStyle = options.background || "rgba(255,253,248,0.94)";
ctx.fill();
ctx.strokeStyle = options.border || "rgba(23,51,59,0.13)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = options.color || "#17333b";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `800 ${options.fontSize || 34}px system-ui, sans-serif`;
ctx.fillText(value, 256, 57, 465);
}
draw(text);
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
})
);
const width = options.width || 2.8;
sprite.scale.set(width, width * 112 / 512, 1);
sprite.userData.setText = (value) => {
draw(value);
texture.needsUpdate = true;
};
sprite.renderOrder = 20;
return sprite;
}
function createGround() {
const base = new THREE.Mesh(
new THREE.BoxGeometry(30, 0.38, 24),
material.groundEdge
);
base.position.y = -0.23;
base.receiveShadow = true;
scene.add(base);
const ground = new THREE.Mesh(new THREE.PlaneGeometry(30, 24), material.ground);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const park = new THREE.Mesh(
new THREE.CircleGeometry(2.25, 12),
material.grass
);
park.rotation.x = -Math.PI / 2;
park.scale.set(1.15, 0.72, 1);
park.position.set(4.15, 0.012, 1.7);
park.receiveShadow = true;
scene.add(park);
const pond = new THREE.Mesh(
new THREE.CircleGeometry(0.86, 10),
material.water
);
pond.rotation.x = -Math.PI / 2;
pond.position.set(4.45, 0.028, 1.7);
scene.add(pond);
}
function createRoad(a, b, width = 1.65) {
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const group = new THREE.Group();
group.position.set((a[0] + b[0]) / 2, 0, (a[1] + b[1]) / 2);
group.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(dx, 0, dz).normalize()
);
const outer = new THREE.Mesh(
new THREE.BoxGeometry(length + 0.16, 0.075, width + 0.55),
material.sidewalk
);
outer.position.y = 0.015;
outer.receiveShadow = true;
group.add(outer);
const road = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.085, width),
material.road
);
road.position.y = 0.055;
road.receiveShadow = true;
group.add(road);
const dashCount = Math.max(0, Math.floor(length / 1.35));
for (let i = 0; i < dashCount; i++) {
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.025, 0.055),
material.lane
);
dash.position.set(-length / 2 + 0.65 + i * 1.35, 0.108, 0);
group.add(dash);
}
scene.add(group);
}
function createRoads() {
createRoad([-11, 4.5], [10, 4.5]);
createRoad([-8, 7], [-8, -8]);
createRoad([-10, -4], [10, -4]);
createRoad([7, 7], [7, -7]);
createRoad([-1, 0], [1, -3], 1.25);
createRoad([1, -3], [4, -6], 1.25);
createRoad([4, -6], [7, -6], 1.25);
createRoad([-4, 2.5], [-7, 0], 1.05);
createRoad([-7, 0], [-8, -4], 1.05);
createRoad([-8, -4], [-5, -7], 1.05);
createRoad([-5, -7], [1, -7], 1.05);
createRoad([1, -7], [4, -5], 1.05);
createRoad([4, -5], [6, -5], 1.05);
createRoad([-3, 2.5], [-7, 4], 0.72);
createRoad([-3, 2.5], [-1, 0], 0.72);
}
const buildingPalette = [
0xe8a588,
0x88afb2,
0xe5c572,
0xb7a4c8,
0xd9d5be,
0x91b294
];
function createBuilding(x, z, width, depth, height, color, roof = true) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({ color, roughness: 0.94, flatShading: true })
);
body.position.y = height / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
if (roof) {
const roofMesh = new THREE.Mesh(
new THREE.ConeGeometry(0.78, 0.72, 4),
new THREE.MeshStandardMaterial({
color: 0x4a6063,
roughness: 0.95,
flatShading: true
})
);
roofMesh.rotation.y = Math.PI / 4;
roofMesh.scale.set(width * 0.77, 1, depth * 0.77);
roofMesh.position.y = height + 0.34;
roofMesh.castShadow = true;
group.add(roofMesh);
} else {
const roofMesh = new THREE.Mesh(
new THREE.BoxGeometry(width * 1.04, 0.18, depth * 1.04),
material.cream
);
roofMesh.position.y = height + 0.08;
roofMesh.castShadow = true;
group.add(roofMesh);
}
const windowStrip = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.64, 0.2, 0.045),
material.glass
);
windowStrip.position.set(0, height * 0.56, depth / 2 + 0.03);
group.add(windowStrip);
scene.add(group);
}
function createBuildings() {
const buildings = [
[-5.7, 7.1, 2.8, 2.2, 2.15, buildingPalette[0], true],
[0.2, 7.0, 3.0, 2.4, 2.8, buildingPalette[1], false],
[5.1, 7.1, 2.7, 2.3, 2.0, buildingPalette[2], true],
[-4.7, 0.3, 2.0, 1.55, 1.45, buildingPalette[3], false],
[-0.5, 1.7, 2.1, 1.6, 1.8, buildingPalette[4], true],
[7.8, 1.1, 2.3, 2.4, 2.25, buildingPalette[0], false],
[9.6, 2.1, 1.6, 2.0, 1.5, buildingPalette[5], true],
[-5.3, -7.7, 2.6, 1.7, 1.7, buildingPalette[1], true],
[3.1, -8.4, 2.5, 1.8, 2.0, buildingPalette[2], false],
[8.8, -7.6, 2.5, 2.0, 2.3, buildingPalette[3], true],
[10.2, -1.6, 1.5, 2.2, 1.7, buildingPalette[4], false]
];
buildings.forEach((building) => createBuilding(...building));
}
function createTree(x, z, scale = 1, light = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.13, 0.72, 5),
material.trunk
);
trunk.position.y = 0.36;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.52, 0),
light ? material.leafLight : material.leaf
);
crown.position.y = 1.02;
crown.scale.set(0.9, 1.1, 0.9);
crown.castShadow = true;
group.add(crown);
scene.add(group);
}
function createTrees() {
const trees = [
[-10.2, 6.5, 1.1], [-6.8, 8.8, 0.9], [-2.2, 8.8, 1.05],
[2.7, 8.9, 0.85], [8.2, 8.2, 1.0], [10.2, 5.1, 0.95],
[-10.2, 1.9, 0.85], [-10.2, -1.7, 1.0], [-5.0, -6.1, 0.8],
[3.8, -9.4, 0.9], [6.0, -8.8, 1.0], [11.0, -8.7, 0.95],
[2.7, 1.0, 0.72], [5.8, 1.8, 0.74], [10.4, 0.1, 0.78]
];
trees.forEach((tree, index) => createTree(...tree, index % 3 === 0));
}
function createStop(point, color, label, positionOffset = [0, 0]) {
const group = new THREE.Group();
group.position.set(point[0], 0, point[1]);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.34, 0.1, 8),
material.cream
);
base.position.y = 0.05;
group.add(base);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.06, 1.05, 6),
material.dark
);
pole.position.y = 0.53;
pole.castShadow = true;
group.add(pole);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.055, 6, 16),
new THREE.MeshBasicMaterial({ color })
);
ring.position.y = 1.05;
group.add(ring);
scene.add(group);
if (label) {
const sprite = createLabelSprite(label, {
width: 2.35,
fontSize: 31,
color: "#30494f",
border: "rgba(23,51,59,0.12)"
});
sprite.position.set(
point[0] + positionOffset[0],
1.65,
point[1] + positionOffset[1]
);
scene.add(sprite);
}
}
function createMapMarkers() {
createStop(POINTS.busStop, 0xef6b52, "CEDAR AVE", [0, 1.25]);
createStop(POINTS.tramStop, 0x148e88, "WILLOW TRAM", [0.15, 0.9]);
createStop(POINTS.bikeDock, 0x6a63c7, "BIKE DOCK", [0, 0.85]);
createStop(POINTS.station, 0x6a63c7, "UNION STATION", [0, -1.15]);
const startGroup = new THREE.Group();
startGroup.position.set(POINTS.start[0], 0, POINTS.start[1]);
const startRing = new THREE.Mesh(
new THREE.TorusGeometry(0.42, 0.075, 6, 20),
new THREE.MeshBasicMaterial({ color: 0xf4c95d })
);
startRing.rotation.x = Math.PI / 2;
startRing.position.y = 0.14;
startGroup.add(startRing);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.18, 0.52, 6),
new THREE.MeshStandardMaterial({ color: 0x2f7182, flatShading: true })
);
body.position.y = 0.48;
body.castShadow = true;
startGroup.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 7, 5),
new THREE.MeshStandardMaterial({ color: 0xf0bf93, flatShading: true })
);
head.position.y = 0.88;
head.castShadow = true;
startGroup.add(head);
scene.add(startGroup);
const youLabel = createLabelSprite("YOU · WILLOW & 3RD", {
width: 3.25,
fontSize: 29,
background: "rgba(255,244,198,0.96)",
border: "rgba(168,125,28,0.18)"
});
youLabel.position.set(-2.4, 1.75, 3.25);
scene.add(youLabel);
const destinationGroup = new THREE.Group();
destinationGroup.position.set(POINTS.destination[0], 0, POINTS.destination[1]);
const destinationBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.62, 0.12, 8),
new THREE.MeshBasicMaterial({ color: 0x3d8b68 })
);
destinationBase.position.y = 0.07;
destinationGroup.add(destinationBase);
const flagPole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.06, 2.0, 6),
material.dark
);
flagPole.position.y = 1.0;
destinationGroup.add(flagPole);
const flag = new THREE.Mesh(
new THREE.BoxGeometry(0.75, 0.43, 0.06),
new THREE.MeshStandardMaterial({ color: 0x3d8b68, flatShading: true })
);
flag.position.set(0.35, 1.72, 0);
destinationGroup.add(flag);
scene.add(destinationGroup);
const destinationRing = new THREE.Mesh(
new THREE.TorusGeometry(0.66, 0.07, 6, 24),
new THREE.MeshBasicMaterial({
color: 0x3d8b68,
transparent: true,
opacity: 0.65
})
);
destinationRing.rotation.x = Math.PI / 2;
destinationRing.position.set(POINTS.destination[0], 0.19, POINTS.destination[1]);
scene.add(destinationRing);
destinationRingRecords.push(destinationRing);
const destinationLabel = createLabelSprite("CLOCKTOWER SQ", {
width: 3.15,
fontSize: 30,
background: "rgba(231,247,238,0.96)",
border: "rgba(61,139,104,0.22)"
});
destinationLabel.position.set(7.1, 2.4, -4.35);
scene.add(destinationLabel);
const delayLabel = createLabelSprite("+12 MIN DELAY", {
width: 2.7,
fontSize: 30,
color: "#a33f2c",
background: "rgba(255,235,227,0.97)",
border: "rgba(239,107,82,0.32)"
});
delayLabel.position.set(-8.3, 2.45, -1.1);
scene.add(delayLabel);
}
const destinationRingRecords = [];
function createAnalogClock() {
const group = new THREE.Group();
group.position.set(9.7, 0, -4.8);
group.rotation.y = -0.15;
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.19, 2.35, 8),
material.dark
);
pole.position.y = 1.17;
pole.castShadow = true;
group.add(pole);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.48, 0.58, 0.2, 8),
material.cream
);
foot.position.y = 0.1;
group.add(foot);
const faceGroup = new THREE.Group();
faceGroup.position.y = 2.62;
const caseMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.84, 0.84, 0.2, 24),
material.dark
);
caseMesh.rotation.x = Math.PI / 2;
faceGroup.add(caseMesh);
const face = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.72, 0.205, 24),
material.cream
);
face.rotation.x = Math.PI / 2;
face.position.z = 0.025;
faceGroup.add(face);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.76, 0.075, 6, 24),
new THREE.MeshStandardMaterial({ color: 0xef6b52, flatShading: true })
);
ring.position.z = 0.14;
faceGroup.add(ring);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(i % 3 === 0 ? 0.075 : 0.045, i % 3 === 0 ? 0.15 : 0.1, 0.025),
material.dark
);
tick.position.set(Math.sin(angle) * 0.58, Math.cos(angle) * 0.58, 0.145);
tick.rotation.z = -angle;
faceGroup.add(tick);
}
const hourPivot = new THREE.Group();
hourPivot.position.z = 0.18;
const hourHand = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.42, 0.04),
material.dark
);
hourHand.position.y = 0.21;
hourPivot.add(hourHand);
faceGroup.add(hourPivot);
const minutePivot = new THREE.Group();
minutePivot.position.z = 0.205;
const minuteHand = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.64, 0.035),
new THREE.MeshBasicMaterial({ color: 0xef6b52 })
);
minuteHand.position.y = 0.32;
minutePivot.add(minuteHand);
faceGroup.add(minutePivot);
const center = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.08, 0.07, 10),
material.dark
);
center.rotation.x = Math.PI / 2;
center.position.z = 0.25;
faceGroup.add(center);
group.add(faceGroup);
scene.add(group);
dynamicClockSprite = createLabelSprite("08:00", {
width: 2.25,
fontSize: 39,
background: "rgba(23,51,59,0.94)",
color: "#fff9e8",
border: "rgba(255,255,255,0.25)"
});
dynamicClockSprite.position.set(9.7, 4.05, -4.8);
scene.add(dynamicClockSprite);
analogClock = { hourPivot, minutePivot };
}
function createTrace(points, color, dashed = false) {
const traceMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const group = new THREE.Group();
for (let i = 0; i < points.length - 1; i++) {
const a = new THREE.Vector3(points[i][0], 0.205, points[i][1]);
const b = new THREE.Vector3(points[i + 1][0], 0.205, points[i + 1][1]);
const vector = b.clone().sub(a);
const length = vector.length();
const direction = vector.clone().normalize();
const addSegment = (start, segmentLength, width) => {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(segmentLength, 0.045, width),
traceMaterial
);
mesh.position.copy(a).add(direction.clone().multiplyScalar(start + segmentLength / 2));
mesh.quaternion.setFromUnitVectors(new THREE.Vector3(1, 0, 0), direction);
mesh.renderOrder = 12;
group.add(mesh);
};
if (dashed) {
const dashLength = 0.38;
const gap = 0.24;
for (let d = 0; d < length; d += dashLength + gap) {
addSegment(d, Math.min(dashLength, length - d), 0.105);
}
} else {
addSegment(0, length, 0.13);
}
}
scene.add(group);
return { group, material: traceMaterial };
}
function createWaitRing(point, color) {
const ringMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.18,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.07, 6, 20),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(point[0], 0.22, point[1]);
ring.renderOrder = 13;
scene.add(ring);
return { ring, material: ringMaterial };
}
function buildRouteTraces() {
for (const route of Object.values(ROUTES)) {
for (const segment of route.segments) {
if (segment.points) {
const trace = createTrace(
segment.points,
route.threeColor,
segment.kind === "walk"
);
routeTraceRecords.push({
routeId: route.id,
material: trace.material
});
}
if (segment.kind === "wait") {
const ring = createWaitRing(segment.point, route.threeColor);
waitRingRecords.push({
routeId: route.id,
segment,
material: ring.material,
ring: ring.ring
});
}
}
}
}
function createVehicle(type, color) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.65,
flatShading: true
});
if (type === "bike") {
const wheelGeometry = new THREE.TorusGeometry(0.23, 0.045, 6, 12);
for (const z of [-0.34, 0.34]) {
const wheel = new THREE.Mesh(wheelGeometry, material.dark);
wheel.position.set(0, 0.3, z);
group.add(wheel);
}
const frame = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.1, 0.85),
new THREE.MeshBasicMaterial({ color: 0xf2c84e })
);
frame.position.y = 0.42;
group.add(frame);
const rider = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.55, 6),
new THREE.MeshStandardMaterial({ color: 0x6a63c7, flatShading: true })
);
rider.rotation.x = Math.PI / 2;
rider.position.set(0, 0.63, -0.05);
group.add(rider);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 6, 4),
new THREE.MeshStandardMaterial({ color: 0xf0bf93, flatShading: true })
);
head.position.set(0, 0.88, -0.16);
group.add(head);
return group;
}
const isTrain = type === "train";
const isTram = type === "tram";
const width = isTrain ? 0.9 : isTram ? 0.82 : 0.76;
const height = isTrain ? 0.7 : isTram ? 0.64 : 0.54;
const length = isTrain ? 2.2 : isTram ? 1.9 : 1.55;
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, length),
bodyMaterial
);
body.position.y = 0.56;
body.castShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(width * 1.04, 0.13, length * 0.92),
material.cream
);
roof.position.y = 0.56 + height / 2 + 0.055;
group.add(roof);
for (const side of [-1, 1]) {
const windows = new THREE.Mesh(
new THREE.BoxGeometry(0.025, height * 0.38, length * 0.68),
material.glass
);
windows.position.set(side * (width / 2 + 0.015), 0.64, 0);
group.add(windows);
}
const frontWindow = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.7, height * 0.34, 0.025),
material.glass
);
frontWindow.position.set(0, 0.64, length / 2 + 0.015);
group.add(frontWindow);
const wheelGeometry = new THREE.CylinderGeometry(0.17, 0.17, 0.12, 8);
for (const side of [-1, 1]) {
for (const z of [-length * 0.31, length * 0.31]) {
const wheel = new THREE.Mesh(wheelGeometry, material.dark);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(side * (width / 2 + 0.015), 0.31, z);
group.add(wheel);
}
}
return group;
}
function getPolylineState(points, progress) {
const vectors = points.map((point) => new THREE.Vector3(point[0], 0, point[1]));
const lengths = [];
let total = 0;
for (let i = 0; i < vectors.length - 1; i++) {
const length = vectors[i].distanceTo(vectors[i + 1]);
lengths.push(length);
total += length;
}
let remaining = THREE.MathUtils.clamp(progress, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i] || i === lengths.length - 1) {
const t = lengths[i] ? remaining / lengths[i] : 0;
const position = vectors[i].clone().lerp(vectors[i + 1], t);
const direction = vectors[i + 1].clone().sub(vectors[i]).normalize();
return { position, direction };
}
remaining -= lengths[i];
}
return {
position: vectors[0].clone(),
direction: new THREE.Vector3(0, 0, 1)
};
}
function placeVehicle(object, points, progress) {
const { position, direction } = getPolylineState(points, progress);
object.position.set(position.x, 0, position.z);
object.rotation.y = Math.atan2(direction.x, direction.z);
}
const vehicles = {
bus: createVehicle("bus", 0xef6b52),
tram: createVehicle("tram", 0x148e88),
bike: createVehicle("bike", 0xf2c84e),
train: createVehicle("train", 0x6a63c7),
delayedBus: createVehicle("bus", 0xef6b52)
};
Object.values(vehicles).forEach((vehicle) => scene.add(vehicle));
function updateVehicles() {
const selected = state.selectedRoute ? ROUTES[state.selectedRoute] : null;
vehicles.delayedBus.visible = state.selectedRoute !== "bus";
if (vehicles.delayedBus.visible) {
placeVehicle(vehicles.delayedBus, ROUTES.bus.segments[2].points, 0.31);
}
vehicles.bus.visible = false;
vehicles.tram.visible = false;
vehicles.bike.visible = false;
vehicles.train.visible = false;
if (!selected) {
vehicles.tram.visible = true;
vehicles.bike.visible = true;
vehicles.train.visible = true;
placeVehicle(vehicles.tram, ROUTES.tram.segments.find(segment => segment.mode === 'tram').points, 0);
placeVehicle(vehicles.bike, ROUTES.rail.segments.find(segment => segment.mode === 'bike').points, 0);
placeVehicle(vehicles.train, ROUTES.rail.segments.find(segment => segment.mode === 'train').points, 0);
} else {
for (const segment of selected.segments) {
if (!segment.mode) continue;
const object = vehicles[segment.mode];
object.visible = true;
const progress = THREE.MathUtils.clamp(
(state.simMinutes - segment.start) / segment.duration,
0,
1
);
placeVehicle(object, segment.points, progress);
}
}
}
function formatClock(minutes) {
const total = Math.round(minutes);
const hour = Math.floor(total / 60);
const minute = total % 60;
return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
}
function formatDelta(route) {
if (route.id === "bus") {
return `+${route.delay} min vs scheduled`;
}
const difference = ROUTES.bus.total - route.total;
return `${difference} min faster than bus`;
}
function renderRouteCards() {
$("#routeCards").innerHTML = Object.values(ROUTES).map((route) => {
const segments = route.segments.map((segment) => {
const kind = segment.kind === "wait"
? "Wait"
: segment.kind === "walk"
? "Walk"
: "Ride";
return `
<div class="segment-row">
<span class="segment-kind">${kind}</span>
<span>${segment.label}</span>
<strong>${segment.duration}m</strong>
</div>
`;
}).join("");
const badge = route.id === "bus"
? `<span class="status-badge">+12 min late</span>`
: `<span class="status-badge good">On schedule</span>`;
return `
<article class="route-card" data-route="${route.id}" style="--route-color:${route.color}">
<div class="route-card-header">
<div class="mode-badge">${route.badge}</div>
<div class="route-title">
<h3>${route.name}</h3>
<p>${route.subtitle}</p>
</div>
${badge}
</div>
<div class="segment-list">${segments}</div>
<div class="route-outcome">
<div class="arrival-block">
<span>Predicted arrival</span>
<strong>${formatClock(route.arrival)}</strong>
</div>
<div class="route-outcome-copy">
<strong>${route.total} min total</strong>
${formatDelta(route)}
</div>
</div>
<button class="choose-route" data-choose="${route.id}" aria-pressed="false">
Take this route
</button>
</article>
`;
}).join("");
$("#comparisonRows").innerHTML = Object.values(ROUTES).map((route) => `
<tr>
<td>
<span class="table-route" style="color:${route.color}">
<span class="route-dot"></span>
<span style="color:var(--ink)">${route.badge}</span>
</span>
</td>
<td>08:00</td>
<td>${formatClock(route.arrival)}</td>
<td>${route.total}m</td>
</tr>
`).join("");
}
function updateTraceVisibility() {
for (const record of routeTraceRecords) {
let opacity = 0.08;
if (state.selectedRoute) {
opacity = record.routeId === state.selectedRoute ? 0.98 : 0.06;
} else if (state.compareMode) {
opacity = record.routeId === "bus" ? 0.92 : 0.78;
} else {
opacity = record.routeId === "bus" ? 0.94 : 0.08;
}
if (state.previewRoute) {
opacity = record.routeId === state.previewRoute
? 1
: state.selectedRoute === record.routeId
? 0.5
: 0.06;
}
record.material.opacity = opacity;
}
for (const record of waitRingRecords) {
let opacity = 0.13;
if (state.selectedRoute === record.routeId) opacity = 0.42;
if (state.compareMode) opacity = 0.38;
if (state.previewRoute === record.routeId) opacity = 0.72;
record.material.opacity = opacity;
}
}
function updateCardClasses() {
document.querySelectorAll(".route-card").forEach((card) => {
const id = card.dataset.route;
const selected = state.selectedRoute === id;
const preview = state.previewRoute === id;
card.classList.toggle("selected", selected);
card.classList.toggle("preview", preview && !selected);
const button = card.querySelector(".choose-route");
button.setAttribute("aria-pressed", String(selected));
button.textContent = selected ? "Trip selected ✓" : "Take this route";
});
}
function updateComparison() {
$("#comparisonPanel").hidden = !state.compareMode;
$("#compareButton").classList.toggle("active", state.compareMode);
$("#compareButton").setAttribute("aria-pressed", String(state.compareMode));
$("#compareButton").textContent = state.compareMode ? "Hide comparison" : "Compare outcomes";
}
function updateWorldClock() {
const totalMinutes = 8 * 60 + state.simMinutes;
const minuteAngle = -((totalMinutes % 60) / 60) * Math.PI * 2;
const hourAngle = -(((totalMinutes % 720) / 720)) * Math.PI * 2;
analogClock.minutePivot.rotation.z = minuteAngle;
analogClock.hourPivot.rotation.z = hourAngle;
dynamicClockSprite.userData.setText(formatClock(8 * 60 + state.simMinutes));
}
function updateUI() {
const selected = state.selectedRoute ? ROUTES[state.selectedRoute] : null;
const currentTime = formatClock(8 * 60 + state.simMinutes);
$("#headerClock").textContent = currentTime;
$("#timelineClock").textContent = currentTime;
$("#clockLabel").textContent = selected ? "Trip clock" : "Decision time";
if (selected) {
const remaining = Math.max(0, selected.total - state.simMinutes);
const arrived = state.simMinutes >= selected.total;
$("#tripCurrent").textContent = currentTime;
$("#tripArrival").textContent = formatClock(selected.arrival);
$("#playButton").textContent = state.playing ? "Ⅱ" : arrived ? "↻" : "▶";
if (arrived) {
const faster = ROUTES.bus.total - selected.total;
$("#tripStatus").textContent = selected.id === "bus"
? `Arrived at ${formatClock(selected.arrival)} — 12 minutes later than scheduled.`
: `Arrived at ${formatClock(selected.arrival)} — ${faster} minutes earlier than the delayed bus.`;
} else {
$("#tripStatus").textContent = `${remaining} minutes remaining · arrival ${formatClock(selected.arrival)}`;
}
$("#eventTitle").textContent = `${selected.name} is your response.`;
$("#eventCopy").textContent =
`Your journey clock is running. The route includes every declared walk, wait, and ride.`;
} else {
$("#tripCurrent").textContent = "08:00";
$("#tripArrival").textContent = "—";
$("#tripStatus").textContent = state.compareMode
? "Comparison mode is on. All route traces are visible on the map."
: "Pick a response below to start the clock.";
$("#playButton").textContent = "▶";
$("#eventTitle").textContent = "Route 17 is running 12 minutes late.";
$("#eventCopy").textContent =
"A stalled coach near Civic Center is blocking the usual path. Compare the declared walking, waiting, and riding times.";
}
["#stepBack", "#stepForward", "#stepFive", "#playButton"].forEach((selector) => {
$(selector).disabled = !selected;
});
updateTraceVisibility();
updateCardClasses();
updateComparison();
updateWorldClock();
}
function chooseRoute(id) {
state.selectedRoute = id;
state.previewRoute = null;
state.compareMode = false;
state.simMinutes = 0;
state.playing = true;
updateUI();
}
function resetScenario() {
state.selectedRoute = null;
state.previewRoute = null;
state.compareMode = false;
state.simMinutes = 0;
state.playing = false;
updateUI();
}
function advance(minutes) {
if (!state.selectedRoute) return;
const route = ROUTES[state.selectedRoute];
state.simMinutes = THREE.MathUtils.clamp(
state.simMinutes + minutes,
0,
route.total
);
if (state.simMinutes >= route.total) {
state.playing = false;
}
updateUI();
}
function togglePlay() {
if (!state.selectedRoute) return;
const route = ROUTES[state.selectedRoute];
if (state.simMinutes >= route.total) {
state.simMinutes = 0;
state.playing = true;
} else {
state.playing = !state.playing;
}
updateUI();
}
renderRouteCards();
createGround();
createRoads();
createBuildings();
createTrees();
createMapMarkers();
createAnalogClock();
buildRouteTraces();
document.querySelectorAll(".route-card").forEach((card) => {
const id = card.dataset.route;
card.addEventListener("mouseenter", () => {
state.previewRoute = id;
updateUI();
});
card.addEventListener("mouseleave", () => {
state.previewRoute = null;
updateUI();
});
card.addEventListener("focusin", () => {
state.previewRoute = id;
updateUI();
});
card.addEventListener("focusout", () => {
state.previewRoute = null;
updateUI();
});
card.querySelector(".choose-route").addEventListener("click", (event) => {
event.stopPropagation();
chooseRoute(id);
});
});
$("#compareButton").addEventListener("click", () => {
state.compareMode = !state.compareMode;
state.previewRoute = null;
updateUI();
});
$("#playButton").addEventListener("click", togglePlay);
$("#stepBack").addEventListener("click", () => advance(-1));
$("#stepForward").addEventListener("click", () => advance(1));
$("#stepFive").addEventListener("click", () => advance(5));
$("#resetButton").addEventListener("click", resetScenario);
$("#zoomIn").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius - 3, 17, 44);
updateCamera();
});
$("#zoomOut").addEventListener("click", () => {
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius + 3, 17, 44);
updateCamera();
});
function resetCamera() {
cameraState.radius = 30;
cameraState.theta = 0.72;
cameraState.phi = 0.77;
cameraState.target.set(0, 0, -0.6);
updateCamera();
}
$("#resetCamera").addEventListener("click", resetCamera);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.38,
1.28
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
17,
44
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraState.theta += 0.09;
else if (key === "arrowright") cameraState.theta -= 0.09;
else if (key === "arrowup") cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - 0.07, 0.38, 1.28);
else if (key === "arrowdown") cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + 0.07, 0.38, 1.28);
else if (key === "+" || key === "=") cameraState.radius = THREE.MathUtils.clamp(cameraState.radius - 2, 17, 44);
else if (key === "-") cameraState.radius = THREE.MathUtils.clamp(cameraState.radius + 2, 17, 44);
else if (key === "r") {
resetCamera();
event.preventDefault();
return;
} else {
return;
}
updateCamera();
event.preventDefault();
});
const resizeObserver = new ResizeObserver(() => {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
});
resizeObserver.observe(stage);
updateUI();
let lastFrame = performance.now();
let lastSimulationTick = lastFrame;
let lastClockMinute = -1;
function animate(now) {
requestAnimationFrame(animate);
const delta = now - lastFrame;
lastFrame = now;
if (state.playing && now - lastSimulationTick > 650) {
advance(1);
lastSimulationTick = now;
}
updateVehicles();
const pulse = 1 + Math.sin(now * 0.004) * 0.08;
for (const ring of destinationRingRecords) {
const arrived = state.selectedRoute && state.simMinutes >= ROUTES[state.selectedRoute].total;
ring.scale.setScalar(pulse * (arrived ? 1.35 : 1));
ring.material.opacity = arrived ? 0.95 : 0.48;
}
for (const record of waitRingRecords) {
if (state.selectedRoute === record.routeId) {
const active = state.simMinutes >= record.segment.start &&
state.simMinutes < record.segment.end;
record.ring.scale.setScalar(active ? 1 + Math.sin(now * 0.009) * 0.18 : 1);
}
}
if (Math.floor(state.simMinutes) !== lastClockMinute) {
updateWorldClock();
lastClockMinute = Math.floor(state.simMinutes);
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```