Prompt specification
Build or customize the Three.js 3D scene "Same expectation different outcome spreads" 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: Same expectation different outcome spreads
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/same-expectation-different-outcome-spreads-x1790
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a comparison of two fictional reward games with equal expected value but different variance; show their full outcome distributions rather than declaring them equally desirable. Stylized solid forms.
Working Three.js Starter (same-expectation-different-outcome-spreads-x1790):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Outcome Lab — Same Mean, Different Outcomes</title>
<style>
:root {
--ink: #182c2d;
--muted: #68706b;
--paper: #f5f1e8;
--cream: #e9e3d8;
--line: rgba(24, 44, 45, 0.16);
--coral: #e76855;
--coral-light: #eda091;
--gold: #efb94f;
--blue: #5576c8;
--blue-light: #91a6d9;
--teal: #49a69d;
--panel: rgba(250, 247, 239, 0.91);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--cream);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#canvas-wrap,
#label-layer {
position: fixed;
inset: 0;
}
#canvas-wrap {
z-index: 1;
}
#canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
#label-layer {
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.grain {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
opacity: 0.12;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
mix-blend-mode: multiply;
}
header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 5;
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 24px 26px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand-mark {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border: 1px solid var(--ink);
border-radius: 50%;
background: var(--paper);
font-size: 10px;
box-shadow: 3px 3px 0 var(--ink);
}
.hero {
position: absolute;
top: 78px;
left: 26px;
max-width: 330px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 10px;
color: var(--coral);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(34px, 4.3vw, 66px);
line-height: 0.94;
letter-spacing: -0.065em;
font-weight: 850;
}
h1 span {
color: var(--muted);
font-weight: 520;
}
.gesture {
margin: 16px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.gesture::before {
content: "";
display: inline-block;
width: 24px;
height: 1px;
margin: 0 8px 3px 0;
background: currentColor;
}
.read-legend {
width: 205px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(250, 247, 239, 0.7);
backdrop-filter: blur(12px);
}
.read-legend strong {
display: block;
margin-bottom: 9px;
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
}
.legend-symbol {
display: inline-block;
width: 17px;
height: 17px;
border: 1px solid var(--ink);
background: var(--paper);
}
.legend-symbol.height {
height: 22px;
background: var(--coral);
}
.legend-symbol.width {
width: 27px;
background: var(--blue);
}
#hud {
position: fixed;
left: 20px;
right: 20px;
bottom: 20px;
z-index: 6;
display: grid;
grid-template-columns: minmax(260px, 0.9fr) minmax(260px, 0.9fr) minmax(280px, 1.05fr);
gap: 12px;
align-items: stretch;
}
.panel {
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(45, 47, 40, 0.09);
backdrop-filter: blur(16px);
}
.game-card {
position: relative;
overflow: hidden;
padding: 15px 16px 14px;
}
.game-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: var(--accent);
}
.game-head {
display: flex;
align-items: center;
gap: 10px;
}
.game-letter {
display: grid;
flex: 0 0 34px;
place-items: center;
width: 34px;
height: 34px;
border-radius: 10px;
background: var(--accent);
color: white;
font-size: 14px;
font-weight: 900;
box-shadow: 3px 3px 0 rgba(24, 44, 45, 0.13);
}
.game-title {
min-width: 0;
flex: 1;
}
.game-title small {
display: block;
margin-bottom: 1px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.game-title h2 {
margin: 0;
font-size: 18px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.play-button {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
transition:
transform 160ms ease,
background 160ms ease;
}
.play-button:hover {
transform: translateY(-2px);
background: white;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin: 12px 0 10px;
padding: 9px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.stat small {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat b {
display: block;
margin-top: 2px;
font-size: 14px;
letter-spacing: -0.025em;
}
.outcomes {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.outcome-pill {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 5px 7px;
border-radius: 7px;
background: rgba(24, 44, 45, 0.045);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.outcome-pill i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--dot);
}
.outcome-pill b {
font-weight: 850;
}
.note-card {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 15px 17px;
background: rgba(24, 44, 45, 0.94);
color: #f8f3e8;
}
.equal-badge {
align-self: flex-start;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 999px;
color: #f2c766;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.note-card h3 {
margin: 10px 0 5px;
font-size: 23px;
letter-spacing: -0.045em;
}
.note-card p {
margin: 0;
color: rgba(248, 243, 232, 0.68);
font-size: 11px;
line-height: 1.45;
}
.lenses {
display: flex;
gap: 5px;
margin-top: 12px;
}
.lenses button {
flex: 1;
padding: 7px 5px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 8px;
background: transparent;
color: rgba(248, 243, 232, 0.65);
cursor: pointer;
font-size: 9px;
font-weight: 750;
transition: 160ms ease;
}
.lenses button:hover,
.lenses button.active {
border-color: #f2c766;
background: rgba(242, 199, 102, 0.12);
color: #f8f3e8;
}
.world-label {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
will-change: transform;
pointer-events: none;
}
.outcome-label {
padding: 5px 8px;
border: 1px solid rgba(24, 44, 45, 0.16);
border-radius: 9px;
background: rgba(250, 247, 239, 0.9);
box-shadow: 0 5px 14px rgba(40, 45, 40, 0.08);
text-align: center;
backdrop-filter: blur(8px);
}
.outcome-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
border-right: 1px solid rgba(24, 44, 45, 0.15);
border-bottom: 1px solid rgba(24, 44, 45, 0.15);
background: rgba(250, 247, 239, 0.9);
transform: translateX(-50%) rotate(45deg);
}
.outcome-label b {
display: block;
color: var(--ink);
font-size: 12px;
line-height: 1;
}
.outcome-label span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.04em;
}
.axis-label {
padding: 2px 4px;
border-radius: 4px;
background: rgba(233, 227, 216, 0.78);
color: rgba(24, 44, 45, 0.6);
font-size: 9px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.mean-label {
padding: 5px 8px;
border-radius: 7px;
background: var(--ink);
color: white;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
box-shadow: 0 4px 10px rgba(24, 44, 45, 0.16);
}
.stage-label {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid rgba(24, 44, 45, 0.12);
border-radius: 9px;
background: rgba(250, 247, 239, 0.87);
box-shadow: 0 5px 14px rgba(40, 45, 40, 0.06);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.stage-label b {
display: grid;
place-items: center;
width: 18px;
height: 18px;
border-radius: 5px;
background: var(--accent);
color: white;
font-size: 9px;
}
.stage-label em {
padding-left: 5px;
border-left: 1px solid var(--line);
color: var(--muted);
font-style: normal;
font-variant-numeric: tabular-nums;
}
#tooltip {
position: fixed;
z-index: 12;
display: none;
min-width: 190px;
padding: 10px 12px;
border: 1px solid rgba(24, 44, 45, 0.15);
border-radius: 10px;
background: rgba(250, 247, 239, 0.96);
box-shadow: 0 12px 35px rgba(24, 44, 45, 0.16);
pointer-events: none;
backdrop-filter: blur(12px);
}
#tooltip b {
display: block;
font-size: 12px;
}
#tooltip span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
#toast {
position: fixed;
top: 25px;
left: 50%;
z-index: 15;
min-width: 260px;
padding: 12px 16px;
border-radius: 12px;
background: var(--ink);
color: white;
box-shadow: 0 14px 38px rgba(24, 44, 45, 0.2);
opacity: 0;
pointer-events: none;
transform: translate(-50%, -18px);
transition:
opacity 180ms ease,
transform 180ms ease;
text-align: center;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast b {
color: #f4ca70;
}
#toast span {
display: block;
margin-top: 3px;
color: rgba(255, 255, 255, 0.7);
font-size: 10px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1040px) {
#hud {
grid-template-columns: 1fr 1fr;
}
.note-card {
grid-column: 1 / -1;
min-height: 150px;
}
.note-card p {
max-width: 650px;
}
.read-legend {
display: none;
}
}
@media (max-width: 650px) {
header {
padding: 15px;
}
.brand {
font-size: 10px;
}
.brand-mark {
width: 26px;
height: 26px;
}
.hero {
top: 58px;
left: 15px;
max-width: 245px;
}
h1 {
font-size: 35px;
}
.gesture {
display: none;
}
#hud {
left: 9px;
right: 9px;
bottom: 9px;
gap: 7px;
}
.game-card {
padding: 12px 10px 10px;
border-radius: 14px;
}
.game-letter {
flex-basis: 27px;
width: 27px;
height: 27px;
border-radius: 8px;
}
.game-title h2 {
font-size: 14px;
}
.game-title small {
font-size: 7px;
}
.play-button {
padding: 6px;
font-size: 7px;
}
.stats {
margin: 9px 0 8px;
padding: 7px 0;
}
.stat small {
font-size: 6px;
}
.stat b {
font-size: 11px;
}
.outcomes {
gap: 4px;
}
.outcome-pill {
padding: 4px 5px;
font-size: 8px;
}
.note-card {
min-height: 135px;
padding: 12px 13px;
}
.note-card h3 {
margin-top: 7px;
font-size: 19px;
}
.note-card p {
font-size: 10px;
}
.equal-badge {
font-size: 7px;
}
.lenses {
margin-top: 8px;
}
.lenses button {
font-size: 8px;
}
.outcome-label {
padding: 4px 6px;
}
.outcome-label b {
font-size: 10px;
}
.outcome-label span {
font-size: 7px;
}
.axis-label,
.stage-label {
font-size: 7px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="canvas-wrap"></div>
<div class="grain"></div>
<div id="label-layer"></div>
<header>
<div class="brand">
<span class="brand-mark">OL</span>
Outcome Lab / 01
</div>
<div class="read-legend">
<strong>How to read the forms</strong>
<div class="legend-row">
<i class="legend-symbol height"></i>
Height = reward
</div>
<div class="legend-row">
<i class="legend-symbol width"></i>
Width = probability
</div>
</div>
</header>
<section class="hero">
<p class="eyebrow">Full distributions · Equal EV</p>
<h1>Same average.<br /><span>Different outcomes.</span></h1>
<p class="gesture">Drag to orbit · Scroll to zoom · Hover a form</p>
</section>
<section id="hud" aria-label="Reward game comparison">
<article class="panel game-card" style="--accent: var(--coral)">
<div class="game-head">
<div class="game-letter">A</div>
<div class="game-title">
<small>The rare-upside game</small>
<h2>Lucky Leap</h2>
</div>
<button class="play-button" data-play="0">Play</button>
</div>
<div class="stats">
<div class="stat">
<small>EV</small>
<b>$9.00</b>
</div>
<div class="stat">
<small>Variance</small>
<b>675.00</b>
</div>
<div class="stat">
<small>Std. dev.</small>
<b>$25.98</b>
</div>
</div>
<div class="outcomes">
<span class="outcome-pill" style="--dot: var(--coral-light)">
<i></i>$0 <b>70%</b>
</span>
<span class="outcome-pill" style="--dot: var(--coral)">
<i></i>$12 <b>25%</b>
</span>
<span class="outcome-pill" style="--dot: var(--gold)">
<i></i>$120 <b>5%</b>
</span>
</div>
</article>
<article class="panel game-card" style="--accent: var(--blue)">
<div class="game-head">
<div class="game-letter">B</div>
<div class="game-title">
<small>The bounded-spread game</small>
<h2>Steady Steps</h2>
</div>
<button class="play-button" data-play="1">Play</button>
</div>
<div class="stats">
<div class="stat">
<small>EV</small>
<b>$9.00</b>
</div>
<div class="stat">
<small>Variance</small>
<b>81.00</b>
</div>
<div class="stat">
<small>Std. dev.</small>
<b>$9.00</b>
</div>
</div>
<div class="outcomes">
<span class="outcome-pill" style="--dot: var(--blue-light)">
<i></i>$0 <b>40%</b>
</span>
<span class="outcome-pill" style="--dot: var(--blue)">
<i></i>$12 <b>50%</b>
</span>
<span class="outcome-pill" style="--dot: var(--teal)">
<i></i>$30 <b>10%</b>
</span>
</div>
</article>
<article class="panel note-card">
<div>
<span class="equal-badge">EV equal · EV $9 each</span>
<h3>Not a verdict.</h3>
<p id="insight-copy">
A puts 5% of its probability on a $120 prize. B never pays more
than $30. The complete distributions matter, not just the mean.
</p>
</div>
<div class="lenses" role="tablist" aria-label="Comparison lens">
<button class="active" data-lens="distribution" role="tab">
Distribution
</button>
<button data-lens="spread" role="tab">Spread</button>
<button data-lens="preference" role="tab">Preference</button>
</div>
</article>
</section>
<div id="tooltip" role="status"></div>
<div id="toast" role="status" aria-live="polite"></div>
<p class="sr-only">
Two fictional games have the same expected value of nine dollars. Lucky
Leap has a rare $120 outcome and a standard deviation of $25.98. Steady
Steps has a maximum reward of $30 and a standard deviation of $9. The
scene does not imply that equal expected value means equal desirability.
</p>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.querySelector("#canvas-wrap");
const labelLayer = document.querySelector("#label-layer");
const tooltip = document.querySelector("#tooltip");
const toast = document.querySelector("#toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d8);
scene.fog = new THREE.Fog(0xe9e3d8, 44, 78);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 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;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
120
);
const target = new THREE.Vector3(0, 1.25, 0);
let yaw = 0;
let pitch = 0.37;
let zoom = 1;
let baseRadius = 23;
const hemi = new THREE.HemisphereLight(0xfffaf0, 0x8d9487, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff3dd, 3.2);
key.position.set(-9, 17, 12);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -25;
key.shadow.camera.right = 25;
key.shadow.camera.top = 22;
key.shadow.camera.bottom = -16;
key.shadow.camera.near = 1;
key.shadow.camera.far = 55;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xb9d4ff, 1.1);
fill.position.set(12, 8, -8);
scene.add(fill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe9e3d8,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const labels = [];
const outcomeMeshes = [];
const flights = [];
const materialCache = new Map();
const games = [
{
letter: "A",
name: "Lucky Leap",
x: -5.15,
accent: "#e76855",
sigma: "$25.98",
outcomes: [
{ amount: 0, probability: 0.70, color: "#eda091", name: "No reward" },
{ amount: 12, probability: 0.25, color: "#e76855", name: "Small reward" },
{ amount: 120, probability: 0.05, color: "#efb94f", name: "Rare jackpot" }
]
},
{
letter: "B",
name: "Steady Steps",
x: 5.15,
accent: "#5576c8",
sigma: "$9.00",
outcomes: [
{ amount: 0, probability: 0.40, color: "#91a6d9", name: "No reward" },
{ amount: 12, probability: 0.50, color: "#5576c8", name: "Small reward" },
{ amount: 30, probability: 0.10, color: "#49a69d", name: "Top reward" }
]
}
];
const PAYOUT_SCALE = 0.055;
const PLATFORM_TOP = 0.52;
const BAR_FLOOR = 0.59;
const MEAN = 9;
const MEAN_Y = BAR_FLOOR + MEAN * PAYOUT_SCALE;
function standardMaterial(color, roughness = 0.72) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0
});
}
function cachedMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(color, standardMaterial(color));
}
return materialCache.get(color);
}
function roundedShape(width, height, radius) {
const r = Math.max(
0.001,
Math.min(radius, width / 3, height / 3)
);
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
shape.closePath();
return shape;
}
function roundedMesh(width, height, depth, radius, material) {
const bevel = Math.min(0.045, radius * 0.28);
const geometry = new THREE.ExtrudeGeometry(
roundedShape(width, height, radius),
{
depth,
bevelEnabled: bevel > 0.002,
bevelSize: bevel,
bevelThickness: bevel,
bevelSegments: 2,
curveSegments: 8
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addWorldLabel(position, html, className, accent) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
if (accent) {
element.style.setProperty("--accent", accent);
}
labelLayer.appendChild(element);
labels.push({ element, position: position.clone() });
return element;
}
function makePlatform(group, accent) {
const body = roundedMesh(
8.25,
0.46,
5.75,
0.26,
standardMaterial("#d3cdc0")
);
body.position.y = 0.23;
group.add(body);
const top = roundedMesh(
8.02,
0.1,
5.52,
0.16,
standardMaterial("#f7f3ea")
);
top.position.y = 0.47;
group.add(top);
const frontBand = new THREE.Mesh(
new THREE.BoxGeometry(5.8, 0.055, 0.055),
standardMaterial(accent)
);
frontBand.position.set(0, 0.31, 2.895);
group.add(frontBand);
}
function makeProbabilityStrip(group, outcomes) {
const count = 20;
const totalWidth = 5.45;
const gap = 0.035;
const cellWidth = (totalWidth - gap * (count - 1)) / count;
const start = -totalWidth / 2;
for (let i = 0; i < count; i++) {
const point = (i + 0.5) / count;
let cumulative = 0;
let color = outcomes[0].color;
for (const outcome of outcomes) {
cumulative += outcome.probability;
if (point <= cumulative + 1e-6) {
color = outcome.color;
break;
}
}
const cell = new THREE.Mesh(
new THREE.BoxGeometry(cellWidth, 0.065, 0.38),
cachedMaterial(color)
);
cell.position.set(
start + i * (cellWidth + gap) + cellWidth / 2,
PLATFORM_TOP + 0.035,
1.73
);
cell.castShadow = true;
group.add(cell);
}
}
function makeSharedAxis(group, stageX) {
const axisMaterial = new THREE.MeshBasicMaterial({
color: 0x344847,
transparent: true,
opacity: 0.42
});
const axisHeight = 120 * PAYOUT_SCALE;
const line = new THREE.Mesh(
new THREE.BoxGeometry(0.035, axisHeight, 0.035),
axisMaterial
);
line.position.set(-3.69, BAR_FLOOR + axisHeight / 2, 1.02);
group.add(line);
[0, 30, 60, 90, 120].forEach((amount) => {
const y = BAR_FLOOR + amount * PAYOUT_SCALE;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.028, 0.035),
axisMaterial
);
tick.position.set(-3.69, y, 1.02);
group.add(tick);
addWorldLabel(
new THREE.Vector3(stageX - 3.91, y, 1.05),
`$${amount}`,
"axis-label"
);
});
}
function makeMeanGuide(group, stageX) {
const guide = new THREE.Mesh(
new THREE.BoxGeometry(6.25, 0.035, 0.04),
new THREE.MeshBasicMaterial({
color: 0x182c2d,
transparent: true,
opacity: 0.72
})
);
guide.position.set(0, MEAN_Y, 1.03);
group.add(guide);
const capGeometry = new THREE.SphereGeometry(0.055, 10, 8);
[-3.12, 3.12].forEach((x) => {
const cap = new THREE.Mesh(
capGeometry,
standardMaterial("#182c2d")
);
cap.position.set(x, MEAN_Y, 1.03);
group.add(cap);
});
addWorldLabel(
new THREE.Vector3(stageX + 3.39, MEAN_Y, 1.05),
"Mean · $9",
"mean-label"
);
}
function makeGame(game, gameIndex) {
const group = new THREE.Group();
group.position.x = game.x;
scene.add(group);
makePlatform(group, game.accent);
makeProbabilityStrip(group, game.outcomes);
makeSharedAxis(group, game.x);
makeMeanGuide(group, game.x);
const barArea = 5.45;
const gap = 0.12;
const totalWidth = barArea + gap * (game.outcomes.length - 1);
let cursor = -totalWidth / 2;
game.bars = [];
game.outcomes.forEach((outcome) => {
const width = outcome.probability * barArea;
const height = outcome.amount === 0
? 0.12
: outcome.amount * PAYOUT_SCALE;
const depth = 2.5;
const localX = cursor + width / 2;
cursor += width + gap;
const footprint = roundedMesh(
width + 0.07,
0.08,
depth + 0.07,
0.035,
standardMaterial("#c8c1b5")
);
footprint.position.set(localX, PLATFORM_TOP + 0.04, -0.45);
group.add(footprint);
const material = standardMaterial(outcome.color, 0.65);
const bar = roundedMesh(
width,
height,
depth,
0.06,
material
);
bar.position.set(localX, BAR_FLOOR + height / 2, -0.45);
group.add(bar);
const capColor = new THREE.Color(outcome.color).lerp(
new THREE.Color(0xffffff),
0.17
);
const cap = roundedMesh(
Math.max(0.1, width * 0.9),
Math.min(0.075, height * 0.45),
depth * 0.9,
0.025,
standardMaterial(capColor, 0.58)
);
cap.position.set(
localX,
BAR_FLOOR + height - cap.geometry.parameters.depth * 0.5,
-0.45
);
group.add(cap);
const deviationTop = BAR_FLOOR + height;
const deviationHeight = Math.abs(deviationTop - MEAN_Y);
if (deviationHeight > 0.01) {
const deviation = new THREE.Mesh(
new THREE.BoxGeometry(0.025, deviationHeight, 0.025),
new THREE.MeshBasicMaterial({
color: 0x243b3b,
transparent: true,
opacity: 0.42
})
);
deviation.position.set(
localX,
(deviationTop + MEAN_Y) / 2,
0.835
);
group.add(deviation);
}
const worldX = game.x + localX;
const worldTop = BAR_FLOOR + height;
bar.userData.outcome = {
...outcome,
gameIndex,
gameName: game.name,
worldX,
worldTop
};
outcomeMeshes.push(bar);
game.bars.push({
...outcome,
mesh: bar,
worldX,
worldTop,
localX
});
addWorldLabel(
new THREE.Vector3(worldX, worldTop + 0.42, 0.35),
`<b>$${outcome.amount}</b><span>${Math.round(
outcome.probability * 100
)}% chance</span>`,
"outcome-label"
);
});
addWorldLabel(
new THREE.Vector3(game.x, 0.68, 2.64),
`<b>${game.letter}</b><span>${game.name}</span><em>σ ${game.sigma}</em>`,
"stage-label",
game.accent
);
}
games.forEach(makeGame);
const markerGeometry = new THREE.IcosahedronGeometry(0.17, 1);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function sampleOutcome(game) {
const roll = Math.random();
let cumulative = 0;
for (const outcome of game.outcomes) {
cumulative += outcome.probability;
if (roll <= cumulative) {
return outcome;
}
}
return game.outcomes[game.outcomes.length - 1];
}
function showToast(game, outcome) {
const contribution = outcome.amount * outcome.probability;
toast.innerHTML = `
<b>${game.name}: $${outcome.amount}</b>
<span>
${Math.round(outcome.probability * 100)}% chance ·
$${contribution.toFixed(2)} contribution to expected value
</span>
`;
toast.classList.add("show");
window.clearTimeout(showToast.timer);
showToast.timer = window.setTimeout(() => {
toast.classList.remove("show");
}, 3300);
}
function playGame(gameIndex) {
const game = games[gameIndex];
const outcome = sampleOutcome(game);
const selectedBar = game.bars.find(
(bar) => bar.amount === outcome.amount
);
const material = new THREE.MeshStandardMaterial({
color: outcome.color,
emissive: outcome.color,
emissiveIntensity: 0.22,
roughness: 0.45,
transparent: true,
opacity: 1
});
const marker = new THREE.Mesh(markerGeometry, material);
marker.castShadow = true;
marker.position.set(
selectedBar.worldX,
8.2,
-0.25
);
scene.add(marker);
flights.push({
mesh: marker,
from: marker.position.clone(),
to: new THREE.Vector3(
selectedBar.worldX,
selectedBar.worldTop + 0.24,
-0.25
),
start: performance.now(),
duration: reducedMotion ? 220 : 1050
});
showToast(game, outcome);
}
document.querySelectorAll("[data-play]").forEach((button) => {
button.addEventListener("click", (event) => {
event.stopPropagation();
playGame(Number(button.dataset.play));
});
});
const lensCopy = {
distribution:
"A puts 5% of its probability on a $120 prize. B never pays more than $30. The complete distributions matter, not just the mean.",
spread:
"Both means are $9, but A's standard deviation is $25.98 while B's is $9.00. Equal expected values can hide very different experiences.",
preference:
"A lower-spread game can feel more predictable, while a rare jackpot can appeal to others. Expected value alone cannot choose for you."
};
document.querySelectorAll("[data-lens]").forEach((button) => {
button.addEventListener("click", () => {
document.querySelectorAll("[data-lens]").forEach((item) => {
item.classList.toggle("active", item === button);
});
document.querySelector("#insight-copy").textContent =
lensCopy[button.dataset.lens];
});
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let hoveredMesh = null;
let dragging = false;
let dragMoved = false;
let previousX = 0;
let previousY = 0;
function clearHover() {
if (hoveredMesh) {
hoveredMesh.material.emissive.set(0x000000);
hoveredMesh.material.emissiveIntensity = 0;
hoveredMesh = null;
}
tooltip.style.display = "none";
renderer.domElement.style.cursor = "grab";
}
function testHover(event) {
if (dragging) {
clearHover();
return;
}
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(outcomeMeshes, false);
const nextMesh = hits.length ? hits[0].object : null;
if (nextMesh !== hoveredMesh) {
clearHover();
hoveredMesh = nextMesh;
if (hoveredMesh) {
const outcome = hoveredMesh.userData.outcome;
const contribution = outcome.amount * outcome.probability;
hoveredMesh.material.emissive.set(outcome.color);
hoveredMesh.material.emissiveIntensity = 0.13;
renderer.domElement.style.cursor = "pointer";
tooltip.innerHTML = `
<b>${outcome.name}: $${outcome.amount}</b>
<span>
${Math.round(outcome.probability * 100)}% chance ·
$${contribution.toFixed(2)} expected-value contribution
</span>
`;
tooltip.style.display = "block";
}
}
if (hoveredMesh) {
const x = Math.min(
event.clientX + 16,
window.innerWidth - 225
);
const y = Math.min(
event.clientY + 16,
window.innerHeight - 75
);
tooltip.style.left = `${x}px`;
tooltip.style.top = `${y}px`;
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
clearHover();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) {
dragMoved = true;
}
yaw -= deltaX * 0.0055;
pitch += deltaY * 0.0038;
pitch = THREE.MathUtils.clamp(pitch, 0.17, 0.78);
previousX = event.clientX;
previousY = event.clientY;
} else {
testHover(event);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!dragMoved) {
testHover(event);
}
});
renderer.domElement.addEventListener("pointerleave", clearHover);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom *= Math.exp(event.deltaY * 0.001);
zoom = THREE.MathUtils.clamp(zoom, 0.72, 1.38);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
yaw = 0;
pitch = 0.37;
zoom = 1;
});
function updateCamera() {
const radius = baseRadius * zoom;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * radius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -150 &&
x < width + 150 &&
y > -100 &&
y < height + 100;
label.element.style.display = visible ? "block" : "none";
label.element.style.transform = `
translate3d(${x}px, ${y}px, 0)
translate(-50%, -50%)
`;
});
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
const requiredPortraitRadius =
20 / (2 * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)) * aspect);
baseRadius = aspect < 1
? Math.max(30, requiredPortraitRadius)
: aspect < 1.35
? 28
: 23;
}
window.addEventListener("resize", resize);
resize();
function animate(now) {
requestAnimationFrame(animate);
updateCamera();
for (let i = flights.length - 1; i >= 0; i--) {
const flight = flights[i];
const progress = THREE.MathUtils.clamp(
(now - flight.start) / flight.duration,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 3);
flight.mesh.position.lerpVectors(flight.from, flight.to, eased);
flight.mesh.rotation.x += 0.08;
flight.mesh.rotation.y += 0.11;
flight.mesh.scale.setScalar(1 + Math.sin(progress * Math.PI) * 0.45);
if (progress >= 1) {
scene.remove(flight.mesh);
flight.mesh.material.dispose();
flights.splice(i, 1);
}
}
renderer.render(scene, camera);
updateLabels();
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```