Prompt specification
Build or customize the Three.js 3D scene "Neighborhood commute-time exhibit" 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: Neighborhood commute-time exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-commute-time-exhibit-x1811
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the mean and median of a dataset. Compose fictional homes with synthetic commute durations beside distribution markers; compare summaries without implying that one number captures every resident's experience. Voxel style.
Working Three.js Starter (neighborhood-commute-time-exhibit-x1811):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Two Summaries. Ten Different Commutes.</title>
<style>
:root {
--paper: #f1ede4;
--paper-light: #fbf8f1;
--ink: #193143;
--muted: #64727a;
--line: #d8d2c5;
--gold: #e2a63a;
--mean: #ef6a57;
--median: #147d78;
--shadow: 0 14px 40px rgba(25, 49, 67, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0 370px 0 0;
overflow: hidden;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
#stage canvas:focus-visible {
box-shadow: inset 0 0 0 3px rgba(20, 125, 120, 0.5);
}
#scene-labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
pointer-events: none;
user-select: none;
}
.data-label {
padding: 3px 5px 2px;
border: 1px solid rgba(25, 49, 67, 0.12);
border-radius: 3px;
background: rgba(255, 252, 244, 0.9);
color: var(--ink);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
box-shadow: 0 3px 8px rgba(25, 49, 67, 0.1);
}
.data-label small {
margin-left: 2px;
color: #8a6a27;
font-size: 7px;
letter-spacing: 0.04em;
}
.tick-label {
color: #66747a;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.axis-title {
color: var(--ink);
font: 800 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-align: center;
text-transform: uppercase;
}
.summary-label {
min-width: 126px;
padding: 8px 10px 8px 12px;
border: 1px solid rgba(25, 49, 67, 0.14);
border-left-width: 6px;
border-radius: 4px;
background: rgba(255, 252, 244, 0.96);
box-shadow: 0 8px 20px rgba(25, 49, 67, 0.15);
transform: translate(-50%, -100%);
}
.summary-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: currentColor;
opacity: 0.5;
}
.summary-label.mean {
border-left-color: var(--mean);
color: var(--mean);
}
.summary-label.median {
border-left-color: var(--median);
color: var(--median);
}
.summary-label span {
display: block;
margin-bottom: 3px;
color: var(--ink);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.summary-label strong {
font: 900 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.summary-label small {
margin-left: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
header {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
width: min(540px, calc(100vw - 420px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #3d6870;
font: 900 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 5px;
background: var(--gold);
box-shadow: 7px 0 0 rgba(226, 166, 58, 0.45);
}
h1 {
max-width: 530px;
margin: 0;
font-size: clamp(31px, 4vw, 54px);
font-weight: 900;
letter-spacing: -0.055em;
line-height: 0.98;
}
.intro {
max-width: 500px;
margin: 13px 0 0;
color: #52636b;
font-size: 14px;
line-height: 1.5;
}
.intro strong {
color: var(--ink);
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
right: 18px;
bottom: 18px;
width: 340px;
padding: 18px;
overflow: auto;
border: 1px solid rgba(25, 49, 67, 0.13);
border-radius: 12px;
background: rgba(251, 248, 241, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #b6b1a7 transparent;
}
.panel::-webkit-scrollbar {
width: 7px;
}
.panel::-webkit-scrollbar-thumb {
border-radius: 10px;
background: #b6b1a7;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.panel-kicker {
color: var(--muted);
font: 900 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.reset {
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 4px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.reset:hover,
.reset:focus-visible {
background: #fff;
outline: 2px solid rgba(20, 125, 120, 0.25);
}
.panel h2 {
margin: 0 0 13px;
font-size: 23px;
letter-spacing: -0.035em;
line-height: 1.05;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
position: relative;
padding: 12px 11px 11px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 7px;
background: #fffdf8;
}
.metric::before {
content: "";
position: absolute;
inset: 0 0 auto;
height: 5px;
background: var(--metric-color);
}
.metric.mean {
--metric-color: var(--mean);
}
.metric.median {
--metric-color: var(--median);
}
.metric-name {
display: block;
margin-bottom: 5px;
color: var(--muted);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
font: 900 25px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.07em;
}
.metric-value small {
margin-left: 4px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0;
}
.metric-copy {
margin: 7px 0 0;
color: #66747a;
font-size: 10px;
line-height: 1.4;
}
.difference {
display: flex;
align-items: center;
gap: 9px;
margin: 10px 0;
padding: 9px 10px;
border: 1px solid #e3d4b9;
border-radius: 6px;
background: #fbf1da;
}
.difference strong {
color: #875a20;
font: 900 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.difference span {
color: #715c3b;
font-size: 10px;
line-height: 1.35;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 17px 0 8px;
color: var(--ink);
font-size: 11px;
font-weight: 900;
}
.section-title small {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.range-card {
padding: 12px 10px 9px;
border: 1px solid var(--line);
border-radius: 7px;
background: #fffdf8;
}
.range-track {
position: relative;
height: 30px;
margin: 0 4px;
border-radius: 3px;
background:
linear-gradient(90deg, rgba(20, 125, 120, 0.09), rgba(239, 106, 87, 0.09));
}
.range-track::before {
content: "";
position: absolute;
top: 14px;
left: 0;
right: 0;
height: 2px;
background: #bfc3bc;
}
.range-dot {
position: absolute;
top: 9px;
width: 11px;
height: 11px;
margin-left: -5px;
border: 2px solid #fffdf8;
border-radius: 2px;
background: var(--gold);
box-shadow: 0 0 0 1px rgba(25, 49, 67, 0.18);
}
.range-rule {
position: absolute;
top: 0;
bottom: 0;
width: 3px;
margin-left: -1px;
border-radius: 2px;
opacity: 0.95;
}
.range-rule.mean {
background: var(--mean);
}
.range-rule.median {
background: var(--median);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #7d8588;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.interpretation {
margin: 11px 0 0;
color: #52636b;
font-size: 11px;
line-height: 1.55;
}
.interpretation strong {
color: var(--ink);
}
.caveat {
margin-top: 11px;
padding: 10px;
border-left: 4px solid var(--gold);
background: #f2efe7;
color: #4d5d64;
font-size: 10px;
line-height: 1.5;
}
.caveat strong {
color: var(--ink);
}
.selected-card {
min-height: 55px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 6px;
background: #fffdf8;
}
.selected-card strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.selected-card span {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.home-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
.home-button {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 6px;
min-width: 0;
padding: 7px;
border: 1px solid #ded8cd;
border-radius: 5px;
background: #fffdf8;
color: var(--ink);
cursor: pointer;
text-align: left;
}
.home-button:hover,
.home-button:focus-visible {
border-color: #9fa9a9;
outline: 2px solid rgba(20, 125, 120, 0.16);
}
.home-button[aria-pressed="true"] {
border-color: var(--mean);
background: #fff1ed;
}
.home-dot {
width: 8px;
height: 8px;
border-radius: 2px;
}
.home-button span:nth-child(2) {
overflow: hidden;
font-size: 10px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.home-button b {
color: #6b7477;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#legend {
position: fixed;
z-index: 5;
bottom: 24px;
left: 30px;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 15px;
max-width: calc(100vw - 430px);
padding: 9px 11px;
border: 1px solid rgba(25, 49, 67, 0.12);
border-radius: 6px;
background: rgba(251, 248, 241, 0.88);
color: #596970;
font-size: 9px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend-swatch {
width: 11px;
height: 11px;
border-radius: 2px;
background: var(--gold);
}
.legend-swatch.mean {
background: var(--mean);
}
.legend-swatch.median {
background: var(--median);
}
.legend-help {
color: #7c8689;
}
#tooltip {
position: fixed;
z-index: 30;
display: none;
min-width: 165px;
padding: 9px 10px;
border: 1px solid rgba(25, 49, 67, 0.15);
border-radius: 5px;
background: rgba(25, 49, 67, 0.94);
color: #fffdf8;
box-shadow: 0 8px 24px rgba(25, 49, 67, 0.22);
pointer-events: none;
}
#tooltip strong,
#tooltip span {
display: block;
}
#tooltip strong {
font-size: 11px;
}
#tooltip span {
margin-top: 3px;
color: #cdd7da;
font: 700 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
color: var(--ink);
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#loading span::after {
content: "";
display: block;
width: 80px;
height: 7px;
margin: 13px auto 0;
background: linear-gradient(
90deg,
var(--mean) 0 33%,
var(--gold) 33% 66%,
var(--median) 66%
);
}
@media (max-width: 900px) {
#stage {
inset: 0 0 44vh 0;
}
header {
top: 14px;
left: 16px;
width: calc(100vw - 32px);
}
h1 {
max-width: 440px;
font-size: clamp(29px, 8vw, 42px);
}
.intro {
max-width: 500px;
margin-top: 9px;
font-size: 12px;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: calc(44vh - 20px);
padding: 14px;
}
#legend {
display: none;
}
.panel h2 {
font-size: 20px;
}
}
@media (max-width: 520px) {
.intro {
max-width: 390px;
}
.intro .desktop-copy {
display: none;
}
.eyebrow {
margin-bottom: 7px;
font-size: 8px;
}
.metric-value {
font-size: 21px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<div id="stage">
<div id="scene-labels" aria-hidden="true"></div>
</div>
<header>
<div class="eyebrow">Synthetic commute study · 10 fictional homes</div>
<h1>Two summaries.<br>Ten different commutes.</h1>
<p class="intro">
Each gold marker lines up with a fictional home behind it.
<strong>The mean and median summarize the set</strong>
<span class="desktop-copy">—they do not stand in for any resident’s full experience.</span>
</p>
</header>
<aside class="panel" aria-label="Commute summary comparison">
<div class="panel-head">
<span class="panel-kicker">Reading the dataset</span>
<button class="reset" id="resetView" type="button">Reset view</button>
</div>
<h2>Two valid summaries,<br>one distribution.</h2>
<div class="metric-grid">
<section class="metric mean">
<span class="metric-name">Mean</span>
<div class="metric-value"><span id="meanValue">—</span><small>min</small></div>
<p class="metric-copy" id="meanDetail"></p>
</section>
<section class="metric median">
<span class="metric-name">Median</span>
<div class="metric-value"><span id="medianValue">—</span><small>min</small></div>
<p class="metric-copy" id="medianDetail"></p>
</section>
</div>
<div class="difference">
<strong id="deltaValue"></strong>
<span id="deltaNote"></span>
</div>
<div class="section-title">
<span>The spread behind the summaries</span>
<small id="spreadValue"></small>
</div>
<div class="range-card" aria-label="Commute duration range">
<div class="range-track" id="rangeTrack"></div>
<div class="range-ends">
<span>0 min</span>
<span>125 min</span>
</div>
</div>
<p class="interpretation">
The longer commutes at the right pull the mean upward. The median stays
closer to the middle pair. <strong>Neither number is “the real” commute</strong>
for a household.
</p>
<div class="caveat">
<strong>Context still matters.</strong>
Time alone cannot describe cost, crowding, reliability, accessibility,
schedule flexibility, or how a journey feels.
</div>
<div class="section-title">
<span>Selected home</span>
<small>Hover or choose below</small>
</div>
<div class="selected-card" id="selectedCard" aria-live="polite">
<strong id="selectedName">No home selected</strong>
<span id="selectedMeta">Select a gold marker or a home to inspect its synthetic commute.</span>
</div>
<div class="section-title">
<span>Fictional homes</span>
<small>Duration in minutes</small>
</div>
<div class="home-list" id="homeList"></div>
</aside>
<div id="legend" aria-hidden="true">
<span class="legend-item">
<i class="legend-swatch"></i>
Individual commute
</span>
<span class="legend-item">
<i class="legend-swatch mean"></i>
Mean
</span>
<span class="legend-item">
<i class="legend-swatch median"></i>
Median
</span>
<span class="legend-item legend-help">
Drag to orbit · wheel/pinch to zoom · 0 resets
</span>
</div>
<div id="tooltip" role="tooltip"></div>
<div id="loading"><span>Building commute landscape</span></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const homes = [
{ name: "Alder House", short: "Alder", minutes: 8, color: "#d56b5d" },
{ name: "Birch House", short: "Birch", minutes: 17, color: "#dfa04c" },
{ name: "Cedar House", short: "Cedar", minutes: 26, color: "#648f86" },
{ name: "Dune House", short: "Dune", minutes: 33, color: "#7186af" },
{ name: "Elm House", short: "Elm", minutes: 40, color: "#b77c77" },
{ name: "Fern House", short: "Fern", minutes: 47, color: "#82a46a" },
{ name: "Grove House", short: "Grove", minutes: 61, color: "#d68b62" },
{ name: "Harbor House", short: "Harbor", minutes: 74, color: "#607c96" },
{ name: "Ivy House", short: "Ivy", minutes: 90, color: "#a987aa" },
{ name: "Juniper House",short: "Juniper", minutes: 116, color: "#d6b25b" }
];
const sorted = homes.map(h => h.minutes).sort((a, b) => a - b);
const mean = sorted.reduce((sum, value) => sum + value, 0) / sorted.length;
const middle = Math.floor(sorted.length / 2);
const median = sorted.length % 2
? sorted[middle]
: (sorted[middle - 1] + sorted[middle]) / 2;
const delta = mean - median;
const range = sorted[sorted.length - 1] - sorted[0];
const stage = document.querySelector("#stage");
const labelLayer = document.querySelector("#scene-labels");
const tooltip = document.querySelector("#tooltip");
const loading = document.querySelector("#loading");
document.querySelector("#meanValue").textContent = mean.toFixed(1);
document.querySelector("#medianValue").textContent = median.toFixed(1);
document.querySelector("#meanDetail").textContent =
`All ${homes.length} commutes added together, then divided by ${homes.length}.`;
document.querySelector("#medianDetail").textContent =
`Middle pair: ${sorted[middle - 1]} and ${sorted[middle]}; their midpoint.`;
document.querySelector("#deltaValue").textContent =
`+${delta.toFixed(1)} min`;
document.querySelector("#deltaNote").textContent =
"The mean is longer than the median because the long right tail pulls the average upward.";
document.querySelector("#spreadValue").textContent =
`${range}-minute range`;
const rangeTrack = document.querySelector("#rangeTrack");
homes.forEach(home => {
const dot = document.createElement("span");
dot.className = "range-dot";
dot.style.left = `${(home.minutes / 125) * 100}%`;
dot.style.background = home.color;
dot.title = `${home.name}: ${home.minutes} minutes`;
rangeTrack.appendChild(dot);
});
["mean", "median"].forEach(type => {
const rule = document.createElement("span");
rule.className = `range-rule ${type}`;
rule.style.left = `${((type === "mean" ? mean : median) / 125) * 100}%`;
rule.title = `${type}: ${(type === "mean" ? mean : median).toFixed(1)} minutes`;
rangeTrack.appendChild(rule);
});
const homeList = document.querySelector("#homeList");
const homeButtons = new Map();
homes.forEach(home => {
const button = document.createElement("button");
button.className = "home-button";
button.type = "button";
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<span class="home-dot" style="background:${home.color}"></span>
<span>${home.short}</span>
<b>${home.minutes}</b>
`;
button.addEventListener("click", () => selectHome(home));
homeList.appendChild(button);
homeButtons.set(home, button);
});
// ---------- Three.js scene ----------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel landscape showing ten fictional homes and their commute durations, with mean and median markers."
);
renderer.domElement.setAttribute(
"aria-describedby",
"camera-help"
);
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#f1ede4");
scene.fog = new THREE.Fog("#f1ede4", 52, 92);
const camera = new THREE.OrthographicCamera(-16, 16, 10, -10, 0.1, 180);
const cameraTarget = new THREE.Vector3(0, 0.55, 0.3);
const hemisphere = new THREE.HemisphereLight("#fff9e9", "#8da09d", 2.3);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff4d6", 3.1);
sun.position.set(-9, 18, 12);
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.0005;
scene.add(sun);
const rim = new THREE.DirectionalLight("#b8d8d6", 1.15);
rim.position.set(12, 8, -10);
scene.add(rim);
const sharedRoofMaterial = new THREE.MeshStandardMaterial({
color: "#263c4c",
roughness: 0.86,
metalness: 0.02,
flatShading: true
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: "#ffe6a1",
emissive: "#8e5d18",
emissiveIntensity: 0.18,
roughness: 0.7
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: "#f0d4a6",
roughness: 0.9
});
function addBox(parent, size, position, materialOrColor, castShadow = true) {
const material = materialOrColor && materialOrColor.isMaterial
? materialOrColor
: new THREE.MeshStandardMaterial({
color: materialOrColor,
roughness: 0.86,
metalness: 0.01,
flatShading: true
});
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 = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Large ground plane for soft shadows.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: "#f1ede4",
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.83;
ground.receiveShadow = true;
scene.add(ground);
// Raised voxel diorama platform.
addBox(scene, [29.4, 0.68, 10.2], [0, -0.43, 0.35], "#cfc8ba");
addBox(scene, [29.0, 0.12, 9.8], [0, -0.035, 0.35], "#e9e3d7", false);
addBox(scene, [28.4, 0.06, 2.7], [0, 0.055, -2.38], "#b9cdb7", false);
addBox(scene, [28.4, 0.06, 1.3], [0, 0.057, 0.47], "#fff9ee", false);
addBox(scene, [28.4, 0.18, 0.22], [0, 0.05, 4.95], "#203747", false);
// Subtle voxel tiles along the front edge.
for (let x = -13.2; x <= 13.2; x += 1.1) {
addBox(
scene,
[0.82, 0.10, 0.30],
[x, 0.13, 4.72],
x % 2 < 0 ? "#d6ae57" : "#b98a3d",
false
);
}
const PLOT_MIN = 0;
const PLOT_MAX = 125;
const PLOT_LEFT = -12.5;
const PLOT_WIDTH = 25;
function minutesToX(minutes) {
return PLOT_LEFT + ((minutes - PLOT_MIN) / (PLOT_MAX - PLOT_MIN)) * PLOT_WIDTH;
}
const interactive = [];
const homeVisuals = new Map();
function makeHouse(home) {
const group = new THREE.Group();
group.position.set(minutesToX(home.minutes), 0.08, -2.35);
scene.add(group);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: home.color,
roughness: 0.88,
metalness: 0,
flatShading: true
});
addBox(group, [1.05, 0.08, 1.02], [0, 0.03, 0], "#9eb29e", false);
const body = addBox(group, [0.84, 0.72, 0.78], [0, 0.43, 0], bodyMaterial);
body.userData.home = home;
addBox(group, [1.02, 0.20, 0.94], [0, 0.89, 0], sharedRoofMaterial);
addBox(group, [0.74, 0.20, 0.68], [0, 1.09, 0], sharedRoofMaterial);
addBox(group, [0.43, 0.18, 0.40], [0, 1.28, -0.02], sharedRoofMaterial);
// Door and block windows face the marker lane.
addBox(group, [0.19, 0.38, 0.05], [0, 0.27, 0.414], doorMaterial, false);
addBox(group, [0.17, 0.17, 0.05], [-0.25, 0.53, 0.414], windowMaterial, false);
addBox(group, [0.17, 0.17, 0.05], [0.25, 0.53, 0.414], windowMaterial, false);
addBox(group, [0.15, 0.33, 0.16], [0.27, 1.33, -0.12], sharedRoofMaterial);
// Small stepping blocks visually connect the home to its duration marker.
[-1.42, -0.98, -0.54, -0.10].forEach((z, index) => {
addBox(
group,
[0.24 - index * 0.015, 0.055, 0.28],
[0, 0.075, z],
index % 2 ? "#d9cbb2" : "#eee3cd",
false
);
});
const markerMaterial = new THREE.MeshStandardMaterial({
color: "#e2a63a",
roughness: 0.75,
emissive: "#000000",
emissiveIntensity: 0
});
const marker = new THREE.Group();
marker.position.set(minutesToX(home.minutes), 0.1, 0.47);
scene.add(marker);
addBox(marker, [0.42, 0.08, 0.42], [0, 0.04, 0], "#9a762f", false);
const markerStem = addBox(
marker,
[0.18, 0.54, 0.18],
[0, 0.34, 0],
markerMaterial
);
const markerCap = addBox(
marker,
[0.34, 0.12, 0.34],
[0, 0.67, 0],
markerMaterial
);
markerStem.userData.home = home;
markerCap.userData.home = home;
interactive.push(body, markerStem, markerCap);
homeVisuals.set(home, {
group,
bodyMaterial,
marker,
markerMaterial
});
}
homes.forEach(makeHouse);
// Timeline tick blocks.
for (let minute = 0; minute <= 120; minute += 20) {
const x = minutesToX(minute);
addBox(scene, [0.075, 0.13, 0.62], [x, 0.14, 0.78], "#435763", false);
}
function makeSummaryPillar(value, color, z, segments, height) {
const group = new THREE.Group();
group.position.set(minutesToX(value), 0.1, z);
scene.add(group);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.68,
metalness: 0.02,
flatShading: true
});
addBox(group, [0.76, 0.14, 0.76], [0, 0.07, 0], color);
for (let i = 0; i < segments; i++) {
addBox(
group,
[0.30, 0.35, 0.30],
[0, 0.30 + i * 0.38, 0],
material
);
}
addBox(group, [0.58, 0.17, 0.58], [0, height, 0], color);
addBox(group, [0.20, 0.18, 0.20], [0, height + 0.17, 0], "#fff7df");
return group;
}
makeSummaryPillar(mean, "#ef6a57", 1.72, 12, 4.78);
makeSummaryPillar(median, "#147d78", 1.72, 10, 3.98);
// Square selection frame, built from voxel-like bars.
const selectionFrame = new THREE.Group();
selectionFrame.visible = false;
scene.add(selectionFrame);
const selectionMaterial = new THREE.MeshStandardMaterial({
color: "#f1b33d",
roughness: 0.7,
emissive: "#7b4d08",
emissiveIntensity: 0.08
});
addBox(selectionFrame, [0.07, 0.07, 1.45], [-0.72, 0, 0], selectionMaterial, false);
addBox(selectionFrame, [0.07, 0.07, 1.45], [0.72, 0, 0], selectionMaterial, false);
addBox(selectionFrame, [1.45, 0.07, 0.07], [0, 0, -0.72], selectionMaterial, false);
addBox(selectionFrame, [1.45, 0.07, 0.07], [0, 0, 0.72], selectionMaterial, false);
// ---------- DOM scene labels ----------
function createLabel(className, html) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.innerHTML = html;
labelLayer.appendChild(element);
return element;
}
const labelEntries = [];
homes.forEach(home => {
const label = createLabel("data-label", `${home.minutes}<small>MIN</small>`);
labelEntries.push({
element: label,
position: new THREE.Vector3(minutesToX(home.minutes), 1.12, 0.47)
});
});
for (let minute = 0; minute <= 120; minute += 20) {
const label = createLabel("tick-label", String(minute));
labelEntries.push({
element: label,
position: new THREE.Vector3(minutesToX(minute), 0.18, 1.52)
});
}
const meanLabel = createLabel(
"summary-label mean",
`<span>Mean</span><strong>${mean.toFixed(1)}</strong><small>min</small>`
);
labelEntries.push({
element: meanLabel,
position: new THREE.Vector3(minutesToX(mean), 5.34, 1.72)
});
const medianLabel = createLabel(
"summary-label median",
`<span>Median</span><strong>${median.toFixed(1)}</strong><small>min</small>`
);
labelEntries.push({
element: medianLabel,
position: new THREE.Vector3(minutesToX(median), 4.49, 1.72)
});
const axisLabel = createLabel(
"axis-title",
"Commute duration · minutes · synthetic values"
);
labelEntries.push({
element: axisLabel,
position: new THREE.Vector3(0, 0.25, 4.35)
});
// ---------- Selection and interaction ----------
let selectedHome = null;
function selectHome(home) {
selectedHome = home;
homeVisuals.forEach((visual, candidate) => {
const selected = candidate === home;
visual.markerMaterial.color.set(selected ? "#ef6a57" : "#e2a63a");
visual.markerMaterial.emissive.set(selected ? "#6e2116" : "#000000");
visual.markerMaterial.emissiveIntensity = selected ? 0.2 : 0;
visual.bodyMaterial.emissive.set(selected ? "#40130b" : "#000000");
visual.bodyMaterial.emissiveIntensity = selected ? 0.18 : 0;
visual.marker.scale.setScalar(selected ? 1.18 : 1);
const button = homeButtons.get(candidate);
button.setAttribute("aria-pressed", String(selected));
});
if (home) {
selectionFrame.visible = true;
selectionFrame.position.set(
minutesToX(home.minutes),
0.15,
-2.35
);
document.querySelector("#selectedName").textContent = home.name;
document.querySelector("#selectedMeta").textContent =
`${home.minutes} minute synthetic commute · one point in the full distribution.`;
} else {
selectionFrame.visible = false;
document.querySelector("#selectedName").textContent = "No home selected";
document.querySelector("#selectedMeta").textContent =
"Select a gold marker or a home to inspect its synthetic commute.";
}
}
homeButtons.forEach((button, home) => {
button.addEventListener("mouseenter", () => {
const rect = button.getBoundingClientRect();
tooltip.innerHTML = `
<strong>${home.name}</strong>
<span>${home.minutes} minute synthetic commute</span>
`;
tooltip.style.display = "block";
tooltip.style.left = `${Math.min(rect.left, window.innerWidth - 190)}px`;
tooltip.style.top = `${Math.max(8, rect.top - 58)}px`;
});
button.addEventListener("mouseleave", () => {
tooltip.style.display = "none";
});
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickHome(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactive, false);
return hits.length ? hits[0].object.userData.home : null;
}
// ---------- Camera controls implemented locally ----------
let yaw = 0.28;
let pitch = 0.60;
let zoom = 1;
const cameraRadius = 42;
function updateCamera() {
const cosPitch = Math.cos(pitch);
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(yaw) * cosPitch,
cameraTarget.y + cameraRadius * Math.sin(pitch),
cameraTarget.z + cameraRadius * Math.cos(yaw) * cosPitch
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
yaw = 0.28;
pitch = 0.60;
zoom = 1;
}
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
const aspect = width / height;
renderer.setSize(width, height, false);
// Preserve the entire width of the diorama on narrow screens.
const visibleHeight = Math.max(17.5, 34 / aspect);
camera.left = -visibleHeight * aspect / 2;
camera.right = visibleHeight * aspect / 2;
camera.top = visibleHeight / 2;
camera.bottom = -visibleHeight / 2;
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
updateCamera();
document.querySelector("#resetView").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
const pointers = new Map();
let dragMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
tooltip.style.display = "none";
});
renderer.domElement.addEventListener("pointermove", event => {
const tracked = pointers.get(event.pointerId);
if (!tracked) {
if (event.pointerType === "mouse") {
const home = pickHome(event.clientX, event.clientY);
if (home) {
tooltip.innerHTML = `
<strong>${home.name}</strong>
<span>${home.minutes} minute synthetic commute</span>
`;
tooltip.style.display = "block";
tooltip.style.left = `${Math.min(event.clientX + 14, window.innerWidth - 205)}px`;
tooltip.style.top = `${Math.min(event.clientY + 14, window.innerHeight - 70)}px`;
renderer.domElement.style.cursor = "pointer";
} else {
tooltip.style.display = "none";
renderer.domElement.style.cursor = "grab";
}
}
return;
}
tracked.x = event.clientX;
tracked.y = event.clientY;
if (pointers.size === 1) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
yaw -= dx * 0.005;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.004, 0.30, 1.10);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.style.cursor = "grabbing";
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
zoom = THREE.MathUtils.clamp(
zoom * (distance / lastPinchDistance),
0.72,
1.65
);
}
lastPinchDistance = distance;
dragMoved = true;
}
});
renderer.domElement.addEventListener("pointerup", event => {
const wasClick = pointers.size === 1 && !dragMoved;
pointers.delete(event.pointerId);
if (wasClick) {
const home = pickHome(event.clientX, event.clientY);
selectHome(home || null);
}
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointerX = remaining.x;
lastPointerY = remaining.y;
}
lastPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
dragMoved = false;
lastPinchDistance = 0;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (pointers.size === 0) tooltip.style.display = "none";
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.65
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
yaw += 0.08;
break;
case "ArrowRight":
yaw -= 0.08;
break;
case "ArrowUp":
pitch = THREE.MathUtils.clamp(pitch + 0.06, 0.30, 1.10);
break;
case "ArrowDown":
pitch = THREE.MathUtils.clamp(pitch - 0.06, 0.30, 1.10);
break;
case "+":
case "=":
zoom = THREE.MathUtils.clamp(zoom * 1.08, 0.72, 1.65);
break;
case "-":
case "_":
zoom = THREE.MathUtils.clamp(zoom / 1.08, 0.72, 1.65);
break;
case "0":
resetCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
// ---------- Render and label projection ----------
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
labelEntries.forEach(entry => {
projected.copy(entry.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
entry.element.style.display = visible ? "block" : "none";
entry.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
entry.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
loading.remove();
</script>
</body>
</html>
```