Prompt specification
Build or customize the Three.js 3D scene "Generation Demand and Balance Scale" 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: Generation Demand and Balance Scale
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/generation-demand-and-balance-scale-x3929
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Model generator and load tokens on opposite sides of a symbolic balance display. Label this as power accounting rather than a physical model of grid frequency.
Working Three.js Starter (generation-demand-and-balance-scale-x3929):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Power Accounting — Symbolic Energy Balance</title>
<style>
:root {
color-scheme: dark;
--bg: #07131d;
--panel: rgba(10, 25, 37, 0.78);
--panel-border: rgba(182, 224, 235, 0.16);
--text: #edf7f8;
--muted: #93aeb8;
--generation: #50e3c2;
--load: #ffb45c;
--balanced: #d7e9ed;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
canvas:focus-visible {
outline: 2px solid var(--generation);
outline-offset: -4px;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.intro {
position: absolute;
top: 28px;
left: 30px;
max-width: 440px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--generation);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1.03;
}
.intro p {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.concept-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid var(--panel-border);
border-radius: 999px;
background: rgba(10, 25, 37, 0.62);
color: #b9ccd1;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.concept-badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--generation);
box-shadow: 0 0 12px var(--generation);
content: "";
}
.metrics {
position: absolute;
top: 28px;
right: 30px;
width: 270px;
padding: 16px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.metric-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--generation);
box-shadow: 0 0 10px var(--generation);
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
align-items: baseline;
padding: 9px 0;
border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.metric span {
color: var(--muted);
font-size: 12px;
}
.metric strong {
font-size: 21px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.metric.generation strong {
color: var(--generation);
}
.metric.load strong {
color: var(--load);
}
.metric.net strong {
color: var(--balanced);
}
.status {
margin-top: 10px;
padding: 9px 10px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #b8cbd0;
font-size: 11px;
font-weight: 650;
text-align: center;
}
.controls {
position: absolute;
right: 30px;
bottom: 74px;
width: 270px;
padding: 14px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.controls-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scenario-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
button {
min-height: 38px;
padding: 7px 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #c9dadd;
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(80, 227, 194, 0.5);
background: rgba(80, 227, 194, 0.08);
color: white;
transform: translateY(-1px);
}
button.active {
border-color: rgba(80, 227, 194, 0.55);
background: rgba(80, 227, 194, 0.12);
color: var(--generation);
}
button:focus-visible {
outline: 2px solid var(--generation);
outline-offset: 2px;
}
.disclaimer {
position: absolute;
bottom: 25px;
left: 50%;
max-width: calc(100% - 40px);
padding: 10px 16px;
border: 1px solid rgba(255, 180, 92, 0.2);
border-radius: 999px;
background: rgba(10, 25, 37, 0.75);
color: #d5c0a4;
font-size: 11px;
line-height: 1.4;
text-align: center;
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
.disclaimer strong {
color: var(--load);
font-weight: 750;
}
.help {
position: absolute;
bottom: 29px;
left: 30px;
color: rgba(176, 202, 208, 0.62);
font-size: 10px;
letter-spacing: 0.03em;
}
.world-label {
position: absolute;
z-index: 3;
min-width: 112px;
padding: 8px 10px;
border: 1px solid var(--panel-border);
border-radius: 10px;
background: rgba(6, 17, 26, 0.83);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
text-align: center;
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(10px);
}
.world-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 8px;
height: 8px;
border-right: 1px solid var(--panel-border);
border-bottom: 1px solid var(--panel-border);
background: rgba(6, 17, 26, 0.83);
content: "";
transform: translateX(-50%) rotate(45deg);
}
.world-label span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.world-label strong {
display: block;
margin-top: 2px;
font-size: 16px;
font-variant-numeric: tabular-nums;
}
.world-label.generation {
border-color: rgba(80, 227, 194, 0.28);
}
.world-label.generation strong {
color: var(--generation);
}
.world-label.load {
border-color: rgba(255, 180, 92, 0.28);
}
.world-label.load strong {
color: var(--load);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
right: 18px;
}
.intro p {
max-width: 310px;
font-size: 12px;
}
.concept-badge {
margin-top: 9px;
}
.metrics {
top: auto;
right: 14px;
bottom: 123px;
left: 14px;
width: auto;
padding: 11px 13px;
}
.metric {
display: inline-flex;
width: 33.333%;
padding: 7px 4px 0;
border-top: 0;
}
.metric strong {
font-size: 17px;
}
.metric-heading,
.status {
display: none;
}
.controls {
right: 14px;
bottom: 62px;
left: 14px;
width: auto;
padding: 10px;
}
.controls-title {
display: none;
}
.help {
display: none;
}
.disclaimer {
bottom: 13px;
width: calc(100% - 28px);
padding: 8px 11px;
font-size: 9px;
}
.world-label {
min-width: 90px;
padding: 6px 8px;
}
.world-label strong {
font-size: 13px;
}
}
@media (prefers-reduced-motion: reduce) {
button {
transition: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="hud">
<section class="intro" aria-labelledby="page-title">
<div class="eyebrow">Power Accounting</div>
<h1 id="page-title">Generation / demand ledger</h1>
<p>
A symbolic balance between a generator token and stacked load tokens.
Values describe power in megawatts.
</p>
<div class="concept-badge">Conceptual accounting view</div>
</section>
<section class="metrics" aria-label="Power accounting values">
<div class="metric-heading">
<span>Power accounting</span>
<span class="live-dot" aria-hidden="true"></span>
</div>
<div class="metric generation">
<span>Generation</span>
<strong><span id="generationValue">64</span> MW</strong>
</div>
<div class="metric load">
<span>Load</span>
<strong><span id="loadValue">60</span> MW</strong>
</div>
<div class="metric net">
<span>Net</span>
<strong><span id="netValue">+4</span> MW</strong>
</div>
<div class="status" id="statusText">Generation surplus</div>
</section>
<section class="controls" aria-label="Conceptual scenarios">
<div class="controls-title">Change the ledger</div>
<div class="scenario-buttons">
<button type="button" data-generation="60" data-load="60">Balanced</button>
<button type="button" data-generation="68" data-load="60">Gen surplus</button>
<button type="button" data-generation="60" data-load="68">Load peak</button>
</div>
</section>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="disclaimer">
<strong>Power accounting</strong> — not a physical model of grid frequency.
</div>
</div>
<div class="world-label generation" id="generationLabel">
<span>Generator</span>
<strong id="generationWorldValue">64 MW</strong>
</div>
<div class="world-label load" id="loadLabel">
<span>Load tokens</span>
<strong id="loadWorldValue">60 MW</strong>
</div>
<p class="sr-only">
An interactive low-poly symbolic balance showing generator output on the left
and demand tokens on the right. It is a power accounting visualization,
not a physical model of grid frequency.
</p>
<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.querySelector("#stage");
const generationValue = document.querySelector("#generationValue");
const loadValue = document.querySelector("#loadValue");
const netValue = document.querySelector("#netValue");
const statusText = document.querySelector("#statusText");
const generationWorldValue = document.querySelector("#generationWorldValue");
const loadWorldValue = document.querySelector("#loadWorldValue");
const generationLabel = document.querySelector("#generationLabel");
const loadLabel = document.querySelector("#loadLabel");
const scenarioButtons = [...document.querySelectorAll("[data-generation]")];
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
// ------------------------------------------------------------
// Renderer, scene, camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional power accounting balance"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 15, 31);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 2.35, 0);
const spherical = new THREE.Spherical(14.2, 1.16, 0.54);
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.48, 1.43);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 8.5, 20);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Lighting and materials
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xb8eaff, 0x101722, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dc, 3.4);
keyLight.position.set(5.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x51d9ff, 1.8);
rimLight.position.set(-7, 5, -6);
scene.add(rimLight);
const generationLight = new THREE.PointLight(0x48e0bd, 13, 9, 2);
generationLight.position.set(-3.4, 2.2, 2.8);
scene.add(generationLight);
const loadLight = new THREE.PointLight(0xffa64e, 11, 9, 2);
loadLight.position.set(3.5, 2.2, 2.6);
scene.add(loadLight);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.08,
flatShading: true,
...options
});
}
const materials = {
floor: standardMaterial(0x071019, { roughness: 0.95 }),
dais: standardMaterial(0x112633, { roughness: 0.82 }),
daisTop: standardMaterial(0x183544, { roughness: 0.78 }),
darkMetal: standardMaterial(0x172733, {
metalness: 0.46,
roughness: 0.46
}),
beam: standardMaterial(0xcbdcdf, {
metalness: 0.28,
roughness: 0.36
}),
teal: standardMaterial(0x39c9aa, {
emissive: 0x0b5548,
emissiveIntensity: 0.34
}),
tealDark: standardMaterial(0x176f66),
amber: standardMaterial(0xe8953f, {
emissive: 0x6d2c05,
emissiveIntensity: 0.35
}),
amberDark: standardMaterial(0x9d5726),
cream: standardMaterial(0xe5eff0),
rope: standardMaterial(0x8aa5ae, {
metalness: 0.12,
roughness: 0.8
}),
ring: new THREE.MeshBasicMaterial({
color: 0x4de3c1,
transparent: true,
opacity: 0.25
})
};
function addEdges(mesh, color = 0xbde8e6, opacity = 0.28) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 25),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
function makeMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground, grid, and display base
// ------------------------------------------------------------
const floor = makeMesh(
new THREE.PlaneGeometry(50, 50),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.castShadow = false;
const dais = makeMesh(
new THREE.CylinderGeometry(4.85, 5.15, 0.26, 48),
materials.dais
);
dais.position.y = 0.13;
dais.castShadow = false;
const daisTop = makeMesh(
new THREE.CylinderGeometry(4.55, 4.72, 0.07, 48),
materials.daisTop
);
daisTop.position.y = 0.295;
daisTop.castShadow = false;
for (const radius of [3.65, 4.25]) {
const ring = makeMesh(
new THREE.TorusGeometry(radius, 0.018, 5, 80),
materials.ring
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.345;
ring.castShadow = false;
ring.receiveShadow = false;
}
const gridPositions = [];
for (let i = -10; i <= 10; i++) {
const p = i * 1.2;
gridPositions.push(
p, 0.015, -6,
p, 0.015, 6,
-6, 0.015, p,
6, 0.015, p
);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x5b8b9b,
transparent: true,
opacity: 0.075
})
);
scene.add(grid);
// ------------------------------------------------------------
// Symbolic balance stand
// ------------------------------------------------------------
const stand = new THREE.Group();
scene.add(stand);
const base = makeMesh(
new THREE.CylinderGeometry(1.95, 2.35, 0.42, 8),
materials.darkMetal,
stand
);
base.position.y = 0.52;
const baseInset = makeMesh(
new THREE.CylinderGeometry(1.32, 1.68, 0.23, 8),
materials.beam,
stand
);
baseInset.position.y = 0.83;
const mast = makeMesh(
new THREE.CylinderGeometry(0.22, 0.5, 2.65, 6),
materials.beam,
stand
);
mast.position.y = 2.13;
const mastCore = makeMesh(
new THREE.CylinderGeometry(0.09, 0.13, 2.58, 6),
materials.tealDark,
stand
);
mastCore.position.set(0, 2.13, 0.24);
const pivotY = 3.67;
const pivot = makeMesh(
new THREE.CylinderGeometry(0.34, 0.34, 0.62, 12),
materials.darkMetal,
stand
);
pivot.rotation.x = Math.PI / 2;
pivot.position.y = pivotY;
const pivotCap = makeMesh(
new THREE.CylinderGeometry(0.15, 0.15, 0.68, 12),
materials.teal,
stand
);
pivotCap.rotation.x = Math.PI / 2;
pivotCap.position.y = pivotY;
const gauge = makeMesh(
new THREE.TorusGeometry(0.78, 0.027, 5, 40, Math.PI),
materials.rope,
stand
);
gauge.position.set(0, pivotY - 0.15, 0.38);
const pointer = makeMesh(
new THREE.ConeGeometry(0.1, 0.38, 3),
materials.amber,
stand
);
pointer.position.set(0, pivotY - 0.56, 0.39);
pointer.rotation.z = Math.PI;
const beamRoot = new THREE.Group();
beamRoot.position.y = pivotY;
scene.add(beamRoot);
const beam = makeMesh(
new THREE.BoxGeometry(7.15, 0.19, 0.34),
materials.beam,
beamRoot
);
beam.castShadow = true;
const beamStripe = makeMesh(
new THREE.BoxGeometry(5.5, 0.035, 0.365),
materials.tealDark,
beamRoot
);
beamStripe.position.y = 0.015;
for (const side of [-1, 1]) {
const cap = makeMesh(
new THREE.CylinderGeometry(0.2, 0.2, 0.38, 10),
side < 0 ? materials.teal : materials.amber,
beamRoot
);
cap.rotation.x = Math.PI / 2;
cap.position.x = side * 3.55;
}
// ------------------------------------------------------------
// Hanging pan assembly
// ------------------------------------------------------------
function createPan() {
const group = new THREE.Group();
scene.add(group);
const platform = makeMesh(
new THREE.CylinderGeometry(1.08, 0.98, 0.16, 8),
materials.darkMetal,
group
);
platform.position.y = -0.08;
const lip = makeMesh(
new THREE.TorusGeometry(1.02, 0.035, 5, 32),
materials.beam,
group
);
lip.rotation.x = Math.PI / 2;
lip.position.y = 0.015;
const rope = makeMesh(
new THREE.CylinderGeometry(0.022, 0.022, 1, 6),
materials.rope,
scene
);
rope.castShadow = false;
return { group, rope };
}
const generatorPan = createPan();
const loadPan = createPan();
// ------------------------------------------------------------
// Generator token: compact turbine and generator housing
// ------------------------------------------------------------
const generatorToken = new THREE.Group();
generatorPan.group.add(generatorToken);
const generatorBase = makeMesh(
new THREE.CylinderGeometry(0.78, 0.87, 0.24, 8),
materials.tealDark,
generatorToken
);
generatorBase.position.y = 0.06;
const generatorBody = makeMesh(
new THREE.BoxGeometry(0.82, 0.7, 0.62),
materials.teal,
generatorToken
);
generatorBody.position.set(-0.13, 0.52, 0);
addEdges(generatorBody, 0xb7fff2, 0.38);
const generatorRoof = makeMesh(
new THREE.ConeGeometry(0.6, 0.27, 4),
materials.tealDark,
generatorToken
);
generatorRoof.position.set(-0.13, 1.01, 0);
generatorRoof.rotation.y = Math.PI / 4;
const turbineTower = makeMesh(
new THREE.CylinderGeometry(0.11, 0.2, 1.03, 6),
materials.cream,
generatorToken
);
turbineTower.position.set(0.3, 1.15, -0.04);
const rotor = new THREE.Group();
rotor.position.set(0.3, 1.7, 0.35);
generatorToken.add(rotor);
const rotorHub = makeMesh(
new THREE.IcosahedronGeometry(0.19, 0),
materials.teal,
rotor
);
for (let i = 0; i < 3; i++) {
const bladePivot = new THREE.Group();
bladePivot.rotation.z = (Math.PI * 2 * i) / 3;
rotor.add(bladePivot);
const blade = makeMesh(
new THREE.BoxGeometry(0.13, 0.7, 0.075),
materials.cream,
bladePivot
);
blade.position.y = 0.43;
addEdges(blade, 0xffffff, 0.25);
}
function createBoltGeometry() {
const shape = new THREE.Shape();
shape.moveTo(0.09, 0.35);
shape.lineTo(-0.16, 0.02);
shape.lineTo(-0.025, 0.02);
shape.lineTo(-0.09, -0.34);
shape.lineTo(0.17, 0.06);
shape.lineTo(0.035, 0.06);
shape.lineTo(0.11, 0.35);
shape.closePath();
return new THREE.ShapeGeometry(shape);
}
const boltMaterial = new THREE.MeshBasicMaterial({
color: 0xf4ffff,
side: THREE.DoubleSide
});
const generatorBolt = makeMesh(
createBoltGeometry(),
boltMaterial,
generatorToken
);
generatorBolt.position.set(-0.13, 0.53, 0.316);
generatorBolt.scale.setScalar(0.72);
const generatorBeacon = makeMesh(
new THREE.OctahedronGeometry(0.09, 0),
materials.cream,
generatorToken
);
generatorBeacon.position.set(-0.56, 0.72, 0.18);
// ------------------------------------------------------------
// Load tokens: stacked demand cubes
// ------------------------------------------------------------
const loadToken = new THREE.Group();
loadPan.group.add(loadToken);
function createLoadToken(x, y, z, size = 0.68) {
const group = new THREE.Group();
group.position.set(x, y, z);
loadToken.add(group);
const cube = makeMesh(
new THREE.BoxGeometry(size, size, size),
materials.amber,
group
);
addEdges(cube, 0xffddb0, 0.34);
const topStrip = makeMesh(
new THREE.BoxGeometry(size * 0.48, 0.025, size * 0.12),
materials.cream,
group
);
topStrip.position.y = size / 2 + 0.014;
const bolt = makeMesh(
createBoltGeometry(),
boltMaterial,
group
);
bolt.position.z = size / 2 + 0.006;
bolt.scale.setScalar(size * 0.75);
return group;
}
createLoadToken(-0.37, 0.36, 0.02);
createLoadToken(0.37, 0.36, -0.04);
createLoadToken(0, 1.06, 0.03, 0.67);
// Small amount-of-load indicator on the pan.
const loadBaseRing = makeMesh(
new THREE.TorusGeometry(0.72, 0.027, 5, 24),
materials.amber,
loadToken
);
loadBaseRing.rotation.x = Math.PI / 2;
loadBaseRing.position.y = 0.02;
// ------------------------------------------------------------
// Accounting state
// ------------------------------------------------------------
let targetGeneration = 64;
let targetLoad = 60;
let currentGeneration = 64;
let currentLoad = 60;
let beamAngle = 0.04;
let targetBeamAngle = 0.04;
function setScenario(generation, load) {
targetGeneration = generation;
targetLoad = load;
for (const button of scenarioButtons) {
const selected =
Number(button.dataset.generation) === generation &&
Number(button.dataset.load) === load;
button.classList.toggle("active", selected);
}
}
for (const button of scenarioButtons) {
button.addEventListener("click", () => {
setScenario(
Number(button.dataset.generation),
Number(button.dataset.load)
);
});
}
setScenario(64, 60);
function signedNumber(value) {
if (Math.abs(value) < 0.05) return "0";
return `${value > 0 ? "+" : ""}${Math.round(value)}`;
}
function updateReadout() {
const net = currentGeneration - currentLoad;
const generationText = Math.round(currentGeneration);
const loadText = Math.round(currentLoad);
const netText = signedNumber(net);
generationValue.textContent = generationText;
loadValue.textContent = loadText;
netValue.textContent = netText;
generationWorldValue.textContent = `${generationText} MW`;
loadWorldValue.textContent = `${loadText} MW`;
if (net > 0.15) {
statusText.textContent = "Generation surplus";
statusText.style.color = "#50e3c2";
netValue.style.color = "#50e3c2";
} else if (net < -0.15) {
statusText.textContent = "Load exceeds generation";
statusText.style.color = "#ffb45c";
netValue.style.color = "#ffb45c";
} else {
statusText.textContent = "Generation and load balanced";
statusText.style.color = "#d7e9ed";
netValue.style.color = "#d7e9ed";
}
}
// ------------------------------------------------------------
// Direct camera controls — no Three.js addons
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (
event.pointerType !== "mouse" &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius += event.deltaY * 0.012;
updateCamera();
},
{ passive: false }
);
function resetCamera() {
spherical.set(14.2, 1.16, 0.54);
cameraTarget.set(0, 2.35, 0);
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") spherical.theta += 0.1;
else if (key === "arrowright") spherical.theta -= 0.1;
else if (key === "arrowup") spherical.phi -= 0.08;
else if (key === "arrowdown") spherical.phi += 0.08;
else if (key === "+" || key === "=") spherical.radius -= 0.6;
else if (key === "-") spherical.radius += 0.6;
else if (key === "r") resetCamera();
else return;
event.preventDefault();
updateCamera();
});
renderer.domElement.style.cursor = "grab";
// ------------------------------------------------------------
// Projection helpers for DOM world labels
// ------------------------------------------------------------
const generatorAnchor = new THREE.Vector3();
const loadAnchor = new THREE.Vector3();
const projected = new THREE.Vector3();
function updateWorldLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function damp(current, target, speed, delta) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-speed * delta)
);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
currentGeneration = damp(
currentGeneration,
targetGeneration,
reduceMotion ? 20 : 5,
delta
);
currentLoad = damp(
currentLoad,
targetLoad,
reduceMotion ? 20 : 5,
delta
);
// This tilt is explicitly symbolic. It represents a power balance,
// not a physical or dynamic grid-frequency model.
targetBeamAngle = THREE.MathUtils.clamp(
(currentGeneration - currentLoad) * 0.025,
-0.15,
0.15
);
beamAngle = damp(
beamAngle,
targetBeamAngle,
reduceMotion ? 20 : 4.5,
delta
);
beamRoot.rotation.z = beamAngle;
for (const [side, pan] of [
[-1, generatorPan],
[1, loadPan]
]) {
const endX = Math.cos(beamAngle) * side * 3.55;
const endY = pivotY + Math.sin(beamAngle) * side * 3.55;
pan.group.position.set(endX, endY - 1.22, 0);
const ropeLength = endY - pan.group.position.y;
pan.rope.position.set(endX, endY - ropeLength / 2, 0);
pan.rope.scale.y = ropeLength;
}
rotor.rotation.z -= delta * (0.65 + Math.abs(currentGeneration - currentLoad) * 0.012);
generatorBeacon.rotation.y += delta * 1.5;
generatorBeacon.rotation.x += delta * 0.7;
updateReadout();
generatorToken.getWorldPosition(generatorAnchor);
generatorAnchor.y += 2.05;
loadToken.getWorldPosition(loadAnchor);
loadAnchor.y += 1.62;
updateWorldLabel(generationLabel, generatorAnchor);
updateWorldLabel(loadLabel, loadAnchor);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
</script>
</body>
</html>
```