Prompt specification
Build or customize the Three.js 3D scene "Island Microgrid Management Board" 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: Island Microgrid Management Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/island-microgrid-management-board-x3931
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build an original island with homes, solar, wind, storage, and a dispatch panel. Use synthetic rates and transparent accounting, separating the model from real grid operation.
Working Three.js Starter (island-microgrid-management-board-x3931):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Isle Volt — Synthetic Voxel Microgrid</title>
<style>
:root {
--ink: #eaf8ff;
--muted: #91afbd;
--panel: rgba(8, 24, 39, 0.91);
--panel-soft: rgba(13, 36, 54, 0.82);
--line: rgba(177, 224, 241, 0.16);
--solar: #ffc857;
--wind: #66e0d0;
--battery: #a991ff;
--grid: #ff796f;
--good: #88e59b;
--cyan: #67d8ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfe3eb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(5, 27, 44, 0.12), transparent 25%),
radial-gradient(circle at center, transparent 45%, rgba(8, 33, 49, 0.15));
}
.topbar {
position: fixed;
z-index: 10;
top: 16px;
left: 16px;
right: 16px;
min-height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 10px 14px 10px 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: rgba(6, 22, 36, 0.92);
box-shadow: 0 16px 45px rgba(5, 25, 39, 0.2);
backdrop-filter: blur(18px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 220px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
display: block;
width: 15px;
height: 15px;
border-radius: 3px;
background: var(--cyan);
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16);
}
.brand-mark i:nth-child(1) { left: 1px; top: 2px; }
.brand-mark i:nth-child(2) { right: 1px; top: 2px; background: var(--solar); }
.brand-mark i:nth-child(3) { left: 1px; bottom: 1px; background: var(--wind); }
.brand-mark i:nth-child(4) { right: 1px; bottom: 1px; background: var(--battery); }
.brand-name {
font-size: 17px;
font-weight: 850;
letter-spacing: 0.08em;
}
.brand-sub {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.simulation-badge {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 12px;
border: 1px solid rgba(255, 200, 87, 0.3);
border-radius: 11px;
background: rgba(255, 200, 87, 0.09);
}
.simulation-badge strong {
color: var(--solar);
font-size: 10px;
letter-spacing: 0.12em;
}
.simulation-badge small {
color: #c3d3db;
font-size: 11px;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--solar);
box-shadow: 0 0 0 5px rgba(255, 200, 87, 0.12);
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
}
.mobile-button {
display: none;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel-soft);
font-size: 11px;
font-weight: 750;
}
.side {
position: fixed;
z-index: 8;
top: 96px;
bottom: 102px;
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 70px rgba(4, 23, 36, 0.26);
backdrop-filter: blur(20px);
scrollbar-width: thin;
scrollbar-color: rgba(103, 216, 255, 0.25) transparent;
}
#metricsPanel { left: 16px; width: 304px; }
#dispatchPanel { right: 16px; width: 326px; }
.eyebrow {
margin-bottom: 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 {
margin-bottom: 5px;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.035em;
}
h2 {
margin-bottom: 7px;
font-size: 21px;
letter-spacing: -0.025em;
}
.subtle {
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.time-chip {
display: inline-flex;
align-items: center;
gap: 7px;
margin: 13px 0 15px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(103, 216, 255, 0.09);
color: var(--cyan);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.05em;
}
.time-chip::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
}
.stat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 14px;
}
.stat {
min-height: 84px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.stat-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat-value {
margin-top: 7px;
font-size: 24px;
font-weight: 830;
letter-spacing: -0.04em;
}
.stat-value small {
margin-left: 2px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0;
}
.stat-note {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 18px 0 9px;
color: #c8dce5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0;
text-transform: none;
}
.balance-bar {
display: flex;
width: 100%;
height: 12px;
overflow: hidden;
border-radius: 20px;
background: rgba(255, 255, 255, 0.06);
}
.balance-bar > div {
height: 100%;
transition: width 220ms ease;
}
#barDirect { background: linear-gradient(90deg, var(--solar), var(--wind)); }
#barBattery { background: var(--battery); }
#barGrid { background: var(--grid); }
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 9px;
margin-top: 8px;
color: var(--muted);
font-size: 9px;
}
.legend-row span {
display: flex;
align-items: center;
gap: 5px;
}
.legend-row i {
width: 7px;
height: 7px;
border-radius: 2px;
}
.ledger {
padding: 2px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.ledger-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 9px 0;
border-bottom: 1px solid rgba(177, 224, 241, 0.08);
font-size: 11px;
}
.ledger-row:last-child { border-bottom: 0; }
.ledger-name {
display: flex;
align-items: center;
gap: 8px;
color: #c8dce5;
}
.ledger-name i {
width: 8px;
height: 8px;
border-radius: 2px;
}
.ledger-value {
text-align: right;
font-variant-numeric: tabular-nums;
font-weight: 760;
}
.ledger-value small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 550;
}
.rate-card {
margin-top: 14px;
padding: 13px;
border: 1px solid rgba(255, 200, 87, 0.2);
border-radius: 12px;
background: rgba(255, 200, 87, 0.065);
}
.rate-main {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 10px;
}
.rate-main strong {
color: var(--solar);
font-size: 25px;
letter-spacing: -0.04em;
}
.rate-main span {
color: #c7d7df;
font-size: 11px;
text-align: right;
}
.rate-meta {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
}
details {
margin-top: 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
summary {
color: #c8dce5;
font-weight: 750;
cursor: pointer;
}
details p { margin: 10px 0 0; }
.mode-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin: 17px 0 10px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(0, 0, 0, 0.13);
}
.mode-tabs button {
padding: 8px 4px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
}
.mode-tabs button.active {
background: var(--cyan);
color: #071b29;
box-shadow: 0 5px 16px rgba(103, 216, 255, 0.18);
}
.mode-description {
min-height: 48px;
margin-bottom: 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.range-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #c8dce5;
font-size: 11px;
font-weight: 700;
}
.range-label strong {
color: var(--battery);
font-size: 12px;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 10px;
outline: none;
background: rgba(169, 145, 255, 0.22);
accent-color: var(--battery);
cursor: pointer;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
}
.soc-block {
margin-top: 18px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.soc-head {
display: flex;
align-items: baseline;
justify-content: space-between;
}
.soc-head strong {
font-size: 25px;
letter-spacing: -0.04em;
}
.soc-head span {
color: var(--muted);
font-size: 10px;
}
.soc-track {
height: 9px;
margin: 10px 0 8px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.06);
}
.soc-fill {
height: 100%;
background: linear-gradient(90deg, var(--battery), var(--cyan));
transition: width 220ms ease;
}
.reserve-marker {
position: relative;
height: 0;
}
.reserve-marker::before {
content: "";
position: absolute;
top: -17px;
left: 25%;
width: 2px;
height: 13px;
background: var(--solar);
}
.soc-caption {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
}
.flow-list {
margin-top: 10px;
border-top: 1px solid var(--line);
}
.flow-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
padding: 10px 0;
border-bottom: 1px solid rgba(177, 224, 241, 0.08);
font-size: 11px;
}
.flow-row i {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.025);
}
.flow-row strong {
font-variant-numeric: tabular-nums;
}
.cost-card {
margin-top: 15px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
}
.cost-main {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 10px;
}
.cost-main strong {
font-size: 29px;
letter-spacing: -0.05em;
}
.cost-main span {
color: var(--muted);
font-size: 10px;
text-align: right;
}
.cost-lines {
display: grid;
gap: 7px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.cost-lines div {
display: flex;
justify-content: space-between;
gap: 12px;
}
.cost-lines strong {
color: #d9ebf3;
font-variant-numeric: tabular-nums;
}
.warning {
margin-top: 14px;
padding: 12px;
border-left: 3px solid var(--solar);
border-radius: 0 9px 9px 0;
background: rgba(255, 200, 87, 0.07);
color: #c7d7df;
font-size: 10px;
line-height: 1.5;
}
.warning strong {
color: var(--solar);
}
.timeline {
position: fixed;
z-index: 9;
left: 50%;
bottom: 16px;
width: min(760px, calc(100% - 32px));
transform: translateX(-50%);
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(6, 22, 36, 0.92);
box-shadow: 0 18px 55px rgba(4, 23, 36, 0.26);
backdrop-filter: blur(18px);
}
.timeline-top {
display: flex;
align-items: center;
gap: 12px;
}
.play-button {
display: grid;
width: 38px;
height: 38px;
flex: 0 0 auto;
place-items: center;
border: 0;
border-radius: 10px;
background: var(--cyan);
color: #071b29;
font-size: 15px;
font-weight: 900;
}
.clock {
width: 54px;
flex: 0 0 auto;
font-size: 14px;
font-weight: 830;
font-variant-numeric: tabular-nums;
}
.timeline input[type="range"] {
background: rgba(103, 216, 255, 0.18);
accent-color: var(--cyan);
}
.preset-buttons {
display: flex;
gap: 5px;
}
.preset-buttons button {
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: #c8dce5;
font-size: 9px;
font-weight: 750;
}
.timeline-ticks {
display: flex;
justify-content: space-between;
margin: 8px 54px 0 116px;
color: var(--muted);
font-size: 9px;
}
.world-label {
position: fixed;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
min-width: 102px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 10px;
background: rgba(7, 27, 42, 0.84);
box-shadow: 0 9px 25px rgba(5, 23, 36, 0.16);
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(10px);
}
.world-label .dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
}
.world-label small {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
}
.world-label strong {
display: block;
margin-top: 2px;
font-size: 12px;
font-variant-numeric: tabular-nums;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #bfe3eb;
color: #173747;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
transition: opacity 300ms ease;
}
@media (max-width: 1050px) {
#metricsPanel { width: 276px; }
#dispatchPanel { width: 292px; }
.simulation-badge small { display: none; }
}
@media (max-width: 860px) {
.topbar { gap: 8px; }
.brand { min-width: 0; }
.brand-sub { display: none; }
.simulation-badge { margin-left: auto; }
.simulation-badge strong { font-size: 9px; }
.mobile-button { display: block; }
.side {
display: none;
top: 92px;
bottom: 108px;
width: min(330px, calc(100% - 32px));
}
.side.open { display: block; }
#metricsPanel { left: 16px; }
#dispatchPanel { right: 16px; }
.world-label { transform: translate(-50%, -100%) scale(0.9); }
}
@media (max-width: 560px) {
.brand-name { font-size: 14px; }
.simulation-badge { padding: 7px; }
.simulation-badge strong { display: none; }
.header-actions { gap: 4px; }
.mobile-button { padding: 7px; }
.timeline { padding: 10px; }
.preset-buttons { display: none; }
.timeline-ticks { margin-right: 0; }
.world-label { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel island microgrid"></canvas>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<div class="brand-name">ISLE // VOLT</div>
<div class="brand-sub">Synthetic voxel microgrid</div>
</div>
</div>
<div class="simulation-badge">
<span class="status-dot"></span>
<strong>SIMULATION ONLY</strong>
<small>Synthetic rates · no telemetry · no grid control</small>
</div>
<div class="header-actions">
<button class="mobile-button" id="metricsToggle">Metrics</button>
<button class="mobile-button" id="dispatchToggle">Dispatch</button>
</div>
</header>
<aside class="side" id="metricsPanel">
<div class="eyebrow">Transparent accounting</div>
<h1>Island dispatch</h1>
<p class="subtle">A stylized community balancing local generation, storage, and an imagined grid connection.</p>
<div class="time-chip" id="hourClock">13:00 · simulated hour</div>
<div class="stat-grid">
<div class="stat">
<div class="stat-label">Island demand</div>
<div class="stat-value"><span id="demandValue">0.0</span><small>kW</small></div>
<div class="stat-note">Synthetic hourly load</div>
</div>
<div class="stat">
<div class="stat-label">Renewable served</div>
<div class="stat-value"><span id="renewableValue">0</span><small>%</small></div>
<div class="stat-note">Direct generation + battery</div>
</div>
<div class="stat">
<div class="stat-label">Grid import</div>
<div class="stat-value"><span id="gridValue">0.0</span><small>kW</small></div>
<div class="stat-note">Imagined utility supply</div>
</div>
<div class="stat">
<div class="stat-label">Battery state</div>
<div class="stat-value"><span id="socValue">0</span><small>%</small></div>
<div class="stat-note">48 kWh synthetic store</div>
</div>
</div>
<div class="section-title">
Demand allocation
<span>One modeled hour</span>
</div>
<div class="balance-bar" aria-label="Demand allocation bar">
<div id="barDirect"></div>
<div id="barBattery"></div>
<div id="barGrid"></div>
</div>
<div class="legend-row">
<span><i style="background:var(--solar)"></i>Solar</span>
<span><i style="background:var(--wind)"></i>Wind</span>
<span><i style="background:var(--battery)"></i>Battery</span>
<span><i style="background:var(--grid)"></i>Grid</span>
</div>
<div class="section-title">
Energy ledger
<span>Production / allocation</span>
</div>
<div class="ledger">
<div class="ledger-row">
<div class="ledger-name"><i style="background:var(--solar)"></i>Solar</div>
<div class="ledger-value"><span id="rowSolar">0.0 kW</span><small id="solarUsed">0.0 kW used</small></div>
</div>
<div class="ledger-row">
<div class="ledger-name"><i style="background:var(--wind)"></i>Wind</div>
<div class="ledger-value"><span id="rowWind">0.0 kW</span><small id="windUsed">0.0 kW used</small></div>
</div>
<div class="ledger-row">
<div class="ledger-name"><i style="background:var(--battery)"></i>Battery discharge</div>
<div class="ledger-value"><span id="rowBattery">0.0 kW</span><small id="batteryCharged">0.0 kW charging</small></div>
</div>
<div class="ledger-row">
<div class="ledger-name"><i style="background:var(--grid)"></i>Grid import</div>
<div class="ledger-value"><span id="rowImport">0.0 kW</span><small>Cost at synthetic rate</small></div>
</div>
<div class="ledger-row">
<div class="ledger-name"><i style="background:#7f95a2"></i>Grid export</div>
<div class="ledger-value"><span id="rowExport">0.0 kW</span><small>Synthetic export credit</small></div>
</div>
</div>
<div class="rate-card">
<div class="eyebrow">Synthetic period rate</div>
<div class="rate-main">
<strong id="rateValue">$0.24</strong>
<span>per modeled kWh<br>illustrative only</span>
</div>
<div class="rate-meta">
<span>Export credit: $0.08</span>
<span id="ratePeriod">Standard period</span>
</div>
</div>
<details>
<summary>Accounting notes & model boundaries</summary>
<p>
All generation, demand, state-of-charge, prices, and grid exchanges are generated
inside this page. They are not measurements and do not represent a real utility,
market, feeder, or dispatch decision.
</p>
<p>
Hourly allocation: direct renewable use first, then battery discharge, then
synthetic grid import. Surplus is charged or exported according to the selected
mode. Because each step represents one hour, modeled kW is treated as kWh for
energy accounting.
</p>
<p>
Net hourly cost = grid import × selected synthetic rate − grid export × $0.08.
No losses, taxes, network constraints, safety rules, frequency response,
forecasting, optimization, or utility telemetry are modeled.
</p>
</details>
</aside>
<aside class="side" id="dispatchPanel">
<div class="eyebrow">Local control sandbox</div>
<h2>Dispatch panel</h2>
<p class="subtle">Change the simulated policy, reserve, and hour. Nothing here commands real equipment.</p>
<div class="mode-tabs" role="group" aria-label="Synthetic dispatch mode">
<button class="active" data-mode="auto">AUTO</button>
<button data-mode="hold">HOLD</button>
<button data-mode="support">SUPPORT</button>
</div>
<div class="mode-description" id="modeDescription">
Auto charges with surplus generation and discharges to cover deficits while respecting the reserve.
</div>
<div class="range-label">
<span>Battery reserve</span>
<strong id="reserveLabel">25%</strong>
</div>
<input id="reserveSlider" type="range" min="10" max="60" step="5" value="25" aria-label="Battery reserve percentage">
<div class="range-scale">
<span>10% minimum</span>
<span>60% protected</span>
</div>
<div class="soc-block">
<div class="soc-head">
<strong id="socBlockValue">0%</strong>
<span id="socEnergy">0.0 / 48.0 kWh</span>
</div>
<div class="soc-track">
<div class="soc-fill" id="socBar"></div>
</div>
<div class="reserve-marker"></div>
<div class="soc-caption">
<span id="socAvailable">0.0 kWh available</span>
<span id="socReserve">12.0 kWh reserved</span>
</div>
</div>
<div class="section-title">
Live source flow
<span>Synthetic kW</span>
</div>
<div class="flow-list">
<div class="flow-row">
<i style="background:var(--solar)"></i>
<span>Solar → island</span>
<strong id="flowSolar">0.0</strong>
</div>
<div class="flow-row">
<i style="background:var(--wind)"></i>
<span>Wind → island</span>
<strong id="flowWind">0.0</strong>
</div>
<div class="flow-row">
<i style="background:var(--battery)"></i>
<span>Battery → island</span>
<strong id="flowBattery">0.0</strong>
</div>
<div class="flow-row">
<i style="background:var(--grid)"></i>
<span>Grid → island</span>
<strong id="flowGrid">0.0</strong>
</div>
</div>
<div class="cost-card">
<div class="eyebrow">Net hourly cost</div>
<div class="cost-main">
<strong id="hourlyCost">$0.00</strong>
<span>day-to-date<br><b id="dayCost">$0.00</b></span>
</div>
<div class="cost-lines">
<div><span>Import charge</span><strong id="importCost">$0.00</strong></div>
<div><span>Export credit</span><strong id="exportCredit">$0.00</strong></div>
<div><span>Produced renewable energy</span><strong id="productionTotal">0.0 kW</strong></div>
</div>
</div>
<div class="warning">
<strong>Model, not operator.</strong> These controls are deliberately local and fictional.
They do not connect to a utility, market, EMS, inverter, battery, or any real grid asset.
</div>
</aside>
<div class="world-label" id="solarLabel">
<span class="dot" style="background:var(--solar)"></span>
<div><small>SOLAR</small><strong id="labelSolar">0.0 kW</strong></div>
</div>
<div class="world-label" id="windLabel">
<span class="dot" style="background:var(--wind)"></span>
<div><small>WIND</small><strong id="labelWind">0.0 kW</strong></div>
</div>
<div class="world-label" id="batteryLabel">
<span class="dot" style="background:var(--battery)"></span>
<div><small>STORAGE</small><strong id="labelBattery">0%</strong></div>
</div>
<div class="world-label" id="dispatchLabel">
<span class="dot" style="background:var(--cyan)"></span>
<div><small>DISPATCH</small><strong id="labelDispatch">AUTO</strong></div>
</div>
<footer class="timeline">
<div class="timeline-top">
<button class="play-button" id="playButton" aria-label="Play simulation">▶</button>
<div class="clock" id="timelineClock">13:00</div>
<input id="hourSlider" type="range" min="0" max="23" step="1" value="13" aria-label="Simulation hour">
<div class="preset-buttons">
<button data-hour="8">08:00</button>
<button data-hour="13">13:00</button>
<button data-hour="19">19:00</button>
</div>
</div>
<div class="timeline-ticks">
<span>00</span><span>06</span><span>12</span><span>18</span><span>23</span>
</div>
</footer>
<div id="loading">BUILDING ISLE // VOLT</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 clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
// ------------------------------------------------------------------
// Synthetic model. One model hour equals one energy-accounting hour.
// ------------------------------------------------------------------
const CAPACITY = 48;
const INITIAL_SOC = 13;
const EXPORT_RATE = 0.08;
let hour = 13;
let mode = "auto";
let reservePercent = 25;
let playing = false;
let playTimer = null;
function deterministicNoise(x, z = 0) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function profile(h) {
const daylight = h > 6 && h < 18
? Math.sin(Math.PI * (h - 6) / 12)
: 0;
const solar = 25 * daylight * (0.91 + 0.09 * Math.cos(h * 0.63));
const wind = 9.4
+ 2.1 * Math.sin((h + 2) * 0.43)
+ 1.2 * Math.cos((h - 1) * 0.21);
const morning = 3.8 * Math.exp(-Math.pow(h - 8, 2) / 9);
const evening = 6.2 * Math.exp(-Math.pow(h - 19, 2) / 7);
const demand = 11.5 + morning + evening + 0.75 * Math.sin(h * 0.34);
let rate = 0.14;
let period = "Off-peak";
if (h >= 8 && h < 18) {
rate = 0.24;
period = "Standard";
} else if (h >= 18 && h < 22) {
rate = 0.42;
period = "Peak";
}
return {
solar: Math.max(0, solar),
wind: Math.max(0, wind),
demand: Math.max(0, demand),
rate,
period
};
}
function simulateDay(selectedMode, selectedReservePercent) {
const reserve = CAPACITY * selectedReservePercent / 100;
const rows = [];
let soc = INITIAL_SOC;
for (let h = 0; h < 24; h++) {
const p = profile(h);
const solarUse = Math.min(p.solar, p.demand);
const windUse = Math.min(p.wind, Math.max(0, p.demand - solarUse));
const surplus = Math.max(0, p.solar + p.wind - p.demand);
const deficit = Math.max(0, p.demand - solarUse - windUse);
const room = Math.max(0, CAPACITY - soc);
const available = Math.max(0, soc - reserve);
let charge = 0;
let discharge = 0;
let gridExport = 0;
if (selectedMode === "auto") {
charge = Math.min(surplus, room, 6);
gridExport = surplus - charge;
discharge = Math.min(deficit, available, 10);
} else if (selectedMode === "hold") {
charge = Math.min(surplus, room, 4);
gridExport = surplus - charge;
discharge = 0;
} else {
// Support mode deliberately skips charging and uses available reserve.
gridExport = surplus;
discharge = Math.min(deficit, available, 16);
}
const gridImport = Math.max(0, deficit - discharge);
const importCost = gridImport * p.rate;
const exportCredit = gridExport * EXPORT_RATE;
const netCost = importCost - exportCredit;
soc = clamp(soc + charge - discharge, 0, CAPACITY);
rows.push({
...p,
solarUse,
windUse,
surplus,
deficit,
charge,
discharge,
gridImport,
gridExport,
importCost,
exportCredit,
netCost,
soc,
reserve,
available: Math.max(0, soc - reserve),
renewableServed: p.demand - gridImport,
renewableShare: p.demand > 0 ? (p.demand - gridImport) / p.demand * 100 : 0
});
}
return rows;
}
// ------------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------------
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfe3eb);
scene.fog = new THREE.Fog(0xbfe3eb, 44, 88);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
160
);
const cameraState = {
theta: 0.72,
phi: 0.86,
radius: 34,
target: new THREE.Vector3(0, 1.8, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrix();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xe9fbff, 0x547267, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.6);
sun.position.set(-12, 22, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00045;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8bdfff, 0.8);
fill.position.set(12, 8, -12);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.8,
metalness: options.metalness ?? 0,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
const mats = {
water: material(0x65bfd4, { roughness: 0.42, metalness: 0.08 }),
foam: material(0xdaf7f5, { roughness: 0.65, transparent: true, opacity: 0.66 }),
earth: material(0x6f8870),
earthDark: material(0x526d61),
rock: material(0x74858a),
sand: material(0xd9c99d),
grass: material(0x7fbd78),
grass2: material(0x71ad6d),
grass3: material(0x91c982),
path: material(0xc8b78e),
trunk: material(0x775743),
leaf: material(0x4b9871),
leaf2: material(0x65ad78),
house: material(0xf0e1c7),
houseBlue: material(0xb8d6d9),
roof: material(0xba6258),
roofBlue: material(0x4e7d8a),
door: material(0x634f49),
window: material(0xffd783, {
emissive: 0xffb84d,
emissiveIntensity: 0.52,
roughness: 0.35
}),
white: material(0xf3f5ed),
metal: material(0x71838b, { metalness: 0.35, roughness: 0.45 }),
dark: material(0x18323d, { roughness: 0.55 }),
panel: material(0x174d72, { metalness: 0.42, roughness: 0.28 }),
panelEdge: material(0x71bfe2, { metalness: 0.35, roughness: 0.3 }),
battery: material(0x6756a8),
batteryLight: material(0x70efc3, {
emissive: 0x46dba7,
emissiveIntensity: 1.4
}),
screenFrame: material(0x203c47),
dock: material(0x9c7658)
};
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ocean and animated foam tiles.
box(scene, [90, 0.65, 90], [0, -1.0, 0], mats.water, false);
const foamTiles = [];
for (let i = 0; i < 88; i++) {
const angle = deterministicNoise(i, 4) * Math.PI * 2;
const radius = 8.2 + deterministicNoise(i, 8) * 13;
const tile = box(
scene,
[0.7 + deterministicNoise(i, 2) * 1.8, 0.035, 0.22],
[
Math.cos(angle) * radius,
-0.655,
Math.sin(angle) * radius * 0.88
],
mats.foam,
false
);
tile.rotation.y = angle + Math.PI / 2;
foamTiles.push({ mesh: tile, phase: deterministicNoise(i, 9) * 10 });
}
// Deterministic island terrain made from one-celled voxel columns.
function islandRadius(x, z) {
const noise = (deterministicNoise(x, z) - 0.5) * 0.11;
return Math.sqrt(Math.pow(x / 7.0, 2) + Math.pow(z / 6.0, 2)) + noise;
}
function terrainHeight(x, z) {
const r = islandRadius(x, z);
const n = deterministicNoise(x + 0.5, z - 0.5);
if (r < 0.67) return 1.38 + Math.floor(n * 2) * 0.16;
return 1.85 + Math.floor(n * 3) * 0.30;
}
for (let x = -7; x <= 7; x++) {
for (let z = -6; z <= 6; z++) {
const r = islandRadius(x, z);
if (r > 0.99) continue;
const top = terrainHeight(x, z);
const bodyMat = r > 0.79 ? mats.sand : (deterministicNoise(x, z) > 0.5 ? mats.earth : mats.earthDark);
box(scene, [0.985, top + 0.65, 0.985], [x, (top - 0.65) / 2, z], bodyMat);
const capMat = r > 0.82
? mats.sand
: (deterministicNoise(x + 10, z + 7) > 0.66 ? mats.grass3 : mats.grass);
box(scene, [0.99, 0.22, 0.99], [x, top - 0.11, z], capMat);
if (r > 0.67 && deterministicNoise(x, z + 30) > 0.53) {
box(
scene,
[0.85, 0.75, 0.85],
[x + 0.12, -0.95 + deterministicNoise(z, x) * 0.2, z - 0.08],
mats.rock
);
}
}
}
// Path cubes connecting homes to the central dispatch area.
const homeLocations = [
[-4, 3],
[0, 3],
[4, 2],
[4, -2],
[-1, -4],
[-4, -3]
];
for (const [hx, hz] of homeLocations) {
const steps = Math.max(Math.abs(hx), Math.abs(hz)) * 2;
for (let i = 1; i < steps; i++) {
const t = i / steps;
const x = lerp(hx, 2, t);
const z = lerp(hz, 0, t);
box(
scene,
[0.52, 0.07, 0.52],
[x, terrainHeight(x, z) + 0.035, z],
mats.path,
false
);
}
}
function createHome(x, z, index) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z), z);
scene.add(group);
box(group, [1.9, 0.20, 1.7], [0, 0.10, 0], mats.path);
box(group, [1.58, 1.35, 1.42], [0, 0.88, 0], index % 3 === 0 ? mats.houseBlue : mats.house);
const roofMat = index % 2 === 0 ? mats.roof : mats.roofBlue;
box(group, [1.82, 0.27, 1.66], [0, 1.66, 0], roofMat);
box(group, [1.43, 0.27, 1.35], [0, 1.90, 0], roofMat);
box(group, [0.94, 0.27, 1.02], [0, 2.14, 0], roofMat);
box(group, [0.38, 0.78, 0.075], [0, 0.53, 0.735], mats.door);
box(group, [0.38, 0.38, 0.075], [-0.51, 0.92, 0.735], mats.window);
box(group, [0.38, 0.38, 0.075], [0.51, 0.92, 0.735], mats.window);
box(group, [0.075, 0.38, 0.38], [0.815, 0.92, 0.05], mats.window);
box(group, [0.26, 0.64, 0.26], [0.53, 2.28, -0.30], mats.dark);
box(group, [0.34, 0.10, 0.34], [0.53, 2.63, -0.30], mats.metal);
if (index === 0 || index === 3) {
const rooftop = new THREE.Group();
rooftop.position.set(0, 2.32, 0.02);
rooftop.rotation.x = -0.20;
group.add(rooftop);
box(rooftop, [1.10, 0.09, 0.70], [0, 0, 0], mats.panel);
for (let i = -2; i <= 2; i++) {
box(rooftop, [0.025, 0.018, 0.66], [i * 0.20, 0.06, 0], mats.panelEdge, false);
}
}
}
homeLocations.forEach(([x, z], index) => createHome(x, z, index));
// Solar farm.
const solarFarm = new THREE.Group();
solarFarm.position.set(-4, terrainHeight(-4, 0), 0);
scene.add(solarFarm);
box(solarFarm, [3.75, 0.18, 2.55], [0, 0.09, 0], mats.path);
const solarPanels = [];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 4; col++) {
const px = -1.32 + col * 0.88;
const pz = -0.58 + row * 1.16;
box(solarFarm, [0.08, 0.62, 0.08], [px - 0.30, 0.42, pz], mats.metal);
box(solarFarm, [0.08, 0.62, 0.08], [px + 0.30, 0.42, pz], mats.metal);
const panelGroup = new THREE.Group();
panelGroup.position.set(px, 0.79, pz);
panelGroup.rotation.x = -0.28;
solarFarm.add(panelGroup);
const panel = box(panelGroup, [1.02, 0.10, 0.73], [0, 0, 0], mats.panel);
solarPanels.push(panel);
for (let j = -2; j <= 2; j++) {
box(panelGroup, [0.025, 0.018, 0.69], [j * 0.19, 0.065, 0], mats.panelEdge, false);
}
}
}
box(solarFarm, [0.54, 0.88, 0.42], [1.76, 0.55, -0.82], mats.dark);
box(solarFarm, [0.32, 0.10, 0.04], [1.76, 0.73, -1.045], mats.batteryLight, false);
// Voxel wind turbines.
const rotors = [];
function createTurbine(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z), z);
group.scale.setScalar(scale);
scene.add(group);
box(group, [0.90, 0.18, 0.90], [0, 0.09, 0], mats.path);
box(group, [0.60, 0.46, 0.60], [0, 0.40, 0], mats.white);
box(group, [0.43, 0.75, 0.43], [0, 0.98, 0], mats.white);
box(group, [0.35, 0.75, 0.35], [0, 1.72, 0], mats.white);
box(group, [0.28, 0.75, 0.28], [0, 2.46, 0], mats.white);
box(group, [0.22, 0.72, 0.22], [0, 3.17, 0], mats.white);
const rotor = new THREE.Group();
rotor.position.set(0, 3.92, 0.20);
rotor.rotation.y = -0.30;
group.add(rotor);
box(rotor, [0.42, 0.42, 0.34], [0, 0, 0], mats.dark);
for (let i = 0; i < 3; i++) {
const pivot = new THREE.Group();
pivot.rotation.z = i * Math.PI * 2 / 3;
rotor.add(pivot);
box(pivot, [0.16, 2.10, 0.12], [0, 1.02, 0], mats.white);
box(pivot, [0.13, 0.56, 0.11], [0, 1.75, 0], mats.roofBlue);
}
rotors.push({ rotor, speed: 0.74 + scale * 0.12 });
}
createTurbine(3.0, -4.15, 1.02);
createTurbine(5.1, -1.75, 0.83);
// Battery storage bank.
const storage = new THREE.Group();
storage.position.set(0, terrainHeight(0, -1.35), -1.35);
scene.add(storage);
box(storage, [2.72, 0.22, 1.65], [0, 0.11, 0], mats.dark);
box(storage, [2.45, 0.10, 1.42], [0, 0.27, 0], mats.metal);
const batteryLights = [];
for (let i = 0; i < 6; i++) {
const bx = -0.98 + i * 0.39;
box(storage, [0.31, 1.05, 0.86], [bx, 0.83, 0], mats.battery);
box(storage, [0.25, 0.11, 0.91], [bx, 1.40, 0], mats.dark);
const light = box(storage, [0.10, 0.10, 0.04], [bx, 1.16, 0.455], mats.batteryLight, false);
batteryLights.push(light);
}
box(storage, [0.52, 0.72, 0.46], [1.46, 0.64, -0.62], mats.houseBlue);
box(storage, [0.27, 0.17, 0.04], [1.46, 0.79, -0.865], mats.panelEdge, false);
// Physical dispatch board with a live canvas display.
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 512;
boardCanvas.height = 320;
const boardContext = boardCanvas.getContext("2d");
const boardTexture = new THREE.CanvasTexture(boardCanvas);
boardTexture.colorSpace = THREE.SRGBColorSpace;
const dispatchBoard = new THREE.Group();
dispatchBoard.position.set(2.05, terrainHeight(2.05, 0.15), 0.15);
dispatchBoard.rotation.y = -0.48;
scene.add(dispatchBoard);
box(dispatchBoard, [0.16, 2.10, 0.16], [-0.94, 1.05, 0], mats.metal);
box(dispatchBoard, [0.16, 2.10, 0.16], [0.94, 1.05, 0], mats.metal);
box(dispatchBoard, [3.16, 1.92, 0.22], [0, 2.15, 0], mats.screenFrame);
box(dispatchBoard, [3.40, 0.16, 0.56], [0, 1.12, 0], mats.dark);
const screenMaterial = new THREE.MeshBasicMaterial({ map: boardTexture });
const screen = new THREE.Mesh(new THREE.PlaneGeometry(2.88, 1.68), screenMaterial);
screen.position.set(0, 2.15, 0.121);
dispatchBoard.add(screen);
function drawBoard(row) {
const ctx = boardContext;
ctx.clearRect(0, 0, 512, 320);
ctx.fillStyle = "#071b27";
ctx.fillRect(0, 0, 512, 320);
ctx.fillStyle = "#102f3d";
ctx.fillRect(0, 0, 512, 55);
ctx.fillStyle = "#67d8ff";
ctx.fillRect(0, 51, 512, 4);
ctx.font = "bold 25px system-ui";
ctx.fillStyle = "#eaf8ff";
ctx.fillText("ISLE // VOLT", 24, 35);
ctx.font = "bold 17px system-ui";
ctx.fillStyle = "#ffc857";
ctx.fillText("SIM", 442, 34);
ctx.font = "14px system-ui";
ctx.fillStyle = "#91afbd";
ctx.fillText(`${String(hour).padStart(2, "0")}:00 • ${mode.toUpperCase()}`, 25, 82);
const values = [
["SOLAR", row.solar, "#ffc857"],
["WIND", row.wind, "#66e0d0"],
["BATTERY", row.discharge, "#a991ff"],
["GRID", row.gridImport, "#ff796f"]
];
values.forEach(([label, value, color], i) => {
const y = 111 + i * 43;
ctx.font = "bold 15px system-ui";
ctx.fillStyle = "#c8dce5";
ctx.fillText(label, 25, y);
ctx.fillStyle = "#173746";
ctx.fillRect(130, y - 13, 260, 16);
ctx.fillStyle = color;
ctx.fillRect(130, y - 13, 260 * clamp(value / 30, 0, 1), 16);
ctx.fillStyle = "#eaf8ff";
ctx.font = "bold 15px system-ui";
ctx.textAlign = "right";
ctx.fillText(`${value.toFixed(1)} kW`, 488, y);
ctx.textAlign = "left";
});
ctx.fillStyle = "#ffc857";
ctx.font = "bold 13px system-ui";
ctx.fillText("LOCAL SIMULATION — NOT GRID CONTROL", 25, 302);
boardTexture.needsUpdate = true;
}
// Small lighthouse and dock for an original island silhouette.
const lighthouse = new THREE.Group();
lighthouse.position.set(5, terrainHeight(5, 3.65), 3.65);
scene.add(lighthouse);
box(lighthouse, [0.90, 1.65, 0.90], [0, 0.83, 0], mats.white);
box(lighthouse, [0.96, 0.22, 0.96], [0, 0.48, 0], mats.roof);
box(lighthouse, [0.78, 0.34, 0.78], [0, 1.84, 0], mats.window);
box(lighthouse, [1.02, 0.18, 1.02], [0, 2.08, 0], mats.roofBlue);
box(lighthouse, [0.16, 0.34, 0.16], [0, 2.30, 0], mats.metal);
const dock = new THREE.Group();
dock.position.set(5.9, 0.18, 4.1);
dock.rotation.y = -0.35;
scene.add(dock);
for (let i = 0; i < 7; i++) {
box(dock, [0.55, 0.16, 0.55], [i * 0.48, 0, 0], mats.dock);
if (i % 2 === 0) {
box(dock, [0.12, 0.70, 0.12], [i * 0.48, -0.39, -0.18], mats.dock);
box(dock, [0.12, 0.70, 0.12], [i * 0.48, -0.39, 0.18], mats.dock);
}
}
// Trees, placed to keep source and home areas readable.
const treePositions = [
[-6, 0], [-6, 2], [-6, -1], [-5, -4], [-3, 4.7],
[-2, 4.7], [2.8, 4.8], [5.8, 1], [6, -3], [-2.5, 1.5],
[1.4, 2.8], [-1.5, -2.9], [3.2, -3.6], [4.7, 0.7]
];
treePositions.forEach(([x, z], i) => {
if (islandRadius(x, z) > 0.96) return;
const y = terrainHeight(x, z);
const tree = new THREE.Group();
tree.position.set(x, y, z);
tree.scale.setScalar(0.85 + deterministicNoise(i, 13) * 0.28);
scene.add(tree);
box(tree, [0.24, 0.85, 0.24], [0, 0.43, 0], mats.trunk);
box(tree, [0.95, 0.62, 0.95], [0, 1.05, 0], i % 2 ? mats.leaf : mats.leaf2);
box(tree, [0.66, 0.56, 0.66], [0, 1.53, 0], mats.leaf2);
});
// Voxel clouds.
const clouds = [];
function createCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, [2.1, 0.55, 0.85], [0, 0, 0], mats.white, false);
box(group, [1.25, 0.75, 0.95], [-0.85, 0.23, 0], mats.white, false);
box(group, [1.45, 0.95, 1.00], [0.35, 0.29, 0], mats.white, false);
box(group, [0.95, 0.55, 0.75], [1.15, 0.03, 0], mats.white, false);
clouds.push({ group, speed: 0.18 + scale * 0.03 });
}
createCloud(-13, 11.8, -13, 1.0);
createCloud(13, 13.5, -19, 1.3);
createCloud(-19, 9.5, 5, 0.75);
// A stylized cube sun.
const cubeSun = new THREE.Group();
cubeSun.position.set(-19, 17, -25);
scene.add(cubeSun);
box(cubeSun, [2.4, 2.4, 2.4], [0, 0, 0], material(0xffd776, {
emissive: 0xffb84a,
emissiveIntensity: 0.65,
roughness: 0.7
}), false);
// ------------------------------------------------------------------
// Animated energy paths
// ------------------------------------------------------------------
const flows = [];
function addFlow(color, points, key, offset) {
const curve = new THREE.CatmullRomCurve3(points.map(p => new THREE.Vector3(...p)));
const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(48));
const lineMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const line = new THREE.Line(geometry, lineMaterial);
scene.add(line);
const particle = box(
scene,
[0.18, 0.18, 0.18],
[0, 0, 0],
material(color, {
emissive: color,
emissiveIntensity: 1.2,
roughness: 0.25
}),
false
);
flows.push({ curve, line, particle, key, offset, value: 0 });
}
addFlow(
0xffc857,
[[-4, 3.2, 0], [-2.5, 3.6, 0.5], [0.2, 3.1, 0.3], [2, 2.7, 0.15]],
"solar",
0.0
);
addFlow(
0x66e0d0,
[[3, 5.1, -4.15], [2.8, 5.0, -2.4], [2.4, 4.0, -0.7], [2, 2.7, 0.15]],
"wind",
0.25
);
addFlow(
0xa991ff,
[[0, 3.1, -1.35], [0.8, 3.2, -0.8], [1.5, 3.0, -0.2], [2, 2.7, 0.15]],
"battery",
0.52
);
addFlow(
0xff796f,
[[8.5, 1.1, -4.5], [6.2, 1.8, -2.8], [4.1, 2.6, -1.2], [2, 2.7, 0.15]],
"grid",
0.76
);
// ------------------------------------------------------------------
// UI updates
// ------------------------------------------------------------------
function money(value) {
const sign = value < 0 ? "-" : "";
return `${sign}$${Math.abs(value).toFixed(2)}`;
}
function updateModel() {
const day = simulateDay(mode, reservePercent);
const row = day[hour];
const reserveEnergy = CAPACITY * reservePercent / 100;
$("hourClock").textContent = `${String(hour).padStart(2, "0")}:00 · simulated hour`;
$("timelineClock").textContent = `${String(hour).padStart(2, "0")}:00`;
$("hourSlider").value = hour;
$("demandValue").textContent = row.demand.toFixed(1);
$("renewableValue").textContent = row.renewableShare.toFixed(0);
$("gridValue").textContent = row.gridImport.toFixed(1);
$("socValue").textContent = Math.round(row.soc / CAPACITY * 100);
const direct = row.solarUse + row.windUse;
$("barDirect").style.width = `${direct / row.demand * 100}%`;
$("barBattery").style.width = `${row.discharge / row.demand * 100}%`;
$("barGrid").style.width = `${row.gridImport / row.demand * 100}%`;
$("rowSolar").textContent = `${row.solar.toFixed(1)} kW`;
$("solarUsed").textContent = `${row.solarUse.toFixed(1)} kW used`;
$("rowWind").textContent = `${row.wind.toFixed(1)} kW`;
$("windUsed").textContent = `${row.windUse.toFixed(1)} kW used`;
$("rowBattery").textContent = `${row.discharge.toFixed(1)} kW`;
$("batteryCharged").textContent = `${row.charge.toFixed(1)} kW charging`;
$("rowImport").textContent = `${row.gridImport.toFixed(1)} kW`;
$("rowExport").textContent = `${row.gridExport.toFixed(1)} kW`;
$("rateValue").textContent = `$${row.rate.toFixed(2)}`;
$("ratePeriod").textContent = `${row.period} period`;
$("reserveLabel").textContent = `${reservePercent}%`;
$("socBlockValue").textContent = `${Math.round(row.soc / CAPACITY * 100)}%`;
$("socEnergy").textContent = `${row.soc.toFixed(1)} / 48.0 kWh`;
$("socBar").style.width = `${row.soc / CAPACITY * 100}%`;
$("socAvailable").textContent = `${row.available.toFixed(1)} kWh available`;
$("socReserve").textContent = `${reserveEnergy.toFixed(1)} kWh reserved`;
$("flowSolar").textContent = `${row.solarUse.toFixed(1)} kW`;
$("flowWind").textContent = `${row.windUse.toFixed(1)} kW`;
$("flowBattery").textContent = `${row.discharge.toFixed(1)} kW`;
$("flowGrid").textContent = `${row.gridImport.toFixed(1)} kW`;
$("hourlyCost").textContent = money(row.netCost);
$("importCost").textContent = money(row.importCost);
$("exportCredit").textContent = money(row.exportCredit);
$("productionTotal").textContent = `${(row.solar + row.wind).toFixed(1)} kW`;
const dayToDate = day.slice(0, hour + 1).reduce((sum, item) => sum + item.netCost, 0);
$("dayCost").textContent = money(dayToDate);
$("labelSolar").textContent = `${row.solar.toFixed(1)} kW`;
$("labelWind").textContent = `${row.wind.toFixed(1)} kW`;
$("labelBattery").textContent = `${Math.round(row.soc / CAPACITY * 100)}%`;
$("labelDispatch").textContent = mode.toUpperCase();
const descriptions = {
auto: "Auto charges with surplus generation and discharges to cover deficits while respecting the reserve.",
hold: "Hold charges with available surplus but does not discharge, protecting the selected battery reserve.",
support: "Support skips charging and uses available battery energy to reduce the synthetic grid import."
};
$("modeDescription").textContent = descriptions[mode];
document.querySelectorAll(".mode-tabs button").forEach(button => {
button.classList.toggle("active", button.dataset.mode === mode);
});
flows[0].value = row.solarUse;
flows[1].value = row.windUse;
flows[2].value = row.discharge;
flows[3].value = row.gridImport;
drawBoard(row);
}
// ------------------------------------------------------------------
// Controls
// ------------------------------------------------------------------
$("hourSlider").addEventListener("input", event => {
hour = Number(event.target.value);
updateModel();
});
document.querySelectorAll(".mode-tabs button").forEach(button => {
button.addEventListener("click", () => {
mode = button.dataset.mode;
updateModel();
});
});
$("reserveSlider").addEventListener("input", event => {
reservePercent = Number(event.target.value);
updateModel();
});
document.querySelectorAll(".preset-buttons button").forEach(button => {
button.addEventListener("click", () => {
hour = Number(button.dataset.hour);
updateModel();
});
});
function togglePlayback() {
playing = !playing;
$("playButton").textContent = playing ? "Ⅱ" : "▶";
$("playButton").setAttribute("aria-label", playing ? "Pause simulation" : "Play simulation");
if (playing) {
playTimer = setInterval(() => {
hour = (hour + 1) % 24;
updateModel();
}, 900);
} else {
clearInterval(playTimer);
}
}
$("playButton").addEventListener("click", togglePlayback);
$("metricsToggle").addEventListener("click", () => {
$("metricsPanel").classList.toggle("open");
$("dispatchPanel").classList.remove("open");
});
$("dispatchToggle").addEventListener("click", () => {
$("dispatchPanel").classList.toggle("open");
$("metricsPanel").classList.remove("open");
});
// Custom orbit / pan / zoom controls. No addons are imported.
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
cameraState.target.addScaledVector(right, -dx * cameraState.radius * 0.0016);
cameraState.target.addScaledVector(up, dy * cameraState.radius * 0.0016);
cameraState.target.x = clamp(cameraState.target.x, -9, 9);
cameraState.target.y = clamp(cameraState.target.y, 0, 7);
cameraState.target.z = clamp(cameraState.target.z, -9, 9);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi + dy * 0.005, 0.34, 1.25);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
18,
58
);
updateCamera();
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------------
// Render loop and world-space labels
// ------------------------------------------------------------------
const projected = new THREE.Vector3();
const labelAnchors = [
{ element: $("solarLabel"), point: new THREE.Vector3(-4, 3.7, 0) },
{ element: $("windLabel"), point: new THREE.Vector3(3, 5.6, -4.15) },
{ element: $("batteryLabel"), point: new THREE.Vector3(0, 3.0, -1.35) },
{ element: $("dispatchLabel"), point: new THREE.Vector3(2.05, 4.3, 0.15) }
];
function positionLabels() {
for (const label of labelAnchors) {
projected.copy(label.point).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "flex" : "none";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
let previousTime = performance.now();
renderer.setAnimationLoop(time => {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
rotors.forEach(({ rotor, speed }) => {
rotor.rotation.z += dt * speed;
});
foamTiles.forEach(({ mesh, phase }) => {
mesh.position.y = -0.655 + Math.sin(time * 0.0013 + phase) * 0.025;
mesh.scale.x = 0.92 + Math.sin(time * 0.001 + phase) * 0.08;
});
clouds.forEach(({ group, speed }) => {
group.position.x += dt * speed;
if (group.position.x > 24) group.position.x = -24;
});
cubeSun.rotation.y += dt * 0.08;
cubeSun.rotation.x += dt * 0.035;
flows.forEach((flow, index) => {
const normalized = clamp(flow.value / 20, 0, 1);
flow.line.material.opacity = flow.value > 0.01 ? 0.22 + normalized * 0.52 : 0.04;
flow.particle.visible = flow.value > 0.01;
const t = (time * 0.00016 * (0.8 + normalized) + flow.offset) % 1;
flow.particle.position.copy(flow.curve.getPointAt(t));
const particleScale = 0.75 + normalized * 0.85;
flow.particle.scale.set(particleScale, particleScale, particleScale);
flow.particle.rotation.x += dt * 2;
flow.particle.rotation.y += dt * 1.6;
});
const currentModel = simulateDay(mode, reservePercent)[hour];
batteryLights.forEach((light, index) => {
const threshold = (index + 1) / batteryLights.length;
light.visible = currentModel.soc / CAPACITY >= threshold;
});
solarPanels.forEach((panel, index) => {
panel.material.emissive.setHex(0x16466a);
panel.material.emissiveIntensity = currentModel.solar > 0.05 ? 0.08 : 0.01;
panel.rotation.z = Math.sin(time * 0.0004 + index) * 0.002;
});
positionLabels();
renderer.render(scene, camera);
});
updateModel();
$("loading").style.opacity = "0";
setTimeout(() => $("loading").remove(), 320);
</script>
</body>
</html>
```