Prompt specification
Build or customize the Three.js 3D scene "Wait or walk to another stop" 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: Wait or walk to another stop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wait-or-walk-to-another-stop-x3854
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a delayed bus and alternative commute choices. Animate a traveler comparing two route cards after the display changes; highlight the selected alternative and keep the destination identical between both choices. Voxel style.
Working Three.js Starter (wait-or-walk-to-another-stop-x3854):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#0b1020" />
<title>Wayfind — Alternative Commute</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1020;
--panel: rgba(16, 24, 43, 0.88);
--line: rgba(255, 255, 255, 0.12);
--text: #f5f7ff;
--muted: #9ba8c4;
--green: #54e6ad;
--red: #ff6b70;
--yellow: #ffc857;
--purple: #9d8cff;
}
* {
box-sizing: border-box;
}
html,
body,
#app {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app {
position: relative;
isolation: isolate;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 24px;
display: flex;
align-items: center;
gap: 12px;
padding: 12px 15px;
border: 1px solid var(--line);
background: rgba(12, 18, 34, 0.76);
backdrop-filter: blur(14px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}
.brand-mark {
position: relative;
width: 32px;
height: 32px;
background: var(--green);
box-shadow:
7px 0 0 #22304e,
0 7px 0 #22304e;
}
.brand-mark::after {
content: "";
position: absolute;
right: 4px;
bottom: 4px;
width: 8px;
height: 8px;
background: #0b1020;
}
.brand b {
display: block;
font-size: 14px;
letter-spacing: 0.16em;
}
.brand small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status {
position: absolute;
top: 24px;
right: 24px;
width: min(320px, calc(100vw - 48px));
padding: 16px 18px 16px 20px;
border: 1px solid var(--line);
border-left: 4px solid var(--yellow);
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
transition: border-color 220ms ease, transform 220ms ease;
}
.status[data-state="alert"] {
border-left-color: var(--red);
}
.status[data-state="compare"] {
border-left-color: var(--purple);
}
.status[data-state="selected"] {
border-left-color: var(--green);
transform: translateY(2px);
}
.status-label {
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-title {
font-size: 21px;
font-weight: 800;
letter-spacing: -0.02em;
}
.status-detail {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.destination {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
align-items: flex-end;
gap: 16px;
padding: 15px 16px;
border: 1px solid var(--line);
background: rgba(12, 18, 34, 0.86);
backdrop-filter: blur(14px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
pointer-events: auto;
}
.destination-copy small {
display: block;
margin-bottom: 5px;
color: var(--green);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.destination-copy strong {
display: block;
font-size: 16px;
letter-spacing: -0.01em;
}
.destination-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
button {
appearance: none;
border: 0;
font: inherit;
cursor: pointer;
}
.choose-button {
min-height: 42px;
padding: 0 14px;
color: #07130f;
background: var(--green);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
box-shadow: 4px 4px 0 rgba(84, 230, 173, 0.18);
transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}
.choose-button:hover:not(:disabled) {
transform: translate(-1px, -1px);
box-shadow: 6px 6px 0 rgba(84, 230, 173, 0.2);
}
.choose-button:active:not(:disabled) {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 rgba(84, 230, 173, 0.18);
}
.choose-button:disabled {
cursor: not-allowed;
opacity: 0.35;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.hint {
padding: 9px 11px;
border: 1px solid var(--line);
color: var(--muted);
background: rgba(12, 18, 34, 0.76);
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
.replay-button {
display: grid;
width: 44px;
height: 44px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.22);
color: var(--text);
background: rgba(20, 29, 50, 0.92);
font-size: 22px;
transition: background 150ms ease, transform 150ms ease;
}
.replay-button:hover {
background: #263554;
transform: rotate(-20deg);
}
.replay-button:focus-visible,
.choose-button:focus-visible {
outline: 3px solid white;
outline-offset: 3px;
}
@media (max-width: 720px) {
.brand {
top: 14px;
left: 14px;
padding: 10px 12px;
}
.brand small {
display: none;
}
.status {
top: 78px;
right: 14px;
width: min(290px, calc(100vw - 28px));
padding: 13px 14px;
}
.status-title {
font-size: 18px;
}
.destination {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 76px);
gap: 10px;
padding: 12px;
}
.destination-copy span {
display: none;
}
.destination-copy strong {
font-size: 13px;
}
.choose-button {
min-height: 38px;
padding: 0 10px;
font-size: 9px;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main id="app">
<div class="hud">
<header class="brand" aria-label="Wayfind commute comparison">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<b>WAYFIND</b>
<small>Commute comparison</small>
</div>
</header>
<section
id="statusPanel"
class="status"
data-state="live"
aria-live="polite"
>
<div id="statusLabel" class="status-label">Live departure</div>
<div id="statusTitle" class="status-title">+2 min</div>
<div id="statusDetail" class="status-detail">
Bus 24 → Central Station
</div>
</section>
<section class="destination" aria-label="Shared destination">
<div class="destination-copy">
<small>Shared destination</small>
<strong>Central Station</strong>
<span>Both routes end in the same place.</span>
</div>
<button id="chooseButton" class="choose-button" type="button" disabled>
Choose Tram 8
</button>
</section>
<div class="controls">
<div class="hint">Drag to orbit · scroll to zoom</div>
<button
id="replayButton"
class="replay-button"
type="button"
aria-label="Replay the commute comparison"
title="Replay comparison"
>
↻
</button>
</div>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const statusPanel = document.getElementById("statusPanel");
const statusLabel = document.getElementById("statusLabel");
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const chooseButton = document.getElementById("chooseButton");
const replayButton = document.getElementById("replayButton");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Voxel transit station showing a delayed bus, two routes to Central Station, and a traveler selecting the on-time tram."
);
renderer.domElement.tabIndex = 0;
app.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1020);
scene.fog = new THREE.Fog(0x0b1020, 23, 43);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 80);
const cameraTarget = new THREE.Vector3(-0.3, 2.35, -0.5);
let cameraYaw = 0.24;
let cameraPitch = 0.43;
const cameraRadius = 20;
function updateCameraPosition() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCameraPosition();
const hemisphere = new THREE.HemisphereLight(0xcfe4ff, 0x20213a, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x778dff, 1.8);
rimLight.position.set(-9, 7, -7);
scene.add(rimLight);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.04,
flatShading: true,
...options
});
}
function voxel(size, position, color, parent = scene, options = {}) {
const material = color?.isMaterial
? color
: standardMaterial(color, options);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeTextPlane(width, height, canvas, position, parent = scene) {
const texture = makeCanvasTexture(canvas);
const material = new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
plane.position.set(position[0], position[1], position[2]);
parent.add(plane);
return { plane, texture, canvas };
}
// ---------------------------------------------------------------------
// Station environment
// ---------------------------------------------------------------------
const groundMaterial = standardMaterial(0x141d32);
const platformMaterial = standardMaterial(0x33425f);
const roadMaterial = standardMaterial(0x111827);
const edgeMaterial = standardMaterial(0x53627d);
const darkMaterial = standardMaterial(0x151d2e);
const whiteMaterial = standardMaterial(0xd8e2f4);
voxel([27, 0.3, 19], [0, -0.37, -0.5], groundMaterial);
voxel([24, 0.18, 3.6], [0, -0.08, 2.55], roadMaterial);
voxel([24, 0.34, 5.4], [0, 0.05, -1.35], platformMaterial);
voxel([24, 0.09, 0.18], [0, 0.25, 1.31], edgeMaterial);
for (let x = -11.5; x <= 11.5; x += 1.25) {
voxel(
[0.64, 0.025, 0.08],
[x, 0.025, 2.55],
standardMaterial(0xd6ddeb)
);
}
for (let x = -11; x <= 11; x += 1.1) {
voxel(
[0.025, 0.015, 4.9],
[x, 0.228, -1.32],
standardMaterial(0x43516b)
);
}
for (let z = -3.7; z <= 1.1; z += 1.2) {
voxel(
[23.5, 0.015, 0.025],
[0, 0.229, z],
standardMaterial(0x43516b)
);
}
// Distant voxel skyline.
const buildingColors = [0x17213a, 0x1b2946, 0x202d4b];
const buildingHeights = [2.2, 3.3, 1.8, 2.8, 2.1, 3.8, 2.4];
for (let i = 0; i < buildingHeights.length; i++) {
const height = buildingHeights[i];
const x = -10 + i * 3.35;
const z = -7.5 - (i % 2) * 0.5;
voxel(
[2.4, height, 2.3],
[x, height / 2 - 0.15, z],
standardMaterial(buildingColors[i % buildingColors.length])
);
voxel(
[2.55, 0.14, 2.45],
[x, height - 0.08, z],
standardMaterial(0x2a3958)
);
}
// Rail line and small tram representing the selected alternative.
voxel([10, 0.06, 0.08], [6.7, -0.1, -4.46], darkMaterial);
voxel([10, 0.06, 0.08], [6.7, -0.1, -3.78], darkMaterial);
const tram = new THREE.Group();
tram.position.set(6.3, -0.04, -4.12);
scene.add(tram);
const tramGreen = standardMaterial(0x39c995);
const tramDark = standardMaterial(0x18364a);
const tramWindow = standardMaterial(0x8bc8e7, {
roughness: 0.3,
metalness: 0.15
});
voxel([3.1, 0.8, 1.1], [0, 0.72, 0], tramGreen, tram);
voxel([3.18, 0.14, 1.18], [0, 1.18, 0], standardMaterial(0x75f1bc), tram);
voxel([0.55, 0.48, 0.28], [-0.92, 0.33, 0.55], darkMaterial, tram);
voxel([0.55, 0.48, 0.28], [0.92, 0.33, 0.55], darkMaterial, tram);
voxel([0.55, 0.48, 0.28], [-0.92, 0.33, -0.55], darkMaterial, tram);
voxel([0.55, 0.48, 0.28], [0.92, 0.33, -0.55], darkMaterial, tram);
for (const x of [-1.03, -0.35, 0.35, 1.03]) {
voxel([0.55, 0.42, 0.025], [x, 0.85, 0.562], tramWindow, tram);
}
const tramSignCanvas = document.createElement("canvas");
tramSignCanvas.width = 512;
tramSignCanvas.height = 160;
const tramSignCtx = tramSignCanvas.getContext("2d");
tramSignCtx.fillStyle = "#07130f";
tramSignCtx.fillRect(0, 0, 512, 160);
tramSignCtx.fillStyle = "#54e6ad";
tramSignCtx.fillRect(0, 0, 18, 160);
tramSignCtx.font = "900 64px ui-monospace, monospace";
tramSignCtx.fillText("TRAM 8", 46, 76);
tramSignCtx.fillStyle = "#d8fff0";
tramSignCtx.font = "700 28px ui-monospace, monospace";
tramSignCtx.fillText("CENTRAL STATION", 46, 124);
makeTextPlane(1.65, 0.52, tramSignCanvas, [0, 1.34, 0.585], tram);
// ---------------------------------------------------------------------
// Delayed bus
// ---------------------------------------------------------------------
const bus = new THREE.Group();
bus.position.set(-4.9, 0.02, 2.45);
scene.add(bus);
const busYellow = standardMaterial(0xf2b84b);
const busRed = standardMaterial(0xef5d62);
const busGlass = standardMaterial(0x29465d, {
roughness: 0.26,
metalness: 0.12
});
const tireMaterial = standardMaterial(0x10141e);
const hubMaterial = standardMaterial(0x66718a);
voxel([3.5, 1.05, 1.5], [0, 1.0, 0], busYellow, bus);
voxel([3.58, 0.18, 1.56], [0, 1.61, 0], standardMaterial(0xffd778), bus);
voxel([3.25, 0.13, 0.035], [0, 0.63, 0.763], busRed, bus);
for (const x of [-1.24, -0.62, 0, 0.62, 1.24]) {
voxel([0.48, 0.42, 0.035], [x, 1.18, 0.758], busGlass, bus);
}
for (const x of [-1.16, 1.16]) {
for (const z of [-0.76, 0.76]) {
voxel([0.56, 0.56, 0.27], [x, 0.39, z], tireMaterial, bus);
voxel([0.26, 0.26, 0.29], [x, 0.39, z * 1.02], hubMaterial, bus);
}
}
const busLabelCanvas = document.createElement("canvas");
busLabelCanvas.width = 512;
busLabelCanvas.height = 170;
const busLabelCtx = busLabelCanvas.getContext("2d");
busLabelCtx.fillStyle = "#181a24";
busLabelCtx.fillRect(0, 0, 512, 170);
busLabelCtx.fillStyle = "#ffd36d";
busLabelCtx.font = "900 60px ui-monospace, monospace";
busLabelCtx.fillText("BUS 24", 24, 70);
busLabelCtx.fillStyle = "#f2f5ff";
busLabelCtx.font = "700 30px ui-monospace, monospace";
busLabelCtx.fillText("CENTRAL STATION", 24, 125);
makeTextPlane(1.65, 0.55, busLabelCanvas, [0.1, 0.93, 0.785], bus);
const brakeMaterial = standardMaterial(0xff4148, {
emissive: 0xff1f28,
emissiveIntensity: 0.5
});
voxel([0.18, 0.13, 0.08], [-1.47, 0.84, 0.79], brakeMaterial, bus);
voxel([0.18, 0.13, 0.08], [1.47, 0.84, 0.79], brakeMaterial, bus);
// ---------------------------------------------------------------------
// Live departure display
// ---------------------------------------------------------------------
const board = new THREE.Group();
board.position.set(-4.9, 0, -1.95);
scene.add(board);
voxel([0.18, 3.1, 0.18], [0, 1.65, 0], darkMaterial, board);
voxel([0.8, 0.15, 0.65], [0, 0.32, 0], darkMaterial, board);
voxel([3.35, 1.92, 0.24], [0, 3.85, 0], darkMaterial, board);
const displayCanvas = document.createElement("canvas");
displayCanvas.width = 768;
displayCanvas.height = 430;
const displayCtx = displayCanvas.getContext("2d");
const displayTexture = makeCanvasTexture(displayCanvas);
const displayMaterial = new THREE.MeshBasicMaterial({
map: displayTexture,
toneMapped: false
});
const displayPlane = new THREE.Mesh(
new THREE.PlaneGeometry(3.08, 1.7),
displayMaterial
);
displayPlane.position.set(0, 3.85, 0.131);
board.add(displayPlane);
const alertLightMaterial = standardMaterial(0xff4c55, {
emissive: 0xff2430,
emissiveIntensity: 0.3
});
voxel([0.16, 0.16, 0.16], [1.47, 4.85, 0], alertLightMaterial, board);
function drawDisplay(delay) {
const ctx = displayCtx;
ctx.clearRect(0, 0, 768, 430);
ctx.fillStyle = "#07111f";
ctx.fillRect(0, 0, 768, 430);
ctx.fillStyle = "#17263d";
ctx.fillRect(0, 0, 768, 74);
ctx.fillStyle = "#8fa2c2";
ctx.font = "800 24px ui-monospace, monospace";
ctx.fillText("NEXT DEPARTURE", 34, 45);
ctx.fillStyle = "#f7f9ff";
ctx.font = "900 55px ui-monospace, monospace";
ctx.fillText("BUS 24", 34, 145);
ctx.fillStyle = "#b8c5dd";
ctx.font = "700 24px ui-monospace, monospace";
ctx.fillText("TO CENTRAL STATION", 34, 190);
ctx.fillStyle = "#ff646a";
ctx.fillRect(34, 226, 700, 4);
ctx.fillStyle = "#ff6b70";
ctx.font = "900 104px ui-monospace, monospace";
ctx.fillText(`+${delay}`, 34, 343);
ctx.fillStyle = "#ffd0d1";
ctx.font = "900 35px ui-monospace, monospace";
ctx.fillText("MIN", 256, 319);
ctx.fillStyle = "#ff8589";
ctx.font = "800 28px ui-monospace, monospace";
ctx.fillText("DELAYED", 256, 358);
ctx.fillStyle = "#111b2d";
ctx.fillRect(520, 244, 214, 130);
ctx.fillStyle = "#ff6b70";
ctx.fillRect(520, 244, 214, 10);
ctx.fillStyle = "#94a5c3";
ctx.font = "700 19px ui-monospace, monospace";
ctx.fillText("SERVICE", 541, 288);
ctx.fillStyle = "#f7f9ff";
ctx.font = "900 23px ui-monospace, monospace";
ctx.fillText("ALERT", 541, 324);
ctx.fillStyle = "#ff8589";
ctx.font = "700 17px ui-monospace, monospace";
ctx.fillText("CHECK ROUTES", 541, 352);
displayTexture.needsUpdate = true;
}
drawDisplay(2);
// ---------------------------------------------------------------------
// Route cards
// ---------------------------------------------------------------------
const cardWidth = 2.18;
const cardHeight = 3.02;
const cardFinalY = 3.42;
function createRouteCard(route, x, accent, frameColor) {
const group = new THREE.Group();
group.position.set(x, cardFinalY - 4.2, -1.45);
scene.add(group);
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 708;
const ctx = canvas.getContext("2d");
const texture = makeCanvasTexture(canvas);
voxel(
[2.36, 3.2, 0.18],
[0, 0, 0],
standardMaterial(0x111a2d),
group
);
const faceMaterial = new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
const face = new THREE.Mesh(
new THREE.PlaneGeometry(cardWidth, cardHeight),
faceMaterial
);
face.position.z = 0.102;
face.userData.route = route;
group.add(face);
const frameMaterial = standardMaterial(frameColor, {
emissive: frameColor,
emissiveIntensity: route === "tram" ? 0.08 : 0.04
});
voxel([2.42, 0.09, 0.09], [0, 1.58, 0.15], frameMaterial, group);
voxel([2.42, 0.09, 0.09], [0, -1.58, 0.15], frameMaterial, group);
voxel([0.09, 3.16, 0.09], [-1.17, 0, 0.15], frameMaterial, group);
voxel([0.09, 3.16, 0.09], [1.17, 0, 0.15], frameMaterial, group);
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0x54e6ad,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const glow = new THREE.Mesh(
new THREE.PlaneGeometry(2.75, 3.58),
glowMaterial
);
glow.position.z = -0.02;
group.add(glow);
const data = {
route,
group,
face,
canvas,
ctx,
texture,
frameMaterial,
glowMaterial,
accent,
selected: false
};
drawRouteCard(data, false);
return data;
}
function drawRouteCard(data, selected) {
const ctx = data.ctx;
const isBus = data.route === "bus";
const accent = isBus ? "#ff6b70" : "#54e6ad";
const border = selected ? "#54e6ad" : isBus ? "#733a48" : "#284c60";
ctx.clearRect(0, 0, 512, 708);
ctx.fillStyle = "#10192d";
ctx.fillRect(0, 0, 512, 708);
ctx.strokeStyle = border;
ctx.lineWidth = selected ? 18 : 12;
ctx.strokeRect(7, 7, 498, 694);
ctx.fillStyle = "#17243a";
ctx.fillRect(22, 22, 468, 112);
ctx.fillStyle = accent;
ctx.fillRect(22, 22, 14, 112);
ctx.fillStyle = accent;
ctx.font = "900 31px ui-monospace, monospace";
ctx.fillText(isBus ? "BUS" : "TRAM", 55, 64);
ctx.fillStyle = "#f4f7ff";
ctx.font = "900 46px ui-monospace, monospace";
ctx.fillText(isBus ? "24" : "8", 55, 112);
// Small block-built transit pictogram.
ctx.fillStyle = accent;
ctx.fillRect(332, 51, 100, 49);
ctx.fillStyle = "#122039";
ctx.fillRect(344, 61, 28, 19);
ctx.fillRect(382, 61, 28, 19);
ctx.fillRect(344, 87, 66, 4);
ctx.fillStyle = "#08131f";
ctx.fillRect(340, 103, 18, 12);
ctx.fillRect(408, 103, 18, 12);
ctx.fillStyle = "#8fa1bf";
ctx.font = "800 22px ui-monospace, monospace";
ctx.fillText("ROUTE OPTION", 32, 177);
ctx.fillStyle = "#f5f7ff";
ctx.font = "900 39px ui-monospace, monospace";
ctx.fillText(isBus ? "+7 MIN" : "2 MIN", 32, 239);
ctx.fillStyle = accent;
ctx.font = "900 29px ui-monospace, monospace";
ctx.fillText(isBus ? "DELAYED" : "AWAY", 32, 281);
ctx.fillStyle = isBus ? "#ff8b8f" : "#8cf3c5";
ctx.font = "800 21px ui-monospace, monospace";
ctx.fillText(
isBus ? "BOARDING DELAY CHANGED" : "ON TIME • DIRECT",
32,
326
);
ctx.fillStyle = "#293a55";
ctx.fillRect(32, 365, 448, 4);
ctx.fillStyle = "#91a3c1";
ctx.font = "800 20px ui-monospace, monospace";
ctx.fillText("DESTINATION", 32, 408);
// Pixel-style location pin.
ctx.fillStyle = accent;
ctx.fillRect(33, 434, 30, 30);
ctx.fillRect(41, 464, 14, 14);
ctx.fillStyle = "#122039";
ctx.fillRect(43, 442, 10, 10);
ctx.fillStyle = "#f5f7ff";
ctx.font = "900 27px ui-monospace, monospace";
ctx.fillText("CENTRAL", 84, 450);
ctx.fillText("STATION", 84, 483);
ctx.fillStyle = "#263651";
ctx.fillRect(22, 526, 468, 152);
ctx.fillStyle = "#91a3c1";
ctx.font = "800 18px ui-monospace, monospace";
ctx.fillText(isBus ? "VIA" : "SERVICE", 39, 558);
ctx.fillStyle = "#dbe4f6";
ctx.font = "800 21px ui-monospace, monospace";
ctx.fillText(
isBus ? "MUSEUM SQUARE" : "EVERY 6 MINUTES",
39,
595
);
ctx.fillStyle = accent;
ctx.font = "800 19px ui-monospace, monospace";
ctx.fillText(
selected ? "✓ SELECTED ALTERNATIVE" : "TO CENTRAL STATION",
39,
645
);
data.texture.needsUpdate = true;
}
const busCard = createRouteCard("bus", -1.25, 0xff6b70, 0xb94b58);
const tramCard = createRouteCard("tram", 1.75, 0x54e6ad, 0x2c6d61);
// 3D check marker that appears on the selected alternative.
const checkMarker = new THREE.Group();
checkMarker.position.set(0.93, 1.22, 0.24);
checkMarker.visible = false;
tramCard.group.add(checkMarker);
const checkMaterial = standardMaterial(0x54e6ad, {
emissive: 0x36d492,
emissiveIntensity: 0.65
});
const checkPartA = voxel(
[0.38, 0.12, 0.12],
[-0.11, -0.04, 0],
checkMaterial,
checkMarker
);
checkPartA.rotation.z = 0.72;
const checkPartB = voxel(
[0.62, 0.12, 0.12],
[0.12, 0.08, 0],
checkMaterial,
checkMarker
);
checkPartB.rotation.z = -0.68;
// Shared destination sign above both route cards.
const destinationCanvas = document.createElement("canvas");
destinationCanvas.width = 1024;
destinationCanvas.height = 170;
const destinationCtx = destinationCanvas.getContext("2d");
destinationCtx.fillStyle = "#07111f";
destinationCtx.fillRect(0, 0, 1024, 170);
destinationCtx.fillStyle = "#54e6ad";
destinationCtx.fillRect(0, 0, 22, 170);
destinationCtx.fillStyle = "#8fa2c2";
destinationCtx.font = "800 24px ui-monospace, monospace";
destinationCtx.fillText("BOTH ROUTES • SAME DESTINATION", 48, 55);
destinationCtx.fillStyle = "#f6f8ff";
destinationCtx.font = "900 48px ui-monospace, monospace";
destinationCtx.fillText("CENTRAL STATION", 48, 119);
makeTextPlane(
4.9,
0.66,
destinationCanvas,
[0.25, 5.48, -1.53]
);
// ---------------------------------------------------------------------
// Voxel traveler
// ---------------------------------------------------------------------
const traveler = new THREE.Group();
traveler.visible = false;
scene.add(traveler);
const skin = standardMaterial(0xd99b72);
const hair = standardMaterial(0x242033);
const jacket = standardMaterial(0x8e7df1);
const pants = standardMaterial(0x27324a);
const shoes = standardMaterial(0x151a25);
const backpack = standardMaterial(0xec8c55);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.22, 0.78, 0);
rightLeg.position.set(0.22, 0.78, 0);
traveler.add(leftLeg, rightLeg);
voxel([0.34, 0.56, 0.38], [0, -0.29, 0], pants, leftLeg);
voxel([0.34, 0.56, 0.38], [0, -0.29, 0], pants, rightLeg);
voxel([0.38, 0.18, 0.55], [0, -0.62, 0.08], shoes, leftLeg);
voxel([0.38, 0.18, 0.55], [0, -0.62, 0.08], shoes, rightLeg);
voxel([0.76, 0.84, 0.46], [0, 1.16, 0], jacket, traveler);
voxel([0.16, 0.14, 0.47], [0, 1.54, 0], skin, traveler);
const headGroup = new THREE.Group();
headGroup.position.set(0, 1.69, 0);
traveler.add(headGroup);
voxel([0.54, 0.54, 0.54], [0, 0.27, 0], skin, headGroup);
voxel([0.59, 0.16, 0.59], [0, 0.57, -0.015], hair, headGroup);
voxel([0.16, 0.35, 0.56], [-0.22, 0.38, 0], hair, headGroup);
voxel([0.07, 0.07, 0.035], [-0.13, 0.29, 0.282], darkMaterial, headGroup);
voxel([0.07, 0.07, 0.035], [0.13, 0.29, 0.282], darkMaterial, headGroup);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.49, 1.43, 0.01);
rightArm.position.set(0.49, 1.43, 0.01);
traveler.add(leftArm, rightArm);
voxel([0.24, 0.65, 0.28], [0, -0.31, 0], jacket, leftArm);
voxel([0.24, 0.65, 0.28], [0, -0.31, 0], jacket, rightArm);
voxel([0.25, 0.22, 0.27], [0, -0.72, 0], skin, leftArm);
voxel([0.25, 0.22, 0.27], [0, -0.72, 0], skin, rightArm);
voxel([0.62, 0.68, 0.25], [0, 1.17, -0.34], backpack, traveler);
voxel([0.37, 0.25, 0.09], [0, 1.26, -0.5], standardMaterial(0xffc56f), traveler);
// ---------------------------------------------------------------------
// Animation state
// ---------------------------------------------------------------------
const state = {
startedAt: performance.now(),
shownDelay: 2,
selected: false,
selectionAt: 0,
statusKey: "",
noticeUntil: 0
};
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function easeOutCubic(value) {
const x = clamp01(value);
return 1 - Math.pow(1 - x, 3);
}
function easeInOutCubic(value) {
const x = clamp01(value);
return x < 0.5
? 4 * x * x * x
: 1 - Math.pow(-2 * x + 2, 3) / 2;
}
function setStatus(key) {
if (state.statusKey === key) return;
state.statusKey = key;
const content = {
live: {
state: "live",
label: "Live departure",
title: "+2 min",
detail: "Bus 24 → Central Station"
},
alert: {
state: "alert",
label: "Display updated",
title: "+7 min",
detail: "The bus delay increased on the station board."
},
compare: {
state: "compare",
label: "Comparing routes",
title: "Same destination",
detail: "The traveler is checking Bus 24 against Tram 8."
},
selected: {
state: "selected",
label: "Alternative selected",
title: "Tram 8 selected",
detail: "On time · Central Station"
},
notice: {
state: "alert",
label: "Delayed option",
title: "Bus 24 is delayed",
detail: "Choose the on-time Tram 8 instead."
}
}[key];
statusPanel.dataset.state = content.state;
statusLabel.textContent = content.label;
statusTitle.textContent = content.title;
statusDetail.textContent = content.detail;
}
function selectAlternative() {
if (state.selected) return;
state.selected = true;
state.selectionAt = performance.now();
tramCard.selected = true;
drawRouteCard(tramCard, true);
checkMarker.visible = true;
setStatus("selected");
}
function resetAnimation() {
state.startedAt = performance.now();
state.shownDelay = 2;
state.selected = false;
state.selectionAt = 0;
state.statusKey = "";
state.noticeUntil = 0;
busCard.selected = false;
tramCard.selected = false;
drawRouteCard(busCard, false);
drawRouteCard(tramCard, false);
drawDisplay(2);
traveler.visible = false;
traveler.position.set(-3.35, 0.24, 0.2);
traveler.rotation.set(0, 0, 0);
leftLeg.rotation.set(0, 0, 0);
rightLeg.rotation.set(0, 0, 0);
leftArm.rotation.set(0, 0, 0);
rightArm.rotation.set(0, 0, 0);
headGroup.rotation.set(0, 0, 0);
busCard.group.position.y = cardFinalY - 4.2;
tramCard.group.position.y = cardFinalY - 4.2;
checkMarker.visible = false;
chooseButton.disabled = true;
setStatus("live");
}
chooseButton.addEventListener("click", () => {
selectAlternative();
});
replayButton.addEventListener("click", () => {
resetAnimation();
});
// ---------------------------------------------------------------------
// Direct camera controls: drag orbit and wheel zoom
// ---------------------------------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const routeFaces = [busCard.face, tramCard.face];
let dragging = false;
let dragMoved = 0;
let previousPointerX = 0;
let previousPointerY = 0;
function setPointerFromEvent(event) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
}
function getRouteIntersection(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(routeFaces, false)[0] || null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = 0;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
dragMoved += Math.abs(deltaX) + Math.abs(deltaY);
cameraYaw -= deltaX * 0.005;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.0035,
0.2,
0.92
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCameraPosition();
return;
}
const hit = getRouteIntersection(event);
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragMoved > 6) return;
const hit = getRouteIntersection(event);
if (!hit) return;
if (hit.object.userData.route === "tram") {
selectAlternative();
} else {
state.noticeUntil = performance.now() + 2600;
setStatus("notice");
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.8
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 0.8 ? 21 : aspect < 1.2 ? 16 : 13.5;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Main timeline
// ---------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const elapsed = (now - state.startedAt) / 1000;
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
// The station display changes from two minutes to seven minutes.
if (elapsed >= 1.8 && state.shownDelay !== 7) {
state.shownDelay = 7;
drawDisplay(7);
drawRouteCard(busCard, false);
setStatus("alert");
}
// The cards rise after the display has changed.
const cardRise = easeOutCubic((elapsed - 2.55) / 1.05);
const busFloat = elapsed > 3.6 ? Math.sin(now * 0.0015) * 0.035 : 0;
const tramFloat = elapsed > 3.6 ? Math.sin(now * 0.0015 + 1.2) * 0.035 : 0;
busCard.group.position.y = cardFinalY - 4.2 + cardRise * 4.2 + busFloat;
tramCard.group.position.y = cardFinalY - 4.2 + cardRise * 4.2 + tramFloat;
if (elapsed >= 2.55) {
chooseButton.disabled = false;
}
// The traveler enters, compares the cards, then selects the alternative.
if (elapsed >= 2.42) {
traveler.visible = true;
const walkProgress = easeInOutCubic((elapsed - 2.42) / 1.65);
traveler.position.x = THREE.MathUtils.lerp(-3.35, 0.28, walkProgress);
const walking = elapsed < 4.07 ? 1 : 0;
const step = Math.sin(elapsed * 10.5);
traveler.position.y = 0.24 + (walking ? Math.abs(step) * 0.045 : 0);
leftLeg.rotation.x = step * 0.48 * walking;
rightLeg.rotation.x = -step * 0.48 * walking;
if (elapsed < 4.55) {
headGroup.rotation.y = -0.42;
} else if (elapsed < 5.15) {
headGroup.rotation.y = 0.42;
} else {
headGroup.rotation.y = 0.3;
}
const pointProgress = easeOutCubic((elapsed - 5.0) / 0.85);
rightArm.rotation.z = pointProgress * 2.25;
leftArm.rotation.z = -0.1 * pointProgress;
leftArm.rotation.x = -step * 0.38 * walking;
rightArm.rotation.x = step * 0.38 * walking;
}
if (elapsed >= 5.15 && !state.selected) {
selectAlternative();
}
// The bus creeps forward and then stops when the delay appears.
const busMove = easeOutCubic(clamp01(elapsed / 1.8));
bus.position.x = -5.12 + busMove * 0.22;
// Brake lights flash while the delayed bus is stopped.
const brakePulse = 0.35 + Math.max(0, Math.sin(now * 0.009)) * 0.9;
brakeMaterial.emissiveIntensity = brakePulse;
alertLightMaterial.emissiveIntensity =
elapsed < 1.8 ? 0.25 : 0.4 + Math.max(0, Math.sin(now * 0.008)) * 1.1;
// Selected-card check and glow.
if (state.selected) {
const selectionProgress = easeOutCubic(
(now - state.selectionAt) / 420
);
const pulse = 0.5 + 0.5 * Math.sin(now * 0.005);
checkMarker.scale.setScalar(Math.max(0.001, selectionProgress));
checkMarker.rotation.y = Math.sin(now * 0.002) * 0.08;
tramCard.frameMaterial.emissiveIntensity = 0.85 + pulse * 0.75;
tramCard.glowMaterial.opacity = 0.11 + pulse * 0.07;
} else {
checkMarker.scale.setScalar(0.001);
tramCard.frameMaterial.emissiveIntensity = 0.08;
tramCard.glowMaterial.opacity = 0;
}
if (state.noticeUntil > 0 && now > state.noticeUntil) {
state.noticeUntil = 0;
state.statusKey = "";
}
if (!state.selected) {
if (elapsed < 1.8) {
setStatus("live");
} else if (elapsed < 2.55) {
setStatus("alert");
} else {
setStatus("compare");
}
}
// Gentle life in the scene.
tram.position.x = 6.3 + Math.sin(now * 0.00035) * 0.08;
renderer.render(scene, camera);
}
resetAnimation();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```