Prompt specification
Build or customize the Three.js 3D scene "Two energy-balance boxes" 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: Two energy-balance boxes
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-energy-balance-boxes-x1218
Scene Description Prompt:
Two stylized energy-balance boxes receive equal inputs but have different output responses; show stored-energy change under stated assumptions. Three.js from cdnjs, one HTML file.
Working Three.js Starter (two-energy-balance-boxes-x1218):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Energy Balance — Equal Input, Different Storage Response</title>
<style>
:root {
color-scheme: dark;
--bg: #071019;
--panel: rgba(10, 22, 33, 0.78);
--panel-border: rgba(153, 213, 236, 0.16);
--text: #eef9ff;
--muted: #8da8b8;
--cyan: #4bd9ff;
--amber: #ffb45b;
--green: #65efb0;
--pink: #ff789d;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
}
* { 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;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active { cursor: grabbing; }
.topbar {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
max-width: 540px;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
margin-bottom: 8px;
}
h1 {
margin: 0;
font-size: clamp(24px, 3.1vw, 43px);
line-height: 1.03;
letter-spacing: -0.045em;
font-weight: 760;
text-shadow: 0 4px 30px rgba(0,0,0,.35);
}
.subtitle {
margin: 10px 0 0;
max-width: 510px;
color: #abc1cf;
font-size: 13px;
line-height: 1.5;
}
.assumptions {
position: fixed;
z-index: 20;
top: 22px;
right: 24px;
width: min(325px, calc(100vw - 48px));
padding: 15px 17px 16px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.assumptions summary {
list-style: none;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
color: #dff7ff;
font-size: 12px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.assumptions summary::-webkit-details-marker { display: none; }
.assumptions summary::after { content: "+"; color: var(--cyan); font-size: 18px; }
.assumptions[open] summary::after { content: "−"; }
.assumption-list {
margin: 13px 0 0;
padding: 0;
list-style: none;
display: grid;
gap: 8px;
color: #a9c0ce;
font-size: 12px;
line-height: 1.42;
}
.assumption-list li {
position: relative;
padding-left: 14px;
}
.assumption-list li::before {
content: "";
position: absolute;
left: 0;
top: .55em;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(75,217,255,.7);
}
.formula {
margin-top: 12px;
padding: 10px 11px;
border: 1px solid rgba(101,239,176,.18);
border-radius: 10px;
background: rgba(101,239,176,.055);
color: #bcebd1;
font: 600 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.world-label {
position: fixed;
z-index: 5;
transform: translate(-50%, -50%);
pointer-events: none;
white-space: nowrap;
text-align: center;
filter: drop-shadow(0 5px 12px rgba(0,0,0,.55));
}
.box-label {
padding: 7px 12px;
border: 1px solid rgba(255,255,255,.14);
border-radius: 999px;
background: rgba(5,15,23,.78);
font-size: 11px;
font-weight: 800;
letter-spacing: .11em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.box-label.a { color: #baf4ff; border-color: rgba(75,217,255,.3); }
.box-label.b { color: #ffd6e3; border-color: rgba(255,120,157,.3); }
.flux-label {
padding: 5px 9px;
border-radius: 8px;
background: rgba(5,14,21,.76);
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
border: 1px solid rgba(255,255,255,.1);
}
.flux-label.input { color: var(--cyan); }
.flux-label.output { color: var(--amber); }
.delta-label {
min-width: 126px;
padding: 8px 11px;
border-radius: 11px;
border: 1px solid rgba(101,239,176,.25);
background: rgba(5,17,21,.82);
backdrop-filter: blur(9px);
}
.delta-label span {
display: block;
color: #89a99b;
font-size: 8px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
}
.delta-label b {
display: block;
margin-top: 2px;
color: var(--green);
font-size: 16px;
}
.cards {
position: fixed;
z-index: 15;
left: 24px;
right: 24px;
bottom: 102px;
display: flex;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.card {
width: min(340px, 31vw);
padding: 16px 17px 15px;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
pointer-events: auto;
}
.card.a { box-shadow: var(--shadow), inset 3px 0 0 rgba(75,217,255,.8); }
.card.b { box-shadow: var(--shadow), inset 3px 0 0 rgba(255,120,157,.8); }
.card-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
}
.card-kicker {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
.card h2 {
margin: 3px 0 0;
font-size: 18px;
letter-spacing: -.02em;
}
.response-tag {
padding: 5px 8px;
border-radius: 999px;
color: #b8c9d3;
background: rgba(255,255,255,.055);
font-size: 9px;
font-weight: 750;
white-space: nowrap;
}
.readout {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 8px;
margin: 14px 0 13px;
}
.readout div {
min-width: 0;
}
.readout span {
display: block;
color: #7793a4;
font-size: 8px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.readout b {
display: block;
margin-top: 3px;
color: #edf9ff;
font: 700 15px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.readout .cyan { color: var(--cyan); }
.readout .amber { color: var(--amber); }
.readout .green { color: var(--green); }
.meter-row {
display: grid;
grid-template-columns: 41px 1fr 47px;
align-items: center;
gap: 8px;
margin-top: 7px;
color: #809aaa;
font-size: 9px;
font-weight: 700;
}
.meter {
height: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(255,255,255,.075);
}
.meter > i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width .08s linear;
}
.meter.input > i { background: var(--cyan); box-shadow: 0 0 12px rgba(75,217,255,.7); }
.meter.output > i { background: var(--amber); box-shadow: 0 0 12px rgba(255,180,91,.55); }
.meter.storage > i { background: var(--green); box-shadow: 0 0 12px rgba(101,239,176,.55); }
.meter-row output {
color: #aec0cb;
text-align: right;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.timeline {
position: fixed;
z-index: 20;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
width: min(720px, calc(100vw - 48px));
display: grid;
grid-template-columns: auto 1fr auto auto;
align-items: center;
gap: 12px;
padding: 12px 14px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
button, select {
border: 1px solid rgba(255,255,255,.13);
border-radius: 9px;
background: rgba(255,255,255,.055);
color: #e7f6fc;
font: inherit;
}
button {
height: 34px;
padding: 0 13px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: .04em;
}
button:hover, select:hover { background: rgba(255,255,255,.1); }
button:focus-visible, select:focus-visible, input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#play {
min-width: 72px;
color: #071019;
background: var(--cyan);
border-color: transparent;
}
#scrub {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
#clock {
min-width: 58px;
color: #c7dce7;
text-align: right;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
select {
height: 34px;
padding: 0 8px;
font-size: 11px;
cursor: pointer;
}
.comparison {
position: fixed;
z-index: 12;
left: 50%;
bottom: 91px;
transform: translateX(-50%);
padding: 7px 12px;
border: 1px solid rgba(101,239,176,.18);
border-radius: 999px;
background: rgba(5,17,20,.78);
color: #a8c5b5;
font-size: 10px;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(9px);
}
.comparison b { color: var(--green); }
.camera-hint {
position: fixed;
left: 50%;
top: 20px;
transform: translateX(-50%);
z-index: 8;
color: rgba(178,205,219,.52);
font-size: 9px;
letter-spacing: .12em;
text-transform: uppercase;
pointer-events: none;
}
#error {
position: fixed;
z-index: 100;
inset: 0;
display: none;
place-items: center;
padding: 30px;
background: #071019;
color: #eaf7ff;
text-align: center;
}
@media (max-width: 980px) {
.camera-hint { display: none; }
.card { width: min(320px, 34vw); }
.topbar { max-width: 46vw; }
.subtitle { font-size: 12px; }
}
@media (max-width: 700px) {
.topbar {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
}
.subtitle { display: none; }
.assumptions {
top: 92px;
right: 14px;
width: 225px;
padding: 11px 13px;
}
.assumption-list { font-size: 10px; gap: 6px; }
.formula { font-size: 10px; }
.cards {
left: 12px;
right: 12px;
bottom: 89px;
gap: 8px;
}
.card {
width: calc(50% - 4px);
padding: 11px;
border-radius: 13px;
}
.card h2 { font-size: 14px; }
.response-tag { display: none; }
.readout { grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.readout div:last-child { grid-column: 1 / -1; }
.readout b { font-size: 13px; }
.meter-row { grid-template-columns: 34px 1fr 38px; gap: 5px; font-size: 8px; }
.timeline {
bottom: 12px;
width: calc(100vw - 24px);
gap: 7px;
padding: 9px;
grid-template-columns: auto 1fr auto;
}
#reset { display: none; }
#clock { min-width: 48px; font-size: 9px; }
select { display: none; }
.comparison { bottom: 78px; font-size: 8px; padding: 6px 9px; }
.flux-label { display: none !important; }
.delta-label { transform: translate(-50%, -50%) scale(.8); }
}
@media (max-height: 690px) and (min-width: 701px) {
.cards { bottom: 87px; }
.card { padding: 11px 14px; }
.readout { margin: 9px 0; }
.timeline { bottom: 12px; }
.comparison { bottom: 80px; }
.subtitle { display: none; }
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive 3D energy balance visualization"></div>
<header class="topbar">
<div class="eyebrow">Interactive energy accounting</div>
<h1>Equal input.<br>Different stored-energy response.</h1>
<p class="subtitle">
Both boxes receive 100 W. Box A leaves with 30 W while Box B leaves with 70 W,
so their stored energy changes at different rates.
</p>
</header>
<details class="assumptions" open>
<summary>Stated assumptions</summary>
<ul class="assumption-list">
<li>Input power is identical: <b>100 W</b> for each box.</li>
<li>Initial stored energy is identical: <b>2.0 kJ</b>.</li>
<li>All energy leaving the boundary is counted as output power.</li>
<li>No other energy flux crosses the accounting boundary.</li>
<li>Storage capacity shown is <b>15 kJ</b> per box.</li>
</ul>
<div class="formula">
ΔE = (P<sub>in</sub> − P<sub>out</sub>) × t<br>
A: (100 − 30) W → +70 W<br>
B: (100 − 70) W → +30 W
</div>
</details>
<div class="camera-hint">Drag to orbit · scroll to zoom</div>
<div id="label-a" class="world-label box-label a">Box A · 30 W output</div>
<div id="label-b" class="world-label box-label b">Box B · 70 W output</div>
<div id="in-a" class="world-label flux-label input">Input · 100 W</div>
<div id="out-a" class="world-label flux-label output">Output · 30 W</div>
<div id="in-b" class="world-label flux-label input">Input · 100 W</div>
<div id="out-b" class="world-label flux-label output">Output · 70 W</div>
<div id="delta-a" class="world-label delta-label">
<span>Stored-energy change</span><b>+0.0 kJ</b>
</div>
<div id="delta-b" class="world-label delta-label">
<span>Stored-energy change</span><b>+0.0 kJ</b>
</div>
<section class="cards" aria-label="Energy balance results">
<article class="card a">
<div class="card-head">
<div>
<div class="card-kicker">System 01</div>
<h2>Box A</h2>
</div>
<div class="response-tag">Lower output response</div>
</div>
<div class="readout">
<div><span>Input</span><b class="cyan">100 W</b></div>
<div><span>Output</span><b class="amber">30 W</b></div>
<div><span>Net storage</span><b class="green">+70 W</b></div>
</div>
<div class="meter-row">
<span>INPUT</span><div class="meter input"><i id="a-in-meter"></i></div><output>100 W</output>
</div>
<div class="meter-row">
<span>OUTPUT</span><div class="meter output"><i id="a-out-meter"></i></div><output>30 W</output>
</div>
<div class="meter-row">
<span>STORED</span><div class="meter storage"><i id="a-store-meter"></i></div><output id="a-store-text">2.0 kJ</output>
</div>
</article>
<article class="card b">
<div class="card-head">
<div>
<div class="card-kicker">System 02</div>
<h2>Box B</h2>
</div>
<div class="response-tag">Higher output response</div>
</div>
<div class="readout">
<div><span>Input</span><b class="cyan">100 W</b></div>
<div><span>Output</span><b class="amber">70 W</b></div>
<div><span>Net storage</span><b class="green">+30 W</b></div>
</div>
<div class="meter-row">
<span>INPUT</span><div class="meter input"><i id="b-in-meter"></i></div><output>100 W</output>
</div>
<div class="meter-row">
<span>OUTPUT</span><div class="meter output"><i id="b-out-meter"></i></div><output>70 W</output>
</div>
<div class="meter-row">
<span>STORED</span><div class="meter storage"><i id="b-store-meter"></i></div><output id="b-store-text">2.0 kJ</output>
</div>
</article>
</section>
<div id="comparison" class="comparison">
At 0.0 s, Box A stores <b>0.0 kJ</b> more than Box B
</div>
<div class="timeline" aria-label="Timeline controls">
<button id="play" type="button" aria-label="Play animation">PLAY</button>
<input id="scrub" type="range" min="0" max="120" step="0.1" value="0" aria-label="Elapsed time">
<output id="clock">0.0 s</output>
<select id="speed" aria-label="Playback speed">
<option value="1">1×</option>
<option value="5" selected>5×</option>
<option value="15">15×</option>
</select>
<button id="reset" type="button">RESET</button>
</div>
<div id="error">
<div>
<h2>3D rendering is unavailable</h2>
<p>This visualization requires WebGL and access to the Three.js CDN module.</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const INPUT_POWER = 100;
const OUTPUT_A = 30;
const OUTPUT_B = 70;
const INITIAL_ENERGY = 2.0;
const CAPACITY = 15.0;
const MAX_TIME = 120;
let elapsed = 0;
let playing = true;
let playbackSpeed = 5;
const stage = $("stage");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
$("error").style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.FogExp2(0x071019, 0.035);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.55, 0);
const orbit = {
theta: 0,
phi: 1.03,
radius: 13.5,
dragging: false,
lastX: 0,
lastY: 0
};
function initialRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.65) return 26;
if (aspect < 1.0) return 20;
if (aspect < 1.35) return 16;
return 13.5;
}
orbit.radius = initialRadius();
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
updateCamera();
// Camera controls implemented directly, without external addons.
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.52, 1.38);
updateCamera();
});
function endDrag(event) {
orbit.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
8,
34
);
updateCamera();
}, { passive: false });
const ambient = new THREE.HemisphereLight(0xb8e8ff, 0x071018, 1.65);
scene.add(ambient);
const key = new THREE.DirectionalLight(0xe8f7ff, 3.0);
key.position.set(-4, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -5;
scene.add(key);
const rim = new THREE.DirectionalLight(0x5acbff, 1.3);
rim.position.set(7, 4, -6);
scene.add(rim);
const warm = new THREE.PointLight(0xff9d55, 18, 9, 2);
warm.position.set(4, 2.5, 3);
scene.add(warm);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.MeshStandardMaterial({
color: 0x08131d,
roughness: 0.9,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 60, 0x1c5668, 0x102b37);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const plinthGeometry = new THREE.CylinderGeometry(1.65, 1.78, 0.2, 48);
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1b27,
roughness: 0.58,
metalness: 0.55
});
function makeRoundedShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width, y + height,
x + width - radius, y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function roundedHousingGeometry() {
const shape = makeRoundedShape(2.42, 3.0, 0.16);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 1.5,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.055,
bevelThickness: 0.055,
curveSegments: 8
});
geometry.translate(0, 0, -0.75);
geometry.computeVertexNormals();
return geometry;
}
const housingGeometry = roundedHousingGeometry();
const edgeGeometry = new THREE.EdgesGeometry(housingGeometry, 24);
function createEnergyBox(x, accent, outputPower) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const housing = new THREE.Mesh(
housingGeometry,
new THREE.MeshPhysicalMaterial({
color: accent,
transparent: true,
opacity: 0.12,
roughness: 0.28,
metalness: 0.28,
clearcoat: 0.7,
clearcoatRoughness: 0.2,
depthWrite: false
})
);
housing.position.y = 1.78;
housing.castShadow = true;
group.add(housing);
const edges = new THREE.LineSegments(
edgeGeometry,
new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.7
})
);
edges.position.y = 1.78;
group.add(edges);
const top = new THREE.Mesh(
new THREE.BoxGeometry(2.52, 0.15, 1.65),
new THREE.MeshStandardMaterial({
color: 0x132735,
roughness: 0.42,
metalness: 0.72
})
);
top.position.y = 3.34;
top.castShadow = true;
group.add(top);
const front = new THREE.Mesh(
new THREE.BoxGeometry(2.12, 2.48, 0.07),
new THREE.MeshPhysicalMaterial({
color: 0x6deaff,
transparent: true,
opacity: 0.075,
roughness: 0.12,
metalness: 0.05,
depthWrite: false
})
);
front.position.set(0, 1.68, 0.79);
group.add(front);
const reservoirBase = 0.47;
const reservoirHeight = 2.27;
const fill = new THREE.Mesh(
new THREE.BoxGeometry(1.96, 1, 0.18),
new THREE.MeshStandardMaterial({
color: 0x21d69c,
emissive: 0x0aa36d,
emissiveIntensity: 1.45,
transparent: true,
opacity: 0.82,
roughness: 0.3,
metalness: 0.15
})
);
fill.position.set(0, reservoirBase + 0.01, 0.70);
group.add(fill);
const fillTop = new THREE.Mesh(
new THREE.PlaneGeometry(1.96, 0.18),
new THREE.MeshBasicMaterial({
color: 0xb2ffe0,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide
})
);
fillTop.rotation.x = -Math.PI / 2;
fillTop.position.set(0, reservoirBase + 0.02, 0.70);
group.add(fillTop);
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(2.08, 2.44, 0.08)),
new THREE.LineBasicMaterial({
color: 0x83d7e9,
transparent: true,
opacity: 0.38
})
);
frame.position.set(0, 1.68, 0.84);
group.add(frame);
const tickMaterial = new THREE.LineBasicMaterial({
color: 0xa5c9d6,
transparent: true,
opacity: 0.28
});
for (let i = 0; i <= 6; i++) {
const y = reservoirBase + (reservoirHeight * i / 6);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0.89, y, 0.88),
new THREE.Vector3(1.00, y, 0.88)
]);
group.add(new THREE.Line(geometry, tickMaterial));
}
const nozzleGeometry = new THREE.CylinderGeometry(0.15, 0.15, 0.35, 18);
const nozzleMaterial = new THREE.MeshStandardMaterial({
color: 0x1b3544,
roughness: 0.35,
metalness: 0.72
});
const inputNozzle = new THREE.Mesh(nozzleGeometry, nozzleMaterial);
inputNozzle.rotation.z = Math.PI / 2;
inputNozzle.position.set(-1.31, 2.88, 0);
group.add(inputNozzle);
const outputNozzle = new THREE.Mesh(nozzleGeometry, nozzleMaterial);
outputNozzle.rotation.z = Math.PI / 2;
outputNozzle.position.set(1.31, 1.18, 0);
group.add(outputNozzle);
const ledMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 2.2
});
for (const ledX of [-0.85, 0.85]) {
const led = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 12, 8),
ledMaterial
);
led.position.set(ledX, 3.34, 0.68);
group.add(led);
}
const plinth = new THREE.Mesh(plinthGeometry, plinthMaterial);
plinth.position.y = 0.11;
plinth.receiveShadow = true;
group.add(plinth);
const halo = new THREE.Mesh(
new THREE.RingGeometry(1.72, 1.79, 64),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.42,
side: THREE.DoubleSide
})
);
halo.rotation.x = -Math.PI / 2;
halo.position.y = 0.222;
group.add(halo);
return {
group,
fill,
fillTop,
reservoirBase,
reservoirHeight,
outputPower
};
}
const boxA = createEnergyBox(-2.45, 0x4bd9ff, OUTPUT_A);
const boxB = createEnergyBox(2.45, 0xff789d, OUTPUT_B);
const fluxParticles = [];
function cylinderBetween(start, end, radius, color, opacity = 0.35) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(radius, radius, length, 12);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
transparent: true,
opacity,
roughness: 0.32,
metalness: 0.3,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
scene.add(mesh);
return mesh;
}
function createFlux(start, end, color, count, speed, opacity) {
cylinderBetween(start, end, 0.055, color, opacity);
const particleGeometry = new THREE.SphereGeometry(0.075, 10, 8);
const particleMaterial = new THREE.MeshBasicMaterial({ color });
for (let i = 0; i < count; i++) {
const particle = new THREE.Mesh(particleGeometry, particleMaterial);
particle.userData = {
start: start.clone(),
end: end.clone(),
phase: i / count,
speed
};
scene.add(particle);
fluxParticles.push(particle);
}
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.35, 14),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: Math.min(1, opacity + 0.4)
})
);
arrow.position.copy(end);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3().subVectors(end, start).normalize()
);
scene.add(arrow);
}
createFlux(
new THREE.Vector3(-6.2, 2.88, 0),
new THREE.Vector3(-3.82, 2.88, 0),
0x4bd9ff, 15, 0.16, 0.24
);
createFlux(
new THREE.Vector3(-0.82, 2.88, 0),
new THREE.Vector3(1.08, 2.88, 0),
0x4bd9ff, 15, 0.16, 0.24
);
createFlux(
new THREE.Vector3(-1.08, 1.18, 0),
new THREE.Vector3(0.72, 1.18, 0),
0xffb45b, 12, 0.075, 0.28
);
createFlux(
new THREE.Vector3(3.82, 1.18, 0),
new THREE.Vector3(5.28, 1.18, 0),
0xffb45b, 12, 0.19, 0.34
);
// A subtle divider reinforces the side-by-side comparison.
const divider = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.04, -1.8),
new THREE.Vector3(0, 3.65, -1.8)
]),
new THREE.LineBasicMaterial({
color: 0x79b6c8,
transparent: true,
opacity: 0.2
})
);
scene.add(divider);
const labelAnchors = {
"label-a": new THREE.Vector3(-2.45, 3.76, 0),
"label-b": new THREE.Vector3(2.45, 3.76, 0),
"in-a": new THREE.Vector3(-5.0, 3.16, 0),
"out-a": new THREE.Vector3(-0.2, 1.48, 0),
"in-b": new THREE.Vector3(0.15, 3.16, 0),
"out-b": new THREE.Vector3(4.55, 1.48, 0),
"delta-a": new THREE.Vector3(-2.45, 1.95, 0.98),
"delta-b": new THREE.Vector3(2.45, 1.95, 0.98)
};
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.visibility = visible ? "visible" : "hidden";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateLabelPositions() {
for (const [id, position] of Object.entries(labelAnchors)) {
positionLabel($(id), position);
}
}
function setFill(box, energy) {
const fraction = THREE.MathUtils.clamp(energy / CAPACITY, 0, 1);
const height = Math.max(0.018, fraction * box.reservoirHeight);
box.fill.scale.y = height;
box.fill.position.y = box.reservoirBase + height / 2;
box.fillTop.position.y = box.reservoirBase + height + 0.004;
box.fillTop.visible = fraction > 0.002;
}
function updateEnergyReadouts() {
const deltaA = (INPUT_POWER - OUTPUT_A) * elapsed / 1000;
const deltaB = (INPUT_POWER - OUTPUT_B) * elapsed / 1000;
const storedA = INITIAL_ENERGY + deltaA;
const storedB = INITIAL_ENERGY + deltaB;
setFill(boxA, storedA);
setFill(boxB, storedB);
$("delta-a").querySelector("b").textContent = `+${deltaA.toFixed(1)} kJ`;
$("delta-b").querySelector("b").textContent = `+${deltaB.toFixed(1)} kJ`;
$("a-in-meter").style.width = "100%";
$("b-in-meter").style.width = "100%";
$("a-out-meter").style.width = `${OUTPUT_A}%`;
$("b-out-meter").style.width = `${OUTPUT_B}%`;
$("a-store-meter").style.width = `${storedA / CAPACITY * 100}%`;
$("b-store-meter").style.width = `${storedB / CAPACITY * 100}%`;
$("a-store-text").textContent = `${storedA.toFixed(1)} kJ`;
$("b-store-text").textContent = `${storedB.toFixed(1)} kJ`;
$("clock").textContent = `${elapsed.toFixed(1)} s`;
$("scrub").value = elapsed.toFixed(1);
const difference = storedA - storedB;
$("comparison").innerHTML =
`At ${elapsed.toFixed(1)} s, Box A stores <b>${difference.toFixed(1)} kJ</b> more than Box B`;
}
$("play").addEventListener("click", () => {
if (!playing && elapsed >= MAX_TIME) elapsed = 0;
playing = !playing;
$("play").textContent = playing ? "PAUSE" : "PLAY";
$("play").setAttribute("aria-label", playing ? "Pause animation" : "Play animation");
});
$("scrub").addEventListener("input", (event) => {
elapsed = Number(event.target.value);
playing = false;
$("play").textContent = "PLAY";
$("play").setAttribute("aria-label", "Play animation");
updateEnergyReadouts();
});
$("speed").addEventListener("change", (event) => {
playbackSpeed = Number(event.target.value);
});
$("reset").addEventListener("click", () => {
elapsed = 0;
playing = false;
$("play").textContent = "PLAY";
updateEnergyReadouts();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let lastTime = 0;
function animate() {
requestAnimationFrame(animate);
const wallTime = clock.getElapsedTime();
const dt = Math.min(wallTime - lastTime, 0.05);
lastTime = wallTime;
if (playing) {
elapsed = Math.min(MAX_TIME, elapsed + dt * playbackSpeed);
if (elapsed >= MAX_TIME) {
playing = false;
$("play").textContent = "PLAY";
}
updateEnergyReadouts();
}
for (const particle of fluxParticles) {
const data = particle.userData;
const t = (wallTime * data.speed + data.phase) % 1;
particle.position.lerpVectors(data.start, data.end, t);
}
boxA.fill.material.emissiveIntensity = 1.35 + Math.sin(wallTime * 2.1) * 0.15;
boxB.fill.material.emissiveIntensity = 1.35 + Math.sin(wallTime * 2.1 + 1.2) * 0.15;
updateLabelPositions();
renderer.render(scene, camera);
}
updateEnergyReadouts();
animate();
</script>
</body>
</html>
```