Prompt specification
Build or customize the Three.js 3D scene "Weighted payout outcome pedestal" 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: Weighted payout outcome pedestal
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/weighted-payout-outcome-pedestal-x1789
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring expected value across weighted outcomes. Build a set of possible toy-game payouts with probability-sized floor tiles; display their weighted average separately from any single possible payout. Low-poly.
Working Three.js Starter (weighted-payout-outcome-pedestal-x1789):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Probability Playground — Expected Value</title>
<style>
:root {
--ink: #20363d;
--muted: #6e7f80;
--paper: rgba(250, 251, 246, 0.94);
--line: rgba(32, 54, 61, 0.12);
--shadow: 0 20px 60px rgba(31, 57, 59, 0.15);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cfe7e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
.masthead {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
max-width: 410px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #4f696b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 3px;
background: #f2a266;
box-shadow: 0 0 0 4px rgba(242, 162, 102, 0.17);
content: "";
}
h1 {
margin: 0;
font-size: clamp(28px, 3.4vw, 50px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.98;
}
.masthead p {
max-width: 360px;
margin: 13px 0 0;
color: #526b6d;
font-size: 14px;
line-height: 1.55;
}
.legend {
display: inline-flex;
align-items: center;
gap: 10px;
margin-top: 17px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 999px;
background: rgba(255, 255, 255, 0.68);
box-shadow: 0 8px 28px rgba(49, 79, 77, 0.09);
backdrop-filter: blur(12px);
color: #536b6d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.area-swatch {
display: inline-block;
width: 15px;
height: 15px;
border: 2px solid #587476;
border-radius: 4px;
}
.panel {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
width: min(370px, calc(100vw - 48px));
max-height: calc(100vh - 48px);
overflow: auto;
padding: 22px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 25px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(20px);
scrollbar-width: thin;
scrollbar-color: #c7d5d0 transparent;
}
.panel-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
}
.panel .eyebrow {
margin: 0 0 8px;
font-size: 10px;
}
.separate-badge {
flex: none;
padding: 7px 9px;
border-radius: 999px;
background: #e8f2ed;
color: #477064;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.ev-value {
display: flex;
align-items: baseline;
gap: 8px;
margin-top: 3px;
}
#ev-value {
font-variant-numeric: tabular-nums;
font-size: clamp(48px, 6vw, 66px);
font-weight: 780;
letter-spacing: -0.065em;
line-height: 1;
}
.ev-unit {
color: var(--muted);
font-size: 13px;
font-weight: 700;
}
.ev-copy {
margin: 12px 0 0;
color: #627677;
font-size: 12px;
line-height: 1.55;
}
.formula {
margin-top: 15px;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(232, 239, 233, 0.6);
color: #4d6667;
font-size: 10px;
font-weight: 700;
line-height: 1.65;
}
.divider {
height: 1px;
margin: 20px 0 17px;
background: var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.section-heading h2 {
margin: 0;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-heading span {
color: var(--muted);
font-size: 10px;
}
.text-button {
border: 0;
padding: 4px 0;
background: transparent;
color: #4c7773;
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.text-button:hover { color: #1d504b; }
.outcome-row {
padding: 12px 0;
border-bottom: 1px solid var(--line);
}
.outcome-row:last-child { border-bottom: 0; }
.outcome-main,
.outcome-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.outcome-name {
display: flex;
align-items: center;
min-width: 0;
gap: 8px;
border: 0;
padding: 0;
background: transparent;
color: var(--ink);
cursor: pointer;
text-align: left;
}
.outcome-name:hover .outcome-title { text-decoration: underline; }
.dot {
width: 10px;
height: 10px;
flex: none;
border-radius: 3px;
background: var(--accent);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.outcome-title {
overflow: hidden;
font-size: 12px;
font-weight: 720;
text-overflow: ellipsis;
white-space: nowrap;
}
.outcome-name strong {
margin-left: 3px;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.outcome-name small {
color: var(--muted);
font-size: 9px;
}
.share {
flex: none;
min-width: 44px;
padding: 5px 8px;
border-radius: 999px;
background: #edf1ed;
color: #486263;
font-size: 10px;
font-weight: 850;
text-align: center;
font-variant-numeric: tabular-nums;
}
.outcome-meta {
margin: 7px 0 8px 18px;
color: #879594;
font-size: 9px;
}
.contribution {
color: #536b6c;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
outline: none;
background: #dce5df;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 7px rgba(31, 51, 52, 0.24);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 7px rgba(31, 51, 52, 0.24);
}
input[type="range"]:focus-visible {
box-shadow: 0 0 0 3px rgba(64, 119, 112, 0.18);
}
.panel-footnote {
margin: 15px 0 0;
color: #82918f;
font-size: 9px;
line-height: 1.5;
}
.inspector {
position: fixed;
z-index: 6;
bottom: 28px;
left: 28px;
width: 230px;
padding: 15px 16px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
background: rgba(250, 251, 246, 0.88);
box-shadow: 0 13px 38px rgba(40, 67, 67, 0.12);
backdrop-filter: blur(14px);
}
.inspector-label {
display: flex;
align-items: center;
gap: 7px;
color: #718381;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.inspector-label .dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.inspector-value {
margin-top: 8px;
font-size: 24px;
font-weight: 780;
letter-spacing: -0.035em;
}
.inspector-detail {
margin-top: 5px;
color: #677b7b;
font-size: 10px;
line-height: 1.55;
}
.camera-tools {
position: fixed;
z-index: 7;
right: 28px;
bottom: 28px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 16px;
background: rgba(250, 251, 246, 0.86);
box-shadow: 0 10px 30px rgba(40, 67, 67, 0.1);
backdrop-filter: blur(14px);
}
.camera-tools button {
width: 34px;
height: 34px;
border: 0;
border-radius: 10px;
background: transparent;
color: #3f5c5d;
cursor: pointer;
font-size: 18px;
font-weight: 650;
}
.camera-tools button:hover {
background: #e7eee8;
}
.scene-hint {
position: fixed;
z-index: 4;
bottom: 31px;
left: 50%;
transform: translateX(-50%);
color: rgba(45, 70, 71, 0.72);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
pointer-events: none;
white-space: nowrap;
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #d9ebe6;
color: #4c6867;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.masthead {
top: 17px;
left: 18px;
max-width: calc(100vw - 36px);
}
.masthead p {
max-width: 290px;
font-size: 12px;
}
.legend { margin-top: 11px; }
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 45vh;
padding: 18px;
border-radius: 21px;
}
.inspector,
.scene-hint {
display: none;
}
.camera-tools {
top: 18px;
right: 16px;
bottom: auto;
}
}
@media (max-width: 480px) {
.masthead p { display: none; }
.legend { font-size: 8px; }
.panel { max-height: 48vh; }
#ev-value { font-size: 48px; }
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly probability board"></div>
<header class="masthead">
<div class="eyebrow">Probability playground</div>
<h1>Chance you can<br />see.</h1>
<p>
Every floor tile is one possible payout. Its area grows with its probability;
the expected value is calculated separately.
</p>
<div class="legend">
<span class="area-swatch"></span>
Tile area = probability
</div>
</header>
<aside class="panel" aria-label="Expected value and outcome weights">
<div class="panel-top">
<div>
<div class="eyebrow">Expected value · weighted average</div>
<div class="ev-value">
<span id="ev-value">2.80</span>
<span class="ev-unit">tokens / play</span>
</div>
</div>
<div class="separate-badge">Separate metric</div>
</div>
<p class="ev-copy">
The long-run average across every outcome. It is not a guaranteed result
and lives outside the individual payout tiles.
</p>
<div class="formula" id="formula"></div>
<div class="divider"></div>
<div class="section-heading">
<h2>Relative odds</h2>
<button class="text-button" id="reset-weights" type="button">Reset</button>
</div>
<div id="outcomes"></div>
<p class="panel-footnote">
Move a slider to change the odds. Shares are normalized to 100%, and each
tile resizes so its area remains proportional to its probability.
</p>
</aside>
<div class="inspector" id="inspector" aria-live="polite">
<div class="inspector-label">
<span class="dot" id="inspector-dot"></span>
Selected outcome
</div>
<div class="inspector-value" id="inspector-value">20 tokens</div>
<div class="inspector-detail" id="inspector-detail"></div>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button id="zoom-out" type="button" title="Zoom out" aria-label="Zoom out">−</button>
<button id="reset-view" type="button" title="Reset camera" aria-label="Reset camera">↺</button>
<button id="zoom-in" type="button" title="Zoom in" aria-label="Zoom in">+</button>
</div>
<div class="scene-hint">Drag to orbit · Scroll to zoom · Click a tile to inspect</div>
<div class="loading" id="loading">Building the probability board…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const outcomes = [
{
name: "No tokens",
payout: 0,
weight: 45,
color: "#9eadaa",
position: [-4.0, 1.45]
},
{
name: "Small win",
payout: 2,
weight: 25,
color: "#f08d69",
position: [0.0, 1.45]
},
{
name: "Good win",
payout: 6,
weight: 15,
color: "#efc857",
position: [4.0, 1.45]
},
{
name: "Great win",
payout: 10,
weight: 10,
color: "#48b6aa",
position: [-2.15, -2.35]
},
{
name: "Jackpot",
payout: 20,
weight: 5,
color: "#8d7bbb",
position: [2.15, -2.35]
}
];
const defaultWeights = outcomes.map((outcome) => outcome.weight);
const probabilities = outcomes.map(() => 0);
let selectedIndex = 4;
let hoveredIndex = -1;
let evTarget = 0;
let evDisplay = 0;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#cfe7e3");
scene.fog = new THREE.Fog("#cfe7e3", 27, 58);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "3D probability board");
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#f5fff5", "#78948d", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff2d3", 3.1);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d9ff", 0.75);
fill.position.set(10, 6, -10);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: "#b9d5c6",
roughness: 1,
flatShading: true
});
const ground = new THREE.Mesh(
new THREE.CircleGeometry(38, 48),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.64;
ground.receiveShadow = true;
scene.add(ground);
function makeBox(width, height, depth, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
flatShading: true
})
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
makeBox(13.9, 0.48, 9.9, "#526d68", 0, -0.28, 0);
makeBox(13.55, 0.16, 9.55, "#f1ead7", 0, 0, 0);
const gridPoints = [];
for (let x = -6.4; x <= 6.4; x += 0.8) {
gridPoints.push(x, 0.083, -4.4, x, 0.083, 4.4);
}
for (let z = -4.4; z <= 4.4; z += 0.8) {
gridPoints.push(-6.4, 0.083, z, 6.4, 0.083, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPoints, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: "#5f716c",
transparent: true,
opacity: 0.11
})
);
scene.add(grid);
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 createCanvasTexture(width, height) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return { canvas, context, texture };
}
function drawTileLabel(outcome, probability) {
const { canvas, context, texture } = outcome.label;
const width = canvas.width;
const height = canvas.height;
context.clearRect(0, 0, width, height);
context.fillStyle = "rgba(255,255,255,0.91)";
context.strokeStyle = "rgba(29,47,51,0.16)";
context.lineWidth = 5;
roundedRect(context, 8, 8, width - 16, height - 16, 32);
context.fill();
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#5a6e6f";
context.font = "800 27px system-ui, sans-serif";
context.fillText("PAYOUT", width / 2, 54);
context.fillStyle = "#20363d";
context.font = "800 88px system-ui, sans-serif";
context.fillText(String(outcome.payout), width / 2, 128);
context.fillStyle = "#6b7d7d";
context.font = "800 25px system-ui, sans-serif";
const percentage = formatPercent(probability);
context.fillText(`${percentage} CHANCE`, width / 2, 198);
texture.needsUpdate = true;
}
function formatPercent(value) {
const percent = value * 100;
return `${Number.isInteger(percent) ? percent.toFixed(0) : percent.toFixed(1)}%`;
}
function createTile(outcome, index) {
const group = new THREE.Group();
group.position.set(outcome.position[0], 0.08, outcome.position[1]);
scene.add(group);
const baseMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(outcome.color).multiplyScalar(0.7),
roughness: 0.95,
flatShading: true
});
const bodyMaterial = new THREE.MeshStandardMaterial({
color: outcome.color,
roughness: 0.72,
flatShading: true
});
const capMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(outcome.color).lerp(new THREE.Color("#ffffff"), 0.3),
roughness: 0.78,
flatShading: true
});
const base = new THREE.Mesh(new THREE.BoxGeometry(1, 0.08, 1), baseMaterial);
base.position.y = 0.04;
base.castShadow = true;
base.receiveShadow = true;
base.userData.outcomeIndex = index;
group.add(base);
const body = new THREE.Mesh(new THREE.BoxGeometry(1, 0.2, 1), bodyMaterial);
body.position.y = 0.16;
body.castShadow = true;
body.receiveShadow = true;
body.userData.outcomeIndex = index;
group.add(body);
const cap = new THREE.Mesh(new THREE.BoxGeometry(1, 0.04, 1), capMaterial);
cap.position.y = 0.285;
cap.castShadow = true;
cap.receiveShadow = true;
cap.userData.outcomeIndex = index;
group.add(cap);
const edgeMaterial = new THREE.LineBasicMaterial({
color: "#243c40",
transparent: true,
opacity: 0.28
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
edgeMaterial
);
edges.position.copy(body.position);
group.add(edges);
const halo = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.035, 1),
new THREE.MeshStandardMaterial({
color: "#fff3a6",
emissive: "#6b5b19",
emissiveIntensity: 0.16,
roughness: 0.8
})
);
halo.position.y = 0.015;
halo.visible = false;
group.add(halo);
outcome.label = createCanvasTexture(512, 256);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(1, 0.5),
new THREE.MeshBasicMaterial({
map: outcome.label.texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
label.rotation.x = -Math.PI / 2;
label.position.y = 0.31;
group.add(label);
return {
group,
base,
body,
cap,
edges,
halo,
label
};
}
const tiles = outcomes.map(createTile);
const hitMeshes = tiles.flatMap((tile) => [tile.body, tile.cap]);
function setTileSize(tile, side) {
const baseGeometry = new THREE.BoxGeometry(side + 0.04, 0.08, side + 0.04);
const bodyGeometry = new THREE.BoxGeometry(side, 0.2, side);
const capGeometry = new THREE.BoxGeometry(side * 0.985, 0.04, side * 0.985);
const haloGeometry = new THREE.BoxGeometry(side + 0.2, 0.035, side + 0.2);
const labelGeometry = new THREE.PlaneGeometry(side * 0.84, side * 0.42);
tile.base.geometry.dispose();
tile.body.geometry.dispose();
tile.cap.geometry.dispose();
tile.edges.geometry.dispose();
tile.halo.geometry.dispose();
tile.label.geometry.dispose();
tile.base.geometry = baseGeometry;
tile.body.geometry = bodyGeometry;
tile.cap.geometry = capGeometry;
tile.halo.geometry = haloGeometry;
tile.label.geometry = labelGeometry;
tile.edges.geometry = new THREE.EdgesGeometry(bodyGeometry);
}
// Low-poly toy-game decorations.
function createTree(x, z, scale, color) {
const tree = new THREE.Group();
tree.position.set(x, -0.63, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.25, 1.1, 5),
new THREE.MeshStandardMaterial({
color: "#87664c",
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.55;
trunk.castShadow = true;
tree.add(trunk);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.95, 2.0, 6),
new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
})
);
lower.position.y = 1.85;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.72, 1.6, 6),
new THREE.MeshStandardMaterial({
color: new THREE.Color(color).lerp(new THREE.Color("#ffffff"), 0.12),
roughness: 1,
flatShading: true
})
);
upper.position.y = 2.65;
upper.castShadow = true;
tree.add(upper);
scene.add(tree);
}
createTree(-9.0, 2.7, 1.15, "#5f9c72");
createTree(-8.2, -5.4, 0.85, "#78a97d");
createTree(8.7, 3.8, 1.25, "#639b76");
createTree(9.2, -4.8, 0.95, "#78a97d");
function createRock(x, z, scale, color) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
})
);
rock.position.set(x, -0.35, z);
rock.rotation.set(0.4, 0.8, 0.15);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
createRock(-7.3, -2.4, 0.75, "#9eaaa2");
createRock(7.1, -1.5, 0.9, "#aab3a8");
createRock(6.8, 5.6, 0.65, "#a2aea4");
const die = makeBox(0.9, 0.9, 0.9, "#fff8e9", -5.65, 0.55, -3.75);
const dieEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(die.geometry),
new THREE.LineBasicMaterial({ color: "#9fb6ad", transparent: true, opacity: 0.6 })
);
die.add(dieEdges);
die.rotation.y = 0.22;
const pipMaterial = new THREE.MeshBasicMaterial({ color: "#426263" });
const pipGeometry = new THREE.CircleGeometry(0.065, 8);
const pipPositions = [
[-0.23, -0.23], [0.23, -0.23], [0, 0],
[-0.23, 0.23], [0.23, 0.23]
];
pipPositions.forEach(([x, z]) => {
const pip = new THREE.Mesh(pipGeometry, pipMaterial);
pip.rotation.x = -Math.PI / 2;
pip.position.set(x, 0.456, z);
die.add(pip);
});
const coinMaterial = new THREE.MeshStandardMaterial({
color: "#e9b84c",
roughness: 0.58,
metalness: 0.18,
flatShading: true
});
for (let i = 0; i < 5; i++) {
const coin = new THREE.Mesh(
new THREE.CylinderGeometry(0.36, 0.36, 0.12, 12),
coinMaterial
);
coin.position.set(5.55 + (i % 2) * 0.05, 0.2 + i * 0.125, -3.75);
coin.rotation.y = i * 0.24;
coin.castShadow = true;
scene.add(coin);
}
function createBoardText() {
const { canvas, context, texture } = createCanvasTexture(1024, 128);
context.clearRect(0, 0, 1024, 128);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#607573";
context.font = "800 42px system-ui, sans-serif";
context.fillText("EACH TILE'S AREA = ITS CHANCE", 512, 64);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(5.8, 0.72),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(0, 0.087, 4.12);
scene.add(mesh);
}
createBoardText();
function createCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
const material = new THREE.MeshStandardMaterial({
color: "#f8fff9",
roughness: 1,
flatShading: true
});
[
[-0.7, 0, 0, 0.62],
[0, 0.18, 0, 0.8],
[0.8, -0.03, 0, 0.56],
[0.28, -0.3, 0.05, 0.62]
].forEach(([px, py, pz, size]) => {
const puff = new THREE.Mesh(
new THREE.DodecahedronGeometry(size, 0),
material
);
puff.position.set(px, py, pz);
cloud.add(puff);
});
scene.add(cloud);
return cloud;
}
const clouds = [
createCloud(-8, 7.4, -13, 1.0),
createCloud(8, 8.7, -15, 1.25),
createCloud(0, 10.5, -21, 1.45)
];
const orbit = {
radius: 19.5,
theta: 0.72,
phi: 0.86,
target: new THREE.Vector3(1.0, 0.25, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetView() {
const mobile = window.innerWidth < 760;
orbit.radius = mobile ? 27.5 : 19.5;
orbit.theta = 0.72;
orbit.phi = mobile ? 0.91 : 0.86;
orbit.target.set(mobile ? 0 : 1.0, 0.25, 0);
updateCamera();
}
const outcomeRows = document.getElementById("outcomes");
const formulaElement = document.getElementById("formula");
const evElement = document.getElementById("ev-value");
const inspectorValue = document.getElementById("inspector-value");
const inspectorDetail = document.getElementById("inspector-detail");
const inspectorDot = document.getElementById("inspector-dot");
outcomes.forEach((outcome, index) => {
const row = document.createElement("div");
row.className = "outcome-row";
row.style.setProperty("--accent", outcome.color);
row.innerHTML = `
<div class="outcome-main">
<button class="outcome-name" type="button" aria-label="Select ${outcome.name}">
<span class="dot"></span>
<span class="outcome-title">${outcome.name}</span>
<strong>${outcome.payout}</strong>
<small>tokens</small>
</button>
<span class="share">0%</span>
</div>
<div class="outcome-meta">
<span>weighted contribution</span>
<span class="contribution">0.00</span>
</div>
<input
type="range"
min="1"
max="100"
step="1"
value="${outcome.weight}"
aria-label="Relative odds for ${outcome.name}"
/>
`;
const slider = row.querySelector('input[type="range"]');
slider.style.setProperty("--accent", outcome.color);
slider.addEventListener("input", (event) => {
outcome.weight = Number(event.target.value);
updateState();
setSelected(index);
});
row.querySelector("button").addEventListener("click", () => {
setSelected(index);
});
outcome.row = row;
outcome.slider = slider;
outcomeRows.appendChild(row);
});
function updateInspector() {
const outcome = outcomes[selectedIndex];
const probability = probabilities[selectedIndex];
const contribution = probability * outcome.payout;
inspectorValue.textContent = `${outcome.payout} ${outcome.payout === 1 ? "token" : "tokens"}`;
inspectorDetail.textContent =
`${formatPercent(probability)} chance · contributes ${contribution.toFixed(2)} tokens to the average`;
inspectorDot.style.background = outcome.color;
}
function setSelected(index) {
selectedIndex = index;
tiles.forEach((tile, tileIndex) => {
tile.halo.visible = tileIndex === selectedIndex;
});
updateInspector();
}
function updateState() {
const totalWeight = outcomes.reduce(
(sum, outcome) => sum + outcome.weight,
0
);
let expectedValue = 0;
const formulaParts = [];
outcomes.forEach((outcome, index) => {
const probability = outcome.weight / totalWeight;
const contribution = probability * outcome.payout;
const side = 3.8 * Math.sqrt(probability);
probabilities[index] = probability;
expectedValue += contribution;
setTileSize(tiles[index], side);
drawTileLabel(outcome, probability);
const row = outcome.row;
const share = row.querySelector(".share");
const contributionElement = row.querySelector(".contribution");
share.textContent = formatPercent(probability);
contributionElement.textContent = contribution.toFixed(2);
outcome.slider.value = outcome.weight;
const sliderPercent = ((outcome.weight - 1) / 99) * 100;
outcome.slider.style.background =
`linear-gradient(to right, ${outcome.color} 0%, ${outcome.color} ${sliderPercent}%, #dce5df ${sliderPercent}%, #dce5df 100%)`;
formulaParts.push(`${formatPercent(probability)} × ${outcome.payout}`);
});
evTarget = expectedValue;
formulaElement.textContent = formulaParts.join(" + ");
updateInspector();
}
document.getElementById("reset-weights").addEventListener("click", () => {
outcomes.forEach((outcome, index) => {
outcome.weight = defaultWeights[index];
});
updateState();
});
// Camera controls are implemented directly without external controls modules.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let dragDistance = 0;
function updatePointer(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;
}
function pickTile(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(hitMeshes, false);
return hits.length ? hits[0].object.userData.outcomeIndex : -1;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
dragDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging && event.pointerId === pointerId) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
dragDistance += Math.abs(dx) + Math.abs(dy);
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.36, 1.34);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
} else {
hoveredIndex = pickTile(event);
renderer.domElement.style.cursor = hoveredIndex >= 0 ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (event.pointerId !== pointerId) return;
if (dragDistance < 7) {
const index = pickTile(event);
if (index >= 0) setSelected(index);
}
dragging = false;
pointerId = null;
renderer.domElement.style.cursor = hoveredIndex >= 0 ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerId = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
11,
34
);
updateCamera();
},
{ passive: false }
);
document.getElementById("zoom-in").addEventListener("click", () => {
orbit.radius = Math.max(11, orbit.radius - 1.5);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
orbit.radius = Math.min(34, orbit.radius + 1.5);
updateCamera();
});
document.getElementById("reset-view").addEventListener("click", resetView);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 760 ? 48 : 40;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
resetView();
updateState();
evDisplay = evTarget;
setSelected(selectedIndex);
let lastTime = performance.now();
function animate(time) {
requestAnimationFrame(animate);
const delta = Math.min((time - lastTime) / 1000, 0.05);
lastTime = time;
evDisplay += (evTarget - evDisplay) * Math.min(1, delta * 9);
evElement.textContent = evDisplay.toFixed(2);
tiles.forEach((tile, index) => {
const selectedLift = index === selectedIndex ? 0.13 : 0;
const hoverLift = index === hoveredIndex ? 0.065 : 0;
const targetY = 0.08 + selectedLift + hoverLift;
tile.group.position.y += (targetY - tile.group.position.y) * 0.13;
});
clouds.forEach((cloud, index) => {
cloud.position.x += Math.sin(time * 0.00007 + index * 2) * 0.0014;
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
</script>
</body>
</html>
```