Prompt specification
Build or customize the Three.js 3D scene "Independence counterexample explorer" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Independence counterexample explorer
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/independence-counterexample-explorer-x1804
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: independence counterexample explorer. Let users compare joint probabilities with products of marginals in small predefined tables; identify dependence mathematically rather than relying on outcomes looking unrelated. Return one self-contained HTML file.
Working Three.js Starter (independence-counterexample-explorer-x1804):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#07111f" />
<title>Independence Counterexample Explorer</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(8, 19, 34, 0.91);
--panel-soft: rgba(16, 33, 54, 0.76);
--border: rgba(149, 190, 224, 0.18);
--text: #edf6ff;
--muted: #9aafc6;
--joint: #ff7165;
--product: #3bd8c8;
--gold: #f5cc66;
--mint: #76edb5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
canvas {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:focus-visible {
outline: 2px solid var(--gold);
outline-offset: -4px;
}
.panel {
position: fixed;
z-index: 10;
top: 16px;
bottom: 16px;
left: 16px;
width: min(390px, calc(100vw - 32px));
overflow-y: auto;
overscroll-behavior: contain;
padding: 20px;
border: 1px solid var(--border);
border-radius: 20px;
background:
linear-gradient(145deg, rgba(21, 42, 65, 0.38), transparent 45%),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(18px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: rgba(125, 166, 201, 0.35) transparent;
}
.panel::-webkit-scrollbar {
width: 7px;
}
.panel::-webkit-scrollbar-thumb {
border-radius: 20px;
background: rgba(125, 166, 201, 0.3);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--gold);
box-shadow: 8px 0 18px rgba(245, 204, 102, 0.45);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 38px);
font-weight: 780;
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 19px 0 9px;
color: #c7d7e8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-label span:last-child {
color: #718ba5;
font-weight: 650;
letter-spacing: 0.05em;
}
.preset-list {
display: grid;
gap: 8px;
}
.preset {
position: relative;
display: grid;
grid-template-columns: 35px 1fr;
gap: 10px;
width: 100%;
padding: 10px 11px;
overflow: hidden;
text-align: left;
border: 1px solid rgba(143, 184, 219, 0.13);
border-radius: 12px;
background: rgba(18, 35, 56, 0.55);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.preset:hover {
border-color: rgba(143, 184, 219, 0.32);
background: rgba(24, 46, 70, 0.68);
transform: translateY(-1px);
}
.preset.active {
border-color: rgba(245, 204, 102, 0.58);
background:
linear-gradient(100deg, rgba(245, 204, 102, 0.11), transparent 62%),
rgba(22, 42, 64, 0.8);
}
.preset.active::after {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
content: "";
background: var(--gold);
}
.preset-mark {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border: 1px solid rgba(143, 184, 219, 0.17);
border-radius: 9px;
color: var(--muted);
background: rgba(5, 14, 27, 0.42);
font-size: 15px;
font-weight: 900;
}
.preset.active .preset-mark {
border-color: rgba(245, 204, 102, 0.36);
color: var(--gold);
}
.preset-name {
display: block;
margin-bottom: 2px;
font-size: 12px;
font-weight: 760;
}
.preset-description {
display: block;
color: var(--muted);
font-size: 10.5px;
line-height: 1.35;
}
.story {
margin: 10px 0 0;
color: #a9bdd2;
font-size: 11.5px;
line-height: 1.5;
}
.status-card {
position: relative;
margin-top: 13px;
padding: 14px;
overflow: hidden;
border: 1px solid rgba(255, 113, 101, 0.28);
border-radius: 14px;
background:
linear-gradient(110deg, rgba(255, 113, 101, 0.12), transparent 70%),
rgba(16, 31, 49, 0.74);
}
.status-card.independent {
border-color: rgba(118, 237, 181, 0.3);
background:
linear-gradient(110deg, rgba(118, 237, 181, 0.11), transparent 70%),
rgba(16, 31, 49, 0.74);
}
.status-top {
display: flex;
align-items: center;
gap: 11px;
}
.status-icon {
display: grid;
flex: 0 0 auto;
width: 38px;
height: 38px;
place-items: center;
border: 1px solid rgba(255, 113, 101, 0.42);
border-radius: 11px;
color: var(--joint);
background: rgba(255, 113, 101, 0.08);
font-size: 22px;
font-weight: 850;
}
.independent .status-icon {
border-color: rgba(118, 237, 181, 0.42);
color: var(--mint);
background: rgba(118, 237, 181, 0.08);
}
.status-title {
margin-bottom: 2px;
font-size: 17px;
font-weight: 800;
}
.status-max {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10.5px;
}
.status-summary {
margin: 10px 0 9px;
color: #b6c7d9;
font-size: 11px;
line-height: 1.45;
}
.meter {
height: 4px;
overflow: hidden;
border-radius: 8px;
background: rgba(255, 255, 255, 0.08);
}
.meter > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--joint);
box-shadow: 0 0 14px rgba(255, 113, 101, 0.45);
transition: width 450ms ease;
}
.independent .meter > span {
background: var(--mint);
box-shadow: 0 0 14px rgba(118, 237, 181, 0.4);
}
.definition {
margin-top: 10px;
padding: 11px 12px;
border: 1px solid rgba(143, 184, 219, 0.13);
border-radius: 11px;
background: rgba(6, 16, 29, 0.48);
color: var(--muted);
font-size: 10.5px;
line-height: 1.5;
}
.definition code {
display: block;
margin-bottom: 5px;
color: #dce9f7;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
}
.matrix-pair {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.matrix-card {
min-width: 0;
padding: 10px;
border: 1px solid rgba(143, 184, 219, 0.13);
border-radius: 13px;
background: rgba(5, 15, 28, 0.48);
}
.matrix-heading {
display: flex;
align-items: center;
gap: 7px;
min-height: 30px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.matrix-heading small {
display: block;
margin-top: 2px;
color: #718aa3;
font-size: 8.5px;
font-weight: 650;
letter-spacing: 0;
}
.swatch {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--joint);
box-shadow: 0 0 10px rgba(255, 113, 101, 0.35);
}
.swatch.product {
background: var(--product);
box-shadow: 0 0 10px rgba(59, 216, 200, 0.35);
}
.matrix-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
}
.matrix-cell {
min-width: 0;
padding: 9px 4px 7px;
border: 1px solid rgba(143, 184, 219, 0.11);
border-radius: 8px;
background: rgba(20, 38, 60, 0.58);
cursor: pointer;
transition:
border-color 140ms ease,
background 140ms ease,
transform 140ms ease;
}
.matrix-cell:hover {
border-color: rgba(245, 204, 102, 0.45);
transform: translateY(-1px);
}
.matrix-cell.selected {
border-color: var(--gold);
background: rgba(245, 204, 102, 0.1);
box-shadow: inset 0 0 0 1px rgba(245, 204, 102, 0.12);
}
.cell-value {
display: block;
color: #f4f8fd;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 750;
}
.cell-delta {
display: block;
min-height: 12px;
margin-top: 2px;
color: var(--joint);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8.5px;
}
.cell-delta.zero {
color: var(--mint);
}
.margins {
display: grid;
gap: 7px;
margin-top: 10px;
}
.margin-row {
display: flex;
flex-wrap: wrap;
gap: 5px;
}
.margin-chip {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 5px 7px;
border: 1px solid rgba(143, 184, 219, 0.12);
border-radius: 7px;
color: #a9bdd2;
background: rgba(11, 26, 44, 0.55);
font-size: 8.5px;
}
.margin-chip b {
color: #e6eff8;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9.5px;
}
.selected-card {
margin-top: 11px;
padding: 13px;
border: 1px solid rgba(245, 204, 102, 0.2);
border-radius: 13px;
background: rgba(245, 204, 102, 0.045);
}
.selected-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.selected-title {
font-size: 12px;
font-weight: 800;
}
.selected-position {
color: #728aa2;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
}
.equation {
display: grid;
grid-template-columns: 82px 1fr;
gap: 6px 8px;
align-items: baseline;
color: #c7d6e5;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.45;
}
.equation .label {
color: #718aa2;
font-family: inherit;
font-size: 8.5px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.difference {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid rgba(143, 184, 219, 0.12);
color: var(--joint);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
}
.difference.zero {
color: var(--mint);
}
.proof {
margin: 8px 0 0;
color: #9eb3c9;
font-size: 10.5px;
line-height: 1.5;
}
.counterexample-button {
width: 100%;
margin-top: 9px;
padding: 9px 11px;
border: 1px solid rgba(245, 204, 102, 0.3);
border-radius: 9px;
color: var(--gold);
background: rgba(245, 204, 102, 0.07);
cursor: pointer;
font-size: 10px;
font-weight: 800;
transition: background 150ms ease;
}
.counterexample-button:hover:not(:disabled) {
background: rgba(245, 204, 102, 0.14);
}
.counterexample-button:disabled {
color: #6f849a;
border-color: rgba(143, 184, 219, 0.12);
background: rgba(143, 184, 219, 0.04);
cursor: default;
}
.footnote {
margin: 15px 0 2px;
color: #718aa2;
font-size: 9.5px;
line-height: 1.5;
}
.hud {
position: fixed;
z-index: 8;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 8px;
}
.hud-button {
padding: 9px 12px;
border: 1px solid rgba(143, 184, 219, 0.2);
border-radius: 10px;
color: #c8d8e8;
background: rgba(8, 19, 34, 0.72);
backdrop-filter: blur(10px);
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.hud-button:hover {
border-color: rgba(245, 204, 102, 0.5);
color: var(--gold);
}
.scene-label {
position: fixed;
z-index: 7;
right: 20px;
bottom: 19px;
display: flex;
align-items: center;
gap: 14px;
padding: 10px 13px;
border: 1px solid rgba(143, 184, 219, 0.15);
border-radius: 11px;
color: #9fb4c9;
background: rgba(8, 19, 34, 0.68);
backdrop-filter: blur(10px);
font-size: 9.5px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-item i {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--joint);
}
.legend-item i.product {
background: var(--product);
}
.legend-item i.selected {
background: var(--gold);
}
.controls-hint {
position: fixed;
z-index: 7;
bottom: 20px;
left: 424px;
color: rgba(172, 193, 212, 0.65);
font-size: 9.5px;
pointer-events: none;
}
#boot {
position: fixed;
z-index: 20;
top: 50%;
left: calc(50% + 190px);
padding: 12px 16px;
transform: translate(-50%, -50%);
border: 1px solid rgba(143, 184, 219, 0.18);
border-radius: 10px;
color: #a9bfd4;
background: rgba(8, 19, 34, 0.88);
font-size: 11px;
transition: opacity 300ms ease;
}
#boot.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 49vh;
padding: 15px;
border-radius: 16px;
}
h1 {
font-size: 25px;
}
.intro {
margin-bottom: 13px;
}
.preset-list {
grid-template-columns: 1fr 1fr;
}
.preset {
grid-template-columns: 29px 1fr;
padding: 8px;
}
.preset-mark {
width: 28px;
height: 28px;
}
.preset-description {
display: none;
}
.matrix-pair {
grid-template-columns: 1fr 1fr;
}
.hud {
top: auto;
right: 10px;
bottom: 10px;
}
.scene-label {
right: 10px;
bottom: 51px;
padding: 8px 10px;
}
.controls-hint {
display: none;
}
#boot {
top: 74%;
left: 50%;
}
}
@media (max-width: 480px) {
.panel {
max-height: 47vh;
}
.preset-list {
gap: 6px;
}
.preset-name {
font-size: 10.5px;
}
.scene-label .legend-item:last-child {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional comparison of joint probabilities and products of marginal probabilities. Drag to orbit, scroll to zoom, and click a bar to inspect its cell."
></canvas>
<aside class="panel" aria-label="Independence explorer controls">
<div class="eyebrow">Probability Lab · Exact 2 × 2 Tables</div>
<h1>Independence<br />Counterexample Explorer</h1>
<p class="intro">
Independence is an exact factorization identity—not a judgment that outcomes
“look unrelated.” Compare each joint cell with the corresponding product
of its marginals.
</p>
<div class="section-label">
<span>Choose a table</span>
<span>Predefined probabilities</span>
</div>
<div id="presetList" class="preset-list"></div>
<p id="story" class="story"></p>
<div id="statusCard" class="status-card" aria-live="polite">
<div class="status-top">
<div id="statusIcon" class="status-icon">≠</div>
<div>
<div id="statusTitle" class="status-title">Dependent</div>
<div id="statusMax" class="status-max">Δmax = 0</div>
</div>
</div>
<p id="statusSummary" class="status-summary"></p>
<div class="meter"><span id="statusMeter"></span></div>
</div>
<div class="definition">
<code>∀ i,j: Pᵢⱼ = rᵢcⱼ</code>
Here <b>rᵢ = P(X=xᵢ)</b> and <b>cⱼ = P(Y=yⱼ)</b>. The variables are
independent if and only if this equality holds in every cell.
</div>
<div class="section-label">
<span>Compare cell by cell</span>
<span>Click any cell or bar</span>
</div>
<div class="matrix-pair">
<div class="matrix-card">
<div class="matrix-heading">
<i class="swatch"></i>
<span>Joint table<small>P(X=xᵢ, Y=yⱼ)</small></span>
</div>
<div id="jointMatrix" class="matrix-grid"></div>
</div>
<div class="matrix-card">
<div class="matrix-heading">
<i class="swatch product"></i>
<span>Marginal product<small>P(X=xᵢ)P(Y=yⱼ)</small></span>
</div>
<div id="productMatrix" class="matrix-grid"></div>
</div>
</div>
<div class="section-label">
<span>Computed marginals</span>
<span>Rows = X · Columns = Y</span>
</div>
<div class="margins">
<div class="margin-row" id="rowMarginals"></div>
<div class="margin-row" id="colMarginals"></div>
</div>
<div class="selected-card">
<div class="selected-heading">
<div id="selectedTitle" class="selected-title">Selected cell</div>
<div id="selectedPosition" class="selected-position"></div>
</div>
<div class="equation">
<span class="label">Joint</span>
<span id="jointEquation"></span>
<span class="label">Product</span>
<span id="productEquation"></span>
</div>
<div id="differenceValue" class="difference"></div>
<p id="selectedProof" class="proof"></p>
<button id="counterexampleButton" class="counterexample-button" type="button">
Go to the strongest counterexample
</button>
</div>
<p class="footnote">
The status uses
<b>Δmax = max |Pᵢⱼ − rᵢcⱼ|</b>.
A nonzero difference in even one exact cell disproves independence;
looking similar does not establish it.
</p>
</aside>
<div class="hud">
<button id="resetCamera" class="hud-button" type="button">Reset view</button>
</div>
<div class="controls-hint">Drag to orbit · Scroll or pinch to zoom · Click a bar to inspect</div>
<div class="scene-label" aria-label="Scene legend">
<span class="legend-item"><i></i>Joint probability</span>
<span class="legend-item"><i class="product"></i>Marginal product</span>
<span class="legend-item"><i class="selected"></i>Selected cell</span>
</div>
<div id="boot">Building the exact probability scene…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const EPSILON = 1e-9;
const HEIGHT_SCALE = 5.15;
const BASE_Y = 0.085;
const PRESETS = [
{
id: "fair-choices",
mark: "=⁄₂",
name: "Two fair choices",
description: "An exact independent baseline",
story:
"Both marginals are 1/2, so every marginal product is 1/4. The complete joint table equals the complete product table.",
xName: "First choice",
yName: "Second choice",
rowLabels: ["Choice A", "Choice B"],
colLabels: ["Signal 0", "Signal 1"],
joint: [
[0.25, 0.25],
[0.25, 0.25],
],
},
{
id: "near-match",
mark: "≈",
name: "Near-match",
description: "Small but exact dependence",
story:
"Every joint value is within 0.025 of its marginal product, yet none is exactly equal. Similar-looking probabilities are still dependent.",
xName: "Process A",
yName: "Process B",
rowLabels: ["A₀", "A₁"],
colLabels: ["B₀", "B₁"],
joint: [
[0.24, 0.26],
[0.29, 0.21],
],
},
{
id: "rain",
mark: "≠",
name: "Rain and umbrellas",
description: "Dependence across all four cells",
story:
"Weather changes the row marginal, umbrella use changes the column marginal, and every cell violates the product identity.",
xName: "Weather",
yName: "Umbrella",
rowLabels: ["Dry", "Rain"],
colLabels: ["No umbrella", "Umbrella"],
joint: [
[0.52, 0.08],
[0.12, 0.28],
],
},
{
id: "linked-switch",
mark: "⇄",
name: "Perfectly linked switch",
description: "A deterministic counterexample",
story:
"The linked copy always has the opposite state. Although both marginals are balanced, the product table assigns 0.25 to every cell.",
xName: "Switch",
yName: "Linked copy",
rowLabels: ["Off", "On"],
colLabels: ["Off", "On"],
joint: [
[0.5, 0.0],
[0.0, 0.5],
],
},
];
const state = {
preset: null,
model: null,
selected: 0,
};
let jointBars = [];
let productBars = [];
let jointHelper = null;
let productHelper = null;
const byId = (id) => document.getElementById(id);
const jointMatrixElement = byId("jointMatrix");
const productMatrixElement = byId("productMatrix");
function formatNumber(value) {
const clean = Math.abs(value) < EPSILON ? 0 : value;
return clean
.toFixed(3)
.replace(/(\.\d*?)0+$/, "$1")
.replace(/\.$/, "");
}
function formatSigned(value) {
if (Math.abs(value) < EPSILON) return "0";
return `${value > 0 ? "+" : ""}${formatNumber(value)}`;
}
function computeModel(preset) {
const rowMarginals = preset.joint.map((row) => row[0] + row[1]);
const colMarginals = [0, 1].map(
(column) => preset.joint[0][column] + preset.joint[1][column],
);
const products = preset.joint.map((_, row) =>
colMarginals.map((columnMarginal) => rowMarginals[row] * columnMarginal),
);
const differences = preset.joint.map((row, rowIndex) =>
row.map((value, columnIndex) => value - products[rowIndex][columnIndex]),
);
const flatDifferences = differences.flat();
const maxDifference = Math.max(
...flatDifferences.map((difference) => Math.abs(difference)),
);
const counterexamples = flatDifferences
.map((difference, index) => ({ difference, index }))
.filter(({ difference }) => Math.abs(difference) > EPSILON);
const matchingCount = 4 - counterexamples.length;
return {
joint: preset.joint,
products,
differences,
rowMarginals,
colMarginals,
maxDifference,
counterexamples,
matchingCount,
independent: counterexamples.length === 0,
};
}
function buildPresetButtons() {
const list = byId("presetList");
for (const preset of PRESETS) {
const button = document.createElement("button");
button.type = "button";
button.className = "preset";
button.dataset.preset = preset.id;
button.setAttribute("aria-pressed", "false");
button.innerHTML = `
<span class="preset-mark">${preset.mark}</span>
<span>
<span class="preset-name">${preset.name}</span>
<span class="preset-description">${preset.description}</span>
</span>
`;
button.addEventListener("click", () => applyPreset(preset.id));
list.appendChild(button);
}
}
function renderMatrix(container, values, kind) {
container.replaceChildren();
for (let row = 0; row < 2; row += 1) {
for (let column = 0; column < 2; column += 1) {
const index = row * 2 + column;
const button = document.createElement("button");
button.type = "button";
button.className = "matrix-cell";
button.dataset.index = String(index);
const value = formatNumber(values[row][column]);
const difference = state.model.differences[row][column];
const differenceMarkup =
kind === "joint"
? `<span class="cell-delta ${Math.abs(difference) < EPSILON ? "zero" : ""}">
Δ ${formatSigned(difference)}
</span>`
: `<span class="cell-delta">rᵢcⱼ</span>`;
button.innerHTML = `
<span class="cell-value">${value}</span>
${differenceMarkup}
`;
button.setAttribute(
"aria-label",
`${kind === "joint" ? "Joint" : "Marginal product"} cell row ${row + 1}, column ${column + 1}: ${value}`,
);
button.addEventListener("click", () => selectCell(index));
container.appendChild(button);
}
}
}
function updateMarginals() {
const preset = state.preset;
const model = state.model;
byId("rowMarginals").innerHTML = model.rowMarginals
.map(
(value, index) => `
<span class="margin-chip">
<span>P(X=${preset.rowLabels[index]})</span>
<b>${formatNumber(value)}</b>
</span>
`,
)
.join("");
byId("colMarginals").innerHTML = model.colMarginals
.map(
(value, index) => `
<span class="margin-chip">
<span>P(Y=${preset.colLabels[index]})</span>
<b>${formatNumber(value)}</b>
</span>
`,
)
.join("");
}
function updateStatus() {
const model = state.model;
const statusCard = byId("statusCard");
const statusIcon = byId("statusIcon");
const statusTitle = byId("statusTitle");
const statusMax = byId("statusMax");
const statusSummary = byId("statusSummary");
const statusMeter = byId("statusMeter");
const counterexampleButton = byId("counterexampleButton");
statusCard.classList.toggle("independent", model.independent);
statusIcon.textContent = model.independent ? "=" : "≠";
statusTitle.textContent = model.independent ? "Independent" : "Dependent";
statusMax.textContent = `Δmax = ${formatNumber(model.maxDifference)}`;
if (model.independent) {
statusSummary.textContent =
"All 4 cells equal their marginal products, so the factorization identity holds for the complete table.";
statusMeter.style.width = "0%";
counterexampleButton.disabled = true;
counterexampleButton.textContent = "No counterexample exists";
} else {
const count = model.counterexamples.length;
statusSummary.textContent =
`${model.matchingCount} of 4 cells match exactly; ${count} exact ` +
`${count === 1 ? "cell violates" : "cells violate"} the independence identity.`;
statusMeter.style.width = `${Math.min((model.maxDifference / 0.5) * 100, 100)}%`;
counterexampleButton.disabled = false;
counterexampleButton.textContent = "Go to the strongest counterexample";
}
if (statusRing) {
statusRing.material.color.set(model.independent ? 0x76edb5 : 0xff7165);
}
if (accentLight) {
accentLight.color.set(model.independent ? 0x76edb5 : 0xff7165);
}
}
function updateSelectedUI() {
const preset = state.preset;
const model = state.model;
const index = state.selected;
const row = Math.floor(index / 2);
const column = index % 2;
const jointValue = model.joint[row][column];
const productValue = model.products[row][column];
const difference = model.differences[row][column];
const nonzero = Math.abs(difference) > EPSILON;
document.querySelectorAll(".matrix-cell").forEach((button) => {
const selected = Number(button.dataset.index) === index;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
});
byId("selectedTitle").textContent =
`${preset.rowLabels[row]} × ${preset.colLabels[column]}`;
byId("selectedPosition").textContent =
`cell (${row + 1}, ${column + 1})`;
byId("jointEquation").innerHTML =
`P<sub>${row}${column}</sub> = ${formatNumber(jointValue)}`;
byId("productEquation").innerHTML =
`${formatNumber(model.rowMarginals[row])} × ` +
`${formatNumber(model.colMarginals[column])} = ${formatNumber(productValue)}`;
const differenceElement = byId("differenceValue");
differenceElement.textContent = `Difference = ${formatSigned(difference)}`;
differenceElement.classList.toggle("zero", !nonzero);
if (model.independent) {
byId("selectedProof").textContent =
"This cell satisfies the factorization identity. Since every other cell does too, the complete table proves independence.";
} else if (nonzero) {
byId("selectedProof").textContent =
"This exact cell alone is a mathematical counterexample: its joint probability differs from the product of its marginals. Therefore the variables are dependent.";
} else {
byId("selectedProof").textContent =
"This particular cell matches its marginal product, but that does not establish independence. Another cell in the same table violates the identity.";
}
if (deltaLabel) {
deltaLabel.set([
{
text: `Δ ${formatSigned(difference)}`,
size: 42,
color: nonzero ? "#ff8a7f" : "#76edb5",
weight: 850,
},
]);
}
for (const record of [...jointBars, ...productBars]) {
const selected = record.index === index;
record.mesh.material.emissive.setHex(
selected ? 0x5b430d : record.kind === "joint" ? 0x2c0806 : 0x032b28,
);
record.mesh.material.emissiveIntensity = selected ? 0.62 : 0.18;
}
}
function selectCell(index) {
state.selected = index;
updateSelectedUI();
}
function applyPreset(id) {
const preset = PRESETS.find((candidate) => candidate.id === id);
if (!preset) return;
state.preset = preset;
state.model = computeModel(preset);
const strongest = state.model.counterexamples[0];
state.selected = strongest ? strongest.index : 0;
document.querySelectorAll(".preset").forEach((button) => {
const active = button.dataset.preset === id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
byId("story").textContent = preset.story;
renderMatrix(jointMatrixElement, state.model.joint, "joint");
renderMatrix(productMatrixElement, state.model.products, "product");
updateMarginals();
updateStatus();
updateSelectedUI();
updateSceneTable();
}
byId("counterexampleButton").addEventListener("click", () => {
const strongest = state.model.counterexamples[0];
if (strongest) selectCell(strongest.index);
});
buildPresetButtons();
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const canvas = byId("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x07111f, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111f, 0.023);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const controls = {
theta: 0.69,
phi: 0.78,
zoom: 1,
target: new THREE.Vector3(-1.15, 0.45, 0),
};
const hemisphere = new THREE.HemisphereLight(0xc7e7ff, 0x142033, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d9, 2.65);
keyLight.position.set(5.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4edbcf, 1.1);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const accentLight = new THREE.PointLight(0xff7165, 22, 12, 2);
accentLight.position.set(-3.6, 2.8, 1.7);
scene.add(accentLight);
function createLowPolyFloor() {
const geometry = new THREE.PlaneGeometry(30, 24, 8, 6).toNonIndexed();
geometry.rotateX(-Math.PI / 2);
const positions = geometry.attributes.position;
const colors = [];
const palette = [
new THREE.Color(0x081525),
new THREE.Color(0x0a192a),
new THREE.Color(0x0b1c2d),
new THREE.Color(0x091827),
];
for (let index = 0; index < positions.count; index += 3) {
const color = palette[Math.floor(index / 3) % palette.length];
for (let vertex = 0; vertex < 3; vertex += 1) {
colors.push(color.r, color.g, color.b);
}
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3),
);
const floor = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true,
}),
);
floor.position.y = -0.39;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0x24445d, 0x132b40);
grid.position.y = -0.375;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
}
createLowPolyFloor();
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.65, 5.9, 0.36, 12),
new THREE.MeshStandardMaterial({
color: 0x10263a,
roughness: 0.82,
metalness: 0.05,
flatShading: true,
}),
);
platform.position.y = -0.18;
platform.receiveShadow = true;
scene.add(platform);
const platformTop = new THREE.Mesh(
new THREE.CylinderGeometry(5.48, 5.55, 0.055, 12),
new THREE.MeshStandardMaterial({
color: 0x132c42,
roughness: 0.88,
flatShading: true,
}),
);
platformTop.position.y = 0.025;
platformTop.receiveShadow = true;
scene.add(platformTop);
const statusRing = new THREE.Mesh(
new THREE.TorusGeometry(4.86, 0.025, 4, 64),
new THREE.MeshBasicMaterial({
color: 0xff7165,
transparent: true,
opacity: 0.28,
}),
);
statusRing.rotation.x = Math.PI / 2;
statusRing.position.y = 0.09;
scene.add(statusRing);
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeLabel(
lines,
accent,
spriteSize,
canvasSize = [512, 160],
) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = canvasSize[0];
labelCanvas.height = canvasSize[1];
const context = labelCanvas.getContext("2d");
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,
toneMapped: false,
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(spriteSize[0], spriteSize[1], 1);
sprite.renderOrder = 20;
function draw(nextLines) {
const width = labelCanvas.width;
const height = labelCanvas.height;
context.clearRect(0, 0, width, height);
roundedRect(context, 4, 4, width - 8, height - 8, 18);
context.fillStyle = "rgba(5, 14, 27, 0.88)";
context.fill();
context.lineWidth = 4;
context.strokeStyle = accent;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
nextLines.forEach((line, index) => {
const y = ((index + 1) * height) / (nextLines.length + 1);
context.font = `${line.weight || 750} ${line.size}px ui-sans-serif, system-ui, sans-serif`;
context.fillStyle = line.color;
context.fillText(line.text, width / 2, y, width - 28);
});
texture.needsUpdate = true;
}
draw(lines);
return {
sprite,
set(nextLines) {
draw(nextLines);
},
};
}
const groupCenters = [-1.55, 1.55];
const columnOffsets = [-0.63, 0.63];
const rowOffsets = [-0.68, 0.68];
const padMaterial = new THREE.MeshStandardMaterial({
color: 0x173149,
roughness: 0.9,
flatShading: true,
});
for (const center of groupCenters) {
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(1.64, 1.75, 0.08, 8),
padMaterial,
);
pad.scale.x = 1.48;
pad.position.set(center, 0.045, 0);
pad.receiveShadow = true;
scene.add(pad);
}
const jointHeading = makeLabel(
[
{ text: "JOINT TABLE", size: 39, color: "#ff8b81", weight: 850 },
{
text: "P(X=xᵢ, Y=yⱼ)",
size: 25,
color: "#c4d4e5",
weight: 650,
},
],
"rgba(255,113,101,0.75)",
[3.05, 0.82],
[640, 170],
);
jointHeading.sprite.position.set(groupCenters[0], 3.12, -1.7);
scene.add(jointHeading.sprite);
const productHeading = makeLabel(
[
{ text: "MARGINAL PRODUCT", size: 36, color: "#67e8db", weight: 850 },
{
text: "P(X=xᵢ) · P(Y=yⱼ)",
size: 25,
color: "#c4d4e5",
weight: 650,
},
],
"rgba(59,216,200,0.75)",
[3.05, 0.82],
[640, 170],
);
productHeading.sprite.position.set(groupCenters[1], 3.12, -1.7);
scene.add(productHeading.sprite);
const barGeometry = new THREE.BoxGeometry(0.92, 1, 0.82);
barGeometry.translate(0, 0.5, 0);
const barEdgeGeometry = new THREE.EdgesGeometry(barGeometry);
function createBar(kind, index, x, z, color, accent) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.67,
metalness: 0.06,
emissive: kind === "joint" ? 0x2c0806 : 0x032b28,
emissiveIntensity: 0.18,
flatShading: true,
});
const mesh = new THREE.Mesh(barGeometry, material);
mesh.position.set(x, BASE_Y, z);
mesh.scale.y = 0.015;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.cellIndex = index;
mesh.userData.kind = kind;
const edges = new THREE.LineSegments(
barEdgeGeometry,
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.19,
}),
);
mesh.add(edges);
scene.add(mesh);
const label = makeLabel(
[{ text: "0", size: 43, color: "#f5f9ff", weight: 850 }],
accent,
[0.98, 0.37],
[256, 96],
);
label.sprite.position.set(x, BASE_Y + 0.4, z);
scene.add(label.sprite);
return {
kind,
index,
x,
z,
mesh,
label,
target: 0,
current: 0,
};
}
for (let row = 0; row < 2; row += 1) {
for (let column = 0; column < 2; column += 1) {
const index = row * 2 + column;
jointBars.push(
createBar(
"joint",
index,
groupCenters[0] + columnOffsets[column],
rowOffsets[row],
0xff7165,
"rgba(255,113,101,0.62)",
),
);
productBars.push(
createBar(
"product",
index,
groupCenters[1] + columnOffsets[column],
rowOffsets[row],
0x3bd8c8,
"rgba(59,216,200,0.62)",
),
);
}
}
jointHelper = new THREE.BoxHelper(jointBars[0].mesh, 0xf5cc66);
productHelper = new THREE.BoxHelper(productBars[0].mesh, 0xf5cc66);
for (const helper of [jointHelper, productHelper]) {
helper.material.depthTest = false;
helper.material.depthWrite = false;
helper.material.transparent = true;
helper.material.opacity = 0.95;
helper.renderOrder = 25;
scene.add(helper);
}
const deltaGeometry = new THREE.BufferGeometry();
deltaGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3),
);
const deltaLine = new THREE.Line(
deltaGeometry,
new THREE.LineBasicMaterial({
color: 0xf5cc66,
transparent: true,
opacity: 0.72,
depthTest: false,
}),
);
deltaLine.renderOrder = 22;
scene.add(deltaLine);
const deltaLabel = makeLabel(
[{ text: "Δ 0", size: 42, color: "#f5cc66", weight: 850 }],
"rgba(245,204,102,0.78)",
[1.45, 0.43],
[320, 96],
);
scene.add(deltaLabel.sprite);
const decorations = [];
function addDecoration(mesh, x, y, z) {
mesh.position.set(x, y, z);
mesh.castShadow = true;
scene.add(mesh);
decorations.push({
mesh,
baseY: y,
phase: decorations.length * 1.73,
});
}
addDecoration(
new THREE.Mesh(
new THREE.DodecahedronGeometry(0.4, 0),
new THREE.MeshStandardMaterial({
color: 0x7a342f,
roughness: 0.8,
flatShading: true,
}),
),
-4.4,
0.9,
-2.15,
);
addDecoration(
new THREE.Mesh(
new THREE.ConeGeometry(0.42, 0.95, 5),
new THREE.MeshStandardMaterial({
color: 0x1d716c,
roughness: 0.8,
flatShading: true,
}),
),
4.25,
0.85,
1.7,
);
addDecoration(
new THREE.Mesh(
new THREE.TetrahedronGeometry(0.48),
new THREE.MeshStandardMaterial({
color: 0x9b7730,
roughness: 0.82,
flatShading: true,
}),
),
3.8,
0.75,
-2.55,
);
addDecoration(
new THREE.Mesh(
new THREE.OctahedronGeometry(0.37, 0),
new THREE.MeshStandardMaterial({
color: 0x284a63,
roughness: 0.85,
flatShading: true,
}),
),
-3.7,
0.7,
2.4,
);
function updateSceneTable() {
const model = state.model;
for (const record of jointBars) {
const row = Math.floor(record.index / 2);
const column = record.index % 2;
const value = model.joint[row][column];
record.target = value * HEIGHT_SCALE;
record.label.set([
{
text: formatNumber(value),
size: 43,
color: "#f7fbff",
weight: 850,
},
]);
}
for (const record of productBars) {
const row = Math.floor(record.index / 2);
const column = record.index % 2;
const value = model.products[row][column];
record.target = value * HEIGHT_SCALE;
record.label.set([
{
text: formatNumber(value),
size: 43,
color: "#f0fffd",
weight: 850,
},
]);
}
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, wheel/pinch zoom, keyboard, bar picking
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointers = new Map();
let lastPinchDistance = 0;
let dragDistance = 0;
let gestureHadMultiplePointers = false;
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function updateCamera() {
const radius = 14;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(controls.theta),
controls.target.y + radius * Math.cos(controls.phi),
controls.target.z + radius * sinPhi * Math.cos(controls.theta),
);
camera.lookAt(controls.target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
controls.theta = 0.69;
controls.phi = 0.78;
controls.zoom = 1;
controls.target.set(
window.innerWidth <= 800 ? 0 : -1.15,
window.innerWidth <= 800 ? 1.15 : 0.45,
0,
);
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(8.8, 7.4 / aspect);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height, false);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
if (width <= 800) {
controls.target.set(0, 1.15, 0);
} else {
controls.target.set(-1.15, 0.45, 0);
}
updateCamera();
}
function pickBar(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
[...jointBars, ...productBars].map((record) => record.mesh),
false,
);
return intersections.length ? intersections[0].object : null;
}
function pinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y,
);
}
canvas.addEventListener("pointerdown", (event) => {
if (pointers.size === 0) {
dragDistance = 0;
gestureHadMultiplePointers = false;
}
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
gestureHadMultiplePointers = true;
lastPinchDistance = pinchDistance();
}
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) {
const hovered = pickBar(event.clientX, event.clientY);
canvas.style.cursor = hovered ? "pointer" : "grab";
return;
}
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
if (pointers.size === 1) {
dragDistance += Math.hypot(dx, dy);
controls.theta -= dx * 0.007;
controls.phi = clamp(controls.phi - dy * 0.006, 0.35, 1.25);
}
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size >= 2) {
const distance = pinchDistance();
if (lastPinchDistance > 0 && distance > 0) {
controls.zoom = clamp(
controls.zoom * (distance / lastPinchDistance),
0.65,
1.85,
);
}
lastPinchDistance = distance;
}
updateCamera();
});
function finishPointer(event) {
const existed = pointers.has(event.pointerId);
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
remaining.x = event.clientX;
remaining.y = event.clientY;
} else {
lastPinchDistance = 0;
}
if (existed && !gestureHadMultiplePointers && dragDistance < 6) {
const selectedMesh = pickBar(event.clientX, event.clientY);
if (selectedMesh) selectCell(selectedMesh.userData.cellIndex);
}
canvas.style.cursor = pointers.size ? "grabbing" : "grab";
}
canvas.addEventListener("pointerup", finishPointer);
canvas.addEventListener("pointercancel", finishPointer);
canvas.addEventListener("pointerleave", () => {
if (!pointers.size) canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.85,
);
updateCamera();
},
{ passive: false },
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta += 0.09;
break;
case "ArrowRight":
controls.theta -= 0.09;
break;
case "ArrowUp":
controls.phi = clamp(controls.phi - 0.07, 0.35, 1.25);
break;
case "ArrowDown":
controls.phi = clamp(controls.phi + 0.07, 0.35, 1.25);
break;
case "+":
case "=":
controls.zoom = clamp(controls.zoom * 1.08, 0.65, 1.85);
break;
case "-":
case "_":
controls.zoom = clamp(controls.zoom * 0.92, 0.65, 1.85);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
byId("resetCamera").addEventListener("click", resetCamera);
window.addEventListener("resize", resize);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
let previousTime = performance.now();
function animate(time) {
const delta = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
const smoothing = reducedMotion ? 1 : 1 - Math.exp(-8 * delta);
for (const record of [...jointBars, ...productBars]) {
record.current += (record.target - record.current) * smoothing;
record.mesh.scale.y = Math.max(record.current, 0.015);
record.label.sprite.position.y = BASE_Y + record.current + 0.36;
}
for (const decoration of decorations) {
decoration.mesh.rotation.y += delta * 0.32;
decoration.mesh.rotation.x += delta * 0.13;
if (!reducedMotion) {
decoration.mesh.position.y =
decoration.baseY +
Math.sin(time * 0.00075 + decoration.phase) * 0.09;
}
}
const selectedJoint = jointBars[state.selected];
const selectedProduct = productBars[state.selected];
if (selectedJoint && selectedProduct) {
jointHelper.setFromObject(selectedJoint.mesh);
productHelper.setFromObject(selectedProduct.mesh);
const y =
BASE_Y +
Math.max(selectedJoint.current, selectedProduct.current) +
0.54;
const positions = deltaGeometry.attributes.position.array;
positions[0] = selectedJoint.x;
positions[1] = y;
positions[2] = selectedJoint.z;
positions[3] = selectedProduct.x;
positions[4] = y;
positions[5] = selectedProduct.z;
deltaGeometry.attributes.position.needsUpdate = true;
deltaGeometry.computeBoundingSphere();
deltaLabel.sprite.position.set(
(selectedJoint.x + selectedProduct.x) / 2,
y + 0.03,
selectedJoint.z,
);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
resetCamera();
applyPreset("rain");
requestAnimationFrame(animate);
requestAnimationFrame(() => {
byId("boot").classList.add("hidden");
});
</script>
</body>
</html>
```