Prompt specification
Build or customize the Three.js 3D scene "Two Walking Speeds One Signal Window" 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: Two Walking Speeds One Signal Window
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-walking-speeds-one-signal-window-x2118
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring pedestrian crossing clearance and signal timing. Animate schematic pedestrians crossing at two stated speeds under the same timer. Show whether each clears the modeled path without treating those speeds as universal human values. Low-poly.
Working Three.js Starter (two-walking-speeds-one-signal-window-x2118):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pedestrian Crossing Clearance Lab</title>
<style>
:root {
--bg: #07131c;
--panel: rgba(8, 22, 31, 0.88);
--panel-edge: rgba(173, 220, 229, 0.18);
--text: #edf8fa;
--muted: #91aeb8;
--mint: #58e0c2;
--blue: #67baff;
--amber: #ffb45e;
--red: #ff6969;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.panel {
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--panel-edge);
border-radius: 18px;
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
}
.masthead {
position: absolute;
top: 22px;
left: 24px;
max-width: 470px;
}
.eyebrow {
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 5px;
font-size: clamp(24px, 3vw, 42px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.masthead p {
margin: 0;
max-width: 440px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.camera-hint {
position: absolute;
top: 24px;
left: 50%;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(255,255,255,0.12);
border-radius: 999px;
background: rgba(5, 17, 25, 0.64);
color: #b7cbd2;
font-size: 11px;
letter-spacing: 0.04em;
white-space: nowrap;
}
.signal-panel {
position: absolute;
top: 22px;
right: 24px;
width: 310px;
padding: 17px;
}
.signal-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.phase {
margin-top: 8px;
font-size: 23px;
font-weight: 850;
line-height: 1.05;
letter-spacing: -0.03em;
color: var(--mint);
}
.phase[data-state="clearance"] { color: var(--amber); }
.phase[data-state="red"] { color: var(--red); }
.countdown {
color: #fff;
font-size: 31px;
font-weight: 800;
font-variant-numeric: tabular-nums;
line-height: 1;
}
.countdown small {
color: var(--muted);
font-size: 13px;
font-weight: 600;
}
.timeline {
display: flex;
height: 39px;
margin-top: 15px;
overflow: hidden;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 9px;
background: rgba(0,0,0,0.18);
}
.phase-segment {
position: relative;
min-width: 0;
overflow: hidden;
border-right: 1px solid rgba(255,255,255,0.12);
}
.phase-segment:last-child { border-right: 0; }
.phase-segment .fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
opacity: 0.22;
background: var(--mint);
}
.phase-segment.clearance .fill { background: var(--amber); }
.phase-segment.red .fill { background: var(--red); }
.phase-segment span {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: #c7d8dd;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
}
.signal-meta {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.button-row {
display: flex;
gap: 7px;
margin-top: 14px;
}
button {
appearance: none;
border: 1px solid rgba(255,255,255,0.14);
border-radius: 9px;
padding: 9px 10px;
background: rgba(255,255,255,0.055);
color: #e9f4f6;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
cursor: pointer;
}
button:hover {
background: rgba(88, 224, 194, 0.13);
border-color: rgba(88, 224, 194, 0.42);
}
button.primary {
background: rgba(88, 224, 194, 0.15);
border-color: rgba(88, 224, 194, 0.4);
color: #a8f4e3;
}
.inputs-panel {
position: absolute;
left: 24px;
bottom: 24px;
width: 330px;
padding: 17px;
}
.panel-title {
margin: 0 0 12px;
font-size: 17px;
letter-spacing: -0.02em;
}
.input-row {
display: flex;
justify-content: space-between;
gap: 14px;
padding: 8px 0;
border-top: 1px solid rgba(255,255,255,0.08);
color: var(--muted);
font-size: 12px;
}
.input-row strong {
color: #f2fbfc;
font-variant-numeric: tabular-nums;
}
.note {
margin: 12px 0 0;
padding: 11px;
border-left: 3px solid var(--mint);
background: rgba(88, 224, 194, 0.07);
color: #b8cdd3;
font-size: 11px;
line-height: 1.48;
}
.results-panel {
position: absolute;
right: 24px;
bottom: 24px;
width: 390px;
padding: 17px;
}
.results-intro {
margin: -3px 0 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.walker-card {
margin-top: 9px;
padding: 12px;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px;
background: rgba(255,255,255,0.035);
}
.walker-top {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 9px;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 0 15px rgba(103,186,255,0.55);
}
.dot.orange {
background: var(--amber);
box-shadow: 0 0 15px rgba(255,180,94,0.5);
}
.walker-name {
font-size: 14px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.walker-sub {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.result-pill {
padding: 5px 7px;
border-radius: 999px;
color: #9ff3de;
background: rgba(88,224,194,0.13);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.07em;
white-space: nowrap;
}
.result-pill.fail {
color: #ffd3a2;
background: rgba(255,180,94,0.13);
}
.walker-now {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid rgba(255,255,255,0.08);
color: #bdced4;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.results-panel .note {
border-left-color: var(--amber);
background: rgba(255,180,94,0.065);
}
@media (max-width: 900px) {
.masthead { max-width: 330px; }
.masthead p { display: none; }
.camera-hint { display: none; }
.signal-panel { width: 270px; }
.inputs-panel { width: 285px; }
.results-panel { width: 340px; }
}
@media (max-width: 680px) {
.masthead { top: 14px; left: 14px; }
.signal-panel {
top: 90px;
right: 12px;
width: 230px;
padding: 13px;
}
.inputs-panel {
left: 12px;
bottom: 12px;
width: calc(100% - 24px);
}
.results-panel {
right: 12px;
bottom: 220px;
width: calc(100% - 24px);
}
.inputs-panel .note { display: none; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="hud">
<header class="masthead">
<div class="eyebrow">Crossing Clearance Lab</div>
<h1>One timer.<br />Two modeled speeds.</h1>
<p>
A schematic signal-timing comparison on a fixed modeled path.
Results describe this geometry and schedule only.
</p>
</header>
<div class="camera-hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
<section class="panel signal-panel" aria-label="Shared signal timer">
<div class="signal-heading">
<div>
<div class="eyebrow">Shared Signal Timer</div>
<div id="phaseName" class="phase" data-state="walk" aria-live="polite">
WALK
</div>
</div>
<div class="countdown">
<span id="phaseCount">12.0</span><small>s</small>
</div>
</div>
<div id="timeline" class="timeline">
<div class="phase-segment" data-phase="walk">
<div class="fill"></div><span>WALK</span>
</div>
<div class="phase-segment clearance" data-phase="clearance">
<div class="fill"></div><span>CLEAR</span>
</div>
<div class="phase-segment red" data-phase="red">
<div class="fill"></div><span>RED</span>
</div>
</div>
<div class="signal-meta">
<span id="cycleClock">0.0 / 30.0 s</span>
<span>30 s repeating cycle</span>
</div>
<div class="button-row">
<button id="pauseButton" class="primary">PAUSE</button>
<button id="replayButton">REPLAY</button>
<button id="rateButton">1×</button>
<button id="cameraButton">RESET VIEW</button>
</div>
</section>
<section class="panel inputs-panel">
<h2 class="panel-title">Modeled inputs</h2>
<div class="input-row">
<span>Crossing path</span>
<strong>20.0 m</strong>
</div>
<div class="input-row">
<span>WALK indication</span>
<strong>12.0 s</strong>
</div>
<div class="input-row">
<span>Flashing DON’T WALK</span>
<strong>8.0 s</strong>
</div>
<div class="input-row">
<span>WALK + clearance window</span>
<strong>20.0 s</strong>
</div>
<div class="input-row">
<span>Entry behavior</span>
<strong>Both enter at t = 0</strong>
</div>
<p class="note">
The 1.10 m/s and 0.80 m/s values are scripted animation inputs,
not labels for people or universal human walking speeds.
</p>
</section>
<section class="panel results-panel">
<h2 class="panel-title">Does each clear the modeled path?</h2>
<p class="results-intro">
Crossing time = 20.0 m ÷ speed. Clearance is judged against the
20.0-second WALK-plus-clearance interval beginning at entry.
</p>
<article class="walker-card" id="fastCard">
<div class="walker-top">
<div class="dot"></div>
<div>
<div class="walker-name">1.10 m/s</div>
<div class="walker-sub">16.7 s to traverse · 3.3 s inside window</div>
</div>
<div class="result-pill">CLEARS</div>
</div>
<div class="walker-now" id="fastNow">Starting at the south curb</div>
</article>
<article class="walker-card" id="slowCard">
<div class="walker-top">
<div class="dot orange"></div>
<div>
<div class="walker-name">0.80 m/s</div>
<div class="walker-sub">25.0 s to traverse · 5.0 s beyond window</div>
</div>
<div class="result-pill fail">DOES NOT CLEAR</div>
</div>
<div class="walker-now" id="slowNow">Starting at the south curb</div>
</article>
<p class="note">
This is a geometry-and-timing illustration, not a traffic-engineering
standard, accessibility finding, or recommendation for real-world
signal timing.
</p>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scenario assumptions
// ---------------------------------------------------------------------
const CONFIG = {
pathLength: 20,
walkDuration: 12,
clearanceDuration: 8,
redDuration: 10,
speeds: {
fast: 1.10,
slow: 0.80
}
};
CONFIG.crossingWindow =
CONFIG.walkDuration + CONFIG.clearanceDuration;
CONFIG.cycleDuration =
CONFIG.walkDuration +
CONFIG.clearanceDuration +
CONFIG.redDuration;
const viewport = document.getElementById("viewport");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131c);
scene.fog = new THREE.Fog(0x07131c, 42, 88);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
140
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xbfefff, 0x1c2832, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d4, 3.0);
sun.position.set(-12, 24, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x6dbdff, 1.25);
rim.position.set(16, 10, -18);
scene.add(rim);
const world = new THREE.Group();
scene.add(world);
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.02,
flatShading: options.flatShading ?? true,
side: options.side ?? THREE.FrontSide,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
function addMesh(geometry, material, x = 0, y = 0, z = 0, parent = world) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, x, y, z, parent = world) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
material,
x, y, z, parent
);
}
// ---------------------------------------------------------------------
// Ground, broad modeled roadway, sidewalks and crosswalk
// ---------------------------------------------------------------------
const groundMat = standard(0x101f27);
const roadMat = standard(0x24323a);
const sidewalkMat = standard(0x6c7e80);
const curbMat = standard(0xb7c3bf);
const stripeMat = standard(0xdce9e5);
const laneMat = standard(0xc6d3c8);
const cyanMat = standard(0x52dfc1, {
emissive: 0x0b5144,
emissiveIntensity: 0.6
});
addBox(76, 0.6, 58, groundMat, 0, -0.65, 0);
// The road is 20 m wide in the crossing direction.
addBox(44, 0.30, CONFIG.pathLength, roadMat, 0, -0.15, 0);
// Sidewalks begin exactly at both modeled path endpoints.
addBox(44, 0.30, 7.0, sidewalkMat, 0, 0.02, 13.5);
addBox(44, 0.30, 7.0, sidewalkMat, 0, 0.02, -13.5);
addBox(44, 0.34, 0.34, curbMat, 0, 0.08, -10.05);
addBox(44, 0.34, 0.34, curbMat, 0, 0.08, 10.05);
// Road lane markings.
for (let x = -19; x <= 19; x += 4.5) {
addBox(2.1, 0.018, 0.13, laneMat, x, 0.015, 0);
}
// Zebra crossing, centered on the 20 m modeled path.
for (let i = 0; i < 11; i++) {
addBox(
5.4, 0.025, 1.05,
stripeMat,
0, 0.025, -9 + i * 1.8
);
}
// Cyan route and direction arrows.
const routeGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.11, -10),
new THREE.Vector3(0, 0.11, 10)
]);
const route = new THREE.Line(
routeGeometry,
new THREE.LineDashedMaterial({
color: 0x52dfc1,
dashSize: 0.65,
gapSize: 0.35,
transparent: true,
opacity: 0.9
})
);
route.computeLineDistances();
world.add(route);
function addArrow(z) {
const shape = new THREE.Shape();
shape.moveTo(0, 1.25);
shape.lineTo(-0.65, 0.25);
shape.lineTo(-0.25, 0.25);
shape.lineTo(-0.25, -1.0);
shape.lineTo(0.25, -1.0);
shape.lineTo(0.25, 0.25);
shape.lineTo(0.65, 0.25);
shape.closePath();
const arrow = addMesh(
new THREE.ShapeGeometry(shape),
standard(0x52dfc1, {
side: THREE.DoubleSide,
emissive: 0x0b5144,
emissiveIntensity: 0.4
}),
0, 0.075, z
);
arrow.rotation.x = Math.PI / 2;
arrow.castShadow = false;
}
addArrow(-5.4);
addArrow(5.4);
// ---------------------------------------------------------------------
// Low-poly context: buildings, trees, bollards
// ---------------------------------------------------------------------
const buildingColors = [0x233943, 0x2d4850, 0x31444b, 0x263840];
function addBuilding(x, z, w, d, h, index) {
const mat = standard(buildingColors[index % buildingColors.length]);
addBox(w, h, d, mat, x, h / 2 - 0.2, z);
// Rooftop details.
addBox(
w * 0.22,
1.2,
d * 0.24,
standard(0x172a31),
x + w * 0.18,
h,
z
);
}
[
[-16, 22, 8, 7, 8],
[-5, 23, 10, 8, 11],
[9, 22, 9, 7, 7],
[18, 24, 7, 9, 13],
[-18, -23, 9, 8, 10],
[-4, -24, 8, 7, 7],
[10, -23, 11, 8, 12],
[21, -22, 6, 7, 8]
].forEach((b, i) => addBuilding(...b, i));
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
addMesh(
new THREE.CylinderGeometry(0.16, 0.23, 1.8, 5),
standard(0x6e5138),
0, 0.9, 0, group
);
addMesh(
new THREE.IcosahedronGeometry(1.25, 0),
standard(0x3f8065),
0, 2.3, 0, group
);
addMesh(
new THREE.IcosahedronGeometry(0.85, 0),
standard(0x59a878),
0.55, 2.85, -0.15, group
);
}
[
[-19, 14.8, 1.0], [-13, 14.8, 0.8], [12, 14.8, 0.9],
[19, 14.8, 1.1], [-18, -14.8, 0.9], [-11, -14.8, 1.0],
[13, -14.8, 0.85], [20, -14.8, 1.05]
].forEach(t => addTree(...t));
const bollardMat = standard(0x344c54);
for (const z of [-10.8, 10.8]) {
for (const x of [-7.2, -5.7, 5.7, 7.2]) {
addMesh(
new THREE.CylinderGeometry(0.11, 0.14, 0.85, 6),
bollardMat,
x, 0.42, z
);
}
}
// ---------------------------------------------------------------------
// 3D labels
// ---------------------------------------------------------------------
function makeLabel(text, color = "#58e0c2") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(5, 17, 25, 0.88)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = color;
ctx.lineWidth = 7;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.fillStyle = color;
ctx.font = "800 43px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
})
);
sprite.scale.set(4.8, 1.125, 1);
return sprite;
}
const startLabel = makeLabel("START • 0 m");
startLabel.position.set(6.4, 1.25, -10);
world.add(startLabel);
const endLabel = makeLabel("END • 20 m");
endLabel.position.set(6.4, 1.25, 10);
world.add(endLabel);
// ---------------------------------------------------------------------
// Pedestrian signals
// ---------------------------------------------------------------------
const signalHeads = [];
const poleMat = standard(0x263c43, { metalness: 0.45, roughness: 0.4 });
const housingMat = standard(0x15242a, { metalness: 0.22, roughness: 0.5 });
function makeLamp(color) {
return standard(color, {
roughness: 0.28,
metalness: 0.05,
emissive: color,
emissiveIntensity: 0
});
}
function addSignal(x, z, facing) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
addMesh(
new THREE.CylinderGeometry(0.10, 0.14, 3.35, 8),
poleMat,
0, 1.67, 0, group
);
addBox(0.72, 0.16, 0.72, poleMat, 0, 0.08, 0, group);
const head = new THREE.Group();
head.position.set(0, 3.15, facing * 0.22);
head.rotation.y = facing > 0 ? 0 : Math.PI;
group.add(head);
addBox(0.82, 1.92, 0.46, housingMat, 0, 0, 0, head);
const red = makeLamp(0xff5555);
const amber = makeLamp(0xffb84f);
const green = makeLamp(0x48e0a7);
const lensGeometry = new THREE.CylinderGeometry(0.19, 0.19, 0.10, 12);
const redLens = addMesh(lensGeometry, red, 0, 0.56, 0.27, head);
const amberLens = addMesh(lensGeometry, amber, 0, 0, 0.27, head);
const greenLens = addMesh(lensGeometry, green, 0, -0.56, 0.27, head);
[redLens, amberLens, greenLens].forEach(lens => {
lens.rotation.x = Math.PI / 2;
});
// Small pedestrian-signal silhouette plate.
addBox(0.46, 0.46, 0.055, housingMat, 0, -1.08, 0.25, head);
signalHeads.push({ red, amber, green });
}
addSignal(-4.45, -10.85, 1);
addSignal(4.45, 10.85, -1);
// ---------------------------------------------------------------------
// Low-poly animated pedestrians
// ---------------------------------------------------------------------
function makePerson(primaryColor, accentColor) {
const root = new THREE.Group();
world.add(root);
const primary = standard(primaryColor);
const accent = standard(accentColor);
const skin = standard(0xd6a77f);
const dark = standard(0x1a2930);
// Torso and pelvis.
addBox(0.68, 0.95, 0.38, primary, 0, 1.48, 0, root);
addBox(0.58, 0.25, 0.34, accent, 0, 0.98, 0, root);
// Faceted head.
addMesh(
new THREE.DodecahedronGeometry(0.30, 0),
skin,
0, 2.18, 0,
root
);
// Hair / cap.
addMesh(
new THREE.DodecahedronGeometry(0.315, 0),
dark,
0, 2.27, -0.035,
root
);
function makeLimb(x, y, color, length, width) {
const pivot = new THREE.Group();
pivot.position.set(x, y, 0);
root.add(pivot);
addBox(
width, length, width,
color,
0, -length / 2, 0,
pivot
);
return pivot;
}
const leftLeg = makeLimb(-0.20, 1.00, dark, 0.82, 0.23);
const rightLeg = makeLimb(0.20, 1.00, dark, 0.82, 0.23);
const leftArm = makeLimb(-0.46, 1.86, accent, 0.74, 0.19);
const rightArm = makeLimb(0.46, 1.86, accent, 0.74, 0.19);
// Simple feet make the gait direction easier to read.
addBox(0.25, 0.14, 0.38, accent, -0.20, 0.18, 0.08, root);
addBox(0.25, 0.14, 0.38, accent, 0.20, 0.18, 0.08, root);
root.traverse(obj => {
if (obj.isMesh) {
obj.castShadow = true;
obj.receiveShadow = true;
}
});
return { root, leftLeg, rightLeg, leftArm, rightArm };
}
const fastPerson = makePerson(0x3a98dc, 0x9edcff);
const slowPerson = makePerson(0xdf7d2c, 0xffd09a);
fastPerson.root.position.set(-1.15, 0.06, -CONFIG.pathLength / 2);
slowPerson.root.position.set(1.15, 0.06, -CONFIG.pathLength / 2);
// ---------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// ---------------------------------------------------------------------
const cameraState = {
yaw: 0.66,
pitch: 0.61,
distance: 39,
target: new THREE.Vector3(0, 1.1, 0)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.yaw = 0.66;
cameraState.pitch = 0.61;
cameraState.distance = 39;
updateCamera();
}
updateCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.25,
1.25
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", e => e.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
22,
65
);
updateCamera();
}, { passive: false });
// ---------------------------------------------------------------------
// Timer and interface
// ---------------------------------------------------------------------
const phaseName = document.getElementById("phaseName");
const phaseCount = document.getElementById("phaseCount");
const cycleClock = document.getElementById("cycleClock");
const fastNow = document.getElementById("fastNow");
const slowNow = document.getElementById("slowNow");
const phaseElements = Array.from(
document.querySelectorAll(".phase-segment")
).map(element => ({
element,
fill: element.querySelector(".fill")
}));
let elapsed = 0;
let paused = false;
let playbackRate = 1;
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
const rateButton = document.getElementById("rateButton");
const cameraButton = document.getElementById("cameraButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
});
replayButton.addEventListener("click", () => {
elapsed = 0;
});
const rates = [1, 2, 0.5];
let rateIndex = 0;
rateButton.addEventListener("click", () => {
rateIndex = (rateIndex + 1) % rates.length;
playbackRate = rates[rateIndex];
rateButton.textContent = `${playbackRate}×`;
});
cameraButton.addEventListener("click", resetCamera);
function getSignalState(time) {
if (time < CONFIG.walkDuration) {
return {
name: "WALK",
state: "walk",
remaining: CONFIG.walkDuration - time,
start: 0,
duration: CONFIG.walkDuration
};
}
if (time < CONFIG.walkDuration + CONFIG.clearanceDuration) {
return {
name: "FLASH DON’T WALK",
state: "clearance",
remaining:
CONFIG.walkDuration + CONFIG.clearanceDuration - time,
start: CONFIG.walkDuration,
duration: CONFIG.clearanceDuration
};
}
return {
name: "DON’T WALK",
state: "red",
remaining: CONFIG.cycleDuration - time,
start: CONFIG.walkDuration + CONFIG.clearanceDuration,
duration: CONFIG.redDuration
};
}
function setLamp(material, active, color) {
material.color.setHex(active ? color : 0x16252a);
material.emissive.setHex(active ? color : 0x000000);
material.emissiveIntensity = active ? 2.6 : 0;
}
function updateSignal(signal, time) {
const walking = time < CONFIG.walkDuration;
const clearing =
time >= CONFIG.walkDuration &&
time < CONFIG.walkDuration + CONFIG.clearanceDuration;
const red = time >= CONFIG.walkDuration + CONFIG.clearanceDuration;
// The clearance indication flashes at 4 Hz.
const amberOn =
clearing && Math.floor((time - CONFIG.walkDuration) * 4) % 2 === 0;
signalHeads.forEach(head => {
setLamp(head.green, walking, 0x48e0a7);
setLamp(head.amber, amberOn, 0xffb84f);
setLamp(head.red, red, 0xff5555);
});
}
function updateTimeline(time, signal) {
phaseElements.forEach(({ element, fill }) => {
const phase = element.dataset.phase;
let start = 0;
let duration = CONFIG.walkDuration;
if (phase === "clearance") {
start = CONFIG.walkDuration;
duration = CONFIG.clearanceDuration;
} else if (phase === "red") {
start = CONFIG.walkDuration + CONFIG.clearanceDuration;
duration = CONFIG.redDuration;
}
const progress = THREE.MathUtils.clamp(
(time - start) / duration,
0,
1
);
fill.style.width = `${progress * 100}%`;
element.style.opacity = signal.state === phase ? "1" : "0.58";
});
}
function updatePerson(person, speed, xPosition, time) {
const traveled = Math.min(time * speed, CONFIG.pathLength);
const moving = traveled < CONFIG.pathLength - 0.001;
person.root.position.x = xPosition;
person.root.position.z =
-CONFIG.pathLength / 2 + traveled;
// Step onto the sidewalk slightly when reaching the end.
const curbBlend = THREE.MathUtils.smoothstep(
traveled,
CONFIG.pathLength - 0.25,
CONFIG.pathLength
);
person.root.position.y = 0.06 + curbBlend * 0.12;
const gait = time * speed * 2.65;
const swing = moving ? 0.56 : 0.02;
person.leftLeg.rotation.x = Math.sin(gait) * swing;
person.rightLeg.rotation.x = -Math.sin(gait) * swing;
person.leftArm.rotation.x = -Math.sin(gait) * swing * 0.82;
person.rightArm.rotation.x = Math.sin(gait) * swing * 0.82;
person.root.position.y += moving
? Math.abs(Math.sin(gait * 2)) * 0.035
: 0;
}
function updateResult(element, speed, time) {
const crossingTime = CONFIG.pathLength / speed;
const traveled = Math.min(time * speed, CONFIG.pathLength);
const remaining = Math.max(0, CONFIG.pathLength - traveled);
if (time >= crossingTime) {
const delay = crossingTime - CONFIG.crossingWindow;
element.textContent = delay <= 0
? `Arrived at ${crossingTime.toFixed(1)} s · ${Math.abs(delay).toFixed(1)} s inside the modeled window`
: `Arrived at ${crossingTime.toFixed(1)} s · ${delay.toFixed(1)} s after the modeled window`;
return;
}
if (time >= CONFIG.crossingWindow) {
element.textContent =
`Still on modeled path · ${remaining.toFixed(1)} m remaining`;
} else {
element.textContent =
`On modeled path · ${remaining.toFixed(1)} m remaining`;
}
}
function updateInterface(time) {
const signal = getSignalState(time);
phaseName.textContent = signal.name;
phaseName.dataset.state = signal.state;
phaseCount.textContent = signal.remaining.toFixed(1);
cycleClock.textContent =
`${time.toFixed(1)} / ${CONFIG.cycleDuration.toFixed(1)} s`;
updateTimeline(time, signal);
updateSignal(signal, time);
updatePerson(
fastPerson,
CONFIG.speeds.fast,
-1.15,
time
);
updatePerson(
slowPerson,
CONFIG.speeds.slow,
1.15,
time
);
updateResult(fastNow, CONFIG.speeds.fast, time);
updateResult(slowNow, CONFIG.speeds.slow, time);
}
// ---------------------------------------------------------------------
// Resize and animation loop
// ---------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, 0.1);
previousTime = now;
if (!paused) {
elapsed += dt * playbackRate;
}
if (elapsed >= CONFIG.cycleDuration) {
elapsed %= CONFIG.cycleDuration;
}
updateInterface(elapsed);
renderer.render(scene, camera);
}
updateInterface(0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```