Prompt specification
Build or customize the Three.js 3D scene "Coordinate a fictional community carpool schedule" 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: Coordinate a fictional community carpool schedule
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coordinate-a-fictional-community-carpool-schedule-x2452
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring the Montgomery Bus Boycott of 1955–1956. Let users match illustrative riders and vehicles subject to capacity and destination constraints. Relate the coordination problem to the historical context without reducing the movement's goals to efficiency. Voxel style.
Working Three.js Starter (coordinate-a-fictional-community-carpool-schedule-x2452):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A Seat for Every Story — Montgomery Bus Boycott</title>
<style>
:root {
--ink: #17242d;
--paper: #f5ecd9;
--cream: #fffaf0;
--line: #17242d;
--orange: #d86543;
--green: #4c956c;
--blue: #277da1;
--yellow: #e9c46a;
--church: #d97745;
--south: #2a9d8f;
--north: #6266ad;
--muted: #66727a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9c6cf;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", "Courier New", monospace;
}
button {
font: inherit;
}
button:focus-visible {
outline: 4px solid #fff3a6;
outline-offset: 3px;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
pointer-events: auto;
background: rgba(255, 250, 240, 0.94);
border: 3px solid var(--line);
box-shadow: 7px 7px 0 rgba(23, 36, 45, 0.28);
backdrop-filter: blur(5px);
}
.masthead {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(410px, calc(100vw - 40px));
padding: 18px 19px 16px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--orange);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.masthead .intro {
margin: 11px 0 13px;
max-width: 360px;
color: #4d5960;
font-family: system-ui, sans-serif;
font-size: 14px;
line-height: 1.45;
}
.text-button,
.small-button {
border: 2px solid var(--line);
background: var(--ink);
color: var(--cream);
padding: 8px 11px;
cursor: pointer;
font-weight: 800;
box-shadow: 3px 3px 0 var(--orange);
}
.text-button:hover,
.small-button:hover {
transform: translate(1px, 1px);
box-shadow: 2px 2px 0 var(--orange);
}
.dispatch {
position: fixed;
z-index: 12;
top: 20px;
right: 20px;
width: 370px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 16px;
scrollbar-width: thin;
scrollbar-color: var(--line) transparent;
}
.dispatch-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.dispatch h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.04em;
}
.dispatch-note {
margin: 0 0 13px;
color: var(--muted);
font-family: system-ui, sans-serif;
font-size: 13px;
line-height: 1.4;
}
.section-label {
display: flex;
align-items: center;
gap: 8px;
margin: 15px 0 8px;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-label::after {
content: "";
height: 3px;
flex: 1;
background: var(--line);
opacity: 0.18;
}
#selection-info {
min-height: 72px;
padding: 11px;
border: 2px dashed rgba(23, 36, 45, 0.38);
background: rgba(23, 36, 45, 0.035);
font-family: system-ui, sans-serif;
font-size: 13px;
line-height: 1.4;
}
#selection-info strong {
display: block;
margin-bottom: 4px;
font-family: ui-monospace, monospace;
font-size: 14px;
}
.selection-actions {
display: flex;
gap: 8px;
margin-top: 9px;
}
.selection-actions button {
border: 0;
padding: 0;
background: transparent;
color: #9c3d28;
text-decoration: underline;
cursor: pointer;
font-weight: 800;
}
.vehicle-list {
display: grid;
gap: 8px;
}
.vehicle-card {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 48px 1fr;
gap: 10px;
padding: 10px;
border: 2px solid var(--line);
background: var(--cream);
color: var(--ink);
text-align: left;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(23, 36, 45, 0.2);
}
.vehicle-card:hover {
transform: translateY(-1px);
box-shadow: 4px 5px 0 rgba(23, 36, 45, 0.25);
}
.vehicle-card.compatible {
outline: 4px solid rgba(233, 196, 106, 0.8);
outline-offset: 1px;
}
.vehicle-card.incompatible {
opacity: 0.48;
}
.vehicle-card.full {
background: #f2ddd4;
}
.vehicle-icon {
width: 44px;
height: 27px;
align-self: center;
position: relative;
border: 3px solid var(--line);
background: var(--vehicle-color);
box-shadow: inset 0 -7px 0 rgba(23, 36, 45, 0.12);
}
.vehicle-icon::before {
content: "";
position: absolute;
left: 4px;
right: 4px;
top: 4px;
height: 7px;
border: 2px solid var(--line);
background: #b9d9dc;
}
.vehicle-icon::after {
content: "";
position: absolute;
left: 4px;
right: 4px;
bottom: -8px;
height: 6px;
border-left: 5px solid var(--line);
border-right: 5px solid var(--line);
}
.vehicle-icon.car {
width: 42px;
height: 20px;
margin-top: 6px;
}
.vehicle-icon.car::before {
left: 11px;
right: 8px;
top: -9px;
height: 9px;
}
.vehicle-icon.car::after {
left: 5px;
right: 5px;
bottom: -7px;
}
.vehicle-title {
display: flex;
justify-content: space-between;
gap: 8px;
align-items: baseline;
font-weight: 900;
font-size: 13px;
}
.vehicle-route {
margin-top: 4px;
color: #4d5960;
font-family: system-ui, sans-serif;
font-size: 12px;
}
.seat-row {
display: flex;
align-items: center;
gap: 4px;
margin-top: 7px;
}
.seat {
width: 11px;
height: 11px;
border: 2px solid var(--line);
background: transparent;
}
.seat.filled {
background: var(--vehicle-color);
}
.occupancy {
margin-left: 4px;
color: #5a656c;
font-size: 10px;
font-weight: 800;
}
.passenger-line {
margin-top: 5px;
color: #5a656c;
font-family: system-ui, sans-serif;
font-size: 11px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.rider-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.rider-card {
min-width: 0;
display: grid;
grid-template-columns: 36px 1fr;
gap: 8px;
align-items: center;
padding: 9px 8px;
border: 2px solid var(--line);
background: var(--cream);
color: var(--ink);
text-align: left;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(23, 36, 45, 0.17);
}
.rider-card:hover {
transform: translateY(-1px);
}
.rider-card.selected {
background: #fff0ba;
outline: 4px solid var(--yellow);
outline-offset: 1px;
}
.rider-card.assigned {
background: #e2eee3;
}
.rider-name {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 11px;
font-weight: 900;
}
.rider-destination {
display: block;
margin-top: 3px;
color: var(--destination-color);
font-size: 9px;
font-weight: 900;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.rider-state {
display: block;
margin-top: 4px;
color: #707a80;
font-family: system-ui, sans-serif;
font-size: 10px;
line-height: 1.1;
}
.pixel-person {
--skin: #8d5524;
--hair: #241b16;
--coat: #d86543;
position: relative;
width: 34px;
height: 44px;
flex: none;
}
.pixel-person::before {
content: "";
position: absolute;
z-index: 2;
left: 11px;
top: 3px;
width: 13px;
height: 13px;
background: var(--skin);
box-shadow:
0 -4px 0 var(--hair),
-3px 10px 0 -2px var(--skin),
3px 10px 0 -2px var(--skin);
}
.pixel-person::after {
content: "";
position: absolute;
left: 7px;
top: 18px;
width: 21px;
height: 20px;
background: var(--coat);
box-shadow:
-5px 7px 0 -3px var(--skin),
5px 7px 0 -3px var(--skin),
-6px 21px 0 -4px #26343d,
6px 21px 0 -4px #26343d;
}
.dispatch-footer {
margin: 12px 0 0;
padding-top: 10px;
border-top: 2px solid rgba(23, 36, 45, 0.15);
color: #68747a;
font-family: system-ui, sans-serif;
font-size: 10px;
line-height: 1.4;
}
.field-note {
position: fixed;
z-index: 9;
left: 20px;
bottom: 20px;
width: 340px;
padding: 14px 15px;
border-left: 8px solid var(--orange);
}
.field-note h3 {
margin: 0 0 6px;
font-size: 13px;
letter-spacing: -0.02em;
}
.field-note p {
margin: 0;
color: #4e5b62;
font-family: system-ui, sans-serif;
font-size: 12px;
line-height: 1.45;
}
.camera-controls {
position: fixed;
z-index: 15;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 5px;
padding: 6px;
background: rgba(23, 36, 45, 0.9);
border: 2px solid #101820;
box-shadow: 4px 4px 0 rgba(23, 36, 45, 0.25);
}
.camera-controls button {
width: 32px;
height: 30px;
border: 2px solid #101820;
background: var(--cream);
color: var(--ink);
cursor: pointer;
font-weight: 900;
}
.camera-controls button:hover {
background: var(--yellow);
}
.camera-help {
padding: 0 8px;
color: #e9e2d4;
font-family: system-ui, sans-serif;
font-size: 10px;
white-space: nowrap;
}
#toast {
position: fixed;
z-index: 40;
left: 50%;
top: 20px;
transform: translate(-50%, -20px);
max-width: min(520px, calc(100vw - 32px));
padding: 11px 15px;
border: 3px solid var(--line);
background: var(--cream);
box-shadow: 5px 5px 0 rgba(23, 36, 45, 0.28);
color: var(--ink);
font-family: system-ui, sans-serif;
font-size: 13px;
font-weight: 700;
line-height: 1.35;
opacity: 0;
pointer-events: none;
transition: opacity 160ms, transform 160ms;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
dialog {
width: min(720px, calc(100vw - 28px));
max-height: calc(100vh - 40px);
overflow: auto;
padding: 0;
border: 4px solid var(--line);
background: var(--cream);
color: var(--ink);
box-shadow: 12px 12px 0 rgba(23, 36, 45, 0.35);
}
dialog::backdrop {
background: rgba(16, 24, 32, 0.74);
backdrop-filter: blur(3px);
}
.dialog-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
padding: 22px 24px 17px;
border-bottom: 3px solid var(--line);
background: var(--paper);
}
.dialog-head h2 {
margin: 0;
max-width: 540px;
font-size: clamp(24px, 4vw, 37px);
line-height: 1;
letter-spacing: -0.05em;
}
.dialog-head button {
width: 35px;
height: 35px;
flex: none;
border: 2px solid var(--line);
background: var(--cream);
cursor: pointer;
font-size: 18px;
font-weight: 900;
}
.dialog-body {
padding: 20px 24px 26px;
font-family: system-ui, sans-serif;
font-size: 14px;
line-height: 1.6;
}
.dialog-body p {
margin: 0 0 13px;
}
.dialog-body h3 {
margin: 22px 0 8px;
font-family: ui-monospace, monospace;
font-size: 17px;
}
.timeline {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 9px;
margin: 18px 0;
}
.timeline article {
padding: 12px;
border: 2px solid var(--line);
background: #f7efdf;
}
.timeline strong {
display: block;
margin-bottom: 5px;
color: var(--orange);
font-family: ui-monospace, monospace;
font-size: 12px;
}
.principle {
padding: 14px 16px;
border-left: 8px solid var(--green);
background: #e5eee3;
}
.disclaimer {
margin-top: 18px;
padding-top: 13px;
border-top: 2px solid rgba(23, 36, 45, 0.16);
color: #66727a;
font-size: 12px;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #a9c6cf;
color: var(--ink);
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#loading.hidden { display: none; }
@media (max-width: 900px) {
.masthead {
top: 12px;
left: 12px;
width: min(355px, calc(100vw - 24px));
padding: 13px;
}
.masthead .intro { display: none; }
.dispatch {
top: auto;
right: 0;
bottom: 0;
left: 0;
width: 100%;
max-height: 47vh;
border-right: 0;
border-bottom: 0;
border-left: 0;
box-shadow: 0 -6px 0 rgba(23, 36, 45, 0.25);
padding: 12px;
}
.dispatch-note { margin-bottom: 8px; }
.field-note { display: none; }
.camera-controls {
top: 112px;
bottom: auto;
left: 12px;
transform: none;
}
.camera-help { display: none; }
.timeline { grid-template-columns: 1fr; }
}
@media (max-width: 500px) {
.rider-grid { grid-template-columns: 1fr; }
.dispatch { max-height: 52vh; }
.dispatch-note { font-size: 12px; }
.dialog-body { padding: 16px; }
.dialog-head { padding: 17px; }
}
</style>
</head>
<body>
<div
id="scene"
role="img"
aria-label="Interactive voxel street scene with buses, a volunteer carpool, and Montgomery residents waiting for a ride."
></div>
<header class="masthead panel">
<p class="eyebrow">Montgomery, Alabama · 1955–1956</p>
<h1>A Seat for Every Story</h1>
<p class="intro">
Match residents with rides that reach their destinations. The dispatch board
models one small part of a much larger community struggle.
</p>
<button class="text-button" id="open-history">Read the historical frame →</button>
</header>
<aside class="dispatch panel" aria-label="Rider and vehicle matching board">
<div class="dispatch-heading">
<div>
<p class="eyebrow" style="margin-bottom: 5px;">Community Dispatch</p>
<h2>Make a plan for everyone</h2>
</div>
</div>
<p class="dispatch-note">
Select a person, then choose a compatible vehicle in the board or directly
in the scene. There is no score and no timer.
</p>
<div id="selection-info" aria-live="polite"></div>
<div class="section-label">Vehicles</div>
<div class="vehicle-list" id="vehicle-list"></div>
<div class="section-label">Riders</div>
<div class="rider-grid" id="rider-list"></div>
<p class="dispatch-footer">
This is a fictionalized teaching puzzle. Names, personal circumstances,
routes, and capacities are illustrative rather than an archival transit map.
</p>
</aside>
<section class="field-note panel">
<h3>Coordination is not merely throughput.</h3>
<p>
The boycott was not simply a transportation problem. It was a sustained
effort to challenge racial segregation, protect dignity and safety, and
turn collective action into constitutional change.
</p>
</section>
<nav class="camera-controls" aria-label="Scene camera controls">
<button id="camera-left" title="Rotate left" aria-label="Rotate left">↶</button>
<button id="camera-zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
<button id="camera-reset" title="Reset camera" aria-label="Reset camera">⌂</button>
<button id="camera-zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button id="camera-right" title="Rotate right" aria-label="Rotate right">↷</button>
<span class="camera-help">Drag to orbit · Scroll to zoom · Click a person or ride</span>
</nav>
<div id="toast" role="status" aria-live="polite"></div>
<dialog id="history-dialog" aria-labelledby="history-title">
<div class="dialog-head">
<h2 id="history-title">Read the movement—not just the schedule.</h2>
<button id="close-history" aria-label="Close historical context">×</button>
</div>
<div class="dialog-body">
<p>
On December 1, 1955, Rosa Parks was arrested in Montgomery after
refusing to give up her seat to a white passenger in violation of the
city’s bus-segregation rules. The arrest helped prompt Black residents
and local activists to organize a boycott of Montgomery’s segregated
bus system.
</p>
<div class="timeline">
<article>
<strong>December 1, 1955</strong>
Rosa Parks is arrested. Organizers begin building a coordinated
response, including support for Parks and others facing arrest.
</article>
<article>
<strong>December 5, 1955</strong>
The 381-day boycott begins. Many residents walk, use volunteer
carpools, or find other ways to travel while buses are boycotted.
</article>
<article>
<strong>December 20, 1956</strong>
After the Supreme Court’s Browder v. Gayle decision rules bus
segregation unconstitutional, Montgomery buses begin operating without
racial segregation.
</article>
</div>
<h3>What the puzzle can—and cannot—show</h3>
<p>
The dispatch board illustrates a narrow logistical slice: destinations,
seats, and the need to coordinate shared transportation. It cannot
represent the full history. The movement depended on meetings, trust,
household labor, economic pressure, legal organizing, mutual aid, and
the willingness to accept risk in the face of intimidation.
</p>
<div class="principle">
<strong>The larger goals were dignity, equal access, safety, solidarity,
and legal change.</strong> A perfectly filled bus was never the point.
The boycott worked because a community collectively refused to accept a
segregated system as normal or unavoidable.
</div>
<h3>How to play</h3>
<p>
Select a rider and choose a vehicle that serves that rider’s destination
and still has an open seat. Riders may be moved between vehicles, and
an assigned rider can be returned to the sidewalk. The puzzle is
deliberately constrained but has no score.
</p>
<p class="disclaimer">
Historical framing is condensed for an interactive learning experience.
All rider names and personal circumstances are fictional composites.
Vehicle capacities and route combinations are invented for the puzzle.
</p>
</div>
</dialog>
<div id="loading">Building Montgomery…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Historical teaching data
// ------------------------------------------------------------
const destinationColors = {
church: "#d97745",
south: "#2a9d8f",
north: "#6266ad"
};
const destinationNames = {
church: "Church Street",
south: "Southside",
north: "Northside"
};
const riders = [
{
id: "beatrice",
name: "Beatrice Hall",
destination: "church",
note: "Needs to reach the courthouse before work.",
skin: "#8d5524",
hair: "#241b16",
coat: "#d86543"
},
{
id: "ruthie",
name: "Ruthie Coleman",
destination: "church",
note: "Cares for two children after school.",
skin: "#6f4e37",
hair: "#171313",
coat: "#e9c46a"
},
{
id: "thomas",
name: "Thomas Reed",
destination: "church",
note: "Taking a class downtown.",
skin: "#a56b45",
hair: "#201a16",
coat: "#457b9d"
},
{
id: "nathaniel",
name: "Nathaniel Brooks",
destination: "south",
note: "Returning from a shift as a hospital porter.",
skin: "#744c35",
hair: "#171313",
coat: "#2a9d8f"
},
{
id: "louise",
name: "Louise Carter",
destination: "south",
note: "Keeping an evening appointment.",
skin: "#9c6645",
hair: "#2b1b16",
coat: "#8ab17d"
},
{
id: "samuel",
name: "Samuel Price",
destination: "south",
note: "Picking up supplies for a neighborhood store.",
skin: "#70452f",
hair: "#181311",
coat: "#6d597a"
},
{
id: "ellis",
name: "Ellis Ward",
destination: "north",
note: "Making a medical appointment.",
skin: "#98613f",
hair: "#211815",
coat: "#6266ad"
},
{
id: "maya",
name: "Maya Thompson",
destination: "north",
note: "Meeting a neighborhood support group.",
skin: "#6f4933",
hair: "#201512",
coat: "#c1666b"
},
{
id: "ada",
name: "Ada Whitfield",
destination: "north",
note: "Heading to a civic meeting.",
skin: "#a56d4b",
hair: "#241915",
coat: "#3d7c8c"
}
];
const vehicles = [
{
id: "green",
name: "Green bus",
label: "GREEN BUS",
subtitle: "CHURCH + NORTHSIDE",
kind: "bus",
color: "#4c956c",
serves: ["church", "north"],
capacity: 4,
x: -7
},
{
id: "blue",
name: "Blue bus",
label: "BLUE BUS",
subtitle: "SOUTHSIDE",
kind: "bus",
color: "#277da1",
serves: ["south"],
capacity: 3,
x: 0
},
{
id: "car",
name: "Volunteer carpool",
label: "VOLUNTEER CARPOOL",
subtitle: "NORTHSIDE",
kind: "car",
color: "#e9c46a",
serves: ["north"],
capacity: 2,
x: 7
}
];
const riderById = new Map(riders.map(r => [r.id, r]));
const vehicleById = new Map(vehicles.map(v => [v.id, v]));
const assignments = new Map();
let selectedRiderId = null;
let toastTimer = null;
// ------------------------------------------------------------
// UI helpers
// ------------------------------------------------------------
const riderList = document.querySelector("#rider-list");
const vehicleList = document.querySelector("#vehicle-list");
const selectionInfo = document.querySelector("#selection-info");
const toastElement = document.querySelector("#toast");
const historyDialog = document.querySelector("#history-dialog");
function passengersFor(vehicleId) {
return riders
.filter(rider => assignments.get(rider.id) === vehicleId)
.map(rider => rider.id);
}
function pixelPerson(rider) {
return `
<span
class="pixel-person"
style="--skin:${rider.skin};--hair:${rider.hair};--coat:${rider.coat}"
aria-hidden="true"
></span>
`;
}
function renderVehicles() {
const selected = selectedRiderId
? riderById.get(selectedRiderId)
: null;
vehicleList.innerHTML = vehicles.map(vehicle => {
const passengerIds = passengersFor(vehicle.id);
const full = passengerIds.length >= vehicle.capacity;
const compatible = Boolean(
selected &&
vehicle.serves.includes(selected.destination) &&
!full
);
const destinationText = vehicle.serves
.map(key => destinationNames[key])
.join(" + ");
const seats = Array.from({ length: vehicle.capacity }, (_, index) => `
<span class="seat ${index < passengerIds.length ? "filled" : ""}"></span>
`).join("");
const passengerText = passengerIds.length
? passengerIds
.map(id => riderById.get(id).name.split(" ")[0])
.join(", ")
: "No riders yet";
return `
<button
class="vehicle-card
${compatible ? "compatible" : ""}
${selected && !compatible ? "incompatible" : ""}
${full ? "full" : ""}"
data-vehicle="${vehicle.id}"
style="--vehicle-color:${vehicle.color}"
aria-label="${vehicle.name}, serves ${destinationText}, ${passengerIds.length} of ${vehicle.capacity} seats occupied"
>
<span class="vehicle-icon ${vehicle.kind}" aria-hidden="true"></span>
<span>
<span class="vehicle-title">
<span>${vehicle.name}</span>
<span>${passengerIds.length}/${vehicle.capacity}</span>
</span>
<span class="vehicle-route">${destinationText}</span>
<span class="seat-row">
${seats}
<span class="occupancy">
${full ? "FULL" : `${vehicle.capacity - passengerIds.length} OPEN`}
</span>
</span>
<span class="passenger-line">${passengerText}</span>
</span>
</button>
`;
}).join("");
}
function renderRiders() {
riderList.innerHTML = riders.map(rider => {
const vehicleId = assignments.get(rider.id);
const vehicle = vehicleId ? vehicleById.get(vehicleId) : null;
const selected = selectedRiderId === rider.id;
return `
<button
class="rider-card ${selected ? "selected" : ""} ${vehicle ? "assigned" : ""}"
data-rider="${rider.id}"
aria-pressed="${selected}"
title="${rider.note}"
>
${pixelPerson(rider)}
<span>
<span class="rider-name">${rider.name}</span>
<span
class="rider-destination"
style="--destination-color:${destinationColors[rider.destination]}"
>
${destinationNames[rider.destination]}
</span>
<span class="rider-state">
${vehicle ? `On ${vehicle.name.toLowerCase()}` : "At the stop"}
</span>
</span>
</button>
`;
}).join("");
}
function renderSelection() {
if (assignments.size === riders.length) {
selectionInfo.innerHTML = `
<strong>All nine neighbors have a ride.</strong>
The board is complete, but the struggle was never about a perfect
schedule. It was about people deciding collectively that a segregated
system should not dictate their lives.
<div class="selection-actions">
<button id="completion-history">Read what changed →</button>
</div>
`;
return;
}
if (!selectedRiderId) {
selectionInfo.innerHTML = `
<strong>Start with a person.</strong>
Select a rider below or click a voxel resident at the stop. The ride
must reach their destination and have an open seat.
`;
return;
}
const rider = riderById.get(selectedRiderId);
const vehicleId = assignments.get(rider.id);
const vehicle = vehicleId ? vehicleById.get(vehicleId) : null;
selectionInfo.innerHTML = `
<strong>${rider.name}</strong>
${rider.note}
<br>
Destination: <strong style="display:inline;color:${destinationColors[rider.destination]}">
${destinationNames[rider.destination]}
</strong>
${vehicle
? `<br>Currently assigned to ${vehicle.name}. Choose another vehicle to move them.`
: `<br>Now choose a compatible vehicle.`}
<div class="selection-actions">
${vehicle
? `<button data-return-rider="${rider.id}">Return to sidewalk</button>`
: ""}
<button data-clear-selection>Clear selection</button>
</div>
`;
}
function renderUI() {
renderVehicles();
renderRiders();
renderSelection();
updateSceneMarkers();
}
function showToast(message) {
clearTimeout(toastTimer);
toastElement.textContent = message;
toastElement.classList.add("visible");
toastTimer = setTimeout(() => {
toastElement.classList.remove("visible");
}, 3400);
}
riderList.addEventListener("click", event => {
const card = event.target.closest("[data-rider]");
if (!card) return;
const id = card.dataset.rider;
selectedRiderId = selectedRiderId === id ? null : id;
renderUI();
});
vehicleList.addEventListener("click", event => {
const card = event.target.closest("[data-vehicle]");
if (!card) return;
if (!selectedRiderId) {
showToast("Select a person first, then choose their ride.");
return;
}
assignRider(selectedRiderId, card.dataset.vehicle);
});
selectionInfo.addEventListener("click", event => {
const returnButton = event.target.closest("[data-return-rider]");
if (returnButton) {
unassignRider(returnButton.dataset.returnRider);
return;
}
if (event.target.closest("[data-clear-selection]")) {
selectedRiderId = null;
renderUI();
return;
}
if (event.target.closest("#completion-history")) {
historyDialog.showModal();
}
});
document.querySelector("#open-history").addEventListener("click", () => {
historyDialog.showModal();
});
document.querySelector("#close-history").addEventListener("click", () => {
historyDialog.close();
});
historyDialog.addEventListener("click", event => {
if (event.target === historyDialog) historyDialog.close();
});
// ------------------------------------------------------------
// Three.js renderer, camera, and lighting
// ------------------------------------------------------------
const sceneContainer = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#a9c6cf");
scene.fog = new THREE.Fog("#a9c6cf", 35, 65);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel street. Drag or use arrow keys to rotate, plus and minus to zoom, and click riders or vehicles."
);
sceneContainer.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 12, -12, 0.1, 100);
const cameraState = {
theta: 0.40,
phi: 0.83,
target: new THREE.Vector3(0, 1.0, 1.6),
zoom: 1.02,
targetZoom: 1.02
};
const cameraRadius = 31;
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraRadius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraRadius * Math.cos(cameraState.phi),
cameraState.target.z + cameraRadius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.zoom += (cameraState.targetZoom - camera.zoom) * 0.12;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = 11.8;
camera.left = -viewHeight * aspect;
camera.right = viewHeight * aspect;
camera.top = viewHeight;
camera.bottom = -viewHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemisphere = new THREE.HemisphereLight("#fff3d2", "#53646c", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.2);
sun.position.set(-9, 18, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
scene.add(sun);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(
width,
height,
depth,
color,
x,
y,
z,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
typeof color === "string" ? material(color) : color
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createLabelSprite(title, subtitle, color = "#fff3cf") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const context = canvas.getContext("2d");
context.fillStyle = "#17242d";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = color;
context.lineWidth = 10;
context.strokeRect(7, 7, canvas.width - 14, canvas.height - 14);
context.fillStyle = color;
context.font = "900 37px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(title, 256, 54);
context.fillStyle = "#fffaf0";
context.font = "700 22px monospace";
context.fillText(subtitle, 256, 105);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(4.8, 1.35, 1);
return sprite;
}
function makeSquareMarker(width, depth, color, parent = scene) {
const marker = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const thickness = 0.10;
box(width, thickness, 0.08, material, 0, 0, depth / 2, marker, false);
box(width, thickness, 0.08, material, 0, 0, -depth / 2, marker, false);
box(0.08, thickness, depth, material, width / 2, 0, 0, marker, false);
box(0.08, thickness, depth, material, -width / 2, 0, 0, marker, false);
marker.visible = false;
parent.add(marker);
return marker;
}
// ------------------------------------------------------------
// Voxel streetscape
// ------------------------------------------------------------
function buildStreet() {
box(34, 0.35, 20, "#809b70", 0, -0.25, 2, scene, false);
box(31, 0.18, 5.1, "#3e484d", 0, 0.02, 0, scene, false);
box(31, 0.28, 2.45, "#d7c7a5", 0, 0.05, 2.25, scene, false);
box(31, 0.16, 0.30, "#f1e3c2", 0, 0.16, 0.91, scene, false);
box(31, 0.16, 1.5, "#7f9c6d", 0, 0.02, 4.3, scene, false);
for (let x = -14; x <= 14; x += 3.2) {
box(1.5, 0.025, 0.13, "#e7d9b9", x, 0.13, 0.25, scene, false);
}
for (let x = -13; x < 14; x += 2.2) {
box(0.62, 0.025, 1.8, "#e8e2cf", x, 0.14, -1.55, scene, false);
box(0.68, 0.028, 0.12, "#e8e2cf", x, 0.15, -0.67, scene, false);
}
// Bus-stop sign.
box(0.12, 2.9, 0.12, "#24343d", -10.6, 1.5, 1.2, scene);
box(1.35, 0.66, 0.12, "#f5ecd9", -10.6, 2.75, 1.2, scene);
box(1.08, 0.08, 0.14, "#d86543", -10.6, 2.86, 1.2, scene);
box(0.78, 0.08, 0.14, "#277da1", -10.6, 2.67, 1.2, scene);
// Streetlights.
[-12, -3.5, 5.5, 12].forEach(x => {
box(0.14, 4.8, 0.14, "#2f3d44", x, 2.4, 4.0, scene);
box(0.14, 0.14, 1.1, "#2f3d44", x, 4.72, 3.55, scene);
box(0.48, 0.25, 0.48, "#ffe6a1", x, 4.57, 3.12, scene);
});
// Trees.
[
[-13.1, 4.15, 1.0],
[-4.8, 4.3, 0.86],
[3.3, 4.2, 1.1],
[11.6, 4.1, 0.9]
].forEach(([x, z, scale]) => {
const tree = new THREE.Group();
tree.position.set(x, 0.14, z);
tree.scale.setScalar(scale);
scene.add(tree);
box(0.36, 2.1, 0.36, "#72523b", 0, 1.05, 0, tree);
box(1.5, 1.35, 1.45, "#4f7d52", 0, 2.45, 0, tree);
box(1.05, 0.85, 1.05, "#5e9160", 0.25, 3.25, 0.05, tree);
box(1.15, 0.8, 1.0, "#456f49", -0.2, 2.35, -0.12, tree);
});
}
function buildBuildings() {
const buildingColors = [
"#9d6654",
"#687c76",
"#b08b62",
"#7f6f80",
"#6c856e",
"#a36d61",
"#71858c",
"#8f765d"
];
const windowColors = ["#e6c878", "#b8d0c8", "#dca66e"];
for (let i = 0; i < 8; i++) {
const x = -12.8 + i * 3.65;
const width = 2.8 + (i % 3) * 0.28;
const height = 3.2 + (i % 4) * 0.72;
const depth = 3.0;
const z = 7.15;
box(width, height, depth, buildingColors[i], x, height / 2 + 0.15, z, scene);
box(width + 0.18, 0.25, depth + 0.14, "#38484f", x, height + 0.2, z, scene);
box(width - 0.2, 0.85, 0.08, "#3c4a4e", x, 0.58, z - depth / 2 - 0.05, scene);
const frontZ = z - depth / 2 - 0.055;
const floors = Math.max(2, Math.floor((height - 1.3) / 1.1));
for (let floor = 0; floor < floors; floor++) {
const windowY = 1.45 + floor * 1.05;
if (windowY + 0.35 > height) continue;
box(0.62, 0.62, 0.07, windowColors[(i + floor) % 3], x - 0.68, windowY, frontZ, scene, false);
box(0.62, 0.62, 0.07, windowColors[(i + floor + 1) % 3], x + 0.68, windowY, frontZ, scene, false);
}
}
const sign = createLabelSprite("MONTGOMERY", "A COMMUNITY IN MOTION", "#e9c46a");
sign.position.set(0, 3.3, 5.54);
sign.scale.set(5.8, 1.55, 1);
scene.add(sign);
const year = createLabelSprite("1955—1956", "381 DAYS OF COLLECTIVE ACTION", "#d86543");
year.position.set(0, 1.15, 4.7);
year.scale.set(4.5, 1.25, 1);
scene.add(year);
}
buildStreet();
buildBuildings();
// ------------------------------------------------------------
// Voxel vehicles
// ------------------------------------------------------------
const pickables = [];
function makeBus(vehicle) {
const group = new THREE.Group();
group.position.set(vehicle.x, 0, 0);
scene.add(group);
box(4.4, 0.25, 1.6, "#263238", 0, 0.43, 0, group);
box(4.25, 1.18, 1.55, vehicle.color, 0, 1.12, 0, group);
box(4.35, 0.18, 1.64, "#f0dfb8", 0, 1.81, 0, group);
box(4.42, 0.12, 1.60, "#263238", 0, 1.94, 0, group);
// Near-side windows and doors.
[-1.55, -0.75, 0.05, 0.85].forEach((windowX, index) => {
const isDoor = index === 3;
box(
isDoor ? 0.72 : 0.66,
0.54,
0.055,
isDoor ? "#b8d9dc" : "#29444d",
windowX,
1.43,
0.805,
group,
false
);
});
// Far-side windows.
[-1.55, -0.75, 0.05, 0.85].forEach(windowX => {
box(0.66, 0.54, 0.055, "#29444d", windowX, 1.43, -0.805, group, false);
});
box(4.05, 0.13, 0.06, "#efe3bd", 0, 0.82, 0.81, group, false);
box(4.05, 0.09, 0.06, "#25343b", 0, 0.58, 0.81, group, false);
// Voxel wheels.
[-1.45, 1.45].forEach(wheelX => {
[-0.82, 0.82].forEach(wheelZ => {
box(0.66, 0.66, 0.28, "#20282c", wheelX, 0.48, wheelZ, group);
box(0.28, 0.28, 0.30, "#aab0ad", wheelX, 0.48, wheelZ, group, false);
});
});
box(0.10, 0.22, 0.08, "#ffe59a", 2.17, 1.03, 0.66, group, false);
box(0.10, 0.22, 0.08, "#ffe59a", 2.17, 1.03, -0.66, group, false);
const label = createLabelSprite(vehicle.label, vehicle.subtitle, vehicle.color);
label.position.set(0, 2.83, 0);
group.add(label);
const marker = makeSquareMarker(
vehicle.kind === "bus" ? 4.95 : 3.6,
vehicle.kind === "bus" ? 2.15 : 1.95,
"#fff3a6",
group
);
marker.position.y = 0.20;
group.traverse(object => {
if (object.isMesh && object !== marker) {
object.userData.kind = "vehicle";
object.userData.vehicleId = vehicle.id;
pickables.push(object);
}
});
return {
...vehicle,
group,
marker,
doorLocal: new THREE.Vector3(1.85, 0.17, 1.12),
passengerSlots: vehicle.kind === "bus"
? [-1.35, -0.45, 0.45, 1.35]
: [-0.45, 0.45]
};
}
function makeCar(vehicle) {
const group = new THREE.Group();
group.position.set(vehicle.x, 0, 0);
scene.add(group);
box(3.35, 0.62, 1.38, vehicle.color, 0, 0.79, 0, group);
box(1.75, 0.68, 1.20, vehicle.color, -0.25, 1.38, 0, group);
box(1.44, 0.47, 0.055, "#29444d", -0.26, 1.43, 0.63, group, false);
box(1.34, 0.47, 0.055, "#29444d", -0.26, 1.43, -0.63, group, false);
box(0.72, 0.48, 0.055, "#29444d", 0.93, 1.43, 0.63, group, false);
box(0.72, 0.48, 0.055, "#29444d", 0.93, 1.43, -0.63, group, false);
box(0.28, 0.12, 1.18, "#d86543", -0.25, 1.76, 0, group, false);
[-1.05, 1.05].forEach(wheelX => {
[-0.70, 0.70].forEach(wheelZ => {
box(0.58, 0.58, 0.25, "#20282c", wheelX, 0.47, wheelZ, group);
box(0.24, 0.24, 0.27, "#b0b6b1", wheelX, 0.47, wheelZ, group, false);
});
});
box(0.10, 0.20, 0.08, "#ffe59a", 1.72, 0.92, 0.43, group, false);
box(0.10, 0.20, 0.08, "#ffe59a", 1.72, 0.92, -0.43, group, false);
const label = createLabelSprite(vehicle.label, vehicle.subtitle, "#f0cf66");
label.position.set(0, 2.57, 0);
label.scale.set(4.7, 1.32, 1);
group.add(label);
const marker = makeSquareMarker(3.8, 2.0, "#fff3a6", group);
marker.position.y = 0.20;
group.traverse(object => {
if (object.isMesh && object !== marker) {
object.userData.kind = "vehicle";
object.userData.vehicleId = vehicle.id;
pickables.push(object);
}
});
return {
...vehicle,
group,
marker,
doorLocal: new THREE.Vector3(1.35, 0.17, 1.05),
passengerSlots: [-0.45, 0.45]
};
}
vehicles.forEach(vehicle => {
const built = vehicle.kind === "bus" ? makeBus(vehicle) : makeCar(vehicle);
vehicleById.set(vehicle.id, built);
});
// ------------------------------------------------------------
// Voxel residents
// ------------------------------------------------------------
const waitPositions = [
[-9.2, 0.17, 2.0],
[-7.2, 0.17, 2.65],
[-5.3, 0.17, 2.0],
[-3.4, 0.17, 2.65],
[-1.4, 0.17, 2.0],
[0.7, 0.17, 2.65],
[2.8, 0.17, 2.0],
[4.9, 0.17, 2.65],
[7.0, 0.17, 2.0]
];
function makeRider(rider, position) {
const group = new THREE.Group();
group.position.set(...position);
scene.add(group);
// Legs and shoes.
box(0.18, 0.54, 0.20, "#26343d", -0.13, 0.27, 0, group);
box(0.18, 0.54, 0.20, "#26343d", 0.13, 0.27, 0, group);
box(0.22, 0.12, 0.31, "#1e282d", -0.13, 0.06, 0.05, group);
box(0.22, 0.12, 0.31, "#1e282d", 0.13, 0.06, 0.05, group);
// Coat.
box(0.56, 0.66, 0.34, rider.coat, 0, 0.82, 0, group);
box(0.10, 0.58, 0.035, "#e8d9b5", 0, 0.80, 0.19, group, false);
// Arms.
box(0.16, 0.58, 0.20, rider.coat, -0.36, 0.80, 0, group);
box(0.16, 0.58, 0.20, rider.coat, 0.36, 0.80, 0, group);
box(0.17, 0.18, 0.19, rider.skin, -0.36, 0.45, 0.02, group);
box(0.17, 0.18, 0.19, rider.skin, 0.36, 0.45, 0.02, group);
// Head, hair, and simple face.
box(0.42, 0.43, 0.40, rider.skin, 0, 1.34, 0, group);
box(0.45, 0.17, 0.43, rider.hair, 0, 1.52, -0.015, group);
box(0.10, 0.23, 0.16, rider.hair, -0.21, 1.39, -0.08, group);
box(0.06, 0.06, 0.025, "#202326", -0.09, 1.38, 0.215, group, false);
box(0.06, 0.06, 0.025, "#202326", 0.09, 1.38, 0.215, group, false);
// Invisible, easily clickable proxy.
const proxyMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const proxy = new THREE.Mesh(
new THREE.BoxGeometry(0.86, 1.75, 0.72),
proxyMaterial
);
proxy.position.y = 0.87;
proxy.userData.kind = "rider";
proxy.userData.riderId = rider.id;
group.add(proxy);
pickables.push(proxy);
return {
...rider,
visual: group,
proxy,
waitPosition: new THREE.Vector3(...position),
motionToken: 0
};
}
riders.forEach((rider, index) => {
const visual = makeRider(rider, waitPositions[index]);
riderById.set(rider.id, visual);
});
const selectionMarker = makeSquareMarker(1.05, 1.05, "#fff3a6");
selectionMarker.position.y = 0.20;
// ------------------------------------------------------------
// Assignment logic and motion
// ------------------------------------------------------------
const animations = [];
const passengerVisuals = new Map();
function animatePosition(object, destination, duration, onComplete) {
const start = object.position.clone();
const token = object.userData.motionToken || 0;
animations.push({
object,
start,
destination: destination.clone(),
duration,
elapsed: 0,
token,
onComplete
});
}
function vehicleDoorWorld(vehicle) {
return vehicle.group.localToWorld(vehicle.doorLocal.clone());
}
function removePassengerVisual(riderId) {
const visual = passengerVisuals.get(riderId);
if (!visual) return;
visual.parent?.remove(visual);
passengerVisuals.delete(riderId);
}
function createPassengerVisual(rider, vehicle) {
const existing = passengerVisuals.get(rider.id);
if (existing) existing.parent?.remove(existing);
const passengerIds = passengersFor(vehicle.id);
const slotIndex = Math.max(0, passengerIds.indexOf(rider.id));
const x = vehicle.passengerSlots[
Math.min(slotIndex, vehicle.passengerSlots.length - 1)
];
const group = new THREE.Group();
group.position.set(
x,
vehicle.kind === "bus" ? 1.40 : 1.37,
vehicle.kind === "bus" ? 0.88 : 0.67
);
box(0.29, 0.24, 0.10, rider.coat, 0, -0.12, 0, group, false);
box(0.27, 0.27, 0.26, rider.skin, 0, 0.11, 0, group, false);
box(0.29, 0.10, 0.28, rider.hair, 0, 0.23, -0.015, group, false);
vehicle.group.add(group);
passengerVisuals.set(rider.id, group);
}
function assignRider(riderId, vehicleId) {
const rider = riderById.get(riderId);
const vehicle = vehicleById.get(vehicleId);
if (!rider || !vehicle) return;
if (assignments.get(riderId) === vehicleId) {
showToast(
`${rider.name} is already riding the ${vehicle.name.toLowerCase()}. ` +
"Choose another vehicle to move them, or return them to the sidewalk."
);
return;
}
if (!vehicle.serves.includes(rider.destination)) {
const serves = vehicle.serves
.map(key => destinationNames[key])
.join(" and ");
showToast(
`The ${vehicle.name.toLowerCase()} serves ${serves}, but ` +
`${rider.name} needs to reach ${destinationNames[rider.destination]}.`
);
return;
}
const targetPassengers = passengersFor(vehicleId).filter(id => id !== riderId);
if (targetPassengers.length >= vehicle.capacity) {
showToast(
`The ${vehicle.name.toLowerCase()} is full. ` +
`Its capacity is ${vehicle.capacity} riders.`
);
return;
}
const oldVehicleId = assignments.get(riderId);
if (oldVehicleId) {
const oldVehicle = vehicleById.get(oldVehicleId);
removePassengerVisual(riderId);
rider.visual.visible = true;
rider.proxy.visible = true;
rider.visual.position.copy(vehicleDoorWorld(oldVehicle));
rider.motionToken += 1;
}
assignments.set(riderId, vehicleId);
selectedRiderId = null;
rider.visual.visible = true;
rider.proxy.visible = true;
rider.motionToken += 1;
const token = rider.motionToken;
const destination = vehicleDoorWorld(vehicle);
animatePosition(
rider.visual,
destination,
850,
() => {
if (token !== rider.motionToken) return;
rider.visual.visible = false;
rider.proxy.visible = false;
createPassengerVisual(rider, vehicle);
}
);
renderUI();
if (assignments.size === riders.length) {
setTimeout(() => {
showToast(
"Everyone has a ride. The plan is complete—and the movement was always about more than a plan."
);
}, 900);
}
}
function unassignRider(riderId) {
const rider = riderById.get(riderId);
const oldVehicleId = assignments.get(riderId);
if (!rider || !oldVehicleId) return;
const vehicle = vehicleById.get(oldVehicleId);
removePassengerVisual(riderId);
assignments.delete(riderId);
rider.visual.visible = true;
rider.proxy.visible = true;
rider.visual.position.copy(vehicleDoorWorld(vehicle));
rider.motionToken += 1;
const token = rider.motionToken;
animatePosition(
rider.visual,
rider.waitPosition,
750,
() => {
if (token !== rider.motionToken) return;
rider.visual.position.copy(rider.waitPosition);
}
);
selectedRiderId = null;
renderUI();
showToast(`${rider.name} is back at the stop.`);
}
function updateSceneMarkers() {
vehicleById.forEach(vehicle => {
const selected = selectedRiderId
? riderById.get(selectedRiderId)
: null;
const routeMatches = Boolean(
selected && vehicle.serves.includes(selected.destination)
);
const full = passengersFor(vehicle.id).length >= vehicle.capacity;
vehicle.marker.visible = routeMatches;
vehicle.marker.children.forEach(child => {
if (child.material?.color) {
child.material.color.set(full ? "#d86543" : "#fff3a6");
}
});
});
if (!selectedRiderId) {
selectionMarker.visible = false;
return;
}
const rider = riderById.get(selectedRiderId);
const assignedVehicle = assignments.get(rider.id);
selectionMarker.visible = true;
if (assignedVehicle) {
const vehicle = vehicleById.get(assignedVehicle);
selectionMarker.position.copy(vehicleDoorWorld(vehicle));
selectionMarker.position.y = 0.20;
} else {
selectionMarker.position.copy(rider.waitPosition);
selectionMarker.position.y = 0.20;
}
}
// ------------------------------------------------------------
// Direct camera and object interaction
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function setPointer(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;
}
function pick(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
for (const hit of hits) {
const data = hit.object.userData;
if (data.kind === "rider") {
return { kind: "rider", id: data.riderId };
}
if (data.kind === "vehicle") {
return { kind: "vehicle", id: data.vehicleId };
}
}
return null;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(event.clientX - lastPointerX) +
Math.abs(event.clientY - lastPointerY) > 2) {
pointerMoved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.55,
1.24
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else {
const hovered = pick(event);
renderer.domElement.style.cursor = hovered ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
pointerDown = false;
if (!pointerMoved) {
const hit = pick(event);
if (hit?.kind === "rider") {
selectedRiderId = selectedRiderId === hit.id ? null : hit.id;
renderUI();
}
if (hit?.kind === "vehicle") {
if (selectedRiderId) {
assignRider(selectedRiderId, hit.id);
} else {
const vehicle = vehicleById.get(hit.id);
const destinations = vehicle.serves
.map(key => destinationNames[key])
.join(" and ");
showToast(
`${vehicle.name}: ${destinations}. Capacity ${vehicle.capacity}. ` +
"Select a rider to assign a seat."
);
}
}
}
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * (event.deltaY > 0 ? 0.91 : 1.10),
0.72,
1.75
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") {
cameraState.theta -= 0.10;
event.preventDefault();
} else if (event.key === "ArrowRight") {
cameraState.theta += 0.10;
event.preventDefault();
} else if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.55, cameraState.phi - 0.08);
event.preventDefault();
} else if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.24, cameraState.phi + 0.08);
event.preventDefault();
} else if (event.key === "+" || event.key === "=") {
cameraState.targetZoom = Math.min(1.75, cameraState.targetZoom + 0.12);
event.preventDefault();
} else if (event.key === "-") {
cameraState.targetZoom = Math.max(0.72, cameraState.targetZoom - 0.12);
event.preventDefault();
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function resetCamera() {
cameraState.theta = 0.40;
cameraState.phi = 0.83;
cameraState.targetZoom = 1.02;
}
document.querySelector("#camera-left").addEventListener("click", () => {
cameraState.theta -= 0.18;
});
document.querySelector("#camera-right").addEventListener("click", () => {
cameraState.theta += 0.18;
});
document.querySelector("#camera-zoom-in").addEventListener("click", () => {
cameraState.targetZoom = Math.min(1.75, cameraState.targetZoom + 0.12);
});
document.querySelector("#camera-zoom-out").addEventListener("click", () => {
cameraState.targetZoom = Math.max(0.72, cameraState.targetZoom - 0.12);
});
document.querySelector("#camera-reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
for (let index = animations.length - 1; index >= 0; index--) {
const animation = animations[index];
animation.elapsed += delta * 1000;
const progress = Math.min(animation.elapsed / animation.duration, 1);
const eased = progress * progress * (3 - 2 * progress);
animation.object.position.lerpVectors(
animation.start,
animation.destination,
eased
);
animation.object.position.y += Math.sin(progress * Math.PI) * 0.9;
if (progress >= 1) {
animation.object.position.copy(animation.destination);
animation.onComplete?.();
animations.splice(index, 1);
}
}
if (selectionMarker.visible) {
const pulse = 1 + Math.sin(clock.elapsedTime * 5) * 0.055;
selectionMarker.scale.set(pulse, 1, pulse);
}
updateCamera();
renderer.render(scene, camera);
}
renderUI();
renderer.setAnimationLoop(animate);
document.querySelector("#loading").classList.add("hidden");
</script>
</body>
</html>
```