Prompt specification
Build or customize the Three.js 3D scene "One test versus many tests comparison" 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: One test versus many tests comparison
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/one-test-versus-many-tests-comparison-x1814
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: one test versus many tests comparison. Run equal-threshold simulations with different numbers of comparisons; show the chance of at least one flagged result increasing without asserting every flag is false in real studies. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (one-test-versus-many-tests-comparison-x1814):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Test vs. Many Tests — Equal-Threshold Simulation</title>
<style>
:root {
color-scheme: dark;
--bg: #071116;
--panel: rgba(8, 22, 29, 0.88);
--panel-border: rgba(144, 226, 229, 0.16);
--text: #ecf8f7;
--muted: #91aeb3;
--mint: #63f0ce;
--cyan: #68d9ff;
--gold: #ffcc70;
--coral: #ff7082;
--shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 18%, rgba(25, 101, 110, 0.23), transparent 35%),
radial-gradient(circle at 22% 72%, rgba(29, 93, 105, 0.16), transparent 32%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
z-index: 0;
outline: none;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.atmosphere {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(3, 10, 14, 0.08), transparent 50%, rgba(3, 10, 14, 0.32)),
radial-gradient(ellipse at center, transparent 48%, rgba(1, 6, 9, 0.52) 100%);
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.title {
position: absolute;
top: 30px;
left: 34px;
width: min(560px, calc(100vw - 420px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 14px;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--mint);
box-shadow: 0 0 12px rgba(99, 240, 206, 0.75);
}
h1 {
margin: 0;
font-size: clamp(34px, 4.2vw, 62px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
h1 span {
color: var(--mint);
}
.lede {
max-width: 510px;
margin: 18px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.panel {
position: absolute;
top: 24px;
right: 24px;
width: 346px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 20px;
border: 1px solid var(--panel-border);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(120%);
pointer-events: auto;
scrollbar-width: thin;
scrollbar-color: rgba(99, 240, 206, 0.3) transparent;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel h2 {
margin: 0 0 5px;
font-size: 15px;
letter-spacing: -0.01em;
}
.panel-subtitle {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.model-badge {
flex: 0 0 auto;
padding: 6px 8px;
border: 1px solid rgba(99, 240, 206, 0.22);
border-radius: 999px;
color: var(--mint);
background: rgba(99, 240, 206, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.control {
margin-top: 17px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.control label,
.section-label {
color: #cfe0e2;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
}
.control output {
color: var(--mint);
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 99px;
background: linear-gradient(90deg, var(--mint) var(--fill, 25%), #183039 var(--fill, 25%));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #082026;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 1px rgba(99, 240, 206, 0.5), 0 0 14px rgba(99, 240, 206, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #082026;
border-radius: 50%;
background: var(--mint);
}
.range-notes {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #66858b;
font-size: 9px;
}
.section-label {
display: block;
margin-bottom: 9px;
}
.rate-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 6px;
}
.rate-choice {
min-width: 0;
padding: 9px 3px 8px;
border: 1px solid rgba(142, 201, 208, 0.12);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 160ms ease;
}
.rate-choice:hover {
border-color: rgba(99, 240, 206, 0.35);
background: rgba(99, 240, 206, 0.055);
}
.rate-choice.active {
border-color: rgba(99, 240, 206, 0.62);
background: rgba(99, 240, 206, 0.1);
box-shadow: inset 0 0 18px rgba(99, 240, 206, 0.045);
}
.rate-choice .count {
display: block;
color: #dcebec;
font-size: 10px;
font-weight: 800;
}
.rate-choice .rate {
display: block;
overflow: hidden;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-variant-numeric: tabular-nums;
text-overflow: ellipsis;
white-space: nowrap;
}
.rate-choice.active .rate {
color: var(--mint);
}
.run-button {
width: 100%;
margin-top: 17px;
padding: 12px 15px;
border: 0;
border-radius: 12px;
color: #05211d;
background: linear-gradient(100deg, var(--mint), #83e8ef);
box-shadow: 0 10px 25px rgba(99, 240, 206, 0.16);
cursor: pointer;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.02em;
transition: 160ms ease;
}
.run-button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 13px 30px rgba(99, 240, 206, 0.23);
}
.run-button:disabled {
cursor: wait;
opacity: 0.68;
}
.status {
min-height: 15px;
margin: 8px 0 0;
color: #77969c;
font-size: 9px;
line-height: 1.45;
text-align: center;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 17px;
}
.metric {
padding: 12px;
border: 1px solid rgba(142, 201, 208, 0.11);
border-radius: 14px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
min-height: 28px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.metric-value {
display: block;
margin-top: 6px;
color: var(--text);
font-size: 25px;
font-weight: 820;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.metric-value.mint {
color: var(--mint);
}
.metric-model {
display: block;
margin-top: 4px;
color: #6f8d93;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.formula {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
padding: 10px 11px;
border-radius: 11px;
color: #95b0b4;
background: rgba(0, 0, 0, 0.16);
font-size: 9px;
}
.formula strong {
color: #d7ebeb;
font-size: 10px;
font-weight: 700;
}
.note {
margin: 15px 0 0;
padding-top: 14px;
border-top: 1px solid rgba(142, 201, 208, 0.11);
color: #78969c;
font-size: 9px;
line-height: 1.55;
}
.note strong {
color: #b9ced0;
}
.scene-key {
position: absolute;
left: 34px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 18px;
max-width: 430px;
color: #78969c;
font-size: 10px;
pointer-events: none;
}
.key-item {
display: inline-flex;
align-items: center;
gap: 8px;
}
.key-tile {
width: 11px;
height: 11px;
border-radius: 3px;
background: #4fd7c7;
box-shadow: 0 0 10px rgba(79, 215, 199, 0.3);
}
.key-tower {
width: 11px;
height: 18px;
border-radius: 6px 6px 2px 2px;
background: linear-gradient(180deg, var(--coral), #b44764);
}
.key-line {
width: 18px;
height: 2px;
background: #8bcfc9;
box-shadow: 0 0 8px rgba(99, 240, 206, 0.3);
}
.panel-toggle {
display: none;
position: absolute;
right: 12px;
bottom: 12px;
z-index: 10;
align-items: center;
gap: 8px;
padding: 11px 15px;
border: 1px solid rgba(99, 240, 206, 0.35);
border-radius: 999px;
color: var(--mint);
background: rgba(8, 25, 31, 0.92);
box-shadow: var(--shadow);
cursor: pointer;
font-size: 11px;
font-weight: 800;
pointer-events: auto;
}
.panel-toggle::before {
width: 7px;
height: 7px;
border-radius: 50%;
content: "";
background: var(--mint);
box-shadow: 0 0 12px rgba(99, 240, 206, 0.6);
}
@media (max-width: 900px) {
.title {
width: calc(100vw - 390px);
}
h1 {
font-size: clamp(32px, 5vw, 48px);
}
}
@media (max-width: 760px) {
.title {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.eyebrow {
margin-bottom: 10px;
font-size: 9px;
}
h1 {
max-width: 420px;
font-size: clamp(28px, 8vw, 42px);
}
.lede {
max-width: 360px;
margin-top: 12px;
font-size: 11px;
line-height: 1.5;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 73vh;
transform: translateY(calc(100% + 35px));
transition: transform 220ms ease;
}
body.panel-open .panel {
transform: translateY(0);
}
.panel-toggle {
display: inline-flex;
}
.scene-key {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
role="img"
aria-label="Interactive three-dimensional comparison of the probability of at least one flagged result for one, three, ten, twenty-five, and fifty independent null comparisons."
></canvas>
<div class="atmosphere"></div>
<main class="hud">
<header class="title">
<div class="eyebrow">Equal-threshold simulation</div>
<h1>One test.<br /><span>Many tests.</span></h1>
<p class="lede">
Give every comparison the same threshold and run independent null simulations.
As the number of comparisons grows, the chance of seeing at least one flagged
result rises.
</p>
</header>
<aside class="panel" aria-label="Simulation controls and results">
<div class="panel-head">
<div>
<h2>Simulation controls</h2>
<p class="panel-subtitle">Independent null comparisons · equal α</p>
</div>
<span class="model-badge">Null benchmark</span>
</div>
<div class="control">
<div class="control-row">
<label for="threshold">Threshold for every comparison</label>
<output id="thresholdValue" for="threshold">α = 0.05</output>
</div>
<input
id="threshold"
type="range"
min="1"
max="20"
step="1"
value="5"
aria-label="Threshold for every comparison"
/>
<div class="range-notes">
<span>α = 0.01</span>
<span>α = 0.20</span>
</div>
</div>
<div class="control">
<div class="control-row">
<label for="runs">Simulation trials</label>
<output id="runsValue" for="runs">50,000</output>
</div>
<input
id="runs"
type="range"
min="10000"
max="100000"
step="5000"
value="50000"
aria-label="Number of simulation trials"
/>
<div class="range-notes">
<span>10k</span>
<span>100k</span>
</div>
</div>
<div class="control">
<span class="section-label">Comparisons in the highlighted family</span>
<div class="rate-grid" id="rateGrid">
<button class="rate-choice" data-m="1" aria-pressed="false">
<span class="count">1 test</span>
<span class="rate" id="rate-1">—</span>
</button>
<button class="rate-choice" data-m="3" aria-pressed="false">
<span class="count">3 tests</span>
<span class="rate" id="rate-3">—</span>
</button>
<button class="rate-choice active" data-m="10" aria-pressed="true">
<span class="count">10 tests</span>
<span class="rate" id="rate-10">—</span>
</button>
<button class="rate-choice" data-m="25" aria-pressed="false">
<span class="count">25 tests</span>
<span class="rate" id="rate-25">—</span>
</button>
<button class="rate-choice" data-m="50" aria-pressed="false">
<span class="count">50 tests</span>
<span class="rate" id="rate-50">—</span>
</button>
</div>
</div>
<button class="run-button" id="runButton" type="button">Run simulation</button>
<p class="status" id="status" aria-live="polite">Preparing simulation…</p>
<div class="metrics">
<div class="metric">
<span class="metric-label">One comparison<br />Monte Carlo</span>
<strong class="metric-value" id="singleObserved">—</strong>
<span class="metric-model" id="singleModel">model —</span>
</div>
<div class="metric">
<span class="metric-label" id="manyLabel">10 comparisons<br />Monte Carlo</span>
<strong class="metric-value mint" id="manyObserved">—</strong>
<span class="metric-model" id="manyModel">model —</span>
</div>
</div>
<div class="formula">
<span>Null model</span>
<strong>1 − (1 − α)<sup>m</sup></strong>
<span id="lift">—</span>
</div>
<p class="note">
<strong>How to read this.</strong> Every comparison receives the same α. The
simulator draws independent p-values uniformly from 0–1, representing a
null-only benchmark. A flag is false by construction only within that
benchmark. Real studies can contain genuine effects and correlated tests,
so this simulation does <strong>not</strong> claim that every flagged result
in a real study is false.
</p>
</aside>
<div class="scene-key" aria-hidden="true">
<span class="key-item"><i class="key-tile"></i> one comparison</span>
<span class="key-item"><i class="key-tower"></i> chance of any flag</span>
<span class="key-item"><i class="key-line"></i> family-level probability</span>
</div>
<button class="panel-toggle" id="panelToggle" type="button" aria-expanded="false">
Controls & results
</button>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07141b, 0.023);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
azimuth: 0.08,
polar: 1.03,
radius: window.innerWidth < 760 ? 24 : 17,
targetAzimuth: 0.08,
targetPolar: 1.03,
targetRadius: window.innerWidth < 760 ? 24 : 17,
target: new THREE.Vector3(0.35, 1.55, 0)
};
scene.add(new THREE.HemisphereLight(0x9deeff, 0x071016, 1.75));
const keyLight = new THREE.DirectionalLight(0xc9ffff, 3.2);
keyLight.position.set(-4, 10, 7);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xff7595, 1.7);
rimLight.position.set(8, 4, -7);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(48, 30),
new THREE.MeshStandardMaterial({
color: 0x08171e,
roughness: 0.86,
metalness: 0.18,
transparent: true,
opacity: 0.78
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
scene.add(floor);
const grid = new THREE.GridHelper(38, 38, 0x287181, 0x14343e);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const particlesGeometry = new THREE.BufferGeometry();
const particlePositions = new Float32Array(180 * 3);
let randomSeed = 1847;
function seededRandom() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
for (let i = 0; i < particlePositions.length; i += 3) {
particlePositions[i] = (seededRandom() - 0.5) * 28;
particlePositions[i + 1] = 0.8 + seededRandom() * 8;
particlePositions[i + 2] = (seededRandom() - 0.5) * 18;
}
particlesGeometry.setAttribute(
"position",
new THREE.BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particlesGeometry,
new THREE.PointsMaterial({
color: 0x72d8d2,
size: 0.026,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
scene.add(particles);
const backdropRing = new THREE.Mesh(
new THREE.TorusGeometry(7.8, 0.014, 8, 160),
new THREE.MeshBasicMaterial({
color: 0x4ab2bb,
transparent: true,
opacity: 0.17
})
);
backdropRing.position.set(0.5, 3.3, -4.5);
scene.add(backdropRing);
const comparisonCounts = [1, 3, 10, 25, 50];
const palette = [0x5ce5bd, 0x6cd9ff, 0xffcc70, 0xff9e72, 0xff6e82];
const xPositions = [-6.2, -3.1, 0, 3.1, 6.2];
const groups = [];
const platformGeometry = new THREE.BoxGeometry(2.68, 0.18, 2.0, 2, 1, 2);
const platformEdgeGeometry = new THREE.EdgesGeometry(platformGeometry);
const tileGeometry = new THREE.BoxGeometry(0.115, 0.19, 0.115);
const trackGeometry = new THREE.CylinderGeometry(0.43, 0.43, 3.55, 32, 1, true);
const barGeometry = new THREE.CylinderGeometry(0.3, 0.38, 1, 32);
const beaconGeometry = new THREE.SphereGeometry(0.105, 20, 14);
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabelSprite() {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 230;
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.35, 1.05, 1);
sprite.renderOrder = 20;
return { sprite, canvas: labelCanvas, texture };
}
function drawLabel(entry, count, probability, modelProbability, selected) {
const ctx = entry.label.canvas.getContext("2d");
const w = entry.label.canvas.width;
const h = entry.label.canvas.height;
ctx.clearRect(0, 0, w, h);
roundedRect(ctx, 10, 8, w - 20, h - 16, 26);
ctx.fillStyle = selected
? "rgba(7, 27, 32, 0.94)"
: "rgba(7, 23, 29, 0.82)";
ctx.fill();
ctx.strokeStyle = selected
? "rgba(99, 240, 206, 0.72)"
: "rgba(117, 177, 184, 0.23)";
ctx.lineWidth = selected ? 4 : 2;
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = selected ? "#63f0ce" : "#9ab8bd";
ctx.font = "800 25px system-ui, sans-serif";
ctx.fillText(
`${count} ${count === 1 ? "TEST" : "TESTS"}`,
w / 2,
48
);
ctx.fillStyle = "#f1fbfa";
ctx.font = "820 66px system-ui, sans-serif";
ctx.fillText(`${(probability * 100).toFixed(1)}%`, w / 2, 119);
ctx.fillStyle = "#9ab8bd";
ctx.font = "750 20px system-ui, sans-serif";
ctx.fillText("CHANCE OF ANY FLAG", w / 2, 158);
ctx.fillStyle = selected ? "#63f0ce" : "#6f9298";
ctx.font = "600 18px system-ui, sans-serif";
ctx.fillText(
`null model ${(modelProbability * 100).toFixed(1)}%`,
w / 2,
195
);
entry.label.texture.needsUpdate = true;
}
comparisonCounts.forEach((count, index) => {
const x = xPositions[index];
const color = palette[index];
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x102830,
roughness: 0.62,
metalness: 0.27,
transparent: true,
opacity: 0.84
});
const platform = new THREE.Mesh(platformGeometry, platformMaterial);
platform.position.set(x, 0.085, 0);
scene.add(platform);
const edge = new THREE.LineSegments(
platformEdgeGeometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.25
})
);
edge.position.copy(platform.position);
scene.add(edge);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.13, 0.024, 8, 72),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.195, 0);
scene.add(ring);
const track = new THREE.Mesh(
trackGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false
})
);
track.position.set(x, 2.0, 0.55);
scene.add(track);
const barMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.38,
roughness: 0.27,
metalness: 0.22,
transparent: true,
opacity: 0.86
});
const bar = new THREE.Mesh(barGeometry, barMaterial);
bar.position.set(x, 0.45, 0.55);
scene.add(bar);
const beacon = new THREE.Mesh(
beaconGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 1
})
);
beacon.position.set(x, 0.62, 0.55);
scene.add(beacon);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0x53d7c8,
emissive: 0x124d49,
emissiveIntensity: 0.42,
roughness: 0.35,
metalness: 0.12,
transparent: true,
opacity: 0.78
});
let columns;
let rows;
if (count === 1) [columns, rows] = [1, 1];
else if (count === 3) [columns, rows] = [3, 1];
else if (count === 10) [columns, rows] = [5, 2];
else if (count === 25) [columns, rows] = [5, 5];
else [columns, rows] = [10, 5];
const stepX = columns === 10 ? 0.205 : 0.255;
const stepZ = rows === 5 ? 0.22 : 0.25;
const tiles = [];
for (let i = 0; i < count; i++) {
const column = i % columns;
const row = Math.floor(i / columns);
const tile = new THREE.Mesh(tileGeometry, tileMaterial);
tile.position.set(
x - 0.53 + (column - (columns - 1) / 2) * stepX,
0.275,
-0.28 + (row - (rows - 1) / 2) * stepZ
);
scene.add(tile);
tiles.push(tile);
}
const label = makeLabelSprite();
label.sprite.position.set(x, 1.65, 0.55);
scene.add(label.sprite);
groups.push({
count,
x,
color,
platform,
edge,
ring,
track,
bar,
beacon,
tileMaterial,
tiles,
label,
probability: 0.05,
modelProbability: 0.05
});
});
const linePositions = new Float32Array(comparisonCounts.length * 3);
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(linePositions, 3)
);
const probabilityLine = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: 0x9ce8df,
transparent: true,
opacity: 0.58
})
);
scene.add(probabilityLine);
const state = {
alpha: 0.05,
runs: 50000,
selected: 10,
estimates: Object.fromEntries(comparisonCounts.map((m) => [m, 0])),
running: false
};
const thresholdInput = document.querySelector("#threshold");
const runsInput = document.querySelector("#runs");
const thresholdValue = document.querySelector("#thresholdValue");
const runsValue = document.querySelector("#runsValue");
const runButton = document.querySelector("#runButton");
const status = document.querySelector("#status");
const singleObserved = document.querySelector("#singleObserved");
const singleModel = document.querySelector("#singleModel");
const manyObserved = document.querySelector("#manyObserved");
const manyModel = document.querySelector("#manyModel");
const manyLabel = document.querySelector("#manyLabel");
const lift = document.querySelector("#lift");
function modelProbability(count, alpha = state.alpha) {
return 1 - Math.pow(1 - alpha, count);
}
function setRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const percent = ((Number(input.value) - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateControlLabels() {
state.alpha = Number(thresholdInput.value) / 100;
state.runs = Number(runsInput.value);
thresholdValue.textContent = `α = ${state.alpha.toFixed(2)}`;
runsValue.textContent = state.runs.toLocaleString();
setRangeFill(thresholdInput);
setRangeFill(runsInput);
}
function updateSelectionVisuals() {
for (const entry of groups) {
const selected = entry.count === state.selected;
entry.ring.visible = selected;
entry.ring.material.opacity = selected ? 0.95 : 0;
entry.bar.material.opacity = selected ? 1 : 0.65;
entry.bar.material.emissiveIntensity = selected ? 0.72 : 0.27;
entry.tileMaterial.opacity = selected ? 0.98 : 0.43;
entry.beacon.material.opacity = selected ? 1 : 0.48;
entry.label.sprite.scale.set(
selected ? 2.48 : 2.27,
selected ? 1.11 : 1.0,
1
);
drawLabel(
entry,
entry.count,
entry.probability,
entry.modelProbability,
selected
);
}
}
function updateResults() {
for (const entry of groups) {
entry.probability = state.estimates[entry.count];
entry.modelProbability = modelProbability(entry.count);
document.querySelector(`#rate-${entry.count}`).textContent =
`${(entry.probability * 100).toFixed(1)}%`;
const height = 0.18 + entry.probability * 3.55;
entry.bar.scale.set(1, height, 1);
entry.bar.position.y = 0.225 + height / 2;
entry.beacon.position.y = 0.225 + height + 0.09;
entry.label.sprite.position.y = 0.225 + height + 1.08;
}
const positions = lineGeometry.attributes.position;
groups.forEach((entry, index) => {
const height = 0.18 + entry.probability * 3.55;
positions.setXYZ(
index,
entry.x,
0.225 + height + 0.09,
0.55
);
});
positions.needsUpdate = true;
const single = state.estimates[1];
const many = state.estimates[state.selected];
const singleModelValue = modelProbability(1);
const manyModelValue = modelProbability(state.selected);
singleObserved.textContent = `${(single * 100).toFixed(1)}%`;
singleModel.textContent = `model ${(singleModelValue * 100).toFixed(1)}%`;
manyObserved.textContent = `${(many * 100).toFixed(1)}%`;
manyModel.textContent = `model ${(manyModelValue * 100).toFixed(1)}%`;
manyLabel.innerHTML =
`${state.selected} ${state.selected === 1 ? "comparison" : "comparisons"}<br />Monte Carlo`;
const ratio = manyModelValue / singleModelValue;
lift.textContent =
state.selected === 1
? "same family size"
: `${ratio.toFixed(1)}× model chance vs. one`;
updateSelectionVisuals();
}
function mulberry32(seed) {
return function () {
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;
};
}
async function runSimulation() {
if (state.running) return;
state.running = true;
runButton.disabled = true;
thresholdInput.disabled = true;
runsInput.disabled = true;
runButton.textContent = "Running…";
status.textContent = "Drawing independent null comparisons…";
await new Promise((resolve) => requestAnimationFrame(resolve));
const seed = (Date.now() ^ Math.floor(Math.random() * 0xffffffff)) >>> 0;
const random = mulberry32(seed);
for (const count of comparisonCounts) {
let flaggedFamilies = 0;
for (let trial = 0; trial < state.runs; trial++) {
let anyFlag = false;
// Under the null, a p-value is uniform on [0, 1].
// A p-value below alpha is flagged.
for (let comparison = 0; comparison < count; comparison++) {
if (random() < state.alpha) {
anyFlag = true;
break;
}
}
if (anyFlag) flaggedFamilies++;
}
state.estimates[count] = flaggedFamilies / state.runs;
}
updateResults();
status.textContent =
`${state.runs.toLocaleString()} trials · seed 0x${seed.toString(16).toUpperCase()}`;
runButton.disabled = false;
thresholdInput.disabled = false;
runsInput.disabled = false;
runButton.textContent = "Run simulation again";
state.running = false;
}
document.querySelectorAll(".rate-choice").forEach((button) => {
button.addEventListener("click", () => {
state.selected = Number(button.dataset.m);
document.querySelectorAll(".rate-choice").forEach((candidate) => {
const active = Number(candidate.dataset.m) === state.selected;
candidate.classList.toggle("active", active);
candidate.setAttribute("aria-pressed", String(active));
});
updateResults();
});
});
let releaseTimer;
function scheduleRun() {
window.clearTimeout(releaseTimer);
releaseTimer = window.setTimeout(runSimulation, 180);
}
thresholdInput.addEventListener("input", () => {
updateControlLabels();
status.textContent = "Threshold changed — running…";
scheduleRun();
});
runsInput.addEventListener("input", () => {
updateControlLabels();
status.textContent = "Trial count changed — running…";
scheduleRun();
});
runButton.addEventListener("click", runSimulation);
const panelToggle = document.querySelector("#panelToggle");
panelToggle.addEventListener("click", () => {
const open = document.body.classList.toggle("panel-open");
panelToggle.setAttribute("aria-expanded", String(open));
});
// Camera interaction implemented here without importing any Three.js addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.targetAzimuth -= dx * 0.005;
cameraState.targetPolar = THREE.MathUtils.clamp(
cameraState.targetPolar - dy * 0.004,
0.5,
1.38
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.012,
9,
31
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") cameraState.targetAzimuth += step;
if (event.key === "ArrowRight") cameraState.targetAzimuth -= step;
if (event.key === "ArrowUp") {
cameraState.targetPolar = Math.max(0.5, cameraState.targetPolar - step);
}
if (event.key === "ArrowDown") {
cameraState.targetPolar = Math.min(1.38, cameraState.targetPolar + step);
}
if (event.key === "+" || event.key === "=") {
cameraState.targetRadius = Math.max(9, cameraState.targetRadius - 0.8);
}
if (event.key === "-") {
cameraState.targetRadius = Math.min(31, cameraState.targetRadius + 0.8);
}
});
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, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.pow(0.001, delta);
cameraState.azimuth = THREE.MathUtils.lerp(
cameraState.azimuth,
cameraState.targetAzimuth,
smoothing
);
cameraState.polar = THREE.MathUtils.lerp(
cameraState.polar,
cameraState.targetPolar,
smoothing
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
smoothing
);
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
const selectedEntry = groups.find((entry) => entry.count === state.selected);
if (selectedEntry) {
const pulse = 1 + Math.sin(clock.elapsedTime * 3.1) * 0.16;
selectedEntry.beacon.scale.setScalar(pulse);
}
backdropRing.rotation.z = clock.elapsedTime * 0.012;
renderer.render(scene, camera);
}
updateControlLabels();
updateResults();
animate();
runSimulation();
</script>
</body>
</html>
```