Prompt specification
Build or customize the Three.js 3D scene "Confidence-coverage simulation 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: Confidence-coverage simulation explorer
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/confidence-coverage-simulation-explorer-x1808
Scene Description Prompt:
Vary sample size and confidence level in a low-poly repeated-sampling model; count intervals covering the fixed parameter. One HTML file with Three.js from cdnjs.
Working Three.js Starter (confidence-coverage-simulation-explorer-x1808):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Repeated Sampling Coverage Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(11, 21, 37, 0.88);
--border: rgba(151, 182, 221, 0.18);
--text: #edf5ff;
--muted: #8ea2bd;
--green: #43dc9a;
--red: #ff6b78;
--gold: #ffd166;
--blue: #75bfff;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
top: 28px;
left: 30px;
width: min(470px, calc(100vw - 410px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
margin-bottom: 10px;
color: var(--blue);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
max-width: 430px;
margin: 15px 0 0;
color: #aec0d7;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
top: 20px;
right: 20px;
width: 340px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 17px;
}
.panel-title {
font-size: 14px;
font-weight: 800;
letter-spacing: 0.02em;
}
.fixed-chip {
padding: 6px 9px;
border: 1px solid rgba(255, 209, 102, 0.25);
border-radius: 999px;
background: rgba(255, 209, 102, 0.08);
color: var(--gold);
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
.stat-card {
padding: 16px;
border: 1px solid rgba(117, 191, 255, 0.16);
border-radius: 15px;
background:
linear-gradient(145deg, rgba(117, 191, 255, 0.09), rgba(117, 191, 255, 0.025));
}
.stat-label {
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.count {
display: flex;
align-items: baseline;
gap: 8px;
margin: 6px 0 0;
font-variant-numeric: tabular-nums;
}
#coverCount {
color: var(--green);
font-size: 46px;
font-weight: 850;
line-height: 1;
letter-spacing: -0.055em;
}
.count-total {
color: var(--muted);
font-size: 18px;
font-weight: 700;
}
.observed {
margin-top: 7px;
color: #d8e8fb;
font-size: 13px;
font-weight: 650;
}
.meter {
position: relative;
height: 8px;
margin-top: 15px;
overflow: visible;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
#coverageFill {
width: 95%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #249f77, var(--green));
transition: width 180ms ease;
}
#nominalTick {
position: absolute;
top: -5px;
left: 95%;
width: 2px;
height: 18px;
border-radius: 2px;
background: var(--gold);
box-shadow: 0 0 10px rgba(255, 209, 102, 0.45);
transition: left 180ms ease;
}
.delta {
min-height: 34px;
margin-top: 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.delta.on-target {
color: var(--green);
}
.delta.off-target {
color: #ffc4ca;
}
.control-group {
margin-top: 20px;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #dbe8f8;
font-size: 12px;
font-weight: 750;
}
.control-heading output {
min-width: 58px;
padding: 4px 8px;
border: 1px solid var(--border);
border-radius: 7px;
background: rgba(255, 255, 255, 0.04);
color: var(--blue);
text-align: center;
font: 800 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 7px 0;
appearance: none;
border-radius: 999px;
background: #223249;
accent-color: var(--blue);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #dff2ff;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 0 0 4px rgba(117, 191, 255, 0.13);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #dff2ff;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 0 0 4px rgba(117, 191, 255, 0.13);
}
.range-notes {
display: flex;
justify-content: space-between;
color: #61748e;
font-size: 10px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 20px;
}
button {
min-height: 40px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.055);
color: #dceaff;
font: 750 12px inherit;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(117, 191, 255, 0.42);
background: rgba(117, 191, 255, 0.1);
}
button:active {
transform: translateY(1px);
}
#resample {
border-color: rgba(117, 191, 255, 0.32);
background: rgba(117, 191, 255, 0.12);
color: #e9f6ff;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 19px;
padding-top: 16px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.swatch.green {
background: var(--green);
}
.swatch.red {
background: var(--red);
}
.swatch.gold {
background: var(--gold);
}
.model-note {
margin: 15px 0 0;
color: #71869f;
font-size: 10px;
line-height: 1.55;
}
.model-note strong {
color: #a8bbd2;
font-weight: 700;
}
.camera-hint {
position: fixed;
bottom: 24px;
left: 30px;
padding: 8px 11px;
border: 1px solid rgba(151, 182, 221, 0.12);
border-radius: 999px;
background: rgba(7, 17, 31, 0.65);
color: #7890aa;
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
@media (max-width: 800px) {
.intro {
top: 16px;
left: 18px;
width: calc(100vw - 36px);
}
.intro h1 {
max-width: 370px;
font-size: 34px;
}
.intro p {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 15px;
border-radius: 16px;
}
.panel-header {
margin-bottom: 11px;
}
.stat-card {
padding: 12px;
}
#coverCount {
font-size: 36px;
}
.control-group {
margin-top: 13px;
}
.button-row {
margin-top: 13px;
}
.legend,
.model-note {
display: none;
}
.camera-hint {
top: 116px;
bottom: auto;
left: 18px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="intro">
<div class="eyebrow">Interactive statistics / Repeated sampling</div>
<h1>Coverage under<br />the golden line</h1>
<p>
Each low-poly bar is one confidence interval from a fresh sample.
The fixed population mean sits behind the golden gate. Count how many
intervals capture it.
</p>
</header>
<aside class="panel">
<div class="panel-header">
<div class="panel-title">Simulation controls</div>
<div class="fixed-chip">μ = 50 fixed</div>
</div>
<section class="stat-card" aria-live="polite">
<div class="stat-label">Intervals covering the parameter</div>
<div class="count">
<span id="coverCount">0</span>
<span class="count-total">/ 80</span>
</div>
<div class="observed">
<span id="coveragePct">0%</span> observed coverage
</div>
<div class="meter" aria-hidden="true">
<div id="coverageFill"></div>
<i id="nominalTick"></i>
</div>
<div id="deltaText" class="delta"></div>
</section>
<section class="control-group">
<div class="control-heading">
<label for="sampleSize">Sample size, n</label>
<output id="sampleSizeValue" for="sampleSize">30</output>
</div>
<input
id="sampleSize"
type="range"
min="5"
max="200"
step="5"
value="30"
/>
<div class="range-notes">
<span>5 observations</span>
<span>200 observations</span>
</div>
</section>
<section class="control-group">
<div class="control-heading">
<label for="confidence">Confidence level</label>
<output id="confidenceValue" for="confidence">95%</output>
</div>
<input
id="confidence"
type="range"
min="80"
max="99.5"
step="0.5"
value="95"
/>
<div class="range-notes">
<span>80%</span>
<span>99.5%</span>
</div>
</section>
<div class="button-row">
<button id="resample" type="button">↻ New samples</button>
<button id="resetCamera" type="button">Reset view</button>
</div>
<div class="legend">
<span class="legend-item">
<i class="swatch green"></i> covers μ
</span>
<span class="legend-item">
<i class="swatch red"></i> misses μ
</span>
<span class="legend-item">
<i class="swatch gold"></i> fixed μ = 50
</span>
</div>
<p class="model-note">
<strong>Model:</strong> 80 repeated samples from N(50, 12²).
The population standard deviation is treated as known.
Larger samples produce narrower intervals; higher confidence produces
wider intervals. Seed: <span id="seedValue">202503</span>.
</p>
</aside>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const MU = 50;
const SIGMA = 12;
const REPETITIONS = 80;
const WORLD_UNITS_PER_VALUE = 10;
const $ = (id) => document.getElementById(id);
const ui = {
scene: $("scene"),
sampleSize: $("sampleSize"),
sampleSizeValue: $("sampleSizeValue"),
confidence: $("confidence"),
confidenceValue: $("confidenceValue"),
coverCount: $("coverCount"),
coveragePct: $("coveragePct"),
coverageFill: $("coverageFill"),
nominalTick: $("nominalTick"),
deltaText: $("deltaText"),
resample: $("resample"),
resetCamera: $("resetCamera"),
seedValue: $("seedValue")
};
let currentN = Number(ui.sampleSize.value);
let currentConfidence = Number(ui.confidence.value);
let seed = 202503;
let sampleMeans = [];
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional repeated-sampling confidence interval model"
);
ui.scene.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 16, 36);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
targetYaw: 0.68,
targetPitch: 0.77,
targetRadius: 15.7,
yaw: 0.68,
pitch: 0.77,
radius: 15.7
};
const cameraTarget = new THREE.Vector3(0, 0.05, 0);
function updateCamera() {
const sinPitch = Math.sin(orbit.pitch);
camera.position.set(
cameraTarget.x + orbit.radius * sinPitch * Math.cos(orbit.yaw),
cameraTarget.y + orbit.radius * Math.cos(orbit.pitch),
cameraTarget.z + orbit.radius * sinPitch * Math.sin(orbit.yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xc9e3ff, 0x142039, 1.75);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5dbbff, 1.4);
rimLight.position.set(-8, 5, -8);
scene.add(rimLight);
const goldLight = new THREE.PointLight(0xffc857, 12, 13, 2);
goldLight.position.set(0, 2.3, -1.8);
scene.add(goldLight);
// Platform and ground.
const platform = new THREE.Mesh(
new THREE.BoxGeometry(15.8, 0.25, 12.6),
new THREE.MeshStandardMaterial({
color: 0x0c1727,
roughness: 0.82,
metalness: 0.15,
flatShading: true
})
);
platform.position.y = -0.69;
platform.receiveShadow = true;
scene.add(platform);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(15.6, 12.4),
new THREE.MeshStandardMaterial({
color: 0x101d2e,
roughness: 0.95,
metalness: 0.04,
flatShading: true
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.555;
floor.receiveShadow = true;
scene.add(floor);
// Grid.
const gridVertices = [];
for (let x = -4; x <= 4.001; x += 0.5) {
gridVertices.push(x, -0.535, -4.6, x, -0.535, 4.6);
}
for (let z = -4.5; z <= 4.501; z += 0.5) {
gridVertices.push(-4.5, -0.535, z, 4.5, -0.535, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x2a3e57,
transparent: true,
opacity: 0.42
})
);
scene.add(grid);
// Brighter horizontal parameter axis.
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-4.45, -0.515, 4.72),
new THREE.Vector3(4.45, -0.515, 4.72)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineBasicMaterial({ color: 0x68819f })
);
scene.add(axis);
// ------------------------------------------------------------
// Fixed-parameter golden gate
// ------------------------------------------------------------
const goldMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x6f4500,
emissiveIntensity: 0.8,
roughness: 0.4,
metalness: 0.25,
flatShading: true
});
const goldGateMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
});
const gateCurtain = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.86, 9.45),
goldGateMaterial
);
gateCurtain.position.set(0, 0, 0);
scene.add(gateCurtain);
const topRail = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.035, 9.45),
goldMaterial
);
topRail.position.set(0, 0.45, 0);
scene.add(topRail);
const bottomRail = topRail.clone();
bottomRail.position.y = -0.43;
scene.add(bottomRail);
const postGeometry = new THREE.CylinderGeometry(0.035, 0.035, 0.88, 6);
for (const z of [-4.72, 4.72]) {
const post = new THREE.Mesh(postGeometry, goldMaterial);
post.position.set(0, 0.01, z);
post.castShadow = true;
scene.add(post);
}
const gateDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.18, 0),
goldMaterial
);
gateDiamond.position.set(0, 0.61, 4.72);
gateDiamond.rotation.z = Math.PI / 4;
scene.add(gateDiamond);
// ------------------------------------------------------------
// Canvas-texture labels
// ------------------------------------------------------------
function createLabel(
text,
color = "#8fa4bf",
worldWidth = 1.25,
fontSize = 42
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `700 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
context.fillStyle = color;
context.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 0.25, 1);
return sprite;
}
for (const x of [-4, -2, 0, 2, 4]) {
const value = 50 + x * WORLD_UNITS_PER_VALUE;
const label = createLabel(String(value), "#7388a2", 1.0, 36);
label.position.set(x, -0.23, 4.95);
scene.add(label);
}
const parameterLabel = createLabel("μ = 50", "#ffd166", 1.65, 46);
parameterLabel.position.set(0, 0.84, -4.8);
scene.add(parameterLabel);
const axisLabel = createLabel("PARAMETER VALUE", "#58708d", 2.5, 34);
axisLabel.position.set(3.25, -0.2, 5.45);
scene.add(axisLabel);
// ------------------------------------------------------------
// Repeated confidence intervals
// ------------------------------------------------------------
const intervalGroup = new THREE.Group();
scene.add(intervalGroup);
const barGeometry = new THREE.BoxGeometry(1, 0.095, 0.05);
const endpointGeometry = new THREE.OctahedronGeometry(0.062, 0);
const meanGeometry = new THREE.OctahedronGeometry(0.042, 0);
const coverMaterial = new THREE.MeshStandardMaterial({
color: 0x43dc9a,
emissive: 0x0b4a32,
emissiveIntensity: 0.55,
roughness: 0.4,
metalness: 0.08,
flatShading: true
});
const missMaterial = new THREE.MeshStandardMaterial({
color: 0xff6b78,
emissive: 0x4d1019,
emissiveIntensity: 0.5,
roughness: 0.48,
metalness: 0.06,
flatShading: true
});
const meanMaterial = new THREE.MeshStandardMaterial({
color: 0xeaf5ff,
emissive: 0x243d58,
emissiveIntensity: 0.3,
roughness: 0.35,
metalness: 0.1,
flatShading: true
});
const rows = [];
for (let i = 0; i < REPETITIONS; i++) {
const z = (i / (REPETITIONS - 1) - 0.5) * 8.8;
const bar = new THREE.Mesh(barGeometry, coverMaterial);
bar.position.set(0, -0.03, z);
bar.castShadow = true;
bar.receiveShadow = true;
intervalGroup.add(bar);
const lower = new THREE.Mesh(endpointGeometry, coverMaterial);
lower.position.set(0, -0.03, z);
lower.castShadow = true;
intervalGroup.add(lower);
const upper = new THREE.Mesh(endpointGeometry, coverMaterial);
upper.position.set(0, -0.03, z);
upper.castShadow = true;
intervalGroup.add(upper);
const mean = new THREE.Mesh(meanGeometry, meanMaterial);
mean.position.set(0, -0.025, z);
intervalGroup.add(mean);
rows.push({
bar,
lower,
upper,
mean,
current: {
scale: 0.01,
middle: 0,
low: 0,
high: 0,
mean: 0
},
target: {
scale: 0.01,
middle: 0,
low: 0,
high: 0,
mean: 0
}
});
}
// ------------------------------------------------------------
// Statistics
// ------------------------------------------------------------
// Acklam's inverse-normal approximation.
function inverseNormal(p) {
const a = [
-3.969683028665376e1,
2.209460984245205e2,
-2.759285104469687e2,
1.38357751867269e2,
-3.066479806614716e1,
2.506628277459239
];
const b = [
-5.447609879822406e1,
1.615858368580409e2,
-1.556989798598866e2,
6.680131188771972e1,
-1.328068155288572e1
];
const c = [
-7.784894002430293e-3,
-3.223964580411365e-1,
-2.400758277161838,
-2.549732539343734,
4.374664141464968,
2.938163982698783
];
const d = [
7.784695709041462e-3,
3.224671290700398e-1,
2.445134137142996,
3.754408661907416
];
const low = 0.02425;
const high = 1 - low;
let q;
let r;
if (p < low) {
q = Math.sqrt(-2 * Math.log(p));
return (
(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) /
((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1)
);
}
if (p > high) {
q = Math.sqrt(-2 * Math.log(1 - p));
return (
-(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) /
((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1)
);
}
q = p - 0.5;
r = q * q;
return (
(((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) *
q /
(((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1)
);
}
function mulberry32(initialSeed) {
let state = initialSeed >>> 0;
return function random() {
state += 0x6d2b79f5;
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;
};
}
function normalRandom(random) {
let u = 0;
let v = 0;
while (u === 0) u = random();
while (v === 0) v = random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
function generateSampleMeans(n) {
const mixedSeed =
(seed ^ Math.imul(n, 2654435761)) >>> 0;
const random = mulberry32(mixedSeed);
const standardError = SIGMA / Math.sqrt(n);
const means = [];
for (let i = 0; i < REPETITIONS; i++) {
means.push(MU + standardError * normalRandom(random));
}
return means;
}
function updateIntervals(animateFromCurrent = true) {
const alpha = 1 - currentConfidence / 100;
const zCritical = inverseNormal(1 - alpha / 2);
const margin = zCritical * (SIGMA / Math.sqrt(currentN));
let coveringCount = 0;
rows.forEach((row, index) => {
const mean = sampleMeans[index];
const low = mean - margin;
const high = mean + margin;
const covers = low <= MU && MU <= high;
if (covers) coveringCount += 1;
const lowX = (low - MU) / WORLD_UNITS_PER_VALUE;
const highX = (high - MU) / WORLD_UNITS_PER_VALUE;
const middleX = (lowX + highX) * 0.5;
const meanX = (mean - MU) / WORLD_UNITS_PER_VALUE;
row.target.scale = Math.max(0.015, highX - lowX);
row.target.middle = middleX;
row.target.low = lowX;
row.target.high = highX;
row.target.mean = meanX;
const material = covers ? coverMaterial : missMaterial;
row.bar.material = material;
row.lower.material = material;
row.upper.material = material;
if (!animateFromCurrent) {
Object.assign(row.current, row.target);
}
});
updateStatistics(coveringCount);
}
function updateStatistics(coveringCount) {
const observed = (coveringCount / REPETITIONS) * 100;
const difference = observed - currentConfidence;
const expectedCount = Math.round(
(REPETITIONS * currentConfidence) / 100
);
ui.coverCount.textContent = String(coveringCount);
ui.coveragePct.textContent = `${observed.toFixed(1)}%`;
ui.coverageFill.style.width = `${observed}%`;
ui.nominalTick.style.left = `${currentConfidence}%`;
if (Math.abs(difference) < 0.25) {
ui.deltaText.textContent =
`Observed coverage matches the nominal target. About ${expectedCount} of 80 intervals are expected to cover μ.`;
ui.deltaText.className = "delta on-target";
} else {
ui.deltaText.textContent =
`${difference > 0 ? "+" : ""}${difference.toFixed(1)} points ` +
`${difference > 0 ? "above" : "below"} the nominal target. ` +
`About ${expectedCount} of 80 are expected to cover μ.`;
ui.deltaText.className = "delta off-target";
}
}
function resample() {
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
sampleMeans = generateSampleMeans(currentN);
ui.seedValue.textContent = String(seed);
updateIntervals(true);
}
ui.sampleSize.addEventListener("input", () => {
currentN = Number(ui.sampleSize.value);
ui.sampleSizeValue.textContent = String(currentN);
sampleMeans = generateSampleMeans(currentN);
updateIntervals(true);
});
ui.confidence.addEventListener("input", () => {
currentConfidence = Number(ui.confidence.value);
ui.confidenceValue.textContent = `${currentConfidence}%`;
updateIntervals(true);
});
ui.resample.addEventListener("click", resample);
// ------------------------------------------------------------
// Custom camera controls: mouse, touch, wheel, keyboard
// ------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.targetYaw -= deltaX * 0.006;
orbit.targetPitch = THREE.MathUtils.clamp(
orbit.targetPitch + deltaY * 0.005,
0.28,
1.36
);
});
function stopDragging(event) {
if (!dragging) return;
if (
pointerId !== null &&
canvas.hasPointerCapture &&
canvas.hasPointerCapture(pointerId)
) {
canvas.releasePointerCapture(pointerId);
}
dragging = false;
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * Math.exp(event.deltaY * 0.001),
8,
28
);
},
{ passive: false }
);
function resetCamera() {
orbit.targetYaw = 0.68;
orbit.targetPitch = 0.77;
orbit.targetRadius = 15.7;
}
canvas.addEventListener("dblclick", resetCamera);
ui.resetCamera.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.key === "ArrowLeft") orbit.targetYaw += 0.09;
if (event.key === "ArrowRight") orbit.targetYaw -= 0.09;
if (event.key === "ArrowUp") {
orbit.targetPitch = Math.max(0.28, orbit.targetPitch - 0.07);
}
if (event.key === "ArrowDown") {
orbit.targetPitch = Math.min(1.36, orbit.targetPitch + 0.07);
}
});
// ------------------------------------------------------------
// Initialization and animation
// ------------------------------------------------------------
sampleMeans = generateSampleMeans(currentN);
updateIntervals(false);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const cameraBlend = 1 - Math.pow(0.001, delta);
const intervalBlend = 1 - Math.pow(0.00005, delta);
orbit.yaw += (orbit.targetYaw - orbit.yaw) * cameraBlend;
orbit.pitch += (orbit.targetPitch - orbit.pitch) * cameraBlend;
orbit.radius += (orbit.targetRadius - orbit.radius) * cameraBlend;
updateCamera();
for (const row of rows) {
row.current.scale +=
(row.target.scale - row.current.scale) * intervalBlend;
row.current.middle +=
(row.target.middle - row.current.middle) * intervalBlend;
row.current.low +=
(row.target.low - row.current.low) * intervalBlend;
row.current.high +=
(row.target.high - row.current.high) * intervalBlend;
row.current.mean +=
(row.target.mean - row.current.mean) * intervalBlend;
row.bar.scale.x = row.current.scale;
row.bar.position.x = row.current.middle;
row.lower.position.x = row.current.low;
row.upper.position.x = row.current.high;
row.mean.position.x = row.current.mean;
}
const pulse = 0.43 + Math.sin(clock.elapsedTime * 2.2) * 0.025;
gateDiamond.position.y = pulse;
goldLight.intensity = 11.5 + Math.sin(clock.elapsedTime * 2.2) * 1.1;
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```