Prompt specification
Build or customize the Three.js 3D scene "Repeated interval ladder" 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: Repeated interval ladder
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/repeated-interval-ladder-x1805
Scene Description Prompt:
Build a ladder of synthetic estimate intervals around a fixed known model parameter; mark which intervals cover it and state the procedure's nominal confidence level. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (repeated-interval-ladder-x1805):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Synthetic Confidence Interval Ladder</title>
<style>
:root {
color-scheme: dark;
--bg: #07121d;
--panel: rgba(10, 25, 39, 0.82);
--panel-border: rgba(165, 218, 232, 0.16);
--text: #edf8f8;
--muted: #9db4bd;
--teal: #39d6b5;
--coral: #ff6f78;
--gold: #ffd166;
--cream: #f4f1de;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}
* {
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;
}
button {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
outline: none;
}
#label-layer {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
color: rgba(229, 244, 246, 0.68);
text-shadow: 0 2px 8px #000;
will-change: left, top;
}
.world-label.tick {
color: rgba(229, 244, 246, 0.72);
font-size: 10px;
}
.world-label.row-label {
min-width: 38px;
padding: 3px 7px;
border: 1px solid rgba(151, 208, 220, 0.12);
border-radius: 5px;
background: rgba(7, 18, 29, 0.58);
color: rgba(229, 244, 246, 0.55);
text-align: center;
}
.world-label.row-label.cover {
border-color: rgba(57, 214, 181, 0.38);
color: var(--teal);
}
.world-label.row-label.miss {
border-color: rgba(255, 111, 120, 0.45);
color: var(--coral);
}
.world-label.row-label.selected {
background: rgba(255, 209, 102, 0.13);
border-color: var(--gold);
color: var(--gold);
box-shadow: 0 0 16px rgba(255, 209, 102, 0.14);
}
.world-label.truth-label {
padding: 6px 10px;
border: 1px solid rgba(255, 209, 102, 0.35);
border-radius: 999px;
background: rgba(30, 25, 13, 0.74);
color: var(--gold);
font-size: 10px;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(120%);
-webkit-backdrop-filter: blur(16px) saturate(120%);
}
#intro {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 19px 20px 17px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
line-height: 1.03;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 29px;
padding: 5px 9px;
border: 1px solid rgba(170, 220, 230, 0.14);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #c8dadd;
font-size: 11px;
font-weight: 650;
}
.chip strong {
color: var(--text);
}
.chip .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 10px rgba(255, 209, 102, 0.5);
}
#coverage-panel {
top: 18px;
right: 18px;
width: min(300px, calc(100vw - 36px));
padding: 17px 18px 16px;
}
.panel-kicker {
margin: 0 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.coverage-main {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
#coverage-count {
font-size: 29px;
font-weight: 780;
letter-spacing: -0.04em;
}
#coverage-percent {
color: var(--teal);
font-size: 17px;
font-weight: 760;
}
.bar {
height: 7px;
margin: 12px 0 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
#coverage-bar {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #21b998, var(--teal));
transition: width 350ms ease;
}
.coverage-note {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#detail-panel {
right: 18px;
top: 206px;
width: min(300px, calc(100vw - 36px));
padding: 17px 18px;
}
.detail-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 11px;
}
#detail-title {
margin: 0;
font-size: 15px;
font-weight: 760;
}
.badge {
padding: 4px 8px;
border-radius: 999px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.badge.cover {
color: var(--teal);
background: rgba(57, 214, 181, 0.11);
border: 1px solid rgba(57, 214, 181, 0.27);
}
.badge.miss {
color: var(--coral);
background: rgba(255, 111, 120, 0.10);
border: 1px solid rgba(255, 111, 120, 0.28);
}
.detail-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 12px;
}
.detail-cell {
padding: 9px 10px;
border: 1px solid rgba(170, 220, 230, 0.10);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.detail-cell span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.detail-cell strong {
font-size: 13px;
font-weight: 720;
}
.detail-explanation {
margin: 12px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#legend-panel {
left: 18px;
bottom: 18px;
width: min(390px, calc(100vw - 36px));
padding: 15px 17px;
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 9px 14px;
align-items: center;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
color: #c4d5d9;
font-size: 11px;
}
.swatch {
width: 17px;
height: 4px;
border-radius: 999px;
background: var(--teal);
}
.swatch.miss {
background: var(--coral);
}
.swatch.truth {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 9px rgba(255, 209, 102, 0.48);
}
.swatch.estimate {
width: 9px;
height: 9px;
background: var(--cream);
transform: rotate(45deg);
border-radius: 2px;
}
.procedure {
margin: 11px 0 0;
padding-top: 10px;
border-top: 1px solid rgba(170, 220, 230, 0.10);
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.procedure strong {
color: var(--text);
}
#controls {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 11;
display: flex;
align-items: center;
gap: 8px;
}
.control-button {
min-height: 38px;
padding: 9px 13px;
border: 1px solid rgba(170, 220, 230, 0.18);
border-radius: 11px;
background: rgba(10, 25, 39, 0.88);
color: var(--text);
cursor: pointer;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 720;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.control-button:hover {
border-color: rgba(57, 214, 181, 0.55);
background: rgba(17, 42, 56, 0.95);
transform: translateY(-1px);
}
.control-button:focus-visible {
outline: 2px solid var(--teal);
outline-offset: 3px;
}
#hint {
position: fixed;
right: 20px;
bottom: 66px;
z-index: 9;
color: rgba(202, 221, 225, 0.6);
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
}
#tooltip {
position: fixed;
z-index: 20;
display: none;
max-width: 250px;
padding: 9px 11px;
border: 1px solid rgba(170, 220, 230, 0.22);
border-radius: 9px;
background: rgba(5, 14, 23, 0.94);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.4);
color: var(--text);
font-size: 11px;
line-height: 1.45;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #07121d;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
.subtitle {
margin-bottom: 10px;
font-size: 12px;
}
#coverage-panel {
top: auto;
right: 12px;
bottom: 152px;
width: 220px;
padding: 13px 14px;
}
#detail-panel {
top: auto;
right: 12px;
bottom: 66px;
width: 220px;
padding: 12px 14px;
}
#detail-panel .detail-grid,
#detail-panel .detail-explanation {
display: none;
}
#legend-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
.procedure {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
z-index: 14;
}
#hint,
.row-label {
display: none !important;
}
.control-button {
min-height: 34px;
padding: 7px 10px;
}
}
</style>
</head>
<body>
<main id="app">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D ladder of synthetic confidence intervals around a fixed true parameter"
></canvas>
<div id="label-layer" aria-hidden="true"></div>
<section id="intro" class="panel">
<p class="eyebrow">Simulation / Coverage diagnostics</p>
<h1>Confidence interval ladder</h1>
<p class="subtitle">
Each rung is one synthetic sample estimate and its confidence interval.
Color shows whether the interval contains the fixed reference parameter.
</p>
<div class="chips">
<span class="chip">
<span class="dot"></span>
Fixed truth <strong>μ₀ = 2.40</strong>
</span>
<span class="chip">
Nominal confidence <strong>95%</strong>
</span>
<span class="chip">
Model <strong>Xᵢ ~ N(2.40, 1²)</strong>
</span>
</div>
</section>
<section id="coverage-panel" class="panel" aria-live="polite">
<p class="panel-kicker">Realized coverage in this batch</p>
<div class="coverage-main">
<span id="coverage-count">21 / 24</span>
<span id="coverage-percent">87.5%</span>
</div>
<div class="bar"><div id="coverage-bar"></div></div>
<p class="coverage-note">
The procedure's nominal level is <strong>95%</strong>. A single synthetic
batch need not realize exactly 95%.
</p>
</section>
<section id="detail-panel" class="panel">
<div class="detail-title">
<h2 id="detail-title">Inspect a rung</h2>
<span id="detail-badge" class="badge cover">95% CI</span>
</div>
<div id="detail-content">
<p class="detail-explanation">
Hover for a quick reading. Click a colored interval or estimate marker
to pin its sample, estimate, endpoints, standard error, and coverage
decision here.
</p>
</div>
</section>
<section id="legend-panel" class="panel">
<div class="legend-row">
<span class="legend-item">
<span class="swatch"></span>
Covers μ₀
</span>
<span class="legend-item">
<span class="swatch miss"></span>
Misses μ₀
</span>
<span class="legend-item">
<span class="swatch truth"></span>
Fixed truth
</span>
<span class="legend-item">
<span class="swatch estimate"></span>
Estimate
</span>
</div>
<p class="procedure">
<strong>Procedure:</strong> known-variance normal-theory CI,
<strong>x̄ ± 1.96 × SE</strong>, with SE = 1/√n.
The colored caps are the interval endpoints; the diamond is x̄.
</p>
</section>
<div id="hint">Drag to orbit · wheel to zoom · click a rung · double-click to reset</div>
<div id="controls">
<button id="regenerate" class="control-button" type="button">New synthetic batch</button>
<button id="reset-camera" class="control-button" type="button">Reset view</button>
</div>
<div id="tooltip" role="status"></div>
<div id="loading">Building interval ladder…</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Constants and state
// ------------------------------------------------------------
const TRUTH = 2.40;
const SIGMA = 1.0;
const NOMINAL = 0.95;
const Z_95 = 1.959963984540054;
const ROW_COUNT = 24;
const X_MIN = 1.0;
const X_MAX = 4.0;
const X_SCALE = 2.25;
const X_CENTER = 2.5;
const FRONT_Z = 3.75;
const BACK_Z = -7.15;
const ROW_SPACING = 0.44;
const RUNG_Y = 0.52;
const COLORS = {
cover: 0x39d6b5,
miss: 0xff6f78,
truth: 0xffd166,
estimate: 0xf4f1de,
axis: 0x9ab8c0
};
const state = {
selected: null,
hovered: null,
batchNumber: 1,
intervals: [],
pickables: []
};
// A deterministic initial synthetic batch: 21 of 24 cover the truth.
const INITIAL_Z = [
-0.42, 0.18, 1.12, -1.48, 0.77, 2.18,
-0.95, 1.71, -2.32, 0.06, 1.93, -1.17,
0.54, -0.66, 2.44, 1.28, -0.31, 0.88,
-1.79, 1.56, 0.23, -1.03, 1.41, -0.74
];
// ------------------------------------------------------------
// DOM references
// ------------------------------------------------------------
const canvas = document.getElementById("scene");
const labelLayer = document.getElementById("label-layer");
const coverageCount = document.getElementById("coverage-count");
const coveragePercent = document.getElementById("coverage-percent");
const coverageBar = document.getElementById("coverage-bar");
const detailTitle = document.getElementById("detail-title");
const detailBadge = document.getElementById("detail-badge");
const detailContent = document.getElementById("detail-content");
const tooltip = document.getElementById("tooltip");
const regenerateButton = document.getElementById("regenerate");
const resetCameraButton = document.getElementById("reset-camera");
const loading = document.getElementById("loading");
// ------------------------------------------------------------
// Three.js renderer, camera, and lights
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121d);
scene.fog = new THREE.FogExp2(0x07121d, 0.021);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xbfefff, 0x132333, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d0, 3.2);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x49c9d7, 1.7);
rimLight.position.set(-8, 5, -9);
scene.add(rimLight);
// ------------------------------------------------------------
// Custom orbit controls, implemented without Three.js addons
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.45, -1.65),
theta: 0.56,
phi: 0.93,
radius: 17.5,
targetTheta: 0.56,
targetPhi: 0.93,
targetRadius: 17.5,
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0,
downX: 0,
downY: 0,
moved: false
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.targetTheta = 0.56;
controls.targetPhi = 0.93;
controls.targetRadius = 17.5;
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerId = event.pointerId;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.downX = event.clientX;
controls.downY = event.clientY;
controls.moved = false;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (controls.dragging) {
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
if (Math.hypot(
event.clientX - controls.downX,
event.clientY - controls.downY
) > 4) {
controls.moved = true;
}
controls.targetTheta -= dx * 0.0055;
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - dy * 0.0045,
0.34,
1.38
);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
hideTooltip();
} else {
updateHover(event);
}
});
canvas.addEventListener("pointerup", (event) => {
const wasClick = !controls.moved;
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (wasClick) {
const hit = pickInterval(event);
if (hit !== null) {
selectInterval(hit);
}
}
});
canvas.addEventListener("pointercancel", () => {
controls.dragging = false;
});
canvas.addEventListener("pointerleave", () => {
hideTooltip();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
10,
25
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.key === "ArrowLeft") {
controls.targetTheta -= 0.10;
}
if (event.key === "ArrowRight") {
controls.targetTheta += 0.10;
}
if (event.key === "ArrowUp") {
controls.targetPhi = Math.max(0.34, controls.targetPhi - 0.08);
}
if (event.key === "ArrowDown") {
controls.targetPhi = Math.min(1.38, controls.targetPhi + 0.08);
}
});
resetCameraButton.addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Low-poly environment
// ------------------------------------------------------------
const environment = new THREE.Group();
scene.add(environment);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0x081722,
roughness: 0.98,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
environment.add(ground);
const grid = new THREE.GridHelper(34, 17, 0x214451, 0x132c38);
grid.position.y = -0.375;
grid.material.transparent = true;
grid.material.opacity = 0.28;
environment.add(grid);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(9.6, 0.38, 13.5),
new THREE.MeshStandardMaterial({
color: 0x102a35,
roughness: 0.91,
metalness: 0.02,
flatShading: true
})
);
platform.position.set(0, -0.20, -1.65);
platform.receiveShadow = true;
platform.castShadow = true;
environment.add(platform);
const platformEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(platform.geometry),
new THREE.LineBasicMaterial({
color: 0x426a72,
transparent: true,
opacity: 0.38
})
);
platformEdges.position.copy(platform.position);
environment.add(platformEdges);
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x31515b,
roughness: 0.78,
metalness: 0.08,
flatShading: true
});
for (const x of [-4.48, 4.48]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.17, 13.0),
railMaterial
);
rail.position.set(x, 0.02, -1.65);
rail.castShadow = true;
environment.add(rail);
}
for (const z of [4.82, -8.08]) {
const crossbar = new THREE.Mesh(
new THREE.BoxGeometry(9.1, 0.15, 0.15),
railMaterial
);
crossbar.position.set(0, 0.02, z);
crossbar.castShadow = true;
environment.add(crossbar);
}
function addRock(x, z, scale, color = 0x24414a) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
new THREE.MeshStandardMaterial({
color,
roughness: 0.96,
flatShading: true
})
);
rock.position.set(x, -0.16 + scale * 0.25, z);
rock.rotation.set(
Math.random() * 0.7,
Math.random() * Math.PI,
Math.random() * 0.5
);
rock.scale.y = 0.68 + Math.random() * 0.35;
rock.castShadow = true;
rock.receiveShadow = true;
environment.add(rock);
}
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.11 * scale, 0.15 * scale, 1.0 * scale, 5),
new THREE.MeshStandardMaterial({
color: 0x634b38,
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.45 * scale;
trunk.castShadow = true;
tree.add(trunk);
const foliage = new THREE.Mesh(
new THREE.ConeGeometry(0.66 * scale, 1.35 * scale, 6),
new THREE.MeshStandardMaterial({
color: 0x1f625b,
roughness: 0.92,
flatShading: true
})
);
foliage.position.y = 1.45 * scale;
foliage.castShadow = true;
tree.add(foliage);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.48 * scale, 1.05 * scale, 6),
new THREE.MeshStandardMaterial({
color: 0x2b7b69,
roughness: 0.9,
flatShading: true
})
);
crown.position.y = 2.03 * scale;
crown.castShadow = true;
tree.add(crown);
tree.position.set(x, -0.2, z);
environment.add(tree);
}
addTree(-5.7, 3.5, 0.85);
addTree(5.6, 2.1, 0.95);
addTree(-5.8, -2.3, 1.0);
addTree(5.7, -4.0, 0.85);
addTree(-5.5, -6.4, 0.75);
addTree(5.5, -7.2, 0.75);
addRock(-5.1, 1.0, 0.40);
addRock(-5.4, -0.4, 0.26);
addRock(5.0, 0.1, 0.34);
addRock(5.4, -5.8, 0.43, 0x2a4650);
addRock(-4.8, -6.8, 0.30);
addRock(5.2, 4.0, 0.28);
// ------------------------------------------------------------
// Axis and fixed-truth plane
// ------------------------------------------------------------
const axisGroup = new THREE.Group();
environment.add(axisGroup);
function xForValue(value) {
return (value - X_CENTER) * X_SCALE;
}
function cylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments, 1, false),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
const axisMaterial = new THREE.MeshStandardMaterial({
color: COLORS.axis,
roughness: 0.7,
metalness: 0.1
});
const axisStart = new THREE.Vector3(xForValue(X_MIN), 0.07, 4.28);
const axisEnd = new THREE.Vector3(xForValue(X_MAX), 0.07, 4.28);
const axisLine = cylinderBetween(
axisStart,
axisEnd,
0.026,
axisMaterial,
6
);
axisGroup.add(axisLine);
const tickValues = [1, 1.5, 2, 2.5, 3, 3.5, 4];
for (const value of tickValues) {
const x = xForValue(value);
const major = Number.isInteger(value);
const tick = cylinderBetween(
new THREE.Vector3(x, 0.08, 4.20),
new THREE.Vector3(x, 0.08, 4.42),
major ? 0.025 : 0.016,
axisMaterial,
6
);
axisGroup.add(tick);
}
const truthX = xForValue(TRUTH);
const truthGeometry = new THREE.BufferGeometry();
truthGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
truthX, 0.02, BACK_Z,
truthX, 2.78, BACK_Z,
truthX, 0.02, FRONT_Z + 0.25,
truthX, 2.78, FRONT_Z + 0.25
], 3)
);
truthGeometry.setIndex([
0, 2, 1,
2, 3, 1
]);
truthGeometry.computeVertexNormals();
const truthPlane = new THREE.Mesh(
truthGeometry,
new THREE.MeshBasicMaterial({
color: COLORS.truth,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
})
);
environment.add(truthPlane);
const truthEdgeMaterial = new THREE.LineBasicMaterial({
color: COLORS.truth,
transparent: true,
opacity: 0.48
});
const truthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(truthGeometry),
truthEdgeMaterial
);
environment.add(truthEdges);
// ------------------------------------------------------------
// Projected DOM labels
// ------------------------------------------------------------
const projectedLabels = [];
function makeWorldLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`.trim();
element.textContent = text;
labelLayer.appendChild(element);
const label = {
element,
position: position.clone()
};
projectedLabels.push(label);
return label;
}
const rowLabels = [];
for (const value of tickValues) {
makeWorldLabel(
value.toFixed(value % 1 === 0 ? 0 : 1),
new THREE.Vector3(xForValue(value), 0.02, 4.57),
"tick"
);
}
for (let i = 0; i < ROW_COUNT; i++) {
const z = FRONT_Z - i * ROW_SPACING;
const label = makeWorldLabel(
`S${String(i + 1).padStart(2, "0")}`,
new THREE.Vector3(-4.87, 0.72, z),
"row-label"
);
rowLabels.push(label);
}
const truthLabel = makeWorldLabel(
"FIXED TRUTH μ₀ = 2.40",
new THREE.Vector3(truthX, 2.93, FRONT_Z + 0.25),
"truth-label"
);
const projected = new THREE.Vector3();
function projectLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of projectedLabels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.18 &&
Math.abs(projected.y) < 1.18;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Synthetic interval construction
// ------------------------------------------------------------
const intervalRoot = new THREE.Group();
scene.add(intervalRoot);
function mulberry32(seed) {
return function random() {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function gaussian(random) {
const u = Math.max(random(), 1e-12);
const v = random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
function disposeIntervalRoot() {
intervalRoot.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
intervalRoot.clear();
}
function buildBatch(zScores = INITIAL_Z) {
disposeIntervalRoot();
state.intervals = [];
state.pickables = [];
state.selected = null;
let covered = 0;
for (let i = 0; i < ROW_COUNT; i++) {
const n = 14 + ((i * 7) % 21);
const se = SIGMA / Math.sqrt(n);
// For normal data, x̄ - μ has distribution N(0, se²).
const estimate = TRUTH + zScores[i] * se;
const halfWidth = Z_95 * se;
const lower = estimate - halfWidth;
const upper = estimate + halfWidth;
const covers = lower <= TRUTH && TRUTH <= upper;
if (covers) covered++;
const z = FRONT_Z - i * ROW_SPACING;
const color = covers ? COLORS.cover : COLORS.miss;
const group = new THREE.Group();
intervalRoot.add(group);
const segmentMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
metalness: 0.05,
emissive: 0x000000,
emissiveIntensity: 0,
flatShading: true
});
const segment = cylinderBetween(
new THREE.Vector3(xForValue(lower), RUNG_Y, z),
new THREE.Vector3(xForValue(upper), RUNG_Y, z),
0.056,
segmentMaterial,
8
);
segment.castShadow = true;
segment.userData.intervalIndex = i;
group.add(segment);
state.pickables.push(segment);
for (const endpoint of [lower, upper]) {
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.056, 0.056, 0.31, 6),
new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
flatShading: true
})
);
cap.position.set(xForValue(endpoint), RUNG_Y, z);
cap.castShadow = true;
cap.userData.intervalIndex = i;
group.add(cap);
state.pickables.push(cap);
}
const markerMaterial = new THREE.MeshStandardMaterial({
color: COLORS.estimate,
roughness: 0.42,
metalness: 0.12,
emissive: 0x000000,
emissiveIntensity: 0,
flatShading: true
});
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.145, 0),
markerMaterial
);
marker.position.set(xForValue(estimate), RUNG_Y + 0.34, z);
marker.rotation.y = Math.PI / 4;
marker.castShadow = true;
marker.userData.intervalIndex = i;
group.add(marker);
state.pickables.push(marker);
const truthBead = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.085, 0),
new THREE.MeshStandardMaterial({
color: COLORS.truth,
emissive: 0x8a5a00,
emissiveIntensity: 0.65,
roughness: 0.42,
flatShading: true
})
);
truthBead.position.set(truthX, RUNG_Y + 0.34, z);
truthBead.userData.intervalIndex = i;
group.add(truthBead);
state.pickables.push(truthBead);
group.userData = {
segment,
marker,
truthBead,
markerBaseY: marker.position.y
};
const interval = {
index: i,
n,
se,
estimate,
lower,
upper,
covers,
z
};
state.intervals.push(interval);
rowLabels[i].element.className =
"world-label row-label " + (covers ? "cover" : "miss");
}
const total = state.intervals.length;
const percent = (covered / total) * 100;
coverageCount.textContent = `${covered} / ${total}`;
coveragePercent.textContent = `${percent.toFixed(1)}%`;
coverageBar.style.width = `${percent}%`;
resetDetail();
highlightSelection();
}
// ------------------------------------------------------------
// Selection, hover, and tooltip
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickInterval(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(state.pickables, false);
if (!hits.length) return null;
const index = hits[0].object.userData.intervalIndex;
return Number.isInteger(index) ? index : null;
}
function updateHover(event) {
const index = pickInterval(event);
state.hovered = index;
if (index === null) {
hideTooltip();
canvas.style.cursor = controls.dragging ? "grabbing" : "grab";
return;
}
canvas.style.cursor = "pointer";
const item = state.intervals[index];
const decision = item.covers ? "covers" : "misses";
tooltip.innerHTML = `
<strong>S${String(index + 1).padStart(2, "0")}</strong> · n=${item.n}<br>
Estimate ${item.estimate.toFixed(3)}<br>
95% CI [${item.lower.toFixed(3)}, ${item.upper.toFixed(3)}]<br>
<span style="color:${item.covers ? "#39d6b5" : "#ff6f78"}">
${decision} μ₀ = 2.40
</span>
`;
tooltip.style.display = "block";
const width = tooltip.offsetWidth;
const height = tooltip.offsetHeight;
let left = event.clientX + 15;
let top = event.clientY + 15;
if (left + width > window.innerWidth - 10) {
left = event.clientX - width - 15;
}
if (top + height > window.innerHeight - 10) {
top = event.clientY - height - 15;
}
tooltip.style.left = `${Math.max(8, left)}px`;
tooltip.style.top = `${Math.max(8, top)}px`;
}
function hideTooltip() {
tooltip.style.display = "none";
state.hovered = null;
}
function selectInterval(index) {
state.selected = index;
highlightSelection();
const item = state.intervals[index];
detailTitle.textContent = `Synthetic sample S${String(index + 1).padStart(2, "0")}`;
detailBadge.textContent = item.covers ? "Covers" : "Misses";
detailBadge.className = `badge ${item.covers ? "cover" : "miss"}`;
detailContent.innerHTML = `
<div class="detail-grid">
<div class="detail-cell">
<span>Estimate x̄</span>
<strong>${item.estimate.toFixed(3)}</strong>
</div>
<div class="detail-cell">
<span>Sample size</span>
<strong>n = ${item.n}</strong>
</div>
<div class="detail-cell">
<span>95% CI</span>
<strong>[${item.lower.toFixed(3)}, ${item.upper.toFixed(3)}]</strong>
</div>
<div class="detail-cell">
<span>Standard error</span>
<strong>${item.se.toFixed(3)}</strong>
</div>
</div>
<p class="detail-explanation">
This interval ${item.covers ? "contains" : "does not contain"} the fixed
reference parameter <strong>μ₀ = 2.40</strong>.
</p>
`;
}
function highlightSelection() {
for (const group of intervalRoot.children) {
const index = state.intervals.findIndex(
(item) => item.index === group.userData.segment.userData.intervalIndex
);
const selected = index === state.selected;
const segment = group.userData.segment;
const marker = group.userData.marker;
segment.material.emissive.setHex(selected ? 0x4a3b11 : 0x000000);
segment.material.emissiveIntensity = selected ? 0.62 : 0;
marker.material.emissive.setHex(selected ? 0x5a4512 : 0x000000);
marker.material.emissiveIntensity = selected ? 0.7 : 0;
if (index >= 0) {
rowLabels[index].element.classList.toggle("selected", selected);
}
}
}
function resetDetail() {
detailTitle.textContent = "Inspect a rung";
detailBadge.textContent = "95% CI";
detailBadge.className = "badge cover";
detailContent.innerHTML = `
<p class="detail-explanation">
Hover for a quick reading. Click a colored interval or estimate marker
to pin its sample, estimate, endpoints, standard error, and coverage
decision here.
</p>
`;
}
// ------------------------------------------------------------
// New synthetic batch
// ------------------------------------------------------------
regenerateButton.addEventListener("click", () => {
state.batchNumber++;
const random = mulberry32(
90210 + state.batchNumber * 7919
);
const randomZ = Array.from({ length: ROW_COUNT }, () => gaussian(random));
buildBatch(randomZ);
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Smooth direct camera controls.
controls.theta += (controls.targetTheta - controls.theta) * 0.12;
controls.phi += (controls.targetPhi - controls.phi) * 0.12;
controls.radius += (controls.targetRadius - controls.radius) * 0.12;
updateCamera();
for (let i = 0; i < intervalRoot.children.length; i++) {
const group = intervalRoot.children[i];
const marker = group.userData.marker;
const truthBead = group.userData.truthBead;
const selected = state.selected === i;
marker.rotation.y += 0.014;
marker.position.y =
group.userData.markerBaseY + Math.sin(elapsed * 2.1 + i * 0.48) * 0.025;
const markerScale = selected ? 1.22 : 1;
marker.scale.setScalar(markerScale);
const beadScale = 1 + Math.sin(elapsed * 2.7 + i * 0.35) * 0.12;
truthBead.scale.setScalar(beadScale);
}
truthPlane.material.opacity =
0.065 + Math.sin(elapsed * 1.7) * 0.016;
truthEdgeMaterial.opacity =
0.44 + Math.sin(elapsed * 1.7) * 0.08;
renderer.render(scene, camera);
projectLabels();
}
buildBatch(INITIAL_Z);
updateCamera();
projectLabels();
renderer.render(scene, camera);
loading.style.display = "none";
animate();
</script>
</body>
</html>
```