Prompt specification
Build or customize the Three.js 3D scene "Small Ferry and Bus Connection Hub" 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: Small Ferry and Bus Connection Hub
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-ferry-and-bus-connection-hub-x2143
Scene Description Prompt:
Connect a voxel ferry stop and bus station with repeating timetables; walking time determines feasible transfers. Three.js from cdnjs, one HTML file.
Working Three.js Starter (small-ferry-and-bus-connection-hub-x2143):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pixel Transit — Harbor District</title>
<style>
:root {
--ink: #16313b;
--muted: #6b7c82;
--paper: rgba(250, 252, 249, 0.94);
--line: #dce5e3;
--ferry: #21b8c5;
--ferry-dark: #087f8a;
--bus: #f5a623;
--bus-dark: #b56c00;
--navy: #15333f;
--green: #bde77e;
--shadow: 0 18px 45px rgba(24, 57, 68, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #bfe3e6;
}
button,
select,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 18px;
left: 20px;
right: 20px;
height: 60px;
display: flex;
align-items: center;
gap: 18px;
padding: 10px 12px 10px 16px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 7px;
background: rgba(250, 252, 249, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: max-content;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 8px);
grid-template-rows: repeat(2, 8px);
gap: 3px;
transform: rotate(-4deg);
}
.brand-mark i {
display: block;
background: var(--ink);
}
.brand-mark i:nth-child(2) {
background: var(--ferry);
}
.brand-mark i:nth-child(3) {
background: var(--bus);
}
.brand-copy strong {
display: block;
font-size: 15px;
line-height: 1.05;
letter-spacing: 0.12em;
}
.brand-copy small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
}
.top-divider {
width: 1px;
height: 30px;
background: var(--line);
}
.network-status {
display: flex;
align-items: center;
gap: 8px;
color: #547079;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
}
.network-status::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #4fc56b;
box-shadow: 0 0 0 4px rgba(79, 197, 107, 0.13);
}
.spacer {
flex: 1;
}
.time-controls {
display: flex;
align-items: center;
gap: 10px;
}
.icon-button {
display: grid;
place-items: center;
width: 36px;
height: 36px;
padding: 0;
border: 0;
border-radius: 4px;
background: var(--ink);
color: white;
font-size: 12px;
cursor: pointer;
transition: transform 0.15s ease, background 0.15s ease;
}
.icon-button:hover {
transform: translateY(-1px);
background: #244a57;
}
.speed-button {
width: auto;
padding: 0 10px;
background: #e8efec;
color: var(--ink);
font-size: 10px;
font-weight: 800;
}
.time-range-wrap {
position: relative;
width: 145px;
}
.time-range-wrap::before {
content: "SIM TIME";
position: absolute;
left: 0;
top: -12px;
color: #89989d;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.14em;
}
#timeRange {
width: 100%;
height: 4px;
margin: 0;
border-radius: 0;
appearance: none;
background: linear-gradient(
90deg,
var(--ferry) 0%,
var(--ferry) 36%,
#dce5e3 36%,
#dce5e3 100%
);
cursor: pointer;
}
#timeRange::-webkit-slider-thumb {
width: 13px;
height: 13px;
border: 3px solid white;
border-radius: 2px;
appearance: none;
background: var(--ink);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}
#timeRange::-moz-range-thumb {
width: 9px;
height: 9px;
border: 3px solid white;
border-radius: 2px;
background: var(--ink);
}
.clock {
min-width: 78px;
padding-left: 12px;
border-left: 1px solid var(--line);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 17px;
font-weight: 800;
letter-spacing: 0.04em;
}
.panel {
position: fixed;
z-index: 10;
top: 94px;
width: 324px;
max-height: calc(100vh - 126px);
overflow: auto;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 7px;
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
}
#board {
left: 20px;
background: var(--paper);
}
#planner {
right: 20px;
width: 348px;
color: white;
border-color: rgba(255, 255, 255, 0.08);
background: rgba(21, 51, 63, 0.95);
}
.panel-inner {
padding: 20px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.2em;
text-transform: uppercase;
}
#planner .eyebrow {
color: #7fc9ce;
}
.panel h1,
.panel h2 {
margin: 0;
font-size: 24px;
line-height: 1.12;
letter-spacing: -0.035em;
}
.subtitle {
margin: 7px 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#planner .subtitle {
color: #abc0c6;
}
.station-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
margin-bottom: 16px;
padding: 4px;
border-radius: 5px;
background: #e8eeeb;
}
.station-tabs button {
min-height: 34px;
border: 0;
border-radius: 3px;
background: transparent;
color: #65777d;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.05em;
cursor: pointer;
}
.station-tabs button.active {
color: var(--ink);
background: white;
box-shadow: 0 2px 7px rgba(33, 59, 67, 0.1);
}
.station-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(255, 255, 255, 0.58);
}
.station-summary strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
}
.station-summary small {
color: var(--muted);
font-size: 10px;
}
.route-badge {
display: inline-grid;
place-items: center;
min-width: 42px;
height: 30px;
padding: 0 9px;
border-radius: 3px;
color: white;
background: var(--ferry);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.08em;
}
.route-badge.bus {
background: var(--bus);
color: #493100;
}
.board-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
padding-bottom: 8px;
border-bottom: 1px solid var(--line);
}
.board-heading strong {
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.board-heading span {
color: var(--muted);
font-size: 9px;
}
.departure-list {
display: grid;
}
.departure-row {
display: grid;
grid-template-columns: 58px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
padding: 12px 0;
border: 0;
border-bottom: 1px solid #e6ece9;
background: transparent;
text-align: left;
cursor: pointer;
}
.departure-row:hover .destination {
color: var(--ferry-dark);
}
.departure-row.bus:hover .destination {
color: var(--bus-dark);
}
.departure-time {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 15px;
font-weight: 900;
}
.destination {
display: block;
margin-bottom: 3px;
font-size: 11px;
font-weight: 800;
transition: color 0.15s ease;
}
.platform {
color: var(--muted);
font-size: 9px;
}
.relative-time {
padding: 4px 6px;
border-radius: 3px;
color: #337160;
background: #e1f0df;
font-size: 8px;
font-weight: 850;
white-space: nowrap;
}
.relative-time.soon {
color: #885500;
background: #fff0cd;
}
.schedule-note {
margin: 13px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.field {
margin-top: 15px;
}
.field label {
display: block;
margin-bottom: 7px;
color: #a9c0c7;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.field select {
width: 100%;
height: 43px;
padding: 0 36px 0 12px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 4px;
outline: none;
color: white;
background: #234651;
font-size: 12px;
font-weight: 750;
cursor: pointer;
}
.field select:focus {
border-color: #6dd3d9;
}
.field select option {
color: var(--ink);
background: white;
}
.walk-card {
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
gap: 10px;
margin: 17px 0;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 4px;
background: rgba(255, 255, 255, 0.045);
}
.walk-icon {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 3px;
color: #13333d;
background: var(--green);
font-size: 18px;
}
.walk-card strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
}
.walk-card small {
color: #9db7be;
font-size: 9px;
}
.walk-duration {
color: #bde77e;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 15px;
font-weight: 900;
}
.transfer-line {
position: relative;
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 8px;
margin: 18px 0;
}
.transfer-line::before {
content: "";
position: absolute;
left: 8px;
right: 8px;
top: 50%;
height: 1px;
background: rgba(255, 255, 255, 0.18);
}
.timeline-stop {
position: relative;
z-index: 1;
text-align: center;
}
.timeline-stop i {
display: block;
width: 17px;
height: 17px;
margin: 0 auto 6px;
border: 4px solid var(--navy);
border-radius: 50%;
background: var(--ferry);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.timeline-stop:last-child i {
background: var(--bus);
}
.timeline-stop span {
display: block;
color: #9db7be;
font-size: 8px;
font-weight: 750;
}
.timeline-stop strong {
display: block;
margin-top: 2px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
}
.walk-chip {
position: relative;
z-index: 1;
padding: 4px 7px;
border-radius: 3px;
color: #17343e;
background: var(--green);
font-size: 8px;
font-weight: 900;
white-space: nowrap;
}
.result {
padding: 13px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-left: 4px solid #58c878;
border-radius: 4px;
background: rgba(88, 200, 120, 0.09);
}
.result.tight {
border-left-color: var(--bus);
background: rgba(245, 166, 35, 0.09);
}
.result.failed {
border-left-color: #ef6d6d;
background: rgba(239, 109, 109, 0.09);
}
.result strong {
display: block;
margin-bottom: 5px;
font-size: 12px;
}
.result p {
margin: 0;
color: #b5c8ce;
font-size: 10px;
line-height: 1.45;
}
.planner-action {
width: 100%;
height: 40px;
margin-top: 14px;
border: 0;
border-radius: 3px;
color: #15333f;
background: var(--green);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.04em;
cursor: pointer;
transition: transform 0.15s ease, filter 0.15s ease;
}
.planner-action:hover {
transform: translateY(-1px);
filter: brightness(1.04);
}
.scene-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(255, 255, 255, 0.86);
border-radius: 4px;
background: rgba(250, 252, 249, 0.92);
box-shadow: 0 8px 22px rgba(20, 50, 60, 0.16);
transform: translate(-50%, -100%);
cursor: pointer;
user-select: none;
backdrop-filter: blur(8px);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 1px;
height: 7px;
background: rgba(23, 54, 64, 0.35);
}
.label-code {
display: grid;
place-items: center;
width: 30px;
height: 27px;
border-radius: 3px;
color: white;
background: var(--ferry);
font-size: 10px;
font-weight: 900;
}
.scene-label.bus .label-code {
color: #493100;
background: var(--bus);
}
.label-copy strong {
display: block;
font-size: 10px;
line-height: 1.1;
}
.label-copy small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
}
.map-legend {
position: fixed;
z-index: 6;
left: 364px;
bottom: 20px;
display: flex;
align-items: center;
gap: 14px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 5px;
background: rgba(250, 252, 249, 0.85);
box-shadow: 0 8px 25px rgba(24, 57, 68, 0.12);
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #5e737a;
font-size: 9px;
font-weight: 750;
}
.legend-line {
width: 18px;
height: 4px;
border-radius: 1px;
background: var(--ferry);
}
.legend-line.bus {
background: var(--bus);
}
.legend-line.walk {
height: 0;
border-top: 2px dashed #91a19b;
background: none;
}
.map-help {
position: fixed;
z-index: 5;
left: 50%;
bottom: 22px;
padding: 9px 13px;
border-radius: 4px;
color: #61777e;
background: rgba(250, 252, 249, 0.72);
font-size: 9px;
font-weight: 700;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
.camera-controls {
position: fixed;
z-index: 8;
right: 20px;
bottom: 20px;
display: flex;
gap: 5px;
}
.camera-controls button {
display: grid;
place-items: center;
width: 36px;
height: 36px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 4px;
background: rgba(250, 252, 249, 0.9);
box-shadow: 0 8px 20px rgba(24, 57, 68, 0.12);
cursor: pointer;
}
.mobile-nav {
display: none;
}
@media (max-width: 1080px) {
.network-status,
.top-divider {
display: none;
}
.panel {
width: 300px;
}
#planner {
width: 318px;
}
.map-legend {
left: 338px;
}
}
@media (max-width: 780px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
height: 56px;
padding: 8px 9px 8px 12px;
}
.brand-copy small,
.time-range-wrap,
.speed-button {
display: none;
}
.brand-copy strong {
font-size: 12px;
}
.clock {
min-width: 68px;
font-size: 14px;
}
.panel {
display: none;
top: 76px;
bottom: 68px;
left: 10px;
right: 10px;
width: auto;
max-height: none;
}
body.show-board #board,
body.show-plan #planner {
display: block;
}
.panel-inner {
padding: 17px;
}
.map-legend,
.map-help,
.camera-controls {
display: none;
}
.mobile-nav {
position: fixed;
z-index: 25;
left: 50%;
bottom: 10px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
width: 230px;
padding: 4px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 6px;
background: rgba(21, 51, 63, 0.92);
box-shadow: var(--shadow);
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.mobile-nav button {
height: 34px;
border: 0;
border-radius: 3px;
color: #b8cbd0;
background: transparent;
font-size: 10px;
font-weight: 850;
}
.mobile-nav button.active {
color: var(--ink);
background: white;
}
.scene-label {
display: none;
}
}
</style>
</head>
<body class="show-board">
<header class="topbar">
<div class="brand">
<span class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</span>
<span class="brand-copy">
<strong>PIXEL TRANSIT</strong>
<small>HARBOR DISTRICT NETWORK</small>
</span>
</div>
<span class="top-divider"></span>
<span class="network-status">NETWORK ONLINE</span>
<div class="spacer"></div>
<div class="time-controls">
<button
id="playButton"
class="icon-button"
type="button"
aria-label="Pause simulation"
aria-pressed="true"
>
❚❚
</button>
<button
id="speedButton"
class="icon-button speed-button"
type="button"
title="Change simulation speed"
>
60×
</button>
<div class="time-range-wrap">
<input
id="timeRange"
type="range"
min="0"
max="1439"
step="1"
value="522"
aria-label="Simulation time"
/>
</div>
<output id="clock" class="clock" aria-live="off">08:42:00</output>
</div>
</header>
<aside id="board" class="panel" aria-label="Live departure board">
<div class="panel-inner">
<p class="eyebrow">Live departure board</p>
<h1 id="stationName">Harbor Ferry Stop</h1>
<p id="stationSubtitle" class="subtitle">
Waterfront edge · Ferry service to Island Quay
</p>
<div class="station-tabs" role="tablist" aria-label="Choose station">
<button
type="button"
class="active"
data-station="ferry"
role="tab"
aria-selected="true"
>
FERRY STOP
</button>
<button
type="button"
data-station="bus"
role="tab"
aria-selected="false"
>
BUS STATION
</button>
</div>
<div class="station-summary">
<div>
<strong id="serviceName">Harbor → Island Quay</strong>
<small id="serviceMeta">F2 · Every 12 minutes · Pier 02</small>
</div>
<span id="routeBadge" class="route-badge">F2</span>
</div>
<div class="board-heading">
<strong>Next departures</strong>
<span id="boardDate">TODAY</span>
</div>
<div id="departureList" class="departure-list"></div>
<p id="scheduleNote" class="schedule-note">
Repeating timetable · First 05:30 · Last 23:30
</p>
</div>
</aside>
<aside id="planner" class="panel" aria-label="Transfer planner">
<div class="panel-inner">
<p class="eyebrow">Transfer planner</p>
<h2>Ferry to bus</h2>
<p class="subtitle">
Check the timetable and leave enough time for the walk.
</p>
<div class="field">
<label for="ferrySelect">Ferry arrival at Harbor</label>
<select id="ferrySelect"></select>
</div>
<div class="walk-card">
<span class="walk-icon" aria-hidden="true">⌁</span>
<div>
<strong>Walk the waterfront path</strong>
<small>650 m · step-free route</small>
</div>
<span class="walk-duration">9 min</span>
</div>
<div class="field">
<label for="busSelect">Bus departure from Central</label>
<select id="busSelect"></select>
</div>
<div class="transfer-line" aria-label="Transfer timeline">
<div class="timeline-stop">
<i></i>
<span>FERRY</span>
<strong id="timelineFerry">08:42</strong>
</div>
<span class="walk-chip">9 MIN WALK</span>
<div class="timeline-stop">
<i></i>
<span>BUS</span>
<strong id="timelineBus">09:00</strong>
</div>
</div>
<div id="result" class="result" aria-live="polite">
<strong id="resultTitle">Connection works</strong>
<p id="resultDetail">
You reach Central at 08:51 and have time to board.
</p>
</div>
<button id="useNextButton" class="planner-action" type="button">
USE NEXT FEASIBLE CONNECTION
</button>
</div>
</aside>
<div
id="ferryLabel"
class="scene-label"
data-station="ferry"
role="button"
tabindex="0"
aria-label="View Harbor Ferry Stop departures"
>
<span class="label-code">F2</span>
<span class="label-copy">
<strong>Harbor Ferry</strong>
<small>PIER 02</small>
</span>
</div>
<div
id="busLabel"
class="scene-label bus"
data-station="bus"
role="button"
tabindex="0"
aria-label="View Central Bus Station departures"
>
<span class="label-code">B24</span>
<span class="label-copy">
<strong>Central Bus</strong>
<small>BAY 04</small>
</span>
</div>
<div class="map-legend" aria-label="Map legend">
<span class="legend-item"><i class="legend-line"></i> Ferry F2</span>
<span class="legend-item"><i class="legend-line bus"></i> Bus B24</span>
<span class="legend-item"><i class="legend-line walk"></i> Walking path</span>
</div>
<div class="map-help">
Drag to orbit · Scroll to zoom · Select a stop
</div>
<div class="camera-controls" aria-label="Camera controls">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetView" type="button" aria-label="Reset camera">↺</button>
</div>
<nav class="mobile-nav" aria-label="Panels">
<button type="button" class="active" data-panel="board">BOARD</button>
<button type="button" data-panel="plan">TRANSFER</button>
</nav>
<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 $$ = (selector) => [...document.querySelectorAll(selector)];
const DAY_SECONDS = 24 * 60 * 60;
const WALK_SECONDS = 9 * 60;
const WALK_METERS = 650;
const schedules = {
ferry: {
route: "F2",
interval: 12,
first: 5 * 60 + 30,
last: 23 * 60 + 30,
destination: "Island Quay",
platform: "Pier 02"
},
bus: {
route: "B24",
interval: 10,
first: 5 * 60 + 40,
last: 23 * 60 + 40,
destination: "North Loop",
platform: "Bay 04"
}
};
const state = {
simSeconds: 8 * 3600 + 42 * 60,
playing: true,
speed: 60,
station: "ferry",
selectedFerry: null,
selectedBus: null,
scrubbing: false
};
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.domElement.id = "scene";
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfe3e6);
scene.fog = new THREE.Fog(0xbfe3e6, 31, 68);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
target: new THREE.Vector3(0.2, 0.4, -0.2),
theta: -0.29,
phi: 0.91,
radius: 31
};
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf0fcff, 0x7c836c, 2.3);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d4, 3.1);
sun.position.set(9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dddeb, 0.9);
fill.position.set(-12, 8, -8);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0
})
);
}
return materialCache.get(color);
}
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x7cd4e3,
transparent: true,
opacity: 0.56,
roughness: 0.18,
metalness: 0.08
});
function box(
width,
height,
depth,
color,
x,
y,
z,
parent = scene,
castShadow = true,
receiveShadow = false
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
typeof color === "number" ? material(color) : color
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
const stationPickables = [];
function stationBox(
width,
height,
depth,
color,
x,
y,
z,
station,
parent = scene
) {
const mesh = box(width, height, depth, color, x, y, z, parent);
mesh.userData.station = station;
stationPickables.push(mesh);
return mesh;
}
function makeSign(text, x, y, z, background, foreground, scale = 2.5) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.lineWidth = 8;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
context.fillStyle = foreground;
context.font = "900 58px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true
})
);
sprite.position.set(x, y, z);
sprite.scale.set(scale, scale * 0.25, 1);
scene.add(sprite);
return sprite;
}
// Water and land.
box(14.2, 0.38, 17, 0x4cb9c9, -9.7, -0.28, 0, scene, false, true);
box(18, 0.62, 17, 0x83a97d, 6.5, -0.31, 0, scene, false, true);
box(17.95, 0.09, 16.95, 0xaecb91, 6.5, 0.045, 0, scene, false, true);
box(0.3, 0.8, 16.6, 0xd7d1b5, -2.6, -0.02, 0, scene, false, true);
// Pixelated shoreline blocks.
for (let z = -7.4; z <= 7.5; z += 1.25) {
box(
0.38,
0.45 + (Math.sin(z * 1.7) + 1) * 0.08,
1.05,
0xd5d0b5,
-2.78,
0.04,
z,
scene,
false
);
}
// Water shimmer blocks.
const waves = [];
const waveMaterial = new THREE.MeshStandardMaterial({
color: 0xe5ffff,
transparent: true,
opacity: 0.48,
roughness: 0.4
});
for (let i = 0; i < 23; i++) {
const x = -15.6 + ((i * 3.71) % 12.4);
const z = -7.2 + ((i * 2.17) % 14.5);
const wave = box(
0.7 + (i % 3) * 0.22,
0.035,
0.12,
waveMaterial,
x,
-0.065,
z,
scene,
false
);
waves.push({
mesh: wave,
baseX: x,
phase: i * 0.73
});
}
// Road, curb, and lane markings.
box(18.4, 0.12, 3.2, 0x53636a, 6.55, 0.13, 4.7, scene, false, true);
box(18.4, 0.12, 0.7, 0xd7d5c5, 6.55, 0.15, 3.0, scene, false, true);
for (let x = -2; x < 15; x += 1.8) {
box(0.85, 0.025, 0.08, 0xf6edc9, x, 0.205, 4.7, scene, false);
}
// Walking path from pier to bus station.
box(4.2, 0.12, 0.88, 0xded8bf, -3.5, 0.15, 1.5, scene, false, true);
box(0.88, 0.12, 2.7, 0xded8bf, -1.4, 0.15, 0.15, scene, false, true);
box(5.4, 0.12, 0.88, 0xded8bf, 1.3, 0.15, -1.2, scene, false, true);
for (let i = 0; i < 12; i++) {
const x = -5.2 + i * 0.82;
box(
0.24,
0.035,
0.3,
i % 3 === 0 ? 0xf5a623 : 0x2bb7c3,
x,
0.235,
1.5,
scene,
false
);
}
// Ferry pier.
box(8.5, 0.3, 4.2, 0xb58b5b, -8, 0.02, 0.7, scene, false, true);
for (let x = -11.8; x < -4; x += 0.65) {
box(0.045, 0.025, 4.05, 0x866443, x, 0.19, 0.7, scene, false);
}
for (const x of [-11.8, -9.6, -7.4, -5.2, -4.25]) {
for (const z of [-1.1, 2.5]) {
box(0.28, 1.25, 0.28, 0x68503d, x, 0.53, z);
box(0.38, 0.16, 0.38, 0xe5dcc0, x, 1.18, z);
}
}
// Ferry terminal.
stationBox(3.8, 2, 2.25, 0xf4f0dc, -9, 1.18, 1.65, "ferry");
stationBox(4.2, 0.3, 2.65, 0x27b8c4, -9, 2.31, 1.65, "ferry");
box(3.6, 0.22, 2.35, 0x168895, -9, 0.2, 1.65, scene, false);
box(0.74, 1.25, 0.08, glassMaterial, -9.95, 1.25, 2.8);
box(1.05, 0.75, 0.09, glassMaterial, -8.45, 1.45, 2.8);
box(0.08, 1.28, 0.12, 0xf5a623, -9.3, 1.25, 2.86);
makeSign("FERRY", -9, 2.64, 2.86, "#168895", "#ffffff", 2.15);
// Bus shelter.
box(6.1, 0.16, 2.1, 0xd2cdb6, 5, 0.14, -1.2, scene, false, true);
stationBox(5.5, 0.28, 1.85, 0xf5a623, 5, 2.62, -1.2, "bus");
box(5.2, 1.45, 0.08, glassMaterial, 5, 1.5, -2.08);
for (const x of [2.45, 7.55]) {
box(0.15, 2.45, 0.15, 0x405a61, x, 1.28, -1.95);
box(0.15, 2.45, 0.15, 0x405a61, x, 1.28, -0.45);
}
box(3.2, 0.22, 0.55, 0x7a5d45, 4.65, 0.65, -1.55);
box(3.2, 0.65, 0.14, 0x7a5d45, 4.65, 0.93, -1.78);
makeSign("B24", 5.2, 2.88, -0.4, "#f5a623", "#493100", 1.25);
// Bus terminal building.
stationBox(5.4, 3, 2.8, 0xf0ecd8, 9.5, 1.6, -4.45, "bus");
stationBox(5.9, 0.28, 3.2, 0x2db8c4, 9.5, 3.23, -4.45, "bus");
box(1.15, 1.65, 0.08, glassMaterial, 8.5, 1.25, -3.01);
box(1.15, 1.65, 0.08, glassMaterial, 10.45, 1.25, -3.01);
makeSign("CENTRAL", 9.5, 3.58, -3, "#2db8c4", "#ffffff", 2.55);
// Small city buildings.
const buildingColors = [0xd5d8ca, 0xc6d1c8, 0xe6d4b4, 0xb9c9c4];
for (let i = 0; i < 5; i++) {
const x = 1.6 + i * 2.55;
const h = 1.6 + (i % 3) * 0.65;
box(1.8, h, 2.3, buildingColors[i % buildingColors.length], x, h / 2 + 0.1, -5.4);
box(1.95, 0.18, 2.45, 0x667a7b, x, h + 0.18, -5.4);
for (let row = 0; row < Math.floor(h / 0.75); row++) {
box(0.42, 0.42, 0.035, 0x789ca0, x - 0.42, 0.65 + row * 0.72, -4.23);
box(0.42, 0.42, 0.035, 0x789ca0, x + 0.42, 0.65 + row * 0.72, -4.23);
}
}
// Trees.
function makeTree(x, z, size = 1) {
box(0.32 * size, 1.3 * size, 0.32 * size, 0x8a6745, x, 0.65 * size, z);
box(
1.25 * size,
0.9 * size,
1.05 * size,
0x6f9f69,
x,
1.65 * size,
z
);
box(
0.8 * size,
0.65 * size,
0.85 * size,
0x86b875,
x - 0.12 * size,
2.22 * size,
z
);
}
[
[-0.3, -6.4, 1.05],
[1.1, -6.7, 0.85],
[12.8, -2.5, 1.1],
[14.0, 0.2, 0.9],
[0.5, 2.7, 0.72],
[10.8, 1.9, 0.78],
[14.1, 6.6, 0.9]
].forEach(([x, z, s]) => makeTree(x, z, s));
// Street lamps.
for (const [x, z] of [[0.2, 2.85], [7.8, 2.85], [14.3, 2.85]]) {
box(0.12, 2.65, 0.12, 0x4d666d, x, 1.38, z);
box(0.12, 0.12, 1.0, 0x4d666d, x, 2.67, z - 0.42);
box(0.38, 0.2, 0.55, 0xffe7a3, x, 2.57, z - 0.82);
}
// Ferry buoy route.
for (let x = -15; x <= -4; x += 2.2) {
box(0.28, 0.38, 0.28, 0xf5a623, x, -0.02, -3.7);
box(0.08, 0.35, 0.08, 0x52666d, x, 0.28, -3.7);
}
// Voxel ferry.
const ferry = new THREE.Group();
scene.add(ferry);
box(3.8, 0.48, 1.45, 0x246f7a, 0, 0.23, 0, ferry);
box(3.55, 0.18, 1.5, 0xf5a623, 0, 0.54, 0, ferry);
box(2.5, 0.9, 1.18, 0xf6f1dc, -0.2, 1.04, 0, ferry);
box(2.72, 0.18, 1.32, 0x23b9c4, -0.2, 1.58, 0, ferry);
box(0.12, 0.52, 1.2, 0xf6f1dc, 1.45, 0.86, 0, ferry);
box(0.04, 0.32, 0.32, 0x72cbd5, -0.2, 1.18, 0.61);
for (const x of [-1.1, -0.65, -0.2, 0.25, 0.7]) {
box(0.32, 0.35, 0.035, glassMaterial, x, 1.18, 0.605, ferry);
}
// Voxel bus.
const bus = new THREE.Group();
scene.add(bus);
box(3.1, 1.15, 1.35, 0xf5a623, 0, 0.75, 0, bus);
box(2.85, 0.2, 1.4, 0xffd27e, 0, 1.4, 0, bus);
for (const x of [-1.05, -0.45, 0.15, 0.75]) {
box(0.43, 0.5, 0.035, glassMaterial, x, 1.02, 0.69, bus);
box(0.43, 0.5, 0.035, glassMaterial, x, 1.02, -0.69, bus);
}
box(0.035, 0.48, 1.02, glassMaterial, 1.56, 1.05, 0, bus);
box(0.12, 0.18, 1.48, 0x49565a, 0, 0.22, 0, bus);
for (const x of [-1.02, 1.02]) {
for (const z of [-0.71, 0.71]) {
box(0.48, 0.48, 0.17, 0x26383d, x, 0.24, z, bus);
}
}
// Walking passengers.
const walkingPath = [
new THREE.Vector3(-5.3, 0.35, 1.5),
new THREE.Vector3(-1.4, 0.35, 1.5),
new THREE.Vector3(-1.4, 0.35, -1.2),
new THREE.Vector3(4.0, 0.35, -1.2)
];
const pathLengths = [];
let totalPathLength = 0;
for (let i = 0; i < walkingPath.length - 1; i++) {
const length = walkingPath[i].distanceTo(walkingPath[i + 1]);
pathLengths.push(length);
totalPathLength += length;
}
function pointOnPath(progress) {
let remaining = progress * totalPathLength;
for (let i = 0; i < pathLengths.length; i++) {
if (remaining <= pathLengths[i]) {
const t = remaining / pathLengths[i];
return walkingPath[i].clone().lerp(walkingPath[i + 1], t);
}
remaining -= pathLengths[i];
}
return walkingPath[walkingPath.length - 1].clone();
}
const people = [];
const personColors = [0xe66969, 0x426f9d, 0x845b9e, 0xe7a63a, 0x3c8f79];
for (let i = 0; i < 5; i++) {
const group = new THREE.Group();
scene.add(group);
box(0.22, 0.38, 0.22, personColors[i], 0, 0.21, 0, group);
box(0.24, 0.23, 0.24, 0xe7b68f, 0, 0.53, 0, group);
box(0.1, 0.12, 0.26, 0x334950, 0, 0.68, 0, group);
people.push({
group,
offset: i / 5,
direction: i % 2 === 0 ? 1 : -1
});
}
// Simple voxel clouds.
const clouds = [];
for (let i = 0; i < 5; i++) {
const cloud = new THREE.Group();
scene.add(cloud);
box(1.7, 0.5, 0.8, 0xf5fbf7, 0, 0, 0, cloud, false);
box(1.1, 0.8, 0.8, 0xf5fbf7, -0.45, 0.23, 0, cloud, false);
box(1.25, 0.7, 0.8, 0xf5fbf7, 0.5, 0.16, 0, cloud, false);
cloud.position.set(-14 + i * 6.4, 7.5 + (i % 2) * 0.7, -6 + (i % 3) * 3.5);
clouds.push(cloud);
}
// Projected HTML labels.
const projectedLabels = [
{
element: $("#ferryLabel"),
anchor: new THREE.Vector3(-9, 3.3, 1.65)
},
{
element: $("#busLabel"),
anchor: new THREE.Vector3(5.1, 3.25, -1.2)
}
];
function updateProjectedLabels() {
for (const label of projectedLabels) {
const point = label.anchor.clone().project(camera);
const visible = point.z > -1 && point.z < 1;
label.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (point.x * 0.5 + 0.5) * window.innerWidth;
const y = (-point.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// Time and timetable helpers.
function formatTime(seconds) {
const dayTime = ((seconds % DAY_SECONDS) + DAY_SECONDS) % DAY_SECONDS;
const hours = Math.floor(dayTime / 3600);
const minutes = Math.floor((dayTime % 3600) / 60);
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
}
function formatClock(seconds) {
const dayTime = ((seconds % DAY_SECONDS) + DAY_SECONDS) % DAY_SECONDS;
const hours = Math.floor(dayTime / 3600);
const minutes = Math.floor((dayTime % 3600) / 60);
const secs = Math.floor(dayTime % 60);
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
}
function dayName(seconds) {
const currentDay = Math.floor(state.simSeconds / DAY_SECONDS);
const departureDay = Math.floor(seconds / DAY_SECONDS);
const difference = departureDay - currentDay;
if (difference === 0) return "TODAY";
if (difference === 1) return "TOMORROW";
return `DAY ${difference + 1}`;
}
function relativeLabel(seconds) {
const difference = Math.max(0, seconds - state.simSeconds);
const minutes = Math.floor(difference / 60);
if (minutes === 0) return "NOW";
if (minutes === 1) return "1 MIN";
return `${minutes} MIN`;
}
function getDepartures(type, count, fromSeconds = state.simSeconds) {
const config = schedules[type];
const result = [];
const startMinute = Math.floor(fromSeconds / 60);
for (let day = 0; day < 3 && result.length < count; day++) {
for (
let minute = config.first;
minute <= config.last;
minute += config.interval
) {
const timestamp = day * DAY_SECONDS + minute * 60;
if (timestamp >= startMinute * 60) {
result.push(timestamp);
if (result.length === count) break;
}
}
}
return result;
}
function selectStation(station) {
state.station = station;
$$(".station-tabs button").forEach((button) => {
const active = button.dataset.station === station;
button.classList.toggle("active", active);
button.setAttribute("aria-selected", String(active));
});
renderBoard();
}
function renderBoard() {
const isFerry = state.station === "ferry";
const type = state.station;
const config = schedules[type];
const departures = getDepartures(type, 6);
$("#stationName").textContent = isFerry
? "Harbor Ferry Stop"
: "Central Bus Station";
$("#stationSubtitle").textContent = isFerry
? "Waterfront edge · Ferry service to Island Quay"
: "Bay Avenue · Frequent service around the district";
$("#serviceName").textContent = isFerry
? "Harbor → Island Quay"
: "Central → North Loop";
$("#serviceMeta").textContent = isFerry
? "F2 · Every 12 minutes · Pier 02"
: "B24 · Every 10 minutes · Bay 04";
$("#routeBadge").textContent = config.route;
$("#routeBadge").classList.toggle("bus", !isFerry);
$("#boardDate").textContent = dayName(departures[0]);
$("#departureList").innerHTML = departures
.map((timestamp) => {
const relative = relativeLabel(timestamp);
const soon = relative === "NOW" || relative === "1 MIN";
return `
<button
class="departure-row ${isFerry ? "ferry" : "bus"}"
type="button"
data-timestamp="${timestamp}"
data-type="${type}"
aria-label="${config.destination} at ${formatTime(timestamp)}"
>
<span class="departure-time">${formatTime(timestamp)}</span>
<span>
<span class="destination">${config.destination}</span>
<span class="platform">${config.route} · ${config.platform}</span>
</span>
<span class="relative-time ${soon ? "soon" : ""}">${relative}</span>
</button>
`;
})
.join("");
$("#scheduleNote").textContent =
`Repeating timetable · First ${String(Math.floor(config.first / 60)).padStart(2, "0")}:${String(config.first % 60).padStart(2, "0")}` +
` · Last ${String(Math.floor(config.last / 60)).padStart(2, "0")}:${String(config.last % 60).padStart(2, "0")}` +
` · Every ${config.interval} minutes`;
}
function optionLabel(timestamp) {
const prefix = dayName(timestamp) === "TODAY" ? "" : `${dayName(timestamp)} `;
return `${prefix}${formatTime(timestamp)}`;
}
function chooseFeasibleBus(ferryTimestamp) {
const options = getDepartures("bus", 30, state.simSeconds);
return options.find((time) => time >= ferryTimestamp + WALK_SECONDS);
}
function renderPlanner() {
const ferryOptions = getDepartures("ferry", 7);
if (
state.selectedFerry === null ||
!ferryOptions.includes(state.selectedFerry)
) {
state.selectedFerry = ferryOptions[0];
}
const busOptions = getDepartures("bus", 14);
if (
state.selectedBus === null ||
!busOptions.includes(state.selectedBus)
) {
state.selectedBus =
busOptions.find(
(time) => time >= state.selectedFerry + WALK_SECONDS
) ?? busOptions[0];
}
$("#ferrySelect").innerHTML = ferryOptions
.map(
(timestamp) =>
`<option value="${timestamp}">${optionLabel(timestamp)} arrival</option>`
)
.join("");
$("#busSelect").innerHTML = busOptions
.map(
(timestamp) =>
`<option value="${timestamp}">${optionLabel(timestamp)} departure</option>`
)
.join("");
$("#ferrySelect").value = state.selectedFerry;
$("#busSelect").value = state.selectedBus;
const walkArrival = state.selectedFerry + WALK_SECONDS;
const waitSeconds = state.selectedBus - walkArrival;
$("#timelineFerry").textContent = formatTime(state.selectedFerry);
$("#timelineBus").textContent = formatTime(state.selectedBus);
const result = $("#result");
result.classList.remove("tight", "failed");
if (waitSeconds >= 0) {
const waitMinutes = Math.floor(waitSeconds / 60);
const tight = waitMinutes < 3;
result.classList.toggle("tight", tight);
$("#resultTitle").textContent = tight
? "Tight but possible"
: "Connection works";
$("#resultDetail").textContent =
`You reach Central at ${formatTime(walkArrival)}. ` +
(waitMinutes === 0
? "The bus leaves as you arrive."
: `You have ${waitMinutes} minute${waitMinutes === 1 ? "" : "s"} to board.`);
} else {
const missedBy = Math.ceil(Math.abs(waitSeconds) / 60);
const nextBus = chooseFeasibleBus(state.selectedFerry);
result.classList.add("failed");
$("#resultTitle").textContent = `Connection missed by ${missedBy} min`;
$("#resultDetail").textContent = nextBus
? `You reach Central at ${formatTime(walkArrival)}. The next possible bus is at ${formatTime(nextBus)}.`
: `You reach Central at ${formatTime(walkArrival)}. No later service is available today.`;
}
}
function renderAll() {
renderBoard();
renderPlanner();
}
// UI events.
$("#departureList").addEventListener("click", (event) => {
const row = event.target.closest(".departure-row");
if (!row) return;
const timestamp = Number(row.dataset.timestamp);
if (row.dataset.type === "ferry") {
state.selectedFerry = timestamp;
const nextBus = chooseFeasibleBus(timestamp);
if (nextBus !== undefined) state.selectedBus = nextBus;
} else {
state.selectedBus = timestamp;
}
renderPlanner();
});
$("#ferrySelect").addEventListener("change", (event) => {
state.selectedFerry = Number(event.target.value);
const nextBus = chooseFeasibleBus(state.selectedFerry);
if (nextBus !== undefined) state.selectedBus = nextBus;
renderPlanner();
});
$("#busSelect").addEventListener("change", (event) => {
state.selectedBus = Number(event.target.value);
renderPlanner();
});
$("#useNextButton").addEventListener("click", () => {
const ferryTime = getDepartures("ferry", 1)[0];
const busTime = chooseFeasibleBus(ferryTime);
state.selectedFerry = ferryTime;
state.selectedBus = busTime ?? getDepartures("bus", 1)[0];
renderPlanner();
});
$$(".station-tabs button").forEach((button) => {
button.addEventListener("click", () => selectStation(button.dataset.station));
});
$$(".scene-label").forEach((label) => {
const activate = () => selectStation(label.dataset.station);
label.addEventListener("click", activate);
label.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
activate();
}
});
});
$$(".mobile-nav button").forEach((button) => {
button.addEventListener("click", () => {
const panel = button.dataset.panel;
document.body.classList.toggle("show-board", panel === "board");
document.body.classList.toggle("show-plan", panel === "plan");
$$(".mobile-nav button").forEach((item) => {
item.classList.toggle("active", item === button);
});
});
});
$("#playButton").addEventListener("click", () => {
state.playing = !state.playing;
$("#playButton").textContent = state.playing ? "❚❚" : "▶";
$("#playButton").setAttribute("aria-pressed", String(state.playing));
$("#playButton").setAttribute(
"aria-label",
state.playing ? "Pause simulation" : "Play simulation"
);
});
$("#speedButton").addEventListener("click", () => {
const speeds = [1, 60, 300];
const current = speeds.indexOf(state.speed);
state.speed = speeds[(current + 1) % speeds.length];
$("#speedButton").textContent = `${state.speed}×`;
});
$("#timeRange").addEventListener("pointerdown", () => {
state.scrubbing = true;
});
window.addEventListener("pointerup", () => {
state.scrubbing = false;
});
$("#timeRange").addEventListener("input", (event) => {
state.simSeconds = Number(event.target.value) * 60;
renderAll();
});
// Custom camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let dragDistance = 0;
let previousX = 0;
let previousY = 0;
function pickStation(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(stationPickables, false)[0];
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragDistance = 0;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) {
renderer.domElement.style.cursor = pickStation(event)
? "pointer"
: "grab";
return;
}
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.004,
0.48,
1.25
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (dragDistance < 7) {
const hit = pickStation(event);
if (hit) selectStation(hit.object.userData.station);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.015,
20,
46
);
updateCamera();
},
{ passive: false }
);
$("#zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(20, cameraState.radius - 2);
updateCamera();
});
$("#zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(46, cameraState.radius + 2);
updateCamera();
});
$("#resetView").addEventListener("click", () => {
cameraState.theta = -0.29;
cameraState.phi = 0.91;
cameraState.radius = 31;
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// Initialize the planner.
const firstFerry = getDepartures("ferry", 1)[0];
state.selectedFerry = firstFerry;
state.selectedBus = chooseFeasibleBus(firstFerry);
renderAll();
let lastFrame = performance.now();
let lastMinute = Math.floor(state.simSeconds / 60);
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastFrame) / 1000, 0.1);
lastFrame = now;
if (state.playing) {
state.simSeconds =
(state.simSeconds + delta * state.speed) % DAY_SECONDS;
}
$("#clock").textContent = formatClock(state.simSeconds);
if (!state.scrubbing) {
$("#timeRange").value = Math.floor(state.simSeconds / 60);
const progress = (state.simSeconds / DAY_SECONDS) * 100;
$("#timeRange").style.background =
`linear-gradient(90deg, #21b8c5 0%, #21b8c5 ${progress}%, #dce5e3 ${progress}%, #dce5e3 100%)`;
}
const currentMinute = Math.floor(state.simSeconds / 60);
if (currentMinute !== lastMinute) {
lastMinute = currentMinute;
renderAll();
}
const virtualMinutes = state.simSeconds / 60;
// Ferry returns to the pier on the repeating 12-minute schedule.
const ferryPhase = (virtualMinutes % 12) / 12;
const ferryTravel = 0.5 - 0.5 * Math.cos(ferryPhase * Math.PI * 2);
ferry.position.set(
-9 - ferryTravel * 7.2,
0.12 + Math.sin(now * 0.0018) * 0.035,
-2.02
);
ferry.rotation.z = Math.sin(now * 0.0012) * 0.008;
// Bus follows the district road.
const busPhase = (virtualMinutes % 4.2) / 4.2;
bus.position.set(
-1 + busPhase * 16.5,
0.22,
4.7
);
// Passengers move along the walking path.
people.forEach((person, index) => {
let progress = (virtualMinutes / 9 + person.offset) % 1;
if (person.direction < 0) progress = 1 - progress;
const point = pointOnPath(progress);
person.group.position.copy(point);
person.group.position.y += Math.abs(Math.sin(now * 0.005 + index)) * 0.025;
person.group.rotation.y =
person.direction > 0 ? 0 : Math.PI;
});
waves.forEach((wave) => {
wave.mesh.position.x =
wave.baseX + Math.sin(now * 0.0007 + wave.phase) * 0.28;
});
clouds.forEach((cloud, index) => {
cloud.position.x += delta * (0.06 + index * 0.008);
if (cloud.position.x > 18) cloud.position.x = -18;
});
camera.updateMatrixWorld();
updateProjectedLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```