Prompt specification
Build or customize the Three.js 3D scene "Compost input-flow accounting 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: Compost input-flow accounting game
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compost-input-flow-accounting-game-x1048
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Create a simplified material-flow board tracking incoming scraps, decomposition state, and outgoing amendment tokens; users balance declared categories without treating the model as real compost-management guidance.
Working Three.js Starter (compost-input-flow-accounting-game-x1048):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Material Flow — Concept Ledger</title>
<style>
:root {
--ink: #23333a;
--muted: #687579;
--paper: #f4f1e9;
--panel: #fbfaf6;
--line: #d8d7cf;
--orange: #df6c49;
--green: #318b78;
--violet: #7568a8;
--shadow: 0 18px 50px rgba(34, 48, 52, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
header {
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(251, 250, 246, 0.94);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
flex: 0 0 auto;
position: relative;
transform: rotate(-8deg);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 3px 9px 9px 3px;
border-radius: 4px;
background: var(--orange);
transform: skewY(-12deg);
}
.brand-mark::after {
inset: 9px 3px 3px 9px;
background: var(--green);
transform: skewY(12deg);
}
.brand h1 {
margin: 0;
font-size: 16px;
line-height: 1.1;
letter-spacing: 0.04em;
white-space: nowrap;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.header-note {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border: 1px solid #cfd6ce;
border-radius: 999px;
color: #49625a;
background: #edf2ec;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
.header-note::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(49, 139, 120, 0.12);
}
main {
height: calc(100% - 72px);
display: grid;
grid-template-columns: 326px minmax(0, 1fr);
}
aside {
overflow-y: auto;
padding: 25px 23px 28px;
border-right: 1px solid var(--line);
background: var(--panel);
z-index: 5;
scrollbar-width: thin;
scrollbar-color: #c8cbc5 transparent;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h2 {
margin: 0;
font-size: 25px;
line-height: 1.15;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 23px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.total-chip {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 21px;
padding: 6px 9px;
border-radius: 7px;
color: #54615e;
background: #eceee8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.total-chip strong {
color: var(--ink);
font-size: 12px;
}
.category {
margin-bottom: 20px;
padding-bottom: 18px;
border-bottom: 1px solid #e5e4dd;
}
.category:last-of-type {
margin-bottom: 16px;
}
.category-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.category-name {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
transform: rotate(8deg);
}
.category-name strong {
display: block;
font-size: 13px;
line-height: 1.2;
}
.category-name small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
output {
min-width: 44px;
text-align: right;
font-size: 18px;
font-weight: 800;
letter-spacing: -0.03em;
}
input[type="range"] {
--accent: var(--orange);
width: 100%;
height: 5px;
margin: 4px 0 0;
border-radius: 999px;
appearance: none;
background: #dedfd9;
cursor: pointer;
accent-color: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid var(--panel);
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 3px 8px rgba(35, 51, 58, 0.2);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent), 0 3px 8px rgba(35, 51, 58, 0.2);
}
input[type="range"]:focus-visible {
outline: 2px solid var(--ink);
outline-offset: 5px;
}
.card {
margin-top: 16px;
padding: 15px;
border: 1px solid #dedfd7;
border-radius: 12px;
background: #fffefa;
}
.card-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.card-title strong {
font-size: 12px;
letter-spacing: 0.03em;
}
.card-title span {
color: var(--muted);
font-size: 10px;
}
.balance-value {
display: flex;
align-items: baseline;
gap: 7px;
margin-bottom: 10px;
}
.balance-value strong {
font-size: 31px;
line-height: 1;
letter-spacing: -0.05em;
}
.balance-value span {
color: var(--muted);
font-size: 11px;
}
.meter {
height: 8px;
overflow: hidden;
border-radius: 999px;
background: #e4e5df;
}
.meter > div {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), #d6a54b 50%, var(--green));
transition: width 280ms ease;
}
.meter-label {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 8px;
color: var(--muted);
font-size: 10px;
}
.state-row {
display: grid;
grid-template-columns: 78px 1fr 32px;
align-items: center;
gap: 9px;
margin-top: 9px;
font-size: 10px;
}
.state-row > span:first-child {
color: #596664;
font-weight: 700;
}
.state-row > span:last-child {
text-align: right;
font-weight: 800;
}
.state-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: #e6e7e1;
}
.state-track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 250ms ease;
}
.token-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid #e8e7e1;
}
.token-line span {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.token-line strong {
font-size: 20px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 15px;
}
button {
min-height: 42px;
border: 1px solid #cdd1ca;
border-radius: 9px;
color: var(--ink);
background: #f7f6f1;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: #aeb8b0;
background: #fff;
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 2px solid var(--ink);
outline-offset: 2px;
}
button.primary {
border-color: var(--ink);
color: white;
background: var(--ink);
}
button.primary:hover {
background: #34474e;
}
.notice {
position: relative;
margin-top: 19px;
padding: 14px 14px 14px 39px;
border: 1px solid #d7cda9;
border-radius: 11px;
color: #655c3e;
background: #fff9e8;
font-size: 10.5px;
line-height: 1.5;
}
.notice::before {
content: "!";
position: absolute;
top: 13px;
left: 13px;
width: 18px;
height: 18px;
border-radius: 50%;
color: #fff9e8;
background: #a88d43;
text-align: center;
font-size: 12px;
font-weight: 900;
line-height: 18px;
}
.notice strong {
display: block;
margin-bottom: 3px;
color: #554a27;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9e6dd;
}
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.scene-chip {
position: absolute;
top: 20px;
left: 21px;
z-index: 2;
display: flex;
align-items: center;
gap: 9px;
color: #50605e;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.scene-chip::before {
content: "";
width: 8px;
height: 8px;
border: 2px solid var(--green);
transform: rotate(45deg);
}
.scene-warning {
position: absolute;
top: 18px;
right: 18px;
z-index: 2;
padding: 7px 10px;
border: 1px solid rgba(103, 116, 111, 0.28);
border-radius: 999px;
color: #61706c;
background: rgba(248, 247, 241, 0.78);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
}
.legend {
position: absolute;
bottom: 20px;
left: 21px;
z-index: 2;
display: flex;
flex-wrap: wrap;
gap: 15px;
max-width: calc(100% - 42px);
padding: 10px 13px;
border: 1px solid rgba(94, 108, 104, 0.2);
border-radius: 10px;
color: #566460;
background: rgba(248, 247, 241, 0.82);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
transform: rotate(8deg);
}
.camera-hint {
position: absolute;
right: 20px;
bottom: 21px;
z-index: 2;
color: #71807c;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
.tooltip {
position: absolute;
z-index: 4;
max-width: 220px;
padding: 9px 11px;
border: 1px solid rgba(37, 53, 57, 0.18);
border-radius: 8px;
color: white;
background: rgba(35, 51, 58, 0.94);
box-shadow: var(--shadow);
font-size: 10px;
line-height: 1.45;
white-space: pre-line;
opacity: 0;
transform: translate(12px, 12px);
transition: opacity 100ms ease;
pointer-events: none;
}
.toast {
position: absolute;
left: 50%;
bottom: 66px;
z-index: 5;
padding: 9px 13px;
border-radius: 999px;
color: white;
background: rgba(35, 51, 58, 0.92);
box-shadow: var(--shadow);
font-size: 10px;
font-weight: 750;
opacity: 0;
transform: translate(-50%, 8px);
transition:
opacity 180ms ease,
transform 180ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 860px) {
body {
height: auto;
overflow: auto;
}
header {
height: 64px;
padding: 0 15px;
}
.brand p {
display: none;
}
.header-note {
max-width: 165px;
overflow: hidden;
text-overflow: ellipsis;
}
main {
height: auto;
display: flex;
flex-direction: column;
}
#stage {
order: -1;
width: 100%;
height: 56vh;
min-height: 390px;
}
aside {
overflow: visible;
width: 100%;
border-right: 0;
border-top: 1px solid var(--line);
}
.scene-warning {
display: none;
}
.camera-hint {
display: none;
}
}
@media (max-width: 480px) {
.brand h1 {
font-size: 13px;
}
.header-note {
max-width: 120px;
padding: 7px 9px;
font-size: 8px;
}
#stage {
height: 51vh;
min-height: 350px;
}
.legend {
right: 14px;
bottom: 14px;
left: 14px;
gap: 9px;
}
.scene-chip {
top: 14px;
left: 14px;
}
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>MATERIAL FLOW / CONCEPT LEDGER</h1>
<p>Low-poly board 01 · fictional routing system</p>
</div>
</div>
<div class="header-note">Interface model · not compost guidance</div>
</header>
<main>
<aside aria-label="Declared category controls">
<p class="eyebrow">Control deck</p>
<h2>Declared category mix</h2>
<p class="intro">
Redistribute the declared units and watch the toy routing board respond.
The balance meter measures equality only.
</p>
<div class="total-chip">
Declared batch <strong id="totalUnits">100 units</strong>
</div>
<div class="category">
<div class="category-head">
<div class="category-name">
<i class="swatch" style="background:#df6c49"></i>
<div>
<strong>Fibrous-like</strong>
<small>Category A → Fresh-like</small>
</div>
</div>
<output id="valueA" for="mixA">38</output>
</div>
<input id="mixA" type="range" min="0" max="100" value="38" />
</div>
<div class="category">
<div class="category-head">
<div class="category-name">
<i class="swatch" style="background:#318b78"></i>
<div>
<strong>Leafy-like</strong>
<small>Category B → Active-like</small>
</div>
</div>
<output id="valueB" for="mixB">34</output>
</div>
<input id="mixB" type="range" min="0" max="100" value="34" />
</div>
<div class="category">
<div class="category-head">
<div class="category-name">
<i class="swatch" style="background:#7568a8"></i>
<div>
<strong>Structural-like</strong>
<small>Category C → Settled-like</small>
</div>
</div>
<output id="valueC" for="mixC">28</output>
</div>
<input id="mixC" type="range" min="0" max="100" value="28" />
</div>
<section class="card" aria-labelledby="balanceHeading">
<div class="card-title">
<strong id="balanceHeading">Distribution balance</strong>
<span>equality index</span>
</div>
<div class="balance-value">
<strong id="balanceScore">82</strong>
<span>/ 100 · <b id="balanceWord">uneven spread</b></span>
</div>
<div class="meter" aria-hidden="true">
<div id="balanceFill"></div>
</div>
<div class="meter-label">
<span>Uneven</span>
<span>Even</span>
</div>
</section>
<section class="card" aria-labelledby="stateHeading">
<div class="card-title">
<strong id="stateHeading">Illustrative state ledger</strong>
<span>units</span>
</div>
<div class="state-row">
<span>Fresh-like</span>
<div class="state-track"><i id="stateA" style="background:#df6c49"></i></div>
<span id="stateValueA">38</span>
</div>
<div class="state-row">
<span>Active-like</span>
<div class="state-track"><i id="stateB" style="background:#318b78"></i></div>
<span id="stateValueB">34</span>
</div>
<div class="state-row">
<span>Settled-like</span>
<div class="state-track"><i id="stateC" style="background:#7568a8"></i></div>
<span id="stateValueC">28</span>
</div>
<div class="token-line">
<span>Symbolic amendment tokens</span>
<strong id="tokenTotal">50</strong>
</div>
</section>
<div class="button-row">
<button id="balanceButton" class="primary" type="button">Balance declared mix</button>
<button id="resetButton" type="button">Reset mix</button>
</div>
<div class="notice" role="note">
<strong>Conceptual visualization only.</strong>
Categories, decomposition states, routing rules, and token conversion are
invented for this interface. This is not compost-management guidance and
must not be used to choose feedstocks, ratios, timing, or amendments.
</div>
</aside>
<section id="stage" aria-label="Interactive low-poly material flow board">
<div class="scene-chip">Material-flow board / live ledger</div>
<div class="scene-warning">Fictional data model</div>
<div class="legend" aria-hidden="true">
<span><i style="background:#df6c49"></i>Fibrous-like</span>
<span><i style="background:#318b78"></i>Leafy-like</span>
<span><i style="background:#7568a8"></i>Structural-like</span>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom · tap bins to adjust</div>
<div id="tooltip" class="tooltip"></div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
</section>
</main>
<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 tooltip = document.getElementById("tooltip");
const toast = document.getElementById("toast");
const categoryData = [
{
key: "A",
name: "Fibrous-like",
state: "Fresh-like",
color: "#df6c49",
colorHex: 0xdf6c49
},
{
key: "B",
name: "Leafy-like",
state: "Active-like",
color: "#318b78",
colorHex: 0x318b78
},
{
key: "C",
name: "Structural-like",
state: "Settled-like",
color: "#7568a8",
colorHex: 0x7568a8
}
];
let mix = [38, 34, 28];
let tokenTotal = 50;
let toastTimer = 0;
const mixInputs = [
document.getElementById("mixA"),
document.getElementById("mixB"),
document.getElementById("mixC")
];
const valueOutputs = [
document.getElementById("valueA"),
document.getElementById("valueB"),
document.getElementById("valueC")
];
const stateBars = [
document.getElementById("stateA"),
document.getElementById("stateB"),
document.getElementById("stateC")
];
const stateValues = [
document.getElementById("stateValueA"),
document.getElementById("stateValueB"),
document.getElementById("stateValueC")
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e6dd);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly material-flow board. Drag to orbit, scroll to zoom, and select bins to change category units."
);
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x667075, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(3, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xffc89f, 1.15);
rimLight.position.set(-8, 5, -8);
scene.add(rimLight);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
standard(0xe9e6dd, { roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.67;
ground.receiveShadow = true;
scene.add(ground);
function addBox(width, height, depth, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const boardMaterial = standard(0xcfc8b8);
const boardTopMaterial = standard(0xded8ca);
const darkMaterial = standard(0x334348);
const railMaterial = standard(0x65716f);
const creamMaterial = standard(0xf1ede2);
const whiteMaterial = standard(0xfaf7ef);
addBox(16.9, 0.38, 7.25, boardMaterial, 0, -0.45, 0);
addBox(16.65, 0.10, 7.0, boardTopMaterial, 0, -0.21, 0, false);
addBox(16.7, 0.10, 0.10, darkMaterial, 0, -0.15, -3.5, false);
addBox(16.7, 0.10, 0.10, darkMaterial, 0, -0.15, 3.5, false);
addBox(0.10, 0.10, 7.0, darkMaterial, -8.42, -0.15, 0, false);
addBox(0.10, 0.10, 7.0, darkMaterial, 8.42, -0.15, 0, false);
addBox(4.7, 0.075, 6.35, standard(0xdfd9ca), -5.15, -0.115, 0, false);
addBox(4.7, 0.075, 6.35, standard(0xd7ddd4), 0, -0.115, 0, false);
addBox(4.7, 0.075, 6.35, standard(0xe1d9cb), 5.15, -0.115, 0, false);
const rows = [-1.8, 0, 1.8];
const clickables = [];
const incomingScraps = [];
const stateScraps = [];
const tokenMeshes = [];
const incomingLabels = [];
const stateLabels = [];
const outputLabels = [];
const particles = [];
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 createLabel(worldWidth = 2.45) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 144 / 512, 1);
sprite.renderOrder = 10;
scene.add(sprite);
return { sprite, canvas, context, texture };
}
function updateLabel(label, lines) {
const { context, canvas, texture } = label;
const width = canvas.width;
const height = canvas.height;
context.clearRect(0, 0, width, height);
roundedRect(context, 4, 4, width - 8, height - 8, 18);
context.fillStyle = "rgba(250, 248, 239, 0.91)";
context.fill();
context.strokeStyle = "rgba(54, 70, 71, 0.22)";
context.lineWidth = 3;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
lines.forEach((line, index) => {
context.fillStyle = line.color || "#314347";
context.font = `${line.weight || 800} ${line.size || 34}px system-ui, sans-serif`;
context.fillText(
line.text,
width / 2,
index === 0 ? 52 : 101
);
});
texture.needsUpdate = true;
}
const zoneLabels = [
{
label: createLabel(3.65),
x: -5.15,
z: -3.12,
lines: [
{ text: "01 INCOMING", size: 33 },
{ text: "DECLARED SCRAPS", size: 27, color: "#68736f" }
]
},
{
label: createLabel(3.65),
x: 0,
z: -3.12,
lines: [
{ text: "02 STATE", size: 33 },
{ text: "ILLUSTRATIVE DECOMPOSITION", size: 23, color: "#68736f" }
]
},
{
label: createLabel(3.65),
x: 5.15,
z: -3.12,
lines: [
{ text: "03 OUTGOING", size: 33 },
{ text: "AMENDMENT TOKENS", size: 27, color: "#68736f" }
]
}
];
zoneLabels.forEach((item) => {
item.label.sprite.position.set(item.x, 0.48, item.z);
updateLabel(item.label, item.lines);
});
const categoryMaterials = categoryData.map((category) =>
standard(category.colorHex, { roughness: 0.66 })
);
const scrapGeometries = [
new THREE.IcosahedronGeometry(0.17, 0),
new THREE.TetrahedronGeometry(0.2, 0),
new THREE.BoxGeometry(0.23, 0.14, 0.18),
new THREE.OctahedronGeometry(0.16, 0)
];
const tokenGeometry = new THREE.CylinderGeometry(0.115, 0.145, 0.075, 6);
function seededRandom(index, salt) {
const raw = Math.sin(index * 12.9898 + salt * 78.233) * 43758.5453;
return raw - Math.floor(raw);
}
function makeClickable(mesh, categoryIndex) {
mesh.userData.categoryIndex = categoryIndex;
clickables.push(mesh);
}
function buildIncomingBin(categoryIndex, z) {
const x = -5.15;
const material = creamMaterial;
const base = addBox(1.85, 0.12, 1.5, whiteMaterial, x, 0.02, z);
makeClickable(base, categoryIndex);
const back = addBox(1.85, 0.82, 0.10, material, x, 0.44, z - 0.70);
const front = addBox(1.85, 0.34, 0.10, material, x, 0.21, z + 0.70);
const left = addBox(0.10, 0.58, 1.42, material, x - 0.88, 0.33, z);
const right = addBox(0.10, 0.58, 1.42, material, x + 0.88, 0.33, z);
[base, back, front, left, right].forEach((mesh) =>
makeClickable(mesh, categoryIndex)
);
addBox(1.95, 0.07, 0.13, categoryMaterials[categoryIndex], x, 0.87, z - 0.70, false);
addBox(1.95, 0.07, 0.13, categoryMaterials[categoryIndex], x, 0.39, z + 0.70, false);
addBox(0.13, 0.07, 1.50, categoryMaterials[categoryIndex], x - 0.89, 0.64, z, false);
addBox(0.13, 0.07, 1.50, categoryMaterials[categoryIndex], x + 0.89, 0.64, z, false);
const pieces = [];
for (let i = 0; i < 22; i++) {
const geometry = scrapGeometries[i % scrapGeometries.length];
const piece = new THREE.Mesh(geometry, categoryMaterials[categoryIndex]);
const layer = Math.floor(i / 6);
const slot = i % 6;
const col = slot % 3;
const row = Math.floor(slot / 3);
piece.position.set(
x + (col - 1) * 0.43 + (seededRandom(i, 1) - 0.5) * 0.12,
0.23 + layer * 0.14,
z + (row - 0.5) * 0.47 + (seededRandom(i, 2) - 0.5) * 0.12
);
piece.rotation.set(
seededRandom(i, 3) * Math.PI,
seededRandom(i, 4) * Math.PI,
seededRandom(i, 5) * Math.PI
);
const scale = 0.75 + seededRandom(i, 6) * 0.5;
piece.scale.setScalar(scale);
piece.castShadow = true;
piece.receiveShadow = true;
scene.add(piece);
makeClickable(piece, categoryIndex);
pieces.push(piece);
}
incomingScraps.push(pieces);
}
function buildStateChamber(categoryIndex, z) {
const x = 0;
const wallMaterial = standard(categoryData[categoryIndex].colorHex, {
transparent: true,
opacity: 0.19,
side: THREE.DoubleSide,
depthWrite: false,
roughness: 0.45
});
const bottom = new THREE.Mesh(
new THREE.CylinderGeometry(1.04, 1.10, 0.13, 8),
whiteMaterial
);
bottom.position.set(x, 0.01, z);
bottom.castShadow = true;
bottom.receiveShadow = true;
scene.add(bottom);
makeClickable(bottom, categoryIndex);
const wall = new THREE.Mesh(
new THREE.CylinderGeometry(1.02, 1.08, 1.15, 8, 1, true),
wallMaterial
);
wall.position.set(x, 0.56, z);
scene.add(wall);
makeClickable(wall, categoryIndex);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(1.025, 0.055, 4, 8),
categoryMaterials[categoryIndex]
);
rim.rotation.x = Math.PI / 2;
rim.position.set(x, 1.14, z);
rim.castShadow = true;
scene.add(rim);
const pieces = [];
for (let i = 0; i < 22; i++) {
const geometry = scrapGeometries[(i + 1) % scrapGeometries.length];
const piece = new THREE.Mesh(geometry, categoryMaterials[categoryIndex]);
const angle = seededRandom(i, 12) * Math.PI * 2;
const radius = 0.12 + seededRandom(i, 13) * 0.57;
const layer = Math.floor(i / 7);
piece.position.set(
x + Math.cos(angle) * radius,
0.22 + layer * 0.17,
z + Math.sin(angle) * radius
);
piece.rotation.set(
seededRandom(i, 14) * Math.PI,
seededRandom(i, 15) * Math.PI,
seededRandom(i, 16) * Math.PI
);
piece.scale.setScalar(0.72 + seededRandom(i, 17) * 0.45);
piece.castShadow = true;
scene.add(piece);
makeClickable(piece, categoryIndex);
pieces.push(piece);
}
stateScraps.push(pieces);
}
function buildOutput(categoryIndex, z) {
const x = 5.15;
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(1.16, 1.22, 0.16, 8),
whiteMaterial
);
platform.position.set(x, 0.015, z);
platform.castShadow = true;
platform.receiveShadow = true;
scene.add(platform);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.16, 0.055, 4, 8),
categoryMaterials[categoryIndex]
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.11, z);
ring.castShadow = true;
scene.add(ring);
const pieces = [];
for (let i = 0; i < 50; i++) {
const token = new THREE.Mesh(tokenGeometry, categoryMaterials[categoryIndex]);
const layer = Math.floor(i / 5);
const slot = i % 5;
token.position.set(
x + (slot - 2) * 0.28,
0.18 + layer * 0.074,
z
);
token.rotation.y = (slot % 2) * Math.PI / 6;
token.castShadow = true;
token.receiveShadow = true;
scene.add(token);
pieces.push(token);
}
tokenMeshes.push(pieces);
}
function buildTrack(start, end, z, color) {
const length = end - start;
const center = (start + end) / 2;
addBox(length, 0.035, 0.045, railMaterial, center, -0.035, z - 0.38, false);
addBox(length, 0.035, 0.045, railMaterial, center, -0.035, z + 0.38, false);
const dashCount = Math.floor(length / 0.43);
for (let i = 0; i < dashCount; i++) {
const x = start + 0.25 + i * 0.43;
addBox(0.20, 0.035, 0.075, color, x, -0.025, z, false);
}
const arrowGeometry = new THREE.ConeGeometry(0.11, 0.28, 3);
const arrow = new THREE.Mesh(arrowGeometry, color);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(center, 0.015, z);
arrow.scale.set(1, 0.35, 1);
scene.add(arrow);
}
categoryData.forEach((category, index) => {
buildIncomingBin(index, rows[index]);
buildStateChamber(index, rows[index]);
buildOutput(index, rows[index]);
buildTrack(-4.1, -1.2, rows[index], categoryMaterials[index]);
buildTrack(1.2, 4.2, rows[index], categoryMaterials[index]);
const incomingLabel = createLabel(2.65);
incomingLabel.sprite.position.set(-5.15, 1.48, rows[index]);
incomingLabels.push(incomingLabel);
const stateLabel = createLabel(2.45);
stateLabel.sprite.position.set(0, 1.72, rows[index]);
stateLabels.push(stateLabel);
const outputLabel = createLabel(2.45);
outputLabel.sprite.position.set(5.15, 1.48, rows[index]);
outputLabels.push(outputLabel);
for (let p = 0; p < 5; p++) {
const particle = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.105, 0),
categoryMaterials[index]
);
particle.castShadow = true;
scene.add(particle);
particles.push({
mesh: particle,
categoryIndex: index,
offset: p / 5 + index * 0.117
});
}
});
function distributeRemainder(total, firstOld, secondOld) {
const oldSum = firstOld + secondOld;
if (oldSum === 0) {
const first = Math.round(total / 2);
return [first, total - first];
}
let first = Math.round(total * firstOld / oldSum);
first = THREE.MathUtils.clamp(first, 0, total);
return [first, total - first];
}
function updateSceneState() {
categoryData.forEach((category, index) => {
const value = mix[index];
const visibleScraps = Math.max(1, Math.ceil(value / 100 * 22));
const visibleTokens = Math.max(0, Math.ceil(value / 2));
incomingScraps[index].forEach((piece, pieceIndex) => {
piece.visible = pieceIndex < visibleScraps;
});
stateScraps[index].forEach((piece, pieceIndex) => {
piece.visible = pieceIndex < visibleScraps;
});
tokenMeshes[index].forEach((token, tokenIndex) => {
token.visible = tokenIndex < visibleTokens;
});
updateLabel(incomingLabels[index], [
{ text: `${category.key} · ${category.name.toUpperCase()}`, size: 31 },
{ text: `${value} UNITS → ${category.state.toUpperCase()}`, size: 24, color: "#68736f" }
]);
updateLabel(stateLabels[index], [
{ text: category.state.toUpperCase(), size: 32 },
{ text: `${value} ILLUSTRATIVE UNITS`, size: 23, color: "#68736f" }
]);
updateLabel(outputLabels[index], [
{ text: `${category.key} · OUTGOING`, size: 31 },
{ text: `${visibleTokens} SYMBOLIC TOKENS`, size: 24, color: "#68736f" }
]);
});
}
function updateUI() {
const deviation = mix.reduce(
(sum, value) => sum + Math.abs(value - 100 / 3),
0
);
const balanceScore = Math.max(0, Math.round(100 - deviation * 0.75));
const balanceWord =
balanceScore >= 94 ? "even spread" :
balanceScore >= 72 ? "mildly uneven" :
"uneven spread";
document.getElementById("balanceScore").textContent = balanceScore;
document.getElementById("balanceWord").textContent = balanceWord;
document.getElementById("balanceFill").style.width = `${balanceScore}%`;
document.getElementById("totalUnits").textContent = "100 units";
tokenTotal = mix.reduce((sum, value) => sum + Math.ceil(value / 2), 0);
document.getElementById("tokenTotal").textContent = tokenTotal;
mixInputs.forEach((input, index) => {
input.value = mix[index];
input.style.setProperty("--accent", categoryData[index].color);
input.setAttribute("aria-valuetext", `${mix[index]} declared units`);
valueOutputs[index].textContent = mix[index];
stateBars[index].style.width = `${mix[index]}%`;
stateValues[index].textContent = mix[index];
});
updateSceneState();
}
function applyMix(values) {
mix = values.map((value) => Math.round(value));
const correction = 100 - mix.reduce((sum, value) => sum + value, 0);
mix[mix.length - 1] += correction;
updateUI();
}
function changeCategory(index, newValue) {
const others = [0, 1, 2].filter((item) => item !== index);
const remaining = 100 - newValue;
const distributed = distributeRemainder(
remaining,
mix[others[0]],
mix[others[1]]
);
const next = [...mix];
next[index] = newValue;
next[others[0]] = distributed[0];
next[others[1]] = distributed[1];
applyMix(next);
}
function adjustCategory(index, delta) {
const nextValue = THREE.MathUtils.clamp(mix[index] + delta, 0, 100);
changeCategory(index, nextValue);
showToast(
`${categoryData[index].name}: ${nextValue} units · equality changed`
);
}
mixInputs.forEach((input, index) => {
input.addEventListener("input", () => {
changeCategory(index, Number(input.value));
});
});
document.getElementById("balanceButton").addEventListener("click", () => {
applyMix([34, 33, 33]);
showToast("Declared categories evenized in the toy ledger");
});
document.getElementById("resetButton").addEventListener("click", () => {
applyMix([38, 34, 28]);
showToast("Declared mix reset");
});
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 1800);
}
// Direct camera controls: no external control addon is used.
const target = new THREE.Vector3(0, 0.15, 0);
let yaw = 0.32;
let pitch = 0.92;
let zoom = 1;
let dragging = false;
let moved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const radius = 22;
const sinPitch = Math.sin(pitch);
camera.position.set(
target.x + radius * sinPitch * Math.sin(yaw),
target.y + radius * Math.cos(pitch),
target.z + radius * sinPitch * Math.cos(yaw)
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = Math.max(stage.clientWidth, 1);
const height = Math.max(stage.clientHeight, 1);
const aspect = width / height;
const viewHeight = Math.max(10.4, 18.6 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pointerToNDC(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 pickCategory(event) {
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickables, false);
return hits.length ? hits[0].object.userData.categoryIndex : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
moved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
tooltip.style.opacity = 0;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 4) {
moved = true;
}
yaw -= dx * 0.005;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.004, 0.42, 1.25);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
return;
}
if (event.pointerType !== "mouse") return;
const categoryIndex = pickCategory(event);
if (categoryIndex === null) {
tooltip.style.opacity = 0;
renderer.domElement.style.cursor = "grab";
return;
}
const rect = stage.getBoundingClientRect();
const category = categoryData[categoryIndex];
tooltip.textContent =
`${category.name} · ${mix[categoryIndex]} units\n` +
`Click: +2 · Shift-click: −2`;
tooltip.style.left = `${event.clientX - rect.left}px`;
tooltip.style.top = `${event.clientY - rect.top}px`;
tooltip.style.opacity = 1;
renderer.domElement.style.cursor = "pointer";
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!moved) {
const categoryIndex = pickCategory(event);
if (categoryIndex !== null) {
adjustCategory(categoryIndex, event.shiftKey ? -2 : 2);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
moved = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
tooltip.style.opacity = 0;
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.45
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
yaw = 0.32;
pitch = 0.92;
zoom = 1;
updateCamera();
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
particles.forEach((particle) => {
const t = (elapsed * 0.105 + particle.offset) % 1;
const z = rows[particle.categoryIndex];
let x;
let y;
if (t < 0.38) {
const u = t / 0.38;
x = THREE.MathUtils.lerp(-4.1, -1.12, u);
y = 0.48 + Math.sin(u * Math.PI) * 0.38;
} else if (t < 0.52) {
const u = (t - 0.38) / 0.14;
x = -0.48 + Math.sin(u * Math.PI * 2) * 0.25;
y = 0.58 + Math.sin(u * Math.PI) * 0.11;
} else {
const u = (t - 0.52) / 0.48;
x = THREE.MathUtils.lerp(-1.12, 4.68, u);
y = 0.5 + Math.sin(u * Math.PI) * 0.24;
}
particle.mesh.position.set(
x,
y,
z + Math.sin(elapsed * 2 + particle.offset * 9) * 0.05
);
particle.mesh.rotation.x = elapsed * 1.8 + particle.offset;
particle.mesh.rotation.y = elapsed * 2.3 + particle.offset;
});
renderer.render(scene, camera);
}
updateUI();
animate();
</script>
</body>
</html>
```