Prompt specification
Build or customize the Three.js 3D scene "Bootstrap sensitivity explorer" 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: Bootstrap sensitivity explorer
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bootstrap-sensitivity-explorer-x1776
Scene Description Prompt:
Create a self-contained HTML file using Three.js from cdnjs for a low-poly bootstrap-resampling exhibit. Represent a small synthetic dataset as numbered tokens on one tray, with a second tray receiving draws sampled with replacement. Offer smooth, strongly skewed, and tiny example datasets, all clearly labeled synthetic. Repeated resamples contribute their statistic to a physical histogram beside the trays; use a consistent seeded sequence when comparing settings. Show the observed statistic, the resampling distribution, and a chosen percentile interval separately. Explain the selected statistic and display limitations for very small or unusual datasets, rather than promising that this one interval construction is reliable in every case.
Let one resample be expanded into its actual token sequence, including repeated selections, so the histogram can be traced back to draws from the displayed dataset.
Technical checks: Keep each traced resample linked to the histogram bin that contains its computed statistic. When the resample is 4, 4, and 7, its mean is 5 and belongs in a bin that contains 5.
Return one complete HTML document that works with the cdnjs Three.js r160 module inside a sandbox with scripts allowed. Make the requested subject visible at the default camera. Use procedural assets and local button handlers. Do not use native form submission, pointer lock, external assets or runtime requests other than Three.js.
Working Three.js Starter (bootstrap-sensitivity-explorer-x1776):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>Bootstrap Lab — Synthetic Resampling Exhibit</title>
<style>
:root {
--ink: #18313b;
--muted: #61727a;
--paper: rgba(251, 250, 244, 0.92);
--line: rgba(24, 49, 59, 0.14);
--teal: #168a80;
--teal-soft: #d8f0eb;
--amber: #e99a32;
--amber-soft: #fff0d7;
--coral: #ef6552;
--coral-soft: #ffe5df;
--magenta: #ad3f86;
--magenta-soft: #f4dfef;
--shadow: 0 14px 40px rgba(35, 58, 65, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background:
radial-gradient(circle at 51% 36%, #fbfaf5 0%, #e8efed 55%, #d7e3e3 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
header {
position: fixed;
top: 18px;
left: 22px;
right: 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
z-index: 5;
}
.title-wrap {
display: flex;
align-items: center;
gap: 13px;
}
.mark {
width: 45px;
height: 45px;
display: grid;
place-items: center;
border-radius: 14px;
color: white;
background: var(--ink);
box-shadow: var(--shadow);
font-weight: 900;
letter-spacing: -0.04em;
transform: rotate(-3deg);
}
h1 {
margin: 0;
font-size: clamp(19px, 2vw, 29px);
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
font-weight: 650;
}
.synthetic-badge, .hint {
border: 1px solid rgba(24, 49, 59, 0.12);
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 8px 24px rgba(35, 58, 65, 0.08);
backdrop-filter: blur(10px);
border-radius: 999px;
padding: 9px 13px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
white-space: nowrap;
}
.synthetic-badge {
color: #0e6f67;
background: var(--teal-soft);
}
.hint {
color: var(--muted);
font-weight: 650;
letter-spacing: 0;
}
.panel {
position: fixed;
z-index: 6;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
box-shadow: var(--shadow);
backdrop-filter: blur(13px);
}
#stats {
top: 82px;
left: 20px;
width: 286px;
padding: 10px;
}
.stat-card {
position: relative;
overflow: hidden;
padding: 12px 13px 11px;
border-radius: 13px;
background: rgba(255,255,255,0.73);
border: 1px solid var(--line);
}
.stat-card + .stat-card { margin-top: 8px; }
.stat-card::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 5px;
background: var(--amber);
}
.stat-card.observed::before { background: var(--magenta); }
.stat-card.interval::before { background: var(--teal); }
.stat-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.stat-value {
margin-top: 4px;
font-size: 27px;
font-weight: 850;
line-height: 1.05;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.stat-sub {
margin-top: 5px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.tag {
display: inline-block;
border-radius: 999px;
padding: 4px 7px;
background: var(--amber-soft);
color: #9b5c0c;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.06em;
}
.tag.observed { background: var(--magenta-soft); color: #8d2d6e; }
.tag.interval { background: var(--teal-soft); color: #0d746b; }
#controls {
left: 20px;
bottom: 20px;
width: 360px;
padding: 15px;
}
.panel-title {
margin: 0 0 10px;
font-size: 14px;
letter-spacing: -0.015em;
}
.control-label {
display: block;
margin: 11px 0 6px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.dataset-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
.dataset-buttons button:first-child { grid-column: 1 / -1; }
button, select, input {
font: inherit;
}
button {
color: var(--ink);
border: 1px solid var(--line);
background: rgba(255,255,255,0.82);
border-radius: 10px;
padding: 9px 10px;
cursor: pointer;
font-weight: 760;
font-size: 11px;
transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:focus-visible, select:focus-visible, input:focus-visible {
outline: 3px solid rgba(22, 138, 128, 0.28);
outline-offset: 2px;
}
button.active {
color: #0b6f66;
background: var(--teal-soft);
border-color: rgba(22, 138, 128, 0.32);
}
.number-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.number-control {
display: flex;
align-items: center;
gap: 6px;
background: rgba(255,255,255,0.82);
border: 1px solid var(--line);
border-radius: 10px;
padding: 6px 8px;
}
.number-control span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
}
.number-control input, .number-control select {
width: 100%;
min-width: 0;
border: 0;
background: transparent;
color: var(--ink);
font-weight: 800;
outline: none;
}
.primary {
width: 100%;
margin-top: 11px;
color: white;
background: var(--ink);
border-color: var(--ink);
box-shadow: 0 8px 18px rgba(24, 49, 59, 0.18);
}
.primary:hover { background: #244651; }
.seed-note {
margin-top: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
details {
margin-top: 10px;
border-top: 1px solid var(--line);
padding-top: 9px;
}
summary {
cursor: pointer;
color: var(--ink);
font-size: 11px;
font-weight: 850;
}
.explanation {
margin-top: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.48;
}
.explanation strong { color: var(--ink); }
#trace {
right: 20px;
bottom: 20px;
width: 360px;
max-height: calc(100vh - 100px);
overflow: auto;
padding: 15px;
}
.trace-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.trace-actions {
display: flex;
gap: 5px;
}
.trace-actions button {
width: 31px;
height: 31px;
padding: 0;
font-size: 15px;
}
#traceTitle {
margin: 0;
font-size: 15px;
}
#traceSubtitle {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
#sequence {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin: 12px 0 9px;
min-height: 45px;
}
.token-chip {
position: relative;
width: 43px;
height: 43px;
display: grid;
place-items: center;
border-radius: 12px;
color: #74460f;
background: var(--amber-soft);
border: 1px solid rgba(233,154,50,0.42);
box-shadow: inset 0 -3px 0 rgba(180, 103, 15, 0.08);
font-weight: 900;
font-size: 18px;
}
.token-chip small {
position: absolute;
bottom: 3px;
right: 5px;
color: #a36b28;
font-size: 7px;
font-weight: 850;
}
.trace-facts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin-bottom: 8px;
}
.fact {
min-width: 0;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,0.68);
}
.fact .k {
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.fact .v {
margin-top: 4px;
overflow-wrap: anywhere;
font-size: 12px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
#relation {
padding: 9px 10px;
border-radius: 10px;
background: var(--teal-soft);
color: #0b6f66;
border: 1px solid rgba(22,138,128,0.25);
font-size: 10px;
font-weight: 800;
line-height: 1.4;
}
#relation.outside {
color: #9b5c0c;
background: var(--amber-soft);
border-color: rgba(233,154,50,0.34);
}
#integrity {
margin-top: 8px;
color: #0b6f66;
font-size: 9px;
font-weight: 850;
line-height: 1.4;
}
#integrity.fail { color: #b23b2c; }
.bin-heading {
display: flex;
justify-content: space-between;
gap: 8px;
margin: 11px 0 6px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.065em;
text-transform: uppercase;
}
#binLinks {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
}
#binLinks button {
padding: 7px 6px;
text-align: left;
line-height: 1.25;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
#binLinks button:disabled {
opacity: 0.38;
cursor: default;
transform: none;
}
.trace-note {
margin-top: 9px;
color: var(--muted);
font-size: 9px;
line-height: 1.42;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--muted);
background: #e8efed;
font-weight: 800;
letter-spacing: 0.04em;
}
@media (max-width: 980px) {
.hint { display: none; }
#stats { width: 245px; }
#controls, #trace { width: 310px; }
.stat-value { font-size: 23px; }
.panel { border-radius: 14px; }
}
@media (max-width: 720px) {
header { top: 10px; left: 12px; right: 12px; }
.subtitle, .synthetic-badge { display: none; }
#stats {
top: 62px;
left: 10px;
width: 190px;
padding: 6px;
}
.stat-card { padding: 8px; }
.stat-value { font-size: 19px; }
.stat-sub { font-size: 9px; }
#controls {
left: 10px;
bottom: 10px;
width: calc(50vw - 15px);
padding: 10px;
}
#trace {
right: 10px;
bottom: 10px;
width: calc(50vw - 15px);
padding: 10px;
}
.dataset-buttons { grid-template-columns: 1fr; }
.dataset-buttons button:first-child { grid-column: auto; }
.number-row { grid-template-columns: 1fr; }
#binLinks { grid-template-columns: 1fr; }
.trace-facts { grid-template-columns: 1fr; }
.explanation { font-size: 9px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional bootstrap resampling exhibit"></div>
<header>
<div class="title-wrap">
<div class="mark">B</div>
<div>
<h1>Bootstrap Resampling Lab</h1>
<div class="subtitle">Follow every draw from synthetic data to a bootstrap mean</div>
</div>
</div>
<div class="synthetic-badge">ALL DATASETS ARE SYNTHETIC</div>
<div class="hint">Drag to orbit · wheel to zoom · click a histogram bar</div>
</header>
<section id="stats" class="panel" aria-label="Observed statistic, bootstrap distribution, and percentile interval">
<article class="stat-card observed">
<div class="stat-label">Observed statistic <span class="tag observed">ORIGINAL DATA</span></div>
<div class="stat-value" id="observedValue">—</div>
<div class="stat-sub" id="observedSub">Arithmetic mean of the displayed synthetic sample.</div>
</article>
<article class="stat-card">
<div class="stat-label">Resampling distribution <span class="tag">BOOTSTRAP MEANS</span></div>
<div class="stat-value" id="distributionValue">—</div>
<div class="stat-sub" id="distributionSub">Each completed resample contributes one count.</div>
</article>
<article class="stat-card interval">
<div class="stat-label">Chosen percentile interval <span class="tag interval">90% PI</span></div>
<div class="stat-value" id="intervalValue">—</div>
<div class="stat-sub" id="intervalSub">5th–95th percentiles of the bootstrap means.</div>
</article>
</section>
<section id="controls" class="panel" aria-label="Experiment controls">
<h2 class="panel-title">Choose an example</h2>
<div class="dataset-buttons" role="group" aria-label="Synthetic datasets">
<button type="button" class="active" data-dataset="tiny">Tiny synthetic · n = 3</button>
<button type="button" data-dataset="smooth">Smooth synthetic · n = 9</button>
<button type="button" data-dataset="skewed">Strongly skewed synthetic · n = 9</button>
</div>
<label class="control-label" for="seedInput">Reproducible seed</label>
<div class="number-row">
<label class="number-control">
<span>Seed</span>
<input id="seedInput" type="number" min="0" max="4294967295" step="1" value="42">
</label>
<label class="number-control">
<span>Draws</span>
<select id="batchInput">
<option value="120">120</option>
<option value="240" selected>240</option>
<option value="500">500</option>
</select>
</label>
</div>
<button type="button" id="runButton" class="primary">Run seeded bootstrap</button>
<button type="button" id="cameraButton" style="width:100%;margin-top:7px">Reset camera</button>
<div class="seed-note">
The same seed restarts the same random stream on every run. When the dataset changes,
the same uniform draws are reused and mapped to the new number of tokens.
</div>
<details open>
<summary>Statistic, method, and limitations</summary>
<div class="explanation">
<strong>Selected statistic: arithmetic mean.</strong>
Each bootstrap resample draws <em>n</em> tokens with replacement, so repeated tokens
are legitimate. Its mean adds one count to the physical histogram.<br><br>
The cyan <strong>90% percentile interval</strong> is the 5th–95th percentile range of
the bootstrap means. It is a separate summary, not a guarantee of 90% coverage.
<span id="datasetLimitation"></span>
</div>
</details>
</section>
<section id="trace" class="panel" aria-label="Expanded bootstrap trace">
<div class="trace-head">
<div>
<h2 id="traceTitle" class="panel-title">Expanded resample</h2>
<div id="traceSubtitle">Select a draw or a histogram bin.</div>
</div>
<div class="trace-actions">
<button type="button" id="prevTrace" title="Previous resample" aria-label="Previous resample">‹</button>
<button type="button" id="nextTrace" title="Next resample" aria-label="Next resample">›</button>
</div>
</div>
<div id="sequence" aria-label="Actual token sequence including repeated selections"></div>
<div class="trace-facts">
<div class="fact">
<div class="k">Traced statistic</div>
<div class="v" id="traceStat">—</div>
</div>
<div class="fact">
<div class="k">Exact histogram bin</div>
<div class="v" id="traceBin">—</div>
</div>
</div>
<div id="relation">—</div>
<div id="integrity">Running link check…</div>
<div class="bin-heading">
<span>Histogram bins</span>
<span>click to trace</span>
</div>
<div id="binLinks"></div>
<div class="trace-note">
The orange bar is the selected resample’s exact statistic bin. The cyan bracket is
the percentile interval of the whole distribution. They are related but are not the
same object; a tail resample can legitimately fall outside the percentile interval.
</div>
</section>
<div id="loading">Building the synthetic exhibit…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DATASETS = {
tiny: {
label: "Tiny synthetic",
values: [4, 4, 7],
limitation: "With only three observations, bootstrap means are discrete and unstable; endpoints can depend strongly on a few possible draws."
},
smooth: {
label: "Smooth synthetic",
values: [2, 3, 4, 4, 5, 6, 7, 8, 9],
limitation: "Regular spacing can look reassuring, but the bootstrap still assumes that this synthetic sample represents a wider population."
},
skewed: {
label: "Strongly skewed synthetic",
values: [1, 1, 2, 2, 2, 3, 3, 4, 12],
limitation: "The mean is highly sensitive to the value 12; percentile intervals can inherit skew and have poor finite-sample coverage."
}
};
const B = {
colors: {
observed: 0xad3f86,
interval: 0x168a80,
bar: 0xe99a32,
selected: 0xef6552,
source: 0x2e8079,
destination: 0xe99a32,
token: 0xf6d79d,
floor: 0xdde7e4
}
};
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xdde7e4, 19, 34);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Three-dimensional bootstrap exhibit");
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.45, 1.15, 0.15);
const orbit = {
theta: 0.57,
phi: 1.03,
radius: 20.7,
targetTheta: 0.57,
targetPhi: 1.03,
targetRadius: 20.7
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xf9fffc, 0x7d9290, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff3dd, 3.1);
keyLight.position.set(2, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9dd9dc, 1.1);
fillLight.position.set(-8, 5, 1);
scene.add(fillLight);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...options
});
}
function box(width, height, depth, color, options = {}) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material(color, options));
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeTextSprite(text, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = options.canvasWidth || 512;
canvas.height = options.canvasHeight || 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (options.background) {
ctx.fillStyle = options.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
if (options.border) {
ctx.strokeStyle = options.border;
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
}
ctx.fillStyle = options.color || "#18313b";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `${options.weight || 800} ${options.fontSize || 44}px system-ui, sans-serif`;
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const spriteMaterial = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest !== false,
depthWrite: false
});
const sprite = new THREE.Sprite(spriteMaterial);
sprite.scale.set(options.width || 2, options.height || 0.5, 1);
return sprite;
}
function makeToken(value, color = B.colors.token) {
const group = new THREE.Group();
const tokenMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.37, 0.28, 10),
material(color, { roughness: 0.64 })
);
tokenMesh.castShadow = true;
tokenMesh.receiveShadow = true;
group.add(tokenMesh);
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 128, 128);
ctx.fillStyle = "#18313b";
ctx.font = "900 70px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(value), 64, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.46, 0.46),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
label.rotation.x = -Math.PI / 2;
label.position.y = 0.146;
group.add(label);
return group;
}
function slotPosition(index, count) {
const columns = Math.ceil(Math.sqrt(count));
const rows = Math.ceil(count / columns);
const column = index % columns;
const row = Math.floor(index / columns);
return new THREE.Vector3(
(column - (columns - 1) / 2) * 0.86,
0.59,
(row - (rows - 1) / 2) * 0.69
);
}
function makeTray(x, z, color, title) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const base = box(3.25, 0.19, 2.38, color);
base.position.y = 0.16;
group.add(base);
const rimHeight = 0.25;
const rimY = 0.37;
const longRim = box(3.45, rimHeight, 0.16, color, { roughness: 0.72 });
longRim.position.set(0, rimY, -1.16);
group.add(longRim);
const longRim2 = longRim.clone();
longRim2.position.z = 1.16;
group.add(longRim2);
const shortRim = box(0.16, rimHeight, 2.16, color, { roughness: 0.72 });
shortRim.position.set(-1.62, rimY, 0);
group.add(shortRim);
const shortRim2 = shortRim.clone();
shortRim2.position.x = 1.62;
group.add(shortRim2);
const label = makeTextSprite(title, {
width: 2.95,
height: 0.43,
fontSize: 35,
color: "#18313b",
background: "rgba(251,250,244,0.92)",
border: "rgba(24,49,59,0.18)"
});
label.position.set(0, 2.02, -0.68);
group.add(label);
return group;
}
const platform = new THREE.Mesh(
new THREE.CircleGeometry(10.7, 12),
material(B.colors.floor, { roughness: 0.96 })
);
platform.rotation.x = -Math.PI / 2;
platform.position.set(0.5, -0.025, 0.1);
platform.receiveShadow = true;
scene.add(platform);
const sourcePosition = new THREE.Vector3(-4.35, 0, 1.05);
const destinationPosition = new THREE.Vector3(-0.85, 0, 1.05);
const sourceTray = makeTray(sourcePosition.x, sourcePosition.z, B.colors.source, "SYNTHETIC DATA");
const destinationTray = makeTray(
destinationPosition.x,
destinationPosition.z,
B.colors.destination,
"RESAMPLE · WITH REPLACEMENT"
);
scene.add(sourceTray, destinationTray);
const sourceTokenRoot = new THREE.Group();
sourceTokenRoot.position.copy(sourcePosition);
const destinationTokenRoot = new THREE.Group();
destinationTokenRoot.position.copy(destinationPosition);
scene.add(sourceTokenRoot, destinationTokenRoot);
const histogramRoot = new THREE.Group();
histogramRoot.position.set(4.45, 0, -0.2);
scene.add(histogramRoot);
let sourceTokenGroups = [];
let histogramBars = [];
let traceAnimations = [];
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse?.((object) => {
object.geometry?.dispose?.();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach((mat) => {
mat.map?.dispose?.();
mat.dispose?.();
});
}
});
}
}
function mulberry32(seed) {
let state = seed >>> 0;
return function() {
state = (state + 0x6D2B79F5) >>> 0;
let value = state;
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
// Find a stable seed whose tiny-data resample #2 is exactly 4, 4, 7.
// This makes the corrected interaction deterministic and directly testable.
function findDefaultSeed() {
for (let seed = 1; seed < 100000; seed++) {
const random = mulberry32(seed);
random(); random(); random(); // complete resample #1
const a = Math.floor(random() * 3);
const b = Math.floor(random() * 3);
const c = Math.floor(random() * 3);
if ((a === 0 || a === 1) && (b === 0 || b === 1) && c === 2) {
return seed;
}
}
return 42;
}
const DEFAULT_SEED = findDefaultSeed();
document.getElementById("seedInput").value = DEFAULT_SEED;
const state = {
datasetKey: "tiny",
values: DATASETS.tiny.values.slice(),
seed: DEFAULT_SEED,
batchSize: 240,
records: [],
selected: 1,
observed: 0,
distributionMean: 0,
distributionSD: 0,
percentile: { lower: 0, upper: 0 },
binEdges: [],
binWidth: 0,
min: 0,
max: 1,
bins: []
};
function mean(values) {
return values.reduce((sum, value) => sum + value, 0) / values.length;
}
function standardDeviation(values, center) {
if (values.length < 2) return 0;
const variance = values.reduce((sum, value) => sum + (value - center) ** 2, 0) / (values.length - 1);
return Math.sqrt(variance);
}
function percentile(sortedValues, probability) {
if (!sortedValues.length) return NaN;
const position = (sortedValues.length - 1) * probability;
const lowerIndex = Math.floor(position);
const upperIndex = Math.ceil(position);
if (lowerIndex === upperIndex) return sortedValues[lowerIndex];
const fraction = position - lowerIndex;
return sortedValues[lowerIndex] * (1 - fraction) + sortedValues[upperIndex] * fraction;
}
function format(value, digits = 2) {
if (!Number.isFinite(value)) return "—";
return value.toLocaleString(undefined, {
minimumFractionDigits: digits,
maximumFractionDigits: digits
});
}
function generateRecords() {
const random = mulberry32(state.seed);
const n = state.values.length;
const records = [];
for (let index = 0; index < state.batchSize; index++) {
const sequence = [];
for (let draw = 0; draw < n; draw++) {
sequence.push(Math.floor(random() * n));
}
const statistic = mean(sequence.map((tokenIndex) => state.values[tokenIndex]));
records.push({ index, sequence, statistic });
}
state.records = records;
state.observed = mean(state.values);
const statistics = records.map((record) => record.statistic);
state.distributionMean = mean(statistics);
state.distributionSD = standardDeviation(statistics, state.distributionMean);
const sorted = statistics.slice().sort((a, b) => a - b);
state.percentile = {
lower: percentile(sorted, 0.05),
upper: percentile(sorted, 0.95)
};
state.min = Math.min(state.observed, ...statistics);
state.max = Math.max(state.observed, ...statistics);
if (state.max === state.min) state.max = state.min + 1;
const binCount = 8;
state.binWidth = (state.max - state.min) / binCount;
state.binEdges = Array.from({ length: binCount + 1 }, (_, index) => state.min + index * state.binWidth);
state.binEdges[binCount] = state.max;
state.bins = Array.from({ length: binCount }, (_, index) => ({
index,
lower: state.binEdges[index],
upper: state.binEdges[index + 1],
count: 0,
records: []
}));
records.forEach((record) => {
let binIndex = Math.floor((record.statistic - state.min) / state.binWidth);
binIndex = Math.max(0, Math.min(binCount - 1, binIndex));
record.binIndex = binIndex;
state.bins[binIndex].count++;
state.bins[binIndex].records.push(record);
});
}
function rebuildSourceTokens() {
clearGroup(sourceTokenRoot);
sourceTokenGroups = [];
state.values.forEach((value, index) => {
const token = makeToken(value, 0xf5d29a);
token.position.copy(slotPosition(index, state.values.length));
sourceTokenRoot.add(token);
sourceTokenGroups.push(token);
});
sourceTokenRoot.updateMatrixWorld(true);
}
function valueToHistogramX(value) {
const domainLeft = -3.42;
const domainRight = 3.42;
return domainLeft + ((value - state.min) / (state.max - state.min)) * (domainRight - domainLeft);
}
function rebuildHistogram() {
clearGroup(histogramRoot);
histogramBars = [];
const board = box(7.5, 3.55, 0.22, 0xf8f5ea, { roughness: 0.94 });
board.position.set(0, 1.94, 0);
board.castShadow = false;
histogramRoot.add(board);
[0.9, 1.5, 2.1, 2.7].forEach((height) => {
const line = box(6.85, 0.018, 0.025, 0xb8cbc6, { roughness: 1 });
line.position.set(0, height, 0.13);
histogramRoot.add(line);
});
const title = makeTextSprite("BOOTSTRAP MEANS · SYNTHETIC", {
width: 4.8,
height: 0.55,
fontSize: 40,
color: "#18313b",
background: "rgba(248,245,234,0.95)"
});
title.position.set(0, 3.92, 0.25);
histogramRoot.add(title);
const intervalLabel = makeTextSprite("90% PERCENTILE INTERVAL", {
width: 2.7,
height: 0.36,
fontSize: 27,
color: "#0c756c",
background: "rgba(216,240,235,0.94)",
border: "rgba(22,138,128,0.28)"
});
const intervalStartX = valueToHistogramX(state.percentile.lower);
const intervalEndX = valueToHistogramX(state.percentile.upper);
const intervalWidth = Math.max(0.1, intervalEndX - intervalStartX);
const intervalCenter = (intervalStartX + intervalEndX) / 2;
const intervalBand = box(intervalWidth, 0.085, 0.07, B.colors.interval, {
transparent: true,
opacity: 0.95,
roughness: 0.55
});
intervalBand.position.set(intervalCenter, 0.55, 0.67);
histogramRoot.add(intervalBand);
[-1, 1].forEach((side) => {
const cap = box(0.075, 0.38, 0.08, B.colors.interval);
cap.position.set(intervalCenter + side * intervalWidth / 2, 0.7, 0.67);
histogramRoot.add(cap);
});
intervalLabel.position.set(intervalCenter, 1.02, 0.74);
histogramRoot.add(intervalLabel);
const maxCount = Math.max(...state.bins.map((bin) => bin.count), 1);
const domainLeft = -3.42;
const domainRight = 3.42;
const binSlot = (domainRight - domainLeft) / state.bins.length;
const barBase = 0.57;
state.bins.forEach((bin, index) => {
const height = 0.25 + (bin.count / maxCount) * 2.25;
const bar = box(binSlot * 0.84, 1, 0.58, B.colors.bar, { roughness: 0.67 });
bar.scale.y = 0.015;
bar.position.set(domainLeft + (index + 0.5) * binSlot, barBase, 0.39);
bar.castShadow = true;
bar.userData = {
binIndex: index,
targetHeight: height,
growth: 0,
countLabel: null
};
histogramRoot.add(bar);
histogramBars.push(bar);
const countLabel = makeTextSprite(String(bin.count), {
width: 0.78,
height: 0.31,
fontSize: 38,
color: "#6d4715",
background: "rgba(255,240,215,0.90)"
});
countLabel.position.set(bar.position.x, barBase + 0.25, 0.73);
histogramRoot.add(countLabel);
bar.userData.countLabel = countLabel;
});
const minLabel = makeTextSprite(format(state.min, 1), {
width: 0.85, height: 0.32, fontSize: 34, color: "#61727a"
});
minLabel.position.set(domainLeft, 0.15, 0.42);
histogramRoot.add(minLabel);
const maxLabel = makeTextSprite(format(state.max, 1), {
width: 0.85, height: 0.32, fontSize: 34, color: "#61727a"
});
maxLabel.position.set(domainRight, 0.15, 0.42);
histogramRoot.add(maxLabel);
const observedX = valueToHistogramX(state.observed);
const observedLine = box(0.045, 2.95, 0.045, B.colors.observed, {
transparent: true,
opacity: 0.82,
roughness: 0.45
});
observedLine.position.set(observedX, 1.84, 0.78);
histogramRoot.add(observedLine);
const observedDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.17, 0),
material(B.colors.observed, { roughness: 0.45 })
);
observedDiamond.position.set(observedX, 0.72, 0.82);
histogramRoot.add(observedDiamond);
const observedLabel = makeTextSprite("OBSERVED MEAN", {
width: 1.75,
height: 0.34,
fontSize: 27,
color: "#8d2d6e",
background: "rgba(244,223,239,0.94)"
});
observedLabel.position.set(observedX, 3.47, 0.83);
histogramRoot.add(observedLabel);
highlightSelectedBar();
}
function highlightSelectedBar() {
const record = state.records[state.selected];
histogramBars.forEach((bar, index) => {
const selected = record && index === record.binIndex;
bar.material.color.setHex(selected ? B.colors.selected : B.colors.bar);
bar.material.emissive.setHex(selected ? 0x5b1008 : 0x000000);
bar.material.emissiveIntensity = selected ? 0.16 : 0;
});
}
function animateExpandedResample(record) {
clearGroup(destinationTokenRoot);
traceAnimations = [];
record.sequence.forEach((sourceIndex, drawIndex) => {
const sourceToken = sourceTokenGroups[sourceIndex];
const sourceWorld = new THREE.Vector3();
sourceToken.getWorldPosition(sourceWorld);
const from = sourceWorld.clone().sub(destinationPosition);
const to = slotPosition(drawIndex, record.sequence.length);
const token = makeToken(state.values[sourceIndex], 0xf3b254);
token.position.copy(from);
destinationTokenRoot.add(token);
traceAnimations.push({
token,
from,
to,
start: performance.now() + drawIndex * 105,
duration: 430
});
});
}
function renderTrace() {
const record = state.records[state.selected];
if (!record) return;
document.getElementById("traceTitle").textContent = `Expanded resample #${record.index + 1}`;
document.getElementById("traceSubtitle").textContent =
`${DATASETS[state.datasetKey].label} · sample size n = ${state.values.length}`;
const sequenceHost = document.getElementById("sequence");
sequenceHost.replaceChildren();
record.sequence.forEach((tokenIndex, drawIndex) => {
const chip = document.createElement("div");
chip.className = "token-chip";
chip.title = `Draw ${drawIndex + 1}: original token ${tokenIndex + 1}, value ${state.values[tokenIndex]}`;
chip.innerHTML = `${state.values[tokenIndex]}<small>D${drawIndex + 1}</small>`;
sequenceHost.appendChild(chip);
});
const bin = state.bins[record.binIndex];
document.getElementById("traceStat").textContent = format(record.statistic);
document.getElementById("traceBin").textContent =
`${format(bin.lower, 2)} – ${format(bin.upper, 2)}`;
const relation = document.getElementById("relation");
const inside = record.statistic >= state.percentile.lower - 1e-9 &&
record.statistic <= state.percentile.upper + 1e-9;
relation.classList.toggle("outside", !inside);
relation.textContent = inside
? `Inside the chosen 90% percentile interval [${format(state.percentile.lower)}, ${format(state.percentile.upper)}].`
: `Outside the chosen 90% percentile interval [${format(state.percentile.lower)}, ${format(state.percentile.upper)}]. This is a legitimate tail draw.`;
document.querySelectorAll("#binLinks button").forEach((button) => {
button.classList.toggle("active", Number(button.dataset.bin) === record.binIndex);
});
highlightSelectedBar();
animateExpandedResample(record);
validateCurrentState();
}
function renderSummary() {
document.getElementById("observedValue").textContent = format(state.observed);
document.getElementById("observedSub").textContent =
`Mean of ${state.values.length} displayed synthetic tokens: [${state.values.join(", ")}].`;
document.getElementById("distributionValue").textContent = format(state.distributionMean);
document.getElementById("distributionSub").textContent =
`SD ${format(state.distributionSD)} · ${state.batchSize} resamples · one count per resample.`;
document.getElementById("intervalValue").textContent =
`[${format(state.percentile.lower)}, ${format(state.percentile.upper)}]`;
document.getElementById("intervalSub").textContent =
`90% percentile bootstrap interval from the ${state.batchSize} resample means.`;
document.getElementById("datasetLimitation").textContent = DATASETS[state.datasetKey].limitation;
const binHost = document.getElementById("binLinks");
binHost.replaceChildren();
state.bins.forEach((bin) => {
const button = document.createElement("button");
button.type = "button";
button.dataset.bin = String(bin.index);
button.disabled = bin.records.length === 0;
button.textContent = `#${bin.index + 1} · ${format(bin.lower, 2)}–${format(bin.upper, 2)} · ${bin.count}`;
button.title = bin.records.length
? `Trace a resample in this exact bin (${bin.records.length} records)`
: "No resample in this bin";
button.addEventListener("click", () => {
const candidate = bin.records.find((record) => record.index === state.selected) || bin.records[0];
if (candidate) selectTrace(candidate.index);
});
binHost.appendChild(button);
});
}
function validateCurrentState() {
const record = state.records[state.selected];
const bar = histogramBars[record?.binIndex];
const bin = state.bins[record?.binIndex];
const epsilon = 1e-8;
const statisticInExactBin = !!record && !!bin &&
record.statistic >= bin.lower - epsilon &&
record.statistic <= bin.upper + epsilon;
const geometryMatchesBin = !!bar &&
bar.userData.binIndex === record.binIndex &&
Math.abs(bar.userData.targetHeight - (0.25 + (bin.count / Math.max(...state.bins.map(b => b.count), 1)) * 2.25)) < epsilon;
const isDefaultTiny = state.datasetKey === "tiny" && state.seed === DEFAULT_SEED;
const secondRecord = state.records[1];
const defaultTinySequenceCorrect = !isDefaultTiny || (
secondRecord &&
secondRecord.sequence.map(index => state.values[index]).join(",") === "4,4,7" &&
Math.abs(secondRecord.statistic - 5) < epsilon
);
const defaultTinyIntervalContainsTrace = !isDefaultTiny || (
state.percentile.lower - epsilon <= 5 &&
state.percentile.upper + epsilon >= 5
);
const pass = statisticInExactBin && geometryMatchesBin &&
defaultTinySequenceCorrect && defaultTinyIntervalContainsTrace;
const badge = document.getElementById("integrity");
badge.classList.toggle("fail", !pass);
if (isDefaultTiny) {
badge.textContent = pass
? "✓ Link test passed: 4, 4, 7 → mean 5.00 → exact bin → inside the 90% PI."
: "✕ Link test failed: the draw, statistic, bin, or interval does not agree.";
} else {
badge.textContent = pass
? "✓ Link test passed: actual draws → statistic → exact physical histogram bar."
: "✕ Link test failed: draw/statistic/bin mapping is inconsistent.";
}
console.assert(pass, "Bootstrap trace integrity check failed", {
record,
bin,
statisticInExactBin,
geometryMatchesBin,
defaultTinySequenceCorrect,
defaultTinyIntervalContainsTrace
});
return {
pass,
statisticInExactBin,
geometryMatchesBin,
defaultTinySequenceCorrect,
defaultTinyIntervalContainsTrace
};
}
function selectTrace(index) {
if (!state.records.length) return;
state.selected = ((index % state.records.length) + state.records.length) % state.records.length;
renderTrace();
}
function runExperiment() {
const parsedSeed = Number(document.getElementById("seedInput").value);
state.seed = Number.isFinite(parsedSeed) ? (parsedSeed >>> 0) : DEFAULT_SEED;
document.getElementById("seedInput").value = state.seed;
state.batchSize = Number(document.getElementById("batchInput").value);
generateRecords();
rebuildSourceTokens();
rebuildHistogram();
renderSummary();
state.selected = Math.min(1, state.records.length - 1);
renderTrace();
}
function applyDataset(key) {
state.datasetKey = key;
state.values = DATASETS[key].values.slice();
document.querySelectorAll("[data-dataset]").forEach((button) => {
const active = button.dataset.dataset === key;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
sourceTray.children[4].material.map?.dispose?.();
sourceTray.remove(sourceTray.children[4]);
const title = makeTextSprite(`${DATASETS[key].label.toUpperCase()} DATA`, {
width: 3.25,
height: 0.43,
fontSize: 31,
color: "#18313b",
background: "rgba(251,250,244,0.92)",
border: "rgba(24,49,59,0.18)"
});
title.position.set(0, 2.02, -0.68);
sourceTray.add(title);
runExperiment();
}
document.querySelectorAll("[data-dataset]").forEach((button) => {
button.addEventListener("click", () => applyDataset(button.dataset.dataset));
});
document.getElementById("runButton").addEventListener("click", runExperiment);
document.getElementById("prevTrace").addEventListener("click", () => selectTrace(state.selected - 1));
document.getElementById("nextTrace").addEventListener("click", () => selectTrace(state.selected + 1));
document.getElementById("cameraButton").addEventListener("click", () => {
orbit.targetTheta = 0.57;
orbit.targetPhi = 1.03;
orbit.targetRadius = 20.7;
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerStart = null;
let pointerMoved = false;
function raycastHistogram(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(histogramBars, false);
return hits.length ? hits[0].object.userData.binIndex : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerStart = { x: event.clientX, y: event.clientY };
pointerMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerStart) {
renderer.domElement.style.cursor = raycastHistogram(event) === null ? "grab" : "pointer";
return;
}
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(orbit.targetPhi - dy * 0.005, 0.38, 1.38);
pointerStart = { x: event.clientX, y: event.clientY };
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerMoved) {
const binIndex = raycastHistogram(event);
if (binIndex !== null) {
const candidate = state.bins[binIndex].records.find(record => record.index === state.selected) ||
state.bins[binIndex].records[0];
if (candidate) selectTrace(candidate.index);
}
}
pointerStart = null;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerStart = null;
pointerMoved = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(orbit.targetRadius + event.deltaY * 0.012, 11, 27);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
orbit.targetTheta = 0.57;
orbit.targetPhi = 1.03;
orbit.targetRadius = 20.7;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate() {
requestAnimationFrame(animate);
orbit.theta += (orbit.targetTheta - orbit.theta) * 0.08;
orbit.phi += (orbit.targetPhi - orbit.phi) * 0.08;
orbit.radius += (orbit.targetRadius - orbit.radius) * 0.08;
updateCamera();
const now = performance.now();
histogramBars.forEach((bar) => {
bar.userData.growth += (1 - bar.userData.growth) * 0.075;
const height = Math.max(0.015, bar.userData.targetHeight * bar.userData.growth);
bar.scale.y = height;
bar.position.y = 0.57 + height / 2;
if (bar.userData.countLabel) {
bar.userData.countLabel.position.y = 0.57 + height + 0.23;
}
});
traceAnimations = traceAnimations.filter(animation => {
const progress = THREE.MathUtils.clamp((now - animation.start) / animation.duration, 0, 1);
const eased = 1 - Math.pow(1 - progress, 3);
animation.token.position.lerpVectors(animation.from, animation.to, eased);
animation.token.position.y += Math.sin(progress * Math.PI) * 0.75;
if (progress < 1) animation.token.rotation.y = progress * Math.PI * 1.8;
return progress < 1;
});
renderer.render(scene, camera);
}
window.__BOOTSTRAP_EXHIBIT__ = {
getState() {
return {
dataset: state.datasetKey,
seed: state.seed,
batchSize: state.batchSize,
values: state.values.slice(),
observed: state.observed,
percentile: { ...state.percentile },
bins: state.bins.map(bin => ({
index: bin.index,
lower: bin.lower,
upper: bin.upper,
count: bin.count
})),
selected: state.records[state.selected] ? {
index: state.records[state.selected].index,
sequenceIndices: state.records[state.selected].sequence.slice(),
sequenceValues: state.records[state.selected].sequence.map(index => state.values[index]),
statistic: state.records[state.selected].statistic,
binIndex: state.records[state.selected].binIndex
} : null,
validation: validateCurrentState()
};
},
selectTrace,
run: runExperiment
};
applyDataset("tiny");
document.getElementById("loading").remove();
animate();
</script>
</body>
</html>
```