Prompt specification
Build or customize the Three.js 3D scene "Growth Versus Capacity Planning Game" 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: Growth Versus Capacity Planning Game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/growth-versus-capacity-planning-game-x3200
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts simple and compound growth over time. Build a fictional storage system whose demand grows by a chosen mathematical rule. Compare added capacity and overflow, separating illustrative growth from predictions about real economies. Low-poly.
Working Three.js Starter (growth-versus-capacity-planning-game-x3200):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Storage Growth Lab — Illustrative Three.js Scene</title>
<style>
:root {
--bg: #07111c;
--panel: rgba(9, 23, 36, 0.88);
--panel-border: rgba(165, 218, 242, 0.16);
--text: #edf7ff;
--muted: #91aabc;
--simple: #49d8c5;
--compound: #ff6f91;
--capacity: #5c91b6;
--addition: #a9e8ff;
--overflow: #ff4d65;
--accent: #f6d66f;
}
* {
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;
}
body {
background:
radial-gradient(circle at 52% 38%, rgba(35, 83, 111, 0.25), transparent 42%),
linear-gradient(145deg, #07111c 0%, #081725 55%, #071019 100%);
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
transform: rotate(30deg);
border: 2px solid var(--simple);
box-shadow: 9px 7px 0 -4px var(--compound);
}
.brand-mark::after {
content: "";
position: absolute;
inset: 8px;
border: 2px solid var(--accent);
}
.brand h1 {
margin: 0;
font-size: clamp(17px, 2vw, 25px);
line-height: 1;
letter-spacing: -0.03em;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.badge {
border: 1px solid rgba(246, 214, 111, 0.45);
background: rgba(246, 214, 111, 0.08);
color: var(--accent);
border-radius: 999px;
padding: 8px 12px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.1em;
white-space: nowrap;
}
.panel {
position: fixed;
z-index: 20;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#controls {
top: 88px;
left: 20px;
width: 294px;
max-height: calc(100vh - 210px);
padding: 18px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #31546b transparent;
}
#readout {
top: 88px;
right: 20px;
width: 348px;
max-height: calc(100vh - 210px);
padding: 18px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #31546b transparent;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h2 {
margin: 5px 0 16px;
font-size: 18px;
letter-spacing: -0.025em;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
padding: 5px;
margin-bottom: 17px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
background: rgba(0, 0, 0, 0.18);
}
.segmented button {
border: 0;
border-radius: 8px;
padding: 9px 7px;
background: transparent;
color: var(--muted);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
.segmented button:hover {
color: white;
}
.segmented button.active[data-rule="simple"] {
background: rgba(73, 216, 197, 0.18);
color: var(--simple);
box-shadow: inset 0 0 0 1px rgba(73, 216, 197, 0.4);
}
.segmented button.active[data-rule="compound"] {
background: rgba(255, 111, 145, 0.18);
color: var(--compound);
box-shadow: inset 0 0 0 1px rgba(255, 111, 145, 0.4);
}
.control {
margin: 0 0 16px;
}
.control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
font-size: 12px;
}
.control-heading span:first-child {
color: #d9e9f4;
font-weight: 650;
}
output {
color: var(--accent);
font-variant-numeric: tabular-nums;
font-weight: 800;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 0;
appearance: none;
border-radius: 99px;
background: #243b4b;
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 15px;
border: 3px solid #102431;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(246, 214, 111, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #102431;
border-radius: 50%;
background: var(--accent);
}
.helper {
margin: -7px 0 15px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.subhead {
margin: 19px 0 11px;
padding-top: 16px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend {
position: fixed;
z-index: 15;
left: 50%;
top: 86px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 8px 14px;
max-width: 480px;
padding: 9px 13px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
background: rgba(7, 17, 28, 0.64);
color: #c3d6e2;
font-size: 10px;
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--swatch);
box-shadow: 0 0 8px color-mix(in srgb, var(--swatch) 50%, transparent);
}
.year-line {
display: flex;
align-items: end;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.year-line h2 {
margin-bottom: 0;
}
.year-badge {
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
white-space: nowrap;
}
.kpis {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 16px;
}
.kpi {
min-width: 0;
padding: 11px 9px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.kpi-label {
display: block;
margin-bottom: 7px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.kpi-value {
display: block;
font-size: 20px;
font-variant-numeric: tabular-nums;
font-weight: 800;
letter-spacing: -0.04em;
}
.kpi-value.danger {
color: var(--overflow);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
th,
td {
padding: 8px 5px;
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
text-align: right;
}
th:first-child,
td:first-child {
text-align: left;
color: var(--muted);
}
thead th {
color: #dcecf6;
font-size: 10px;
letter-spacing: 0.04em;
}
thead th.selected-column {
color: var(--compound);
}
tbody tr:last-child td {
border-bottom: 0;
}
.overflow-value {
color: var(--overflow);
font-weight: 750;
}
.formula {
margin-top: 15px;
padding: 12px;
border-left: 2px solid var(--accent);
border-radius: 0 9px 9px 0;
background: rgba(246, 214, 111, 0.06);
color: #d8e7ef;
font-size: 11px;
line-height: 1.65;
}
.formula strong {
color: var(--accent);
}
.fine-print {
margin: 10px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#timeline {
left: 50%;
bottom: 45px;
width: min(680px, calc(100% - 40px));
padding: 12px 14px;
transform: translateX(-50%);
display: grid;
grid-template-columns: auto minmax(120px, 1fr) auto;
align-items: center;
gap: 14px;
}
.icon-button {
min-width: 84px;
height: 36px;
border: 1px solid rgba(246, 214, 111, 0.34);
border-radius: 9px;
background: rgba(246, 214, 111, 0.1);
color: var(--accent);
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: 150ms ease;
}
.icon-button:hover {
background: rgba(246, 214, 111, 0.18);
}
.timeline-label {
color: #dcebf4;
font-size: 11px;
font-weight: 750;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
#camera-reset {
position: fixed;
z-index: 18;
right: 20px;
bottom: 18px;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 50%;
background: rgba(7, 17, 28, 0.8);
color: #bed1df;
cursor: pointer;
}
#camera-reset:hover {
color: white;
border-color: rgba(255, 255, 255, 0.35);
}
.disclaimer {
position: fixed;
z-index: 14;
left: 20px;
bottom: 13px;
width: min(760px, calc(100% - 85px));
color: #7f99aa;
font-size: 10px;
line-height: 1.35;
pointer-events: none;
}
.disclaimer strong {
color: #b9cdd9;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #07111c;
color: var(--accent);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 980px) {
.legend {
top: 74px;
}
#controls,
#readout {
top: 118px;
}
#controls {
width: 265px;
}
#readout {
width: 310px;
}
}
@media (max-width: 720px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand p,
.badge {
display: none;
}
.brand-mark {
width: 30px;
height: 30px;
}
.legend {
top: 58px;
width: calc(100% - 24px);
max-width: none;
border-radius: 12px;
}
#controls,
#readout {
top: 105px;
max-height: calc(100vh - 255px);
padding: 12px;
}
#controls {
left: 10px;
width: calc(50% - 15px);
}
#readout {
right: 10px;
width: calc(50% - 15px);
}
h2 {
font-size: 15px;
}
.kpis {
grid-template-columns: 1fr;
}
.kpi {
padding: 7px 9px;
}
.kpi-value {
font-size: 17px;
}
.control {
margin-bottom: 12px;
}
.control-heading {
font-size: 10px;
}
#timeline {
bottom: 43px;
width: calc(100% - 20px);
gap: 9px;
padding: 10px;
}
.disclaimer {
left: 10px;
bottom: 8px;
width: calc(100% - 58px);
font-size: 8px;
}
#camera-reset {
right: 10px;
bottom: 10px;
width: 32px;
height: 32px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional storage growth comparison"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Storage Growth Lab</h1>
<p>Simple vs compound demand · fictional system</p>
</div>
</div>
<div class="badge">Illustrative model — not a forecast</div>
</header>
<div class="legend" aria-label="Scene legend">
<span class="legend-item"><i class="swatch" style="--swatch:#49d8c5"></i>Simple demand</span>
<span class="legend-item"><i class="swatch" style="--swatch:#ff6f91"></i>Compound demand</span>
<span class="legend-item"><i class="swatch" style="--swatch:#5c91b6"></i>Capacity</span>
<span class="legend-item"><i class="swatch" style="--swatch:#a9e8ff"></i>Added this year</span>
<span class="legend-item"><i class="swatch" style="--swatch:#ff4d65"></i>Overflow</span>
</div>
<aside id="controls" class="panel">
<div class="eyebrow">Scenario builder</div>
<h2>Fictional warehouse</h2>
<div class="segmented" role="group" aria-label="Selected growth rule">
<button type="button" data-rule="simple">Simple growth</button>
<button type="button" data-rule="compound" class="active">Compound growth</button>
</div>
<div class="control">
<div class="control-heading">
<span>Opening demand</span>
<output id="demand-output">7 units</output>
</div>
<input id="demand" type="range" min="2" max="16" step="0.5" value="7" />
</div>
<div class="control">
<div class="control-heading">
<span id="rate-label">Annual compound rate</span>
<output id="rate-output">22%</output>
</div>
<input id="rate" type="range" min="1" max="40" step="1" value="22" />
</div>
<p class="helper">
Each rule keeps its own growth input. Both lanes begin with the same
opening demand and use the same storage capacity.
</p>
<div class="subhead">Storage response</div>
<div class="control">
<div class="control-heading">
<span>Opening capacity</span>
<output id="opening-output">8 units</output>
</div>
<input id="opening" type="range" min="2" max="16" step="0.5" value="8" />
</div>
<div class="control">
<div class="control-heading">
<span>Capacity added per year</span>
<output id="added-output">1.8 units</output>
</div>
<input id="added" type="range" min="0" max="4" step="0.1" value="1.8" />
</div>
<div class="control">
<div class="control-heading">
<span>Years shown</span>
<output id="horizon-output">8 years</output>
</div>
<input id="horizon" type="range" min="5" max="10" step="1" value="8" />
</div>
<p class="helper">
Bars use one shared unit scale. Red segments show demand above capacity;
the side crates are overflow markers. The table gives exact quantities.
</p>
</aside>
<aside id="readout" class="panel">
<div class="eyebrow">Comparison</div>
<div class="year-line">
<h2>Selected year</h2>
<span id="year-badge" class="year-badge">YEAR 8 / 8</span>
</div>
<div class="kpis">
<div class="kpi">
<span class="kpi-label">Demand</span>
<span id="kpi-demand" class="kpi-value">—</span>
</div>
<div class="kpi">
<span class="kpi-label">Capacity</span>
<span id="kpi-capacity" class="kpi-value">—</span>
</div>
<div class="kpi">
<span class="kpi-label">Overflow now</span>
<span id="kpi-overflow" class="kpi-value">—</span>
</div>
</div>
<table>
<thead>
<tr>
<th scope="col">Measure</th>
<th scope="col" id="simple-heading">Simple</th>
<th scope="col" id="compound-heading">Compound</th>
</tr>
</thead>
<tbody id="comparison-body"></tbody>
</table>
<div class="formula">
<strong id="formula-title">Compound rule</strong><br />
<span id="formula-demand"></span><br />
<span id="formula-capacity"></span>
</div>
<p class="fine-print">
“Overflow to date” sums unmet demand from the opening year through the
selected year. The yellow outline marks the year currently being inspected.
</p>
</aside>
<div id="timeline" class="panel">
<button id="play" class="icon-button" type="button" aria-pressed="false">▶ Play</button>
<input id="year" type="range" min="0" max="7" step="1" value="7" aria-label="Selected year" />
<span id="timeline-label" class="timeline-label">Year 8 / 8</span>
</div>
<footer class="disclaimer">
<strong>Illustrative only.</strong>
This fictional warehouse uses invented parameters to demonstrate mathematical
growth and capacity comparisons. It is not a forecast, causal claim, or model
of real economic growth, storage demand, infrastructure, or investment outcomes.
</footer>
<button id="camera-reset" type="button" title="Reset camera" aria-label="Reset camera">↺</button>
<div id="loading">Loading Three.js scene…</div>
<noscript>This scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// State
// ---------------------------------------------------------------------
const state = {
rule: "compound",
initialDemand: 7,
rates: {
simple: 2.2,
compound: 22
},
openingCapacity: 8,
addedCapacity: 1.8,
horizon: 8,
year: 7,
playing: false
};
const colors = {
simple: 0x49d8c5,
compound: 0xff6f91,
capacity: 0x5c91b6,
addition: 0xa9e8ff,
overflow: 0xff4d65,
accent: 0xf6d66f,
simpleCss: "#49d8c5",
compoundCss: "#ff6f91"
};
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const sceneHost = $("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111c);
scene.fog = new THREE.FogExp2(0x07111c, 0.024);
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.12;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls: yaw, pitch, and distance around a fixed target.
const cameraControls = {
target: new THREE.Vector3(0, 2.15, -1.25),
yaw: 0.66,
pitch: 0.66,
distance: 18.4,
dragging: false,
previousX: 0,
previousY: 0
};
function updateCamera() {
const { target, yaw, pitch, distance } = cameraControls;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
function resetCamera() {
cameraControls.yaw = 0.66;
cameraControls.pitch = 0.66;
cameraControls.distance = 18.4;
updateCamera();
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting and environment
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xa8dcff, 0x07111c, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d5, 2.5);
keyLight.position.set(8, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3bc8ff, 1.3);
rimLight.position.set(-10, 7, -9);
scene.add(rimLight);
const warmRim = new THREE.DirectionalLight(0xff6f91, 0.65);
warmRim.position.set(8, 4, -10);
scene.add(warmRim);
const ground = new THREE.Mesh(
new THREE.BoxGeometry(20, 0.3, 18),
new THREE.MeshStandardMaterial({
color: 0x091722,
roughness: 0.95,
metalness: 0.05
})
);
ground.position.y = -0.15;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(20, 20, 0x245064, 0x12313f);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const groundBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(20, 0.3, 18)),
new THREE.LineBasicMaterial({
color: 0x2c5a70,
transparent: true,
opacity: 0.52
})
);
groundBorder.position.y = -0.15;
scene.add(groundBorder);
const dynamicGroup = new THREE.Group();
scene.add(dynamicGroup);
let demandMeshes = { simple: [], compound: [] };
let capacityMeshes = { simple: [], compound: [] };
let overflowSegments = { simple: [], compound: [] };
let overflowMarkerGroups = { simple: [], compound: [] };
let selectedHighlights = [];
// ---------------------------------------------------------------------
// Model calculations
// ---------------------------------------------------------------------
function demandFor(rule, elapsedYears) {
if (rule === "simple") {
return state.initialDemand + state.rates.simple * elapsedYears;
}
return state.initialDemand *
Math.pow(1 + state.rates.compound / 100, elapsedYears);
}
function calculateData() {
const simple = [];
const compound = [];
for (let t = 0; t < state.horizon; t += 1) {
const capacity =
state.openingCapacity + state.addedCapacity * t;
const simpleDemand = demandFor("simple", t);
const compoundDemand = demandFor("compound", t);
simple.push({
elapsed: t,
demand: simpleDemand,
capacity,
added: t === 0 ? 0 : state.addedCapacity,
overflow: Math.max(0, simpleDemand - capacity)
});
compound.push({
elapsed: t,
demand: compoundDemand,
capacity,
added: t === 0 ? 0 : state.addedCapacity,
overflow: Math.max(0, compoundDemand - capacity)
});
}
return { simple, compound };
}
function cumulativeOverflow(rows, throughIndex) {
let total = 0;
for (let i = 0; i <= throughIndex; i += 1) {
total += rows[i].overflow;
}
return total;
}
// ---------------------------------------------------------------------
// Small helpers
// ---------------------------------------------------------------------
function disposeGroup(group) {
group.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
const materials = Array.isArray(object.material)
? object.material
: object.material
? [object.material]
: [];
for (const material of materials) {
if (material.map) {
material.map.dispose();
}
material.dispose();
}
});
group.clear();
}
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(text, accent = "#dcecf6", width = 2.3) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 6, 6, 756, 148, 24);
context.fillStyle = "rgba(5, 16, 27, 0.82)";
context.fill();
context.lineWidth = 4;
context.strokeStyle = accent;
context.stroke();
context.fillStyle = "#eef8ff";
context.font = "700 48px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * (160 / 768), 1);
sprite.renderOrder = 20;
return sprite;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.68,
metalness: 0.08,
flatShading: true,
...options
});
}
function formatNumber(value) {
if (Math.abs(value - Math.round(value)) < 0.001) {
return String(Math.round(value));
}
return value.toFixed(1);
}
function timelineZ(index) {
return 3.2 - index * 1.12;
}
// ---------------------------------------------------------------------
// 3D scene construction
// ---------------------------------------------------------------------
function buildLane(rule, rows, maxValue, maxOverflow, zStart, zEnd) {
const lane = new THREE.Group();
lane.position.x = rule === "simple" ? -2.65 : 2.65;
const isSelected = state.rule === rule;
const laneColor = rule === "simple" ? colors.simple : colors.compound;
const laneBase = new THREE.Mesh(
new THREE.BoxGeometry(3.15, 0.18, Math.abs(zEnd - zStart) + 1.7),
standardMaterial(
isSelected ? 0x183342 : 0x102330,
{
roughness: 0.9,
metalness: 0.02
}
)
);
laneBase.position.set(0, 0.09, (zStart + zEnd) / 2);
laneBase.receiveShadow = true;
lane.add(laneBase);
const baseBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(3.15, 0.18, Math.abs(zEnd - zStart) + 1.7)
),
new THREE.LineBasicMaterial({
color: laneColor,
transparent: true,
opacity: isSelected ? 0.78 : 0.23
})
);
baseBorder.position.copy(laneBase.position);
lane.add(baseBorder);
const laneName = makeLabel(
rule === "simple" ? "SIMPLE · +UNITS / YEAR" : "COMPOUND · +% / YEAR",
rule === "simple" ? colors.simpleCss : colors.compoundCss,
2.75
);
laneName.position.set(0, 0.38, zStart + 1.05);
lane.add(laneName);
const demandLinePoints = [];
const capacityLinePoints = [];
const heightScale = 7.9 / maxValue;
const baseY = 0.18;
rows.forEach((row, index) => {
const z = timelineZ(index);
const demandHeight = Math.max(0.14, row.demand * heightScale);
const capacityHeight = Math.max(0.14, row.capacity * heightScale);
const overflowHeight = row.overflow * heightScale;
const demandMaterial = standardMaterial(laneColor, {
emissive: laneColor,
emissiveIntensity: 0.18,
roughness: 0.58
});
const demandMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.64, demandHeight, 0.68),
demandMaterial
);
demandMesh.position.set(-0.48, baseY + demandHeight / 2, z);
demandMesh.castShadow = true;
demandMesh.receiveShadow = true;
lane.add(demandMesh);
demandMeshes[rule].push(demandMesh);
const capacityMaterial = standardMaterial(colors.capacity, {
emissive: 0x173c57,
emissiveIntensity: 0.18,
roughness: 0.72
});
const capacityMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.64, capacityHeight, 0.68),
capacityMaterial
);
capacityMesh.position.set(0.48, baseY + capacityHeight / 2, z);
capacityMesh.castShadow = true;
capacityMesh.receiveShadow = true;
lane.add(capacityMesh);
capacityMeshes[rule].push(capacityMesh);
// A bright tile marks the capacity added after the opening year.
if (index > 0) {
const additionSize = 0.17 +
Math.min(0.13, state.addedCapacity / maxValue * 0.8);
const additionTile = new THREE.Mesh(
new THREE.BoxGeometry(additionSize, 0.1, additionSize),
standardMaterial(colors.addition, {
emissive: colors.addition,
emissiveIntensity: 0.65
})
);
additionTile.position.set(
0.48,
baseY + capacityHeight + 0.065,
z + 0.27
);
lane.add(additionTile);
}
// The exact overflow is the red segment above capacity.
if (overflowHeight > 0.001) {
const overflowMaterial = standardMaterial(colors.overflow, {
emissive: colors.overflow,
emissiveIntensity: 0.42
});
const overflowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.64, overflowHeight, 0.68),
overflowMaterial
);
overflowMesh.position.set(
0.48,
baseY + capacityHeight + 0.14 + overflowHeight / 2,
z
);
overflowMesh.castShadow = true;
lane.add(overflowMesh);
overflowSegments[rule].push(overflowMesh);
} else {
overflowSegments[rule].push(null);
}
// Side crates are qualitative overflow markers.
const markerGroup = new THREE.Group();
if (row.overflow > 0.001 && maxOverflow > 0) {
const count = Math.max(
1,
Math.min(6, Math.ceil(row.overflow / maxOverflow * 6))
);
for (let crate = 0; crate < count; crate += 1) {
const crateMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 0.3, 0.3),
standardMaterial(
crate % 2 === 0 ? colors.overflow : 0xd9354d,
{
emissive: colors.overflow,
emissiveIntensity: 0.22
}
)
);
crateMesh.position.set(
(crate % 2) * 0.035,
0.34 + crate * 0.31,
((crate % 3) - 1) * 0.035
);
crateMesh.rotation.y = (crate % 2 ? -1 : 1) * 0.12;
crateMesh.castShadow = true;
markerGroup.add(crateMesh);
}
}
markerGroup.position.x = rule === "simple" ? -1.28 : 1.28;
markerGroup.position.z = z;
lane.add(markerGroup);
overflowMarkerGroups[rule].push(markerGroup);
demandLinePoints.push(
new THREE.Vector3(
-0.48,
baseY + demandHeight + 0.04,
z
)
);
capacityLinePoints.push(
new THREE.Vector3(
0.48,
baseY + capacityHeight + 0.04,
z
)
);
});
const demandLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(demandLinePoints),
new THREE.LineBasicMaterial({
color: laneColor,
transparent: true,
opacity: 0.95
})
);
lane.add(demandLine);
const capacityLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(capacityLinePoints),
new THREE.LineDashedMaterial({
color: colors.addition,
dashSize: 0.18,
gapSize: 0.11,
transparent: true,
opacity: 0.62
})
);
capacityLine.computeLineDistances();
lane.add(capacityLine);
dynamicGroup.add(lane);
}
function buildYearLabels() {
for (let index = 0; index < state.horizon; index += 1) {
const label = makeLabel(`Y${index + 1}`, "#829dac", 0.58);
label.position.set(0, 0.19, timelineZ(index));
dynamicGroup.add(label);
}
}
function buildSelectedHighlights() {
selectedHighlights = [];
for (const rule of ["simple", "compound"]) {
const laneX = rule === "simple" ? -2.65 : 2.65;
const highlight = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(3.03, 0.08, 0.98)
),
new THREE.LineBasicMaterial({
color: colors.accent,
transparent: true,
opacity: 0.88
})
);
highlight.position.set(laneX, 0.225, timelineZ(state.year));
dynamicGroup.add(highlight);
selectedHighlights.push(highlight);
}
}
function rebuildScene() {
disposeGroup(dynamicGroup);
demandMeshes = { simple: [], compound: [] };
capacityMeshes = { simple: [], compound: [] };
overflowSegments = { simple: [], compound: [] };
overflowMarkerGroups = { simple: [], compound: [] };
const data = calculateData();
const allRows = [...data.simple, ...data.compound];
const maxValue = Math.max(
...allRows.map((row) => Math.max(row.demand, row.capacity))
);
const maxOverflow = Math.max(
...allRows.map((row) => row.overflow)
);
const zStart = timelineZ(0);
const zEnd = timelineZ(state.horizon - 1);
buildLane(
"simple",
data.simple,
maxValue,
maxOverflow,
zStart,
zEnd
);
buildLane(
"compound",
data.compound,
maxValue,
maxOverflow,
zStart,
zEnd
);
buildYearLabels();
buildSelectedHighlights();
updateYearVisuals();
}
function updateYearVisuals() {
const z = timelineZ(state.year);
for (const rule of ["simple", "compound"]) {
demandMeshes[rule].forEach((mesh, index) => {
mesh.material.emissiveIntensity = index === state.year ? 0.72 : 0.18;
});
capacityMeshes[rule].forEach((mesh, index) => {
mesh.material.emissiveIntensity = index === state.year ? 0.48 : 0.16;
});
overflowSegments[rule].forEach((mesh, index) => {
if (mesh) {
mesh.material.emissiveIntensity =
index === state.year ? 0.85 : 0.42;
}
});
overflowMarkerGroups[rule].forEach((group, index) => {
const scale = index === state.year ? 1.14 : 1;
group.scale.setScalar(scale);
});
}
selectedHighlights.forEach((highlight) => {
highlight.position.z = z;
});
}
// ---------------------------------------------------------------------
// Interface rendering
// ---------------------------------------------------------------------
function updateRateControl() {
const input = $("#rate");
const output = $("#rate-output");
const label = $("#rate-label");
if (state.rule === "simple") {
input.min = "0.5";
input.max = "6";
input.step = "0.1";
input.value = state.rates.simple;
label.textContent = "Simple annual addition";
output.textContent = `${formatNumber(state.rates.simple)} units`;
} else {
input.min = "1";
input.max = "40";
input.step = "1";
input.value = state.rates.compound;
label.textContent = "Annual compound rate";
output.textContent = `${formatNumber(state.rates.compound)}%`;
}
}
function updateReadout() {
const data = calculateData();
const selected = data[state.rule][state.year];
const simpleRows = data.simple;
const compoundRows = data.compound;
$("#year-badge").textContent =
`YEAR ${state.year + 1} / ${state.horizon}`;
$("#timeline-label").textContent =
`Year ${state.year + 1} / ${state.horizon}`;
$("#year").value = String(state.year);
$("#kpi-demand").textContent = formatNumber(selected.demand);
$("#kpi-capacity").textContent = formatNumber(selected.capacity);
$("#kpi-overflow").textContent = formatNumber(selected.overflow);
$("#kpi-overflow").classList.toggle("danger", selected.overflow > 0.001);
const rows = [
{
label: "Demand",
simple: simpleRows[state.year].demand,
compound: compoundRows[state.year].demand
},
{
label: "Capacity",
simple: simpleRows[state.year].capacity,
compound: compoundRows[state.year].capacity
},
{
label: "Added since opening",
simple: simpleRows[state.year].added,
compound: compoundRows[state.year].added
},
{
label: "Overflow now",
simple: simpleRows[state.year].overflow,
compound: compoundRows[state.year].overflow,
overflow: true
},
{
label: "Overflow to date",
simple: cumulativeOverflow(simpleRows, state.year),
compound: cumulativeOverflow(compoundRows, state.year),
overflow: true
}
];
$("#comparison-body").innerHTML = rows.map((row) => {
const simpleClass = row.overflow && row.simple > 0.001
? "overflow-value"
: "";
const compoundClass = row.overflow && row.compound > 0.001
? "overflow-value"
: "";
return `
<tr>
<td>${row.label}</td>
<td class="${simpleClass}">${formatNumber(row.simple)}</td>
<td class="${compoundClass}">${formatNumber(row.compound)}</td>
</tr>
`;
}).join("");
const simpleHeading = $("#simple-heading");
const compoundHeading = $("#compound-heading");
simpleHeading.classList.toggle(
"selected-column",
state.rule === "simple"
);
compoundHeading.classList.toggle(
"selected-column",
state.rule === "compound"
);
$("#formula-title").textContent =
state.rule === "simple" ? "Simple growth rule" : "Compound growth rule";
$("#formula-demand").innerHTML = state.rule === "simple"
? "D<sub>t</sub> = D<sub>0</sub> + r × t"
: "D<sub>t</sub> = D<sub>0</sub> × (1 + r)<sup>t</sup>";
$("#formula-capacity").innerHTML =
"C<sub>t</sub> = C<sub>0</sub> + a × t";
updateYearVisuals();
}
function updateAll() {
updateRateControl();
updateReadout();
}
// ---------------------------------------------------------------------
// Controls and events
// ---------------------------------------------------------------------
$$(".segmented button").forEach((button) => {
button.addEventListener("click", () => {
state.rule = button.dataset.rule;
$$(".segmented button").forEach((candidate) => {
candidate.classList.toggle("active", candidate === button);
});
updateRateControl();
rebuildScene();
updateReadout();
});
});
$("#demand").addEventListener("input", (event) => {
state.initialDemand = Number(event.target.value);
$("#demand-output").textContent =
`${formatNumber(state.initialDemand)} units`;
rebuildScene();
updateReadout();
});
$("#rate").addEventListener("input", (event) => {
const value = Number(event.target.value);
state.rates[state.rule] = value;
if (state.rule === "simple") {
$("#rate-output").textContent = `${formatNumber(value)} units`;
} else {
$("#rate-output").textContent = `${formatNumber(value)}%`;
}
rebuildScene();
updateReadout();
});
$("#opening").addEventListener("input", (event) => {
state.openingCapacity = Number(event.target.value);
$("#opening-output").textContent =
`${formatNumber(state.openingCapacity)} units`;
rebuildScene();
updateReadout();
});
$("#added").addEventListener("input", (event) => {
state.addedCapacity = Number(event.target.value);
$("#added-output").textContent =
`${formatNumber(state.addedCapacity)} units`;
rebuildScene();
updateReadout();
});
$("#horizon").addEventListener("input", (event) => {
state.horizon = Number(event.target.value);
state.year = Math.min(state.year, state.horizon - 1);
$("#horizon-output").textContent = `${state.horizon} years`;
$("#year").max = String(state.horizon - 1);
rebuildScene();
updateReadout();
});
$("#year").addEventListener("input", (event) => {
state.year = Number(event.target.value);
updateReadout();
});
$("#play").addEventListener("click", () => {
state.playing = !state.playing;
$("#play").textContent = state.playing ? "Ⅱ Pause" : "▶ Play";
$("#play").setAttribute("aria-pressed", String(state.playing));
});
$("#camera-reset").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("pointerdown", (event) => {
cameraControls.dragging = true;
cameraControls.previousX = event.clientX;
cameraControls.previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!cameraControls.dragging) {
return;
}
const deltaX = event.clientX - cameraControls.previousX;
const deltaY = event.clientY - cameraControls.previousY;
cameraControls.previousX = event.clientX;
cameraControls.previousY = event.clientY;
cameraControls.yaw -= deltaX * 0.006;
cameraControls.pitch = THREE.MathUtils.clamp(
cameraControls.pitch + deltaY * 0.0045,
0.32,
1.28
);
updateCamera();
});
function stopDragging(event) {
cameraControls.dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraControls.distance = THREE.MathUtils.clamp(
cameraControls.distance + event.deltaY * 0.012,
11,
28
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (tag === "INPUT" || tag === "BUTTON") {
return;
}
if (event.key === "ArrowLeft") {
state.year = Math.max(0, state.year - 1);
updateReadout();
}
if (event.key === "ArrowRight") {
state.year = Math.min(state.horizon - 1, state.year + 1);
updateReadout();
}
if (event.code === "Space") {
event.preventDefault();
$("#play").click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
let previousTime = performance.now();
let playbackAccumulator = 0;
renderer.setAnimationLoop((time) => {
const delta = Math.min(0.1, (time - previousTime) / 1000);
previousTime = time;
if (state.playing) {
playbackAccumulator += delta * 1000;
if (playbackAccumulator >= 850) {
playbackAccumulator = 0;
state.year = (state.year + 1) % state.horizon;
updateReadout();
}
}
renderer.render(scene, camera);
});
// ---------------------------------------------------------------------
// Initialize
// ---------------------------------------------------------------------
$("#demand-output").textContent =
`${formatNumber(state.initialDemand)} units`;
$("#opening-output").textContent =
`${formatNumber(state.openingCapacity)} units`;
$("#added-output").textContent =
`${formatNumber(state.addedCapacity)} units`;
$("#horizon-output").textContent = `${state.horizon} years`;
$("#year").max = String(state.horizon - 1);
updateAll();
rebuildScene();
updateReadout();
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
setTimeout(() => $("#loading").remove(), 350);
});
</script>
</body>
</html>
```