Prompt specification
Build or customize the Three.js 3D scene "Factory assembly and chemistry analogy gallery" 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: Factory assembly and chemistry analogy gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/factory-assembly-and-chemistry-analogy-gallery-x1999
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows stoichiometry and limiting reactants. Compose toy-part assembly beside molecular bookkeeping using the same ratio logic; explain the analogy while distinguishing chemical transformation from physically snapping manufactured parts together. Voxel style.
Working Three.js Starter (factory-assembly-and-chemistry-analogy-gallery-x1999):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Same Ratio, Different Meaning — Limiting Reactants</title>
<style>
:root {
--bg: #08101a;
--panel: #101b29;
--panel-2: #152337;
--line: #2b3c53;
--text: #f3f7fb;
--muted: #9eb0c4;
--cyan: #59d9ff;
--lime: #b8f35b;
--gold: #ffc857;
--blue: #5684ff;
--danger: #ff7a7a;
--shadow: 6px 6px 0 #03070d;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
margin: 0;
min-height: 100vh;
color: var(--text);
background:
linear-gradient(rgba(89, 217, 255, .035) 1px, transparent 1px),
linear-gradient(90deg, rgba(89, 217, 255, .035) 1px, transparent 1px),
var(--bg);
background-size: 32px 32px;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
.app {
width: min(1480px, calc(100% - 32px));
margin: 0 auto;
padding: 34px 0 48px;
}
.masthead {
display: grid;
grid-template-columns: 1fr auto;
gap: 28px;
align-items: end;
margin-bottom: 24px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 8px;
background: var(--cyan);
box-shadow: 4px 4px 0 #1c6d87;
}
h1 {
max-width: 900px;
margin: 0;
font-size: clamp(38px, 5vw, 72px);
line-height: .96;
letter-spacing: -.055em;
}
h1 span { color: var(--lime); }
.lede {
max-width: 760px;
margin: 18px 0 0;
color: var(--muted);
font-size: clamp(15px, 1.5vw, 18px);
line-height: 1.6;
}
.masthead-badge {
min-width: 230px;
padding: 17px 18px;
border: 2px solid var(--line);
background: var(--panel);
box-shadow: var(--shadow);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
line-height: 1.7;
text-transform: uppercase;
letter-spacing: .08em;
}
.masthead-badge b {
display: block;
margin-bottom: 5px;
color: var(--cyan);
font-size: 16px;
}
.lab-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
gap: 20px;
align-items: stretch;
}
.stage {
position: relative;
min-height: 660px;
overflow: hidden;
border: 2px solid var(--line);
background: #0a121e;
box-shadow: var(--shadow);
isolation: isolate;
}
.stage::after {
content: "";
position: absolute;
inset: 0;
pointer-events: none;
background:
linear-gradient(90deg, rgba(5, 10, 17, .55), transparent 14%, transparent 86%, rgba(5, 10, 17, .55)),
linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
background-size: auto, 20px 20px, 20px 20px;
mix-blend-mode: screen;
z-index: 2;
}
#three-canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
z-index: 1;
}
#three-canvas:active { cursor: grabbing; }
.stage-divider {
position: absolute;
z-index: 3;
top: 14%;
bottom: 14%;
left: 50%;
width: 1px;
background: linear-gradient(transparent, #344b64 15%, #344b64 85%, transparent);
pointer-events: none;
}
.stage-divider::before,
.stage-divider::after {
content: "";
position: absolute;
left: -4px;
width: 9px;
height: 9px;
background: var(--cyan);
box-shadow: 0 0 0 2px #0a121e;
}
.stage-divider::before { top: 0; }
.stage-divider::after { bottom: 0; }
.scene-label {
position: absolute;
z-index: 5;
width: 218px;
padding: 12px 13px 11px;
border: 1px solid #3a4d65;
border-left: 5px solid var(--cyan);
background: rgba(9, 17, 28, .92);
box-shadow: 4px 4px 0 rgba(0, 0, 0, .45);
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(7px);
}
.scene-label.molecule { border-left-color: var(--lime); }
.scene-label .label-top {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 5px;
color: var(--muted);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .11em;
text-transform: uppercase;
}
.scene-label .label-top i {
display: grid;
width: 21px;
height: 21px;
place-items: center;
color: #07101a;
background: var(--cyan);
font-style: normal;
}
.scene-label.molecule .label-top i { background: var(--lime); }
.scene-label strong {
display: block;
margin-bottom: 5px;
font-size: 15px;
letter-spacing: -.01em;
}
.scene-label small {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.stage-hint {
position: absolute;
z-index: 5;
top: 14px;
left: 15px;
padding: 8px 10px;
border: 1px solid #2c3e54;
color: #8ea2b8;
background: rgba(9, 17, 28, .8);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .08em;
text-transform: uppercase;
pointer-events: none;
}
.stage-tools {
position: absolute;
z-index: 6;
top: 14px;
right: 14px;
display: flex;
gap: 6px;
}
.icon-button {
border: 1px solid #3a4d65;
background: #101c2c;
padding: 8px 10px;
color: #c8d5e3;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .06em;
text-transform: uppercase;
}
.icon-button:hover {
color: #07101a;
background: var(--cyan);
border-color: var(--cyan);
}
.stage-readout {
position: absolute;
z-index: 5;
left: 50%;
bottom: 16px;
width: min(660px, calc(100% - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 12px;
padding: 12px 14px;
border: 1px solid #344a63;
background: rgba(8, 16, 26, .94);
box-shadow: 4px 4px 0 rgba(0, 0, 0, .5);
pointer-events: none;
}
.readout-side {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
font: 800 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.readout-side b { color: var(--gold); }
.readout-side.molecule b { color: var(--lime); }
.ratio-plus {
color: #72879d;
font: 900 16px/1 ui-monospace, monospace;
}
.stage-status {
position: absolute;
z-index: 5;
left: 14px;
bottom: 92px;
max-width: calc(100% - 28px);
padding: 8px 10px;
color: var(--cyan);
border-left: 3px solid var(--cyan);
background: rgba(7, 14, 23, .82);
font: 700 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
.control-panel {
display: flex;
flex-direction: column;
gap: 14px;
padding: 20px;
border: 2px solid var(--line);
background: var(--panel);
box-shadow: var(--shadow);
}
.panel-kicker {
color: var(--cyan);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .12em;
text-transform: uppercase;
}
.panel-title {
margin: 5px 0 0;
font-size: 25px;
line-height: 1.05;
letter-spacing: -.035em;
}
.equation-card {
padding: 15px;
border: 1px solid #38506a;
background:
linear-gradient(135deg, rgba(89, 217, 255, .08), transparent),
#0b1522;
}
.equation {
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
white-space: nowrap;
font-size: 25px;
font-weight: 800;
}
.coefficient {
align-self: flex-start;
margin-top: -5px;
color: var(--lime);
font: 900 12px/1 ui-monospace, monospace;
}
.equation-arrow { color: var(--cyan); }
.equation-note {
margin-top: 8px;
color: var(--muted);
text-align: center;
font: 600 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: .04em;
text-transform: uppercase;
}
.control-block {
padding-top: 2px;
}
.range-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 13px;
font-weight: 800;
}
.range-title output {
min-width: 58px;
padding: 4px 7px;
color: #07101a;
background: var(--cyan);
text-align: center;
font: 900 12px/1 ui-monospace, monospace;
}
.range-title.output-gold output { background: var(--gold); }
input[type="range"] {
--pct: 50%;
width: 100%;
height: 10px;
margin: 0;
border: 0;
border-radius: 0;
appearance: none;
background: linear-gradient(to right, var(--cyan) 0 var(--pct), #2a3a50 var(--pct) 100%);
cursor: pointer;
}
input[type="range"].gold {
background: linear-gradient(to right, var(--gold) 0 var(--pct), #2a3a50 var(--pct) 100%);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 22px;
border: 3px solid #07101a;
border-radius: 0;
appearance: none;
background: #f7fbff;
box-shadow: 3px 3px 0 #020509;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 18px;
border: 3px solid #07101a;
border-radius: 0;
background: #f7fbff;
box-shadow: 3px 3px 0 #020509;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #71869c;
font: 700 9px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.preset-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.preset {
min-height: 46px;
padding: 7px 5px;
border: 1px solid #344960;
background: #142235;
color: #aebed0;
font: 750 9px/1.25 ui-monospace, monospace;
text-transform: uppercase;
}
.preset:hover,
.preset.active {
border-color: var(--cyan);
color: #07101a;
background: var(--cyan);
}
.run-button {
position: relative;
width: 100%;
min-height: 50px;
border: 0;
background: var(--lime);
color: #07101a;
box-shadow: 4px 4px 0 #385323;
font: 900 13px/1 ui-monospace, monospace;
letter-spacing: .06em;
text-transform: uppercase;
}
.run-button:hover { transform: translate(-1px, -1px); }
.run-button:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 #385323; }
.run-button:disabled { opacity: .72; cursor: wait; }
.progress {
height: 7px;
margin-top: -4px;
overflow: hidden;
background: #23344a;
}
.progress > div {
width: 0;
height: 100%;
background: var(--lime);
transition: width .08s linear;
}
.result-card {
padding: 13px;
border: 1px solid #38506a;
background: #0c1725;
}
.limit-badge {
display: inline-flex;
align-items: center;
padding: 6px 8px;
color: #07101a;
background: var(--gold);
font: 900 11px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.limit-badge.lime { background: var(--lime); }
.limit-badge.blue { background: var(--cyan); }
.result-main {
margin: 10px 0 5px;
font-size: 20px;
font-weight: 850;
letter-spacing: -.025em;
}
.result-detail,
.leftover-detail {
color: var(--muted);
font-size: 12px;
line-height: 1.48;
}
.leftover-detail { margin-top: 7px; color: #c1cfdd; }
.ledger {
border-top: 1px solid var(--line);
padding-top: 13px;
}
.ledger-title {
margin-bottom: 9px;
font: 850 11px/1 ui-monospace, monospace;
letter-spacing: .08em;
text-transform: uppercase;
}
table {
width: 100%;
border-collapse: collapse;
font: 700 11px/1 ui-monospace, monospace;
}
th, td {
padding: 7px 5px;
border-bottom: 1px solid #26384e;
text-align: right;
}
th:first-child, td:first-child { text-align: left; }
th { color: #7f94aa; font-size: 9px; text-transform: uppercase; }
td:first-child { color: var(--cyan); }
.balanced { color: var(--lime); }
.ledger-note {
margin: 8px 0 0;
color: #8196ab;
font-size: 10px;
line-height: 1.45;
}
.takeaway {
margin-top: 24px;
border: 2px solid var(--line);
background: var(--panel);
box-shadow: var(--shadow);
}
.takeaway-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 16px 20px;
border-bottom: 1px solid var(--line);
background: #0c1623;
}
.takeaway-header strong {
font: 900 12px/1 ui-monospace, monospace;
letter-spacing: .1em;
text-transform: uppercase;
}
.takeaway-header span {
color: var(--muted);
font-size: 12px;
}
.shared-logic {
display: grid;
grid-template-columns: repeat(3, 1fr);
border-bottom: 1px solid var(--line);
}
.logic-step {
position: relative;
padding: 18px 20px;
border-right: 1px solid var(--line);
}
.logic-step:last-child { border-right: 0; }
.logic-step b {
display: block;
margin-bottom: 5px;
color: var(--cyan);
font: 900 11px/1 ui-monospace, monospace;
}
.logic-step span {
color: #c6d3df;
font-size: 13px;
line-height: 1.4;
}
.distinction-grid {
display: grid;
grid-template-columns: 1fr 1fr;
}
.distinction {
padding: 22px;
border-right: 1px solid var(--line);
}
.distinction:last-child { border-right: 0; }
.distinction-tag {
display: inline-block;
margin-bottom: 10px;
padding: 5px 7px;
color: #07101a;
background: var(--gold);
font: 900 10px/1 ui-monospace, monospace;
letter-spacing: .06em;
text-transform: uppercase;
}
.distinction.chemistry .distinction-tag { background: var(--lime); }
.distinction h2 {
margin: 0 0 10px;
font-size: 22px;
letter-spacing: -.025em;
}
.distinction p {
margin: 0 0 11px;
color: #aebed0;
font-size: 14px;
line-height: 1.55;
}
.distinction .mini-equation {
margin: 14px 0;
padding: 11px 12px;
border-left: 4px solid var(--gold);
background: #0b1522;
font: 900 14px/1.4 ui-monospace, monospace;
}
.chemistry .mini-equation { border-left-color: var(--lime); }
.distinction ul {
margin: 0;
padding: 0;
list-style: none;
}
.distinction li {
position: relative;
margin: 7px 0;
padding-left: 18px;
color: #c6d3df;
font-size: 13px;
line-height: 1.45;
}
.distinction li::before {
content: "";
position: absolute;
left: 0;
top: .55em;
width: 7px;
height: 7px;
background: var(--gold);
}
.chemistry li::before { background: var(--lime); }
.final-note {
margin: 0;
padding: 14px 20px;
border-top: 1px solid var(--line);
color: #93a7bb;
background: #0b1522;
font-size: 12px;
line-height: 1.55;
}
.final-note b { color: var(--text); }
@media (max-width: 1100px) {
.lab-grid { grid-template-columns: 1fr; }
.control-panel {
display: grid;
grid-template-columns: 1fr 1fr;
align-items: start;
}
.control-panel > .panel-heading,
.control-panel > .ledger { grid-column: 1 / -1; }
.stage { min-height: 650px; }
}
@media (max-width: 720px) {
.app { width: min(100% - 20px, 1480px); padding-top: 22px; }
.masthead { grid-template-columns: 1fr; }
.masthead-badge { min-width: 0; }
.stage { min-height: 760px; }
.stage-divider { display: none; }
.scene-label { width: 190px; }
.scene-label strong { font-size: 13px; }
.scene-label small { font-size: 10px; }
.stage-readout { grid-template-columns: 1fr; gap: 5px; }
.ratio-plus { display: none; }
.control-panel { display: flex; }
.shared-logic { grid-template-columns: 1fr; }
.logic-step { border-right: 0; border-bottom: 1px solid var(--line); }
.logic-step:last-child { border-bottom: 0; }
.distinction-grid { grid-template-columns: 1fr; }
.distinction { border-right: 0; border-bottom: 1px solid var(--line); }
.distinction:last-child { border-bottom: 0; }
.takeaway-header { align-items: flex-start; flex-direction: column; }
.stage-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
* { scroll-behavior: auto !important; }
.run-button, .progress > div { transition: none; }
}
</style>
</head>
<body>
<main class="app">
<header class="masthead">
<div>
<div class="eyebrow">Visual chemistry / Stoichiometry 01</div>
<h1>Same ratio.<br><span>Different meaning.</span></h1>
<p class="lede">
Build a manufactured toy kit beside a balanced molecular reaction.
The arithmetic is the same, but a chemical reaction is not the physical
act of snapping toy pieces together.
</p>
</div>
<aside class="masthead-badge">
<b>Interactive voxel model</b>
N₂ + 3 H₂ → 2 NH₃<br>
Change inventory → find the limit
</aside>
</header>
<section class="lab-grid">
<div class="stage" id="stage" aria-label="Interactive 3D comparison of toy assembly and molecular bookkeeping">
<div class="stage-hint">Drag to orbit · Scroll to zoom</div>
<div class="stage-tools">
<button class="icon-button" id="top-view" type="button">Top</button>
<button class="icon-button" id="reset-view" type="button">Reset</button>
</div>
<div class="stage-divider" aria-hidden="true"></div>
<div class="scene-label" id="toy-label">
<div class="label-top"><i>A</i> Manufactured analogy</div>
<strong>Count toy-part kits</strong>
<small>1 chassis + 3 tabs makes 1 kit.</small>
</div>
<div class="scene-label molecule" id="molecule-label">
<div class="label-top"><i>B</i> Chemical bookkeeping</div>
<strong>Count whole molecules</strong>
<small>1 N₂ + 3 H₂ makes 2 NH₃.</small>
</div>
<div class="stage-status" id="stage-status">Ready · whole ratio groups are available</div>
<div class="stage-readout">
<div class="readout-side"><b>1</b> chassis + <b>3</b> tabs → 1 kit</div>
<div class="ratio-plus">≡</div>
<div class="readout-side molecule"><b>1</b> N₂ + <b>3</b> H₂ → 2 NH₃</div>
</div>
</div>
<aside class="control-panel">
<div class="panel-heading">
<div class="panel-kicker">Inventory controls</div>
<h2 class="panel-title">Set the starting stock</h2>
</div>
<div class="equation-card">
<div class="equation" aria-label="Nitrogen plus three hydrogen equals two ammonia">
<span class="coefficient">1</span><span>N₂</span>
<span>+</span>
<span class="coefficient">3</span><span>H₂</span>
<span class="equation-arrow">→</span>
<span class="coefficient">2</span><span>NH₃</span>
</div>
<div class="equation-note">Balanced atom count · whole-molecule batches</div>
</div>
<div class="control-block">
<label class="range-title" for="nitrogen">
Nitrogen molecules, N₂
<output id="nitrogen-value" for="nitrogen">4</output>
</label>
<input id="nitrogen" type="range" min="1" max="6" step="1" value="4">
<div class="range-ends"><span>1 molecule</span><span>6 molecules</span></div>
</div>
<div class="control-block">
<label class="range-title output-gold" for="hydrogen">
Hydrogen molecules, H₂
<output id="hydrogen-value" for="hydrogen">10</output>
</label>
<input class="gold" id="hydrogen" type="range" min="3" max="18" step="1" value="10">
<div class="range-ends"><span>3 molecules</span><span>18 molecules</span></div>
</div>
<div class="control-block">
<div class="panel-kicker" style="margin-bottom:8px">Try an inventory</div>
<div class="preset-row">
<button class="preset" type="button" data-n="4" data-h="12">Exact<br>ratio</button>
<button class="preset" type="button" data-n="2" data-h="12">N₂<br>limited</button>
<button class="preset active" type="button" data-n="4" data-h="10">H₂<br>limited</button>
</div>
</div>
<button class="run-button" id="run" type="button">▶ Assemble & account</button>
<div class="progress" aria-hidden="true"><div id="progress-fill"></div></div>
<div class="result-card">
<div class="limit-badge" id="limit-badge">H₂ is limiting</div>
<div class="result-main" id="result-main">3 batches → 6 NH₃</div>
<div class="result-detail" id="result-detail"></div>
<div class="leftover-detail" id="leftover-detail"></div>
</div>
<div class="ledger">
<div class="ledger-title">Atom ledger for the planned reaction</div>
<table>
<thead>
<tr>
<th>Atom</th>
<th>Start</th>
<th>Product</th>
<th>Left</th>
</tr>
</thead>
<tbody>
<tr>
<td>N</td>
<td id="n-start">8</td>
<td id="n-product">6</td>
<td id="n-left">2</td>
</tr>
<tr>
<td>H</td>
<td id="h-start">20</td>
<td id="h-product">18</td>
<td id="h-left">2</td>
</tr>
</tbody>
</table>
<p class="ledger-note">
N₂ has 2 N atoms; H₂ has 2 H atoms; each NH₃ has 1 N and 3 H atoms.
Every row balances.
</p>
</div>
</aside>
</section>
<section class="takeaway" aria-labelledby="takeaway-title">
<div class="takeaway-header">
<strong id="takeaway-title">One ratio / two interpretations</strong>
<span>The shared rule finds the limit; the science determines what the symbols mean.</span>
</div>
<div class="shared-logic">
<div class="logic-step">
<b>01 / READ THE RATIO</b>
<span>One nitrogen unit requires three hydrogen units for each complete batch.</span>
</div>
<div class="logic-step">
<b>02 / COUNT BATCHES</b>
<span>Only whole groups count: min(N₂ available, floor(H₂ available ÷ 3)).</span>
</div>
<div class="logic-step">
<b>03 / FIND THE LIMIT</b>
<span>The inventory that runs out first determines how much product can form.</span>
</div>
</div>
<div class="distinction-grid">
<article class="distinction">
<span class="distinction-tag">Toy analogy · physical joining</span>
<h2>Parts retain their identity.</h2>
<div class="mini-equation">1 chassis + 3 tabs → 1 manufactured kit</div>
<p>
A toy assembly is a physical operation: separate manufactured pieces are
positioned and attached. The chassis and tabs remain the same objects.
</p>
<ul>
<li>“Snapping” together describes a real mechanical assembly.</li>
<li>The toy is a model of counting groups and inventory.</li>
<li>No chemical bond is represented by a toy snap.</li>
</ul>
</article>
<article class="distinction chemistry">
<span class="distinction-tag">Chemistry · atomic rearrangement</span>
<h2>Reactants become new molecules.</h2>
<div class="mini-equation">1 N₂ + 3 H₂ → 2 NH₃</div>
<p>
In a chemical reaction, existing bonds break or change while new bonds form.
Atoms are conserved, but their molecular arrangement is different.
</p>
<ul>
<li>Reactant molecules are consumed as products form.</li>
<li>The product is not made by attaching pre-existing toy tabs.</li>
<li>The animation is bookkeeping—not a molecular mechanism.</li>
</ul>
</article>
</div>
<p class="final-note">
<b>Bottom line:</b> both sides use the same ratio logic to answer
“How many complete groups can this inventory support?” Only the molecular side
describes a chemical transformation. The toy side helps us inspect the
stoichiometric arithmetic without pretending that chemistry is physical snapping.
</p>
</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 nitrogenInput = document.getElementById("nitrogen");
const hydrogenInput = document.getElementById("hydrogen");
const nitrogenValue = document.getElementById("nitrogen-value");
const hydrogenValue = document.getElementById("hydrogen-value");
const runButton = document.getElementById("run");
const progressFill = document.getElementById("progress-fill");
const stageStatus = document.getElementById("stage-status");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a121e);
scene.fog = new THREE.Fog(0x0a121e, 20, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
} catch (error) {
stage.innerHTML = "<p style='padding:2rem;color:#fff'>This interactive model requires WebGL.</p>";
throw error;
}
renderer.domElement.id = "three-canvas";
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.prepend(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xcce8ff, 0x172033, 2.25);
scene.add(ambient);
const key = new THREE.DirectionalLight(0xffffff, 3.2);
key.position.set(7, 13, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -16;
key.shadow.camera.right = 16;
key.shadow.camera.top = 13;
key.shadow.camera.bottom = -13;
key.shadow.camera.near = 1;
key.shadow.camera.far = 40;
key.shadow.bias = -0.0005;
scene.add(key);
const cyanLight = new THREE.PointLight(0x42cfff, 28, 24, 2);
cyanLight.position.set(-8, 4, 5);
scene.add(cyanLight);
const limeLight = new THREE.PointLight(0xb8f35b, 24, 22, 2);
limeLight.position.set(9, 3, 4);
scene.add(limeLight);
const COLORS = {
blue: 0x5684ff,
gold: 0xffc857,
cyan: 0x59d9ff,
lime: 0xb8f35b,
dark: 0x142238,
ink: 0x07101a,
platform: 0x101d2d,
white: 0xdbe8f3
};
const materialCache = new Map();
const edgeMaterial = new THREE.LineBasicMaterial({
color: COLORS.ink,
transparent: true,
opacity: 0.86
});
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
flatShading: true
}));
}
return materialCache.get(color);
}
function outlinedBox(width, height, depth, color) {
const group = new THREE.Group();
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, material(color));
mesh.castShadow = true;
mesh.receiveShadow = true;
const edges = new THREE.LineSegments(new THREE.EdgesGeometry(geometry), edgeMaterial);
group.add(mesh, edges);
return group;
}
function createPlatform(parent, accent) {
const platform = outlinedBox(7.25, 0.18, 5.75, COLORS.platform);
platform.position.y = -0.88;
parent.add(platform);
const grid = new THREE.GridHelper(6.7, 14, accent, 0x26384c);
grid.position.y = -0.78;
grid.material.transparent = true;
grid.material.opacity = 0.42;
parent.add(grid);
const rail = outlinedBox(6.7, 0.12, 0.13, accent);
rail.position.set(0, -0.72, -2.62);
parent.add(rail);
const sideRailA = outlinedBox(0.1, 0.1, 4.9, 0x26384c);
sideRailA.position.set(-3.42, -0.73, 0);
parent.add(sideRailA);
const sideRailB = sideRailA.clone();
sideRailB.position.x = 3.42;
parent.add(sideRailB);
}
function createChassis(scale = 1) {
const group = new THREE.Group();
const body = outlinedBox(0.72 * scale, 0.5 * scale, 0.72 * scale, COLORS.blue);
group.add(body);
const slot = outlinedBox(0.38 * scale, 0.035 * scale, 0.18 * scale, COLORS.dark);
slot.position.y = 0.255 * scale;
group.add(slot);
return group;
}
function createTab() {
const group = new THREE.Group();
const body = outlinedBox(0.31, 0.22, 0.31, COLORS.gold);
group.add(body);
const notch = outlinedBox(0.13, 0.025, 0.08, 0xb77818);
notch.position.y = 0.115;
group.add(notch);
return group;
}
function createN2() {
const group = new THREE.Group();
const a = outlinedBox(0.4, 0.4, 0.4, COLORS.blue);
const b = outlinedBox(0.4, 0.4, 0.4, COLORS.blue);
a.position.x = -0.25;
b.position.x = 0.25;
const bond = outlinedBox(0.18, 0.1, 0.1, COLORS.white);
group.add(a, b, bond);
return group;
}
function createH2() {
const group = new THREE.Group();
const a = outlinedBox(0.34, 0.34, 0.34, COLORS.gold);
const b = outlinedBox(0.34, 0.34, 0.34, COLORS.gold);
a.position.x = -0.21;
b.position.x = 0.21;
const bond = outlinedBox(0.14, 0.08, 0.08, 0xfff0c2);
group.add(a, b, bond);
return group;
}
function createToyProduct() {
const group = new THREE.Group();
const body = outlinedBox(0.86, 0.86, 0.86, COLORS.blue);
group.add(body);
const slot = outlinedBox(0.42, 0.035, 0.2, COLORS.dark);
slot.position.y = 0.44;
group.add(slot);
const targets = [
new THREE.Vector3(0, 0.55, 0),
new THREE.Vector3(-0.59, 0, 0),
new THREE.Vector3(0.59, 0, 0)
];
const starts = [
new THREE.Vector3(0, 1.8, 0.2),
new THREE.Vector3(-1.8, 1.35, 0.1),
new THREE.Vector3(1.8, 1.35, -0.1)
];
const tabs = targets.map((target, index) => {
const tab = createTab();
tab.position.copy(starts[index]);
tab.visible = false;
group.add(tab);
return { mesh: tab, target, start: starts[index] };
});
group.userData = { body, tabs };
group.visible = false;
return group;
}
function createNH3Product() {
const group = new THREE.Group();
const body = outlinedBox(0.47, 0.47, 0.47, COLORS.blue);
group.add(body);
const targets = [
new THREE.Vector3(0, 0.65, 0),
new THREE.Vector3(-0.64, -0.27, 0.22),
new THREE.Vector3(0.64, -0.27, 0.22)
];
const starts = [
new THREE.Vector3(0, 1.8, 0.1),
new THREE.Vector3(-1.7, 1.2, 0.2),
new THREE.Vector3(1.7, 1.2, -0.2)
];
const hydrogens = targets.map((target, index) => {
const atom = outlinedBox(0.29, 0.29, 0.29, COLORS.gold);
atom.position.copy(starts[index]);
atom.visible = false;
group.add(atom);
return { mesh: atom, target, start: starts[index] };
});
group.userData = { body, hydrogens };
group.visible = false;
return group;
}
const toyGroup = new THREE.Group();
const moleculeGroup = new THREE.Group();
scene.add(toyGroup, moleculeGroup);
createPlatform(toyGroup, COLORS.cyan);
createPlatform(moleculeGroup, COLORS.lime);
const toyChassis = [];
const toyTabs = [];
const nitrogenTokens = [];
const hydrogenTokens = [];
const toyProducts = [];
const ammoniaProducts = [];
for (let i = 0; i < 6; i++) {
const chassis = createChassis();
chassis.position.set(
-2.15 + (i % 2) * 0.95,
-0.45,
-1.82 + Math.floor(i / 2) * 0.86
);
toyGroup.add(chassis);
toyChassis.push(chassis);
}
for (let i = 0; i < 18; i++) {
const tab = createTab();
tab.position.set(
1.05 + (i % 6) * 0.46,
-0.63,
-2.02 + Math.floor(i / 6) * 0.58
);
toyGroup.add(tab);
toyTabs.push(tab);
}
for (let i = 0; i < 6; i++) {
const token = createN2();
token.position.set(
-2.15 + (i % 2) * 0.9,
-0.5,
-1.83 + Math.floor(i / 2) * 0.86
);
moleculeGroup.add(token);
nitrogenTokens.push(token);
}
for (let i = 0; i < 18; i++) {
const token = createH2();
token.position.set(
0.85 + (i % 6) * 0.46,
-0.58,
-2.02 + Math.floor(i / 6) * 0.58
);
moleculeGroup.add(token);
hydrogenTokens.push(token);
}
for (let i = 0; i < 6; i++) {
const product = createToyProduct();
product.position.set(
-1.65 + (i % 3) * 1.62,
-0.28,
0.68 + Math.floor(i / 3) * 1.38
);
toyGroup.add(product);
toyProducts.push(product);
}
for (let i = 0; i < 12; i++) {
const product = createNH3Product();
product.position.set(
-2.55 + (i % 6) * 1.02,
-0.25,
0.58 + Math.floor(i / 6) * 1.25
);
moleculeGroup.add(product);
ammoniaProducts.push(product);
}
const decorativeCubes = [];
for (let i = 0; i < 12; i++) {
const cube = outlinedBox(0.12, 0.12, 0.12, i % 3 === 0 ? COLORS.lime : COLORS.cyan);
cube.position.set(
-10 + (i % 6) * 4,
3.2 + Math.floor(i / 6) * 1.1,
-6 - (i % 2) * 1.5
);
cube.material = null;
scene.add(cube);
decorativeCubes.push(cube);
}
const clamp = (value, min = 0, max = 1) => Math.max(min, Math.min(max, value));
const easeOut = value => 1 - Math.pow(1 - clamp(value), 3);
const easeInOut = value =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
let currentCounts = { n2: 4, h2: 10 };
let reactionCount = 3;
let animation = null;
let mobileLayout = false;
function applyProduct(group, progress, molecular = false) {
const p = clamp(progress);
group.visible = p > 0;
const body = group.userData.body;
body.visible = p > 0;
body.scale.setScalar(Math.max(0.001, easeOut(clamp(p / 0.38))));
const pieces = molecular ? group.userData.hydrogens : group.userData.tabs;
pieces.forEach((piece, index) => {
const localProgress = easeInOut(clamp((p - (0.18 + index * 0.08)) / 0.66));
piece.mesh.visible = localProgress > 0;
piece.mesh.scale.setScalar(Math.max(0.001, localProgress));
piece.mesh.position.lerpVectors(piece.start, piece.target, localProgress);
});
}
function updateVisual(batchProgress) {
const usedN2 = Math.ceil(batchProgress - 0.000001);
const usedH2 = Math.ceil(batchProgress * 3 - 0.000001);
toyChassis.forEach((token, i) => token.visible = i >= usedN2);
toyTabs.forEach((token, i) => token.visible = i >= usedH2);
nitrogenTokens.forEach((token, i) => token.visible = i >= usedN2);
hydrogenTokens.forEach((token, i) => token.visible = i >= usedH2);
toyProducts.forEach((product, i) => {
applyProduct(product, clamp(batchProgress - i, 0, 1), false);
});
ammoniaProducts.forEach((product, i) => {
applyProduct(product, clamp(batchProgress - i, 0, 1), true);
});
}
function rangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--pct", `${percentage}%`);
}
function updateStats() {
const n2 = Number(nitrogenInput.value);
const h2 = Number(hydrogenInput.value);
currentCounts = { n2, h2 };
nitrogenValue.textContent = n2;
hydrogenValue.textContent = h2;
rangeFill(nitrogenInput);
rangeFill(hydrogenInput);
reactionCount = Math.min(n2, Math.floor(h2 / 3));
const neededH2 = n2 * 3;
const leftoverN2 = n2 - reactionCount;
const leftoverH2 = h2 - reactionCount * 3;
const productMolecules = reactionCount * 2;
const badge = document.getElementById("limit-badge");
badge.classList.remove("lime", "blue");
if (h2 > neededH2) {
badge.textContent = "N₂ is limiting";
badge.classList.add("blue");
document.getElementById("result-detail").textContent =
`All ${n2} N₂ can react with ${neededH2} H₂. The extra ${leftoverH2} H₂ cannot form another whole batch.`;
} else if (h2 < neededH2) {
badge.textContent = "H₂ is limiting";
badge.classList.add("lime");
document.getElementById("result-detail").textContent =
`${h2} H₂ supports ${reactionCount} whole ${reactionCount === 1 ? "batch" : "batches"} of ${3} H₂ each.`;
} else {
badge.textContent = "Both co-limiting";
badge.classList.add("blue");
document.getElementById("result-detail").textContent =
`The inventory divides exactly into ${reactionCount} complete 1:3 ratio ${reactionCount === 1 ? "group" : "groups"}.`;
}
document.getElementById("result-main").textContent =
`${reactionCount} ${reactionCount === 1 ? "batch" : "batches"} → ${productMolecules} NH₃`;
document.getElementById("leftover-detail").textContent =
`Remaining inventory: ${leftoverN2} N₂ and ${leftoverH2} H₂.`;
document.getElementById("n-start").textContent = n2 * 2;
document.getElementById("n-product").textContent = reactionCount * 2;
document.getElementById("n-left").textContent = leftoverN2 * 2;
document.getElementById("h-start").textContent = h2 * 2;
document.getElementById("h-product").textContent = reactionCount * 6;
document.getElementById("h-left").textContent = leftoverH2 * 2;
document.querySelectorAll(".preset").forEach(button => {
button.classList.toggle(
"active",
Number(button.dataset.n) === n2 && Number(button.dataset.h) === h2
);
});
stageStatus.textContent =
`Ready · ${reactionCount} complete ratio ${reactionCount === 1 ? "group" : "groups"} possible`;
animation = null;
progressFill.style.width = "0%";
runButton.disabled = false;
runButton.textContent = "▶ Assemble & account";
updateVisual(0);
}
nitrogenInput.addEventListener("input", updateStats);
hydrogenInput.addEventListener("input", updateStats);
document.querySelectorAll(".preset").forEach(button => {
button.addEventListener("click", () => {
nitrogenInput.value = button.dataset.n;
hydrogenInput.value = button.dataset.h;
updateStats();
});
});
runButton.addEventListener("click", () => {
updateVisual(0);
const duration = 1500 + reactionCount * 480;
animation = {
start: performance.now(),
duration,
count: reactionCount
};
runButton.disabled = true;
runButton.textContent = "Counting ratio groups…";
stageStatus.textContent = `Processing 1 of ${reactionCount} complete ratio groups`;
});
const cameraState = {
yaw: 0,
pitch: 0.68,
zoom: 1
};
function layoutScene() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
const aspect = width / height;
mobileLayout = aspect < 1.15;
if (mobileLayout) {
toyGroup.position.set(0, 2.8, 0);
moleculeGroup.position.set(0, -2.8, 0);
toyGroup.scale.setScalar(0.78);
moleculeGroup.scale.setScalar(0.78);
} else {
toyGroup.position.set(-5.35, 0, 0);
moleculeGroup.position.set(5.35, 0, 0);
toyGroup.scale.setScalar(1);
moleculeGroup.scale.setScalar(1);
}
const viewHeight = mobileLayout ? 19.5 : 14.7;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
}
function updateCamera() {
const radius = 23;
camera.position.set(
Math.sin(cameraState.yaw) * Math.cos(cameraState.pitch) * radius,
Math.sin(cameraState.pitch) * radius,
Math.cos(cameraState.yaw) * Math.cos(cameraState.pitch) * radius
);
camera.lookAt(0, 0, 0);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.yaw = 0;
cameraState.pitch = 0.68;
cameraState.zoom = 1;
layoutScene();
}
document.getElementById("reset-view").addEventListener("click", resetCamera);
document.getElementById("top-view").addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.pitch = 1.38;
cameraState.zoom = 0.94;
layoutScene();
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw = clamp(cameraState.yaw + dx * 0.006, -0.72, 0.72);
cameraState.pitch = clamp(cameraState.pitch + dy * 0.004, 0.28, 1.48);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = clamp(cameraState.zoom * Math.exp(-event.deltaY * 0.001), 0.72, 1.55);
camera.updateProjectionMatrix();
}, { passive: false });
const toyLabel = document.getElementById("toy-label");
const moleculeLabel = document.getElementById("molecule-label");
function positionLabel(element, group, localY) {
const point = new THREE.Vector3(0, localY, -2.25);
group.localToWorld(point);
point.project(camera);
const x = (point.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-point.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
const anchorY = mobileLayout ? 3.55 : 3.05;
positionLabel(toyLabel, toyGroup, anchorY);
positionLabel(moleculeLabel, moleculeGroup, anchorY);
}
const resizeObserver = new ResizeObserver(layoutScene);
resizeObserver.observe(stage);
updateStats();
layoutScene();
function frame(now) {
requestAnimationFrame(frame);
if (animation) {
const elapsed = now - animation.start;
const linearProgress = clamp(elapsed / animation.duration);
const smoothProgress = easeInOut(linearProgress);
const batchProgress = smoothProgress * animation.count;
updateVisual(batchProgress);
progressFill.style.width = `${linearProgress * 100}%`;
const activeBatch = Math.min(animation.count, Math.floor(batchProgress) + 1);
if (linearProgress < 1) {
stageStatus.textContent = `Processing ${activeBatch} of ${animation.count} complete ratio groups`;
}
if (linearProgress >= 1) {
animation = null;
updateVisual(animation ? animation.count : reactionCount);
progressFill.style.width = "100%";
runButton.disabled = false;
runButton.textContent = "↻ Replay the count";
stageStatus.textContent =
`Complete · ${reactionCount} ${reactionCount === 1 ? "batch" : "batches"} made ${reactionCount * 2} NH₃`;
}
}
decorativeCubes.forEach((cube, i) => {
cube.rotation.x = now * 0.00012 + i;
cube.rotation.y = now * 0.00018 + i * 0.7;
});
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(frame);
</script>
</body>
</html>
```