Prompt specification
Build or customize the Three.js 3D scene "Power-time budgeting explorer" 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: Power-time budgeting explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/power-time-budgeting-explorer-x1632
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing electrical power and accumulated energy use. Let users schedule a few synthetic loads and inspect cumulative energy; keep units explicit and show that doubling duration differs from changing instantaneous power. Voxel style.
Working Three.js Starter (power-time-budgeting-explorer-x1632):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Grid Lab — Voxel Energy Scheduler</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1115;
--panel: #121b20;
--panel-2: #172329;
--panel-3: #1d2b31;
--line: #2b3b42;
--text: #edf4ef;
--muted: #93a8ad;
--green: #b8f34a;
--cyan: #4ed9d0;
--orange: #ffb45c;
--purple: #ba93ff;
--red: #ff6f70;
--shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select,
input[type="range"] {
cursor: pointer;
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
outline: 2px solid var(--green);
outline-offset: 2px;
}
.app-header {
min-height: 72px;
padding: 15px 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
border-bottom: 1px solid var(--line);
background:
linear-gradient(90deg, rgba(184, 243, 74, 0.05), transparent 35%),
#10171b;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
width: 39px;
height: 39px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-3deg);
}
.brand-mark i {
display: block;
background: var(--green);
border-radius: 1px;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(9) {
opacity: 0.28;
}
.brand-mark i:nth-child(5) {
background: var(--cyan);
}
.brand-title {
margin: 0;
font-size: 17px;
letter-spacing: 0.13em;
font-weight: 850;
}
.brand-subtitle {
margin: 4px 0 0;
color: var(--muted);
font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
}
.header-status {
display: flex;
align-items: center;
gap: 16px;
color: var(--muted);
font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.05em;
text-align: right;
}
.live-dot {
width: 8px;
height: 8px;
display: inline-block;
margin-right: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px rgba(184, 243, 74, 0.85);
}
.workspace {
min-height: calc(100vh - 72px);
display: grid;
grid-template-columns: 370px minmax(480px, 1fr) 350px;
gap: 14px;
padding: 14px;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: var(--shadow);
overflow: hidden;
}
.sidebar,
.insights {
max-height: calc(100vh - 100px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #42545c transparent;
}
.panel-heading {
padding: 17px 18px 15px;
border-bottom: 1px solid var(--line);
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--green);
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
.panel-heading h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.sidebar-body {
padding: 15px;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 0 0 11px;
color: #bdcbd0;
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section-label span:last-child {
color: var(--muted);
letter-spacing: 0;
text-transform: none;
}
.load-list {
display: grid;
gap: 9px;
}
.load-card {
position: relative;
padding: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel-2);
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.load-card:hover {
border-color: #496069;
transform: translateY(-1px);
}
.load-card.selected {
border-color: var(--load-color);
background:
linear-gradient(100deg, color-mix(in srgb, var(--load-color) 10%, transparent), transparent 58%),
var(--panel-2);
box-shadow: inset 3px 0 0 var(--load-color);
}
.load-card.disabled {
opacity: 0.48;
}
.load-top {
display: grid;
grid-template-columns: 18px minmax(0, 1fr) auto auto;
align-items: center;
gap: 8px;
margin-bottom: 11px;
}
.load-swatch {
width: 13px;
height: 13px;
padding: 0;
border: 0;
border-radius: 3px;
background: var(--load-color);
box-shadow: 0 0 12px color-mix(in srgb, var(--load-color) 50%, transparent);
}
.name-input {
min-width: 0;
padding: 2px 3px;
border: 1px solid transparent;
border-radius: 4px;
background: transparent;
color: var(--text);
font-size: 13px;
font-weight: 750;
}
.name-input:hover,
.name-input:focus {
border-color: var(--line);
background: #11191d;
}
.toggle {
position: relative;
width: 31px;
height: 18px;
display: block;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle span {
position: absolute;
inset: 0;
border-radius: 20px;
background: #36464d;
transition: 150ms ease;
}
.toggle span::after {
content: "";
position: absolute;
width: 12px;
height: 12px;
top: 3px;
left: 3px;
border-radius: 3px;
background: white;
transition: 150ms ease;
}
.toggle input:checked + span {
background: var(--green);
}
.toggle input:checked + span::after {
transform: translateX(13px);
background: #152006;
}
.remove-button {
width: 25px;
height: 25px;
padding: 0;
border: 1px solid transparent;
border-radius: 5px;
background: transparent;
color: var(--muted);
line-height: 1;
}
.remove-button:hover {
border-color: #633e42;
background: #3a2528;
color: #ff9c9d;
}
.load-fields {
display: grid;
grid-template-columns: 0.8fr 1fr 1fr;
gap: 7px;
}
.field-label {
min-width: 0;
color: var(--muted);
font: 9px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.field-label input,
.field-label select {
width: 100%;
height: 31px;
margin-top: 5px;
padding: 0 7px;
border: 1px solid #34464e;
border-radius: 6px;
background: #10181c;
color: var(--text);
font-size: 11px;
}
.field-label select {
padding-right: 3px;
}
.load-meta {
margin-top: 9px;
color: #a8bac0;
font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.row-error {
margin-top: 7px;
color: #ff9c9d;
font-size: 10px;
}
.add-load {
width: 100%;
margin-top: 11px;
padding: 10px 12px;
border: 1px dashed #455961;
border-radius: 8px;
background: transparent;
color: #c6d4d8;
font-size: 12px;
font-weight: 700;
}
.add-load:hover {
border-color: var(--green);
color: var(--green);
background: rgba(184, 243, 74, 0.04);
}
.synthetic-note {
margin: 15px 0 0;
padding: 11px;
border: 1px solid #314148;
border-radius: 8px;
background: #10181c;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.synthetic-note strong {
color: #d7e2e5;
}
.stage-panel {
min-height: 640px;
display: grid;
grid-template-rows: minmax(430px, 1fr) auto;
}
.scene-shell {
position: relative;
min-height: 430px;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, rgba(70, 217, 208, 0.07), transparent 36%),
#111a1f;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.stage-title {
position: absolute;
z-index: 4;
top: 17px;
left: 18px;
pointer-events: none;
}
.stage-title h2 {
margin: 0;
font-size: 15px;
}
.stage-title p {
margin: 5px 0 0;
color: var(--muted);
font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.stage-legend {
position: absolute;
z-index: 4;
top: 16px;
right: 16px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: 220px;
pointer-events: none;
}
.legend-chip {
padding: 5px 7px;
border: 1px solid rgba(66, 86, 94, 0.9);
border-radius: 5px;
background: rgba(13, 20, 24, 0.82);
color: #b6c6cb;
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.legend-chip i {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 2px;
background: var(--green);
}
.scene-help {
position: absolute;
z-index: 4;
left: 16px;
bottom: 14px;
padding: 7px 9px;
border: 1px solid rgba(66, 86, 94, 0.9);
border-radius: 6px;
background: rgba(13, 20, 24, 0.84);
color: var(--muted);
font: 9px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
pointer-events: none;
}
#label-layer {
position: absolute;
z-index: 3;
inset: 0;
pointer-events: none;
}
.voxel-label {
position: absolute;
min-width: 102px;
padding: 7px 8px;
border: 1px solid color-mix(in srgb, var(--load-color) 65%, #314148);
border-radius: 6px;
background: rgba(12, 19, 23, 0.92);
color: var(--text);
text-align: left;
box-shadow: 0 7px 18px rgba(0, 0, 0, 0.28);
transform: translate(-50%, -100%);
pointer-events: auto;
backdrop-filter: blur(5px);
}
.voxel-label strong {
display: block;
max-width: 145px;
overflow: hidden;
color: #e8f0ed;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.voxel-label span {
display: block;
margin-top: 3px;
color: var(--load-color);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.voxel-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font: 9px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.timeline-panel {
border-top: 1px solid var(--line);
background: #11191d;
}
.playback-row {
display: grid;
grid-template-columns: auto 76px minmax(100px, 1fr) auto;
align-items: center;
gap: 11px;
padding: 12px 15px 10px;
}
.play-button {
min-width: 91px;
height: 34px;
padding: 0 12px;
border: 0;
border-radius: 6px;
background: var(--green);
color: #172006;
font-size: 11px;
font-weight: 850;
}
.clock {
color: var(--text);
font: 15px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 800;
}
#time-slider {
width: 100%;
accent-color: var(--green);
}
.speed-select {
height: 31px;
padding: 0 7px;
border: 1px solid #34464e;
border-radius: 6px;
background: #10181c;
color: var(--text);
font-size: 10px;
}
.timeline-wrap {
position: relative;
padding: 0 15px 14px;
}
.time-ruler {
position: relative;
height: 24px;
margin: 0 0 3px 86px;
border-bottom: 1px solid #34464e;
cursor: crosshair;
}
.ruler-tick {
position: absolute;
bottom: 4px;
transform: translateX(-50%);
color: #81969c;
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.ruler-tick::after {
content: "";
position: absolute;
left: 50%;
top: 13px;
width: 1px;
height: 7px;
background: #43565e;
}
.timeline-lanes {
position: relative;
}
.timeline-lane {
position: relative;
height: 22px;
margin-bottom: 4px;
}
.lane-name {
position: absolute;
left: 0;
top: 4px;
width: 80px;
overflow: hidden;
color: #9eb0b5;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.lane-track {
position: absolute;
left: 86px;
right: 0;
top: 3px;
height: 15px;
border-radius: 3px;
background:
repeating-linear-gradient(
90deg,
transparent 0,
transparent calc(8.333% - 1px),
rgba(89, 108, 115, 0.22) calc(8.333% - 1px),
rgba(89, 108, 115, 0.22) 8.333%
);
}
.timeline-bar {
position: absolute;
top: 2px;
height: 11px;
min-width: 3px;
border-radius: 2px;
background: var(--load-color);
box-shadow: 0 0 10px color-mix(in srgb, var(--load-color) 25%, transparent);
cursor: pointer;
}
.timeline-bar.disabled {
opacity: 0.3;
box-shadow: none;
}
.timeline-cursor {
position: absolute;
z-index: 5;
top: 0;
bottom: 0;
left: 86px;
width: 1px;
background: var(--green);
box-shadow: 0 0 9px rgba(184, 243, 74, 0.7);
pointer-events: none;
}
.timeline-cursor::before {
content: "";
position: absolute;
top: -2px;
left: -4px;
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--green);
}
.insights {
display: flex;
flex-direction: column;
}
.metrics {
padding: 14px;
border-bottom: 1px solid var(--line);
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric-card {
min-height: 93px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel-2);
}
.metric-card.wide {
grid-column: 1 / -1;
background:
linear-gradient(125deg, rgba(184, 243, 74, 0.09), transparent 60%),
var(--panel-2);
}
.metric-name {
color: var(--muted);
font: 9px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metric-value {
margin-top: 9px;
color: var(--text);
font-size: 25px;
font-weight: 850;
letter-spacing: -0.045em;
}
.metric-card.wide .metric-value {
color: var(--green);
font-size: 31px;
}
.metric-unit {
margin-left: 4px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0;
}
.metric-caption {
margin-top: 5px;
color: #82979d;
font-size: 10px;
line-height: 1.35;
}
.chart-section {
padding: 14px;
border-bottom: 1px solid var(--line);
}
.chart-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
}
.chart-heading h3 {
margin: 0;
font-size: 12px;
}
.chart-heading span {
color: var(--muted);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.chart {
width: 100%;
height: auto;
display: block;
overflow: visible;
}
.chart text {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.comparison {
padding: 14px;
}
.comparison h3 {
margin: 0;
font-size: 13px;
}
.comparison-subtitle {
margin: 5px 0 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.compare-table-wrap {
overflow-x: auto;
border: 1px solid var(--line);
border-radius: 8px;
}
.compare-table {
width: 100%;
min-width: 305px;
border-collapse: collapse;
background: #10181c;
font: 9px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.compare-table th,
.compare-table td {
padding: 9px 7px;
border-bottom: 1px solid var(--line);
text-align: right;
white-space: nowrap;
}
.compare-table th:first-child,
.compare-table td:first-child {
text-align: left;
}
.compare-table th {
color: #8fa3a9;
font-weight: 600;
}
.compare-table td {
color: #d8e3e5;
}
.compare-table tr:last-child td {
border-bottom: 0;
}
.compare-table .scenario-duration td:first-child {
color: var(--cyan);
}
.compare-table .scenario-power td:first-child {
color: var(--orange);
}
.comparison-note {
margin: 11px 0 0;
padding: 10px;
border-left: 3px solid var(--green);
border-radius: 0 6px 6px 0;
background: rgba(184, 243, 74, 0.055);
color: #b9c9cd;
font-size: 10px;
line-height: 1.5;
}
.comparison-note strong {
color: var(--green);
}
.toast {
position: fixed;
z-index: 20;
left: 50%;
bottom: 24px;
max-width: min(90vw, 420px);
padding: 10px 14px;
border: 1px solid #4d646d;
border-radius: 8px;
background: #172229;
color: white;
box-shadow: var(--shadow);
font-size: 12px;
transform: translate(-50%, 20px);
opacity: 0;
pointer-events: none;
transition: 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1220px) {
.workspace {
grid-template-columns: 340px minmax(470px, 1fr);
}
.insights {
grid-column: 1 / -1;
max-height: none;
display: grid;
grid-template-columns: 0.9fr 1.1fr 1.25fr;
}
.metrics,
.chart-section {
border-bottom: 0;
border-right: 1px solid var(--line);
}
.comparison {
padding: 14px;
}
}
@media (max-width: 820px) {
.app-header {
align-items: flex-start;
}
.header-status {
display: none;
}
.workspace {
grid-template-columns: 1fr;
}
.sidebar,
.insights {
max-height: none;
}
.insights {
grid-column: auto;
display: block;
}
.metrics,
.chart-section {
border-right: 0;
border-bottom: 1px solid var(--line);
}
.stage-panel {
min-height: 610px;
}
.scene-shell {
min-height: 430px;
}
}
@media (max-width: 520px) {
.workspace {
padding: 8px;
gap: 8px;
}
.brand-subtitle {
display: none;
}
.playback-row {
grid-template-columns: auto 62px 1fr;
}
.speed-select {
grid-column: 1 / -1;
width: 100%;
}
.stage-legend {
display: none;
}
.load-fields {
grid-template-columns: 1fr 1fr;
}
.load-fields .field-label:first-child {
grid-column: 1 / -1;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<h1 class="brand-title">GRID LAB</h1>
<p class="brand-subtitle">VOXEL ENERGY SCHEDULER / 24-HOUR MODEL</p>
</div>
</div>
<div class="header-status">
<div>
SYNTHETIC LOAD PROFILE<br />
CONSTANT-POWER ASSUMPTION
</div>
<div><span class="live-dot"></span>LOCAL SIMULATION</div>
</div>
</header>
<main class="workspace">
<aside class="panel sidebar">
<div class="panel-heading">
<div>
<p class="eyebrow">01 / Schedule</p>
<h2>Synthetic loads</h2>
<p>Edit power and operating windows. All values are constant while active.</p>
</div>
</div>
<div class="sidebar-body">
<div class="section-label">
<span>Load definitions</span>
<span id="load-count">0 loads</span>
</div>
<div id="load-list" class="load-list"></div>
<button id="add-load" class="add-load" type="button">+ Add synthetic load</button>
<p class="synthetic-note">
<strong>Model scope:</strong> one calendar day, no standby power, no losses,
no ramping, and no utility tariff data. Scheduled energy is calculated as
<strong>kW × hours = kWh</strong>.
</p>
</div>
</aside>
<section class="panel stage-panel">
<div id="scene-shell" class="scene-shell">
<div id="scene"></div>
<div id="label-layer"></div>
<div class="stage-title">
<p class="eyebrow">02 / Spatial view</p>
<h2>Voxel demand map</h2>
<p>Active machines glow; cube towers show accumulated energy.</p>
</div>
<div class="stage-legend">
<div class="legend-chip"><i></i>ENERGY CUBES = kWh</div>
<div class="legend-chip">DRAG = ORBIT</div>
<div class="legend-chip">SCROLL = ZOOM</div>
</div>
<div class="scene-help">Click a voxel station to inspect its load</div>
</div>
<div class="timeline-panel">
<div class="playback-row">
<button id="play-button" class="play-button" type="button">▶ Play day</button>
<output id="current-clock" class="clock">18:00</output>
<input
id="time-slider"
type="range"
min="0"
max="1440"
step="5"
value="1080"
aria-label="Inspection time"
/>
<select id="playback-speed" class="speed-select" aria-label="Playback speed">
<option value="60">1 hour / second</option>
<option value="180" selected>3 hours / second</option>
<option value="360">6 hours / second</option>
</select>
</div>
<div class="timeline-wrap">
<div id="time-ruler" class="time-ruler"></div>
<div id="timeline-lanes" class="timeline-lanes"></div>
<div id="timeline-cursor" class="timeline-cursor"></div>
</div>
</div>
</section>
<aside class="panel insights">
<div class="metrics">
<div class="section-label">
<span>03 / Inspect</span>
<span id="inspection-time">at 18:00</span>
</div>
<div class="metric-grid">
<div class="metric-card">
<div class="metric-name">Instantaneous power</div>
<div class="metric-value">
<span id="current-power">0.0</span><span class="metric-unit">kW</span>
</div>
<div id="active-count" class="metric-caption">0 active loads</div>
</div>
<div class="metric-card">
<div class="metric-name">Scheduled energy</div>
<div class="metric-value">
<span id="scheduled-energy">0.0</span><span class="metric-unit">kWh</span>
</div>
<div class="metric-caption">Full 24-hour day</div>
</div>
<div class="metric-card wide">
<div class="metric-name">Accumulated energy</div>
<div class="metric-value">
<span id="accumulated-energy">0.0</span><span class="metric-unit">kWh</span>
</div>
<div id="energy-caption" class="metric-caption">
From 00:00 to the selected inspection time
</div>
</div>
</div>
</div>
<section class="chart-section">
<div class="chart-heading">
<h3>Instantaneous demand</h3>
<span>kW vs time</span>
</div>
<svg id="power-chart" class="chart" viewBox="0 0 300 145" aria-label="Power profile"></svg>
</section>
<section class="chart-section">
<div class="chart-heading">
<h3>Accumulated energy</h3>
<span>kWh vs time</span>
</div>
<svg id="energy-chart" class="chart" viewBox="0 0 300 145" aria-label="Cumulative energy curve"></svg>
</section>
<section class="comparison">
<p class="eyebrow">Power × time</p>
<h3 id="compare-title">Compare selected load</h3>
<p class="comparison-subtitle">
Doubling duration and doubling instantaneous power can produce the same
energy, but they create different demand profiles.
</p>
<div class="compare-table-wrap">
<table class="compare-table">
<thead>
<tr>
<th>Case</th>
<th>Power (kW)</th>
<th>Duration (h)</th>
<th>Energy (kWh)</th>
<th>Peak (kW)</th>
</tr>
</thead>
<tbody id="compare-body"></tbody>
</table>
</div>
<p class="comparison-note" id="comparison-note"></p>
</section>
</aside>
</main>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DAY = 24 * 60;
const HOUR = 60;
const state = {
cursor: 18 * HOUR,
selectedId: "ev",
playing: false,
speed: 180,
loads: [
{
id: "ev",
name: "EV fast charger",
power: 7.2,
start: 0,
end: 7.5 * HOUR,
enabled: true,
color: "#4ed9d0"
},
{
id: "water",
name: "Water heater",
power: 4.5,
start: 6 * HOUR,
end: 8 * HOUR,
enabled: true,
color: "#ffb45c"
},
{
id: "dryer",
name: "Laundry dryer",
power: 2.8,
start: 10 * HOUR,
end: 11.5 * HOUR,
enabled: true,
color: "#ba93ff"
},
{
id: "hvac",
name: "Room HVAC",
power: 3.6,
start: 16 * HOUR,
end: 21 * HOUR,
enabled: true,
color: "#b8f34a"
},
{
id: "heatpump",
name: "Heat pump",
power: 1.8,
start: 19 * HOUR,
end: 23 * HOUR,
enabled: true,
color: "#ff6f70"
}
]
};
const palette = [
"#4ed9d0",
"#ffb45c",
"#ba93ff",
"#b8f34a",
"#ff6f70",
"#73a8ff",
"#f7df67",
"#ed82c8"
];
const dom = {
loadList: document.querySelector("#load-list"),
loadCount: document.querySelector("#load-count"),
addLoad: document.querySelector("#add-load"),
playButton: document.querySelector("#play-button"),
playbackSpeed: document.querySelector("#playback-speed"),
slider: document.querySelector("#time-slider"),
clock: document.querySelector("#current-clock"),
inspectionTime: document.querySelector("#inspection-time"),
currentPower: document.querySelector("#current-power"),
scheduledEnergy: document.querySelector("#scheduled-energy"),
accumulatedEnergy: document.querySelector("#accumulated-energy"),
activeCount: document.querySelector("#active-count"),
energyCaption: document.querySelector("#energy-caption"),
powerChart: document.querySelector("#power-chart"),
energyChart: document.querySelector("#energy-chart"),
compareTitle: document.querySelector("#compare-title"),
compareBody: document.querySelector("#compare-body"),
comparisonNote: document.querySelector("#comparison-note"),
ruler: document.querySelector("#time-ruler"),
lanes: document.querySelector("#timeline-lanes"),
cursor: document.querySelector("#timeline-cursor"),
scene: document.querySelector("#scene"),
sceneShell: document.querySelector("#scene-shell"),
labelLayer: document.querySelector("#label-layer"),
toast: document.querySelector("#toast")
};
function escapeHTML(value) {
return String(value).replace(/[&<>'"]/g, character => ({
"&": "&",
"<": "<",
">": ">",
"'": "'",
'"': """
}[character]));
}
function formatClock(minutes, includeEnd = false) {
const total = Math.max(0, Math.min(DAY, Math.round(minutes)));
const h = Math.floor(total / 60);
const m = total % 60;
if (includeEnd && total === DAY) return "24:00";
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function formatNumber(value, decimals = 1) {
return Number(value).toLocaleString(undefined, {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals
});
}
function formatDuration(minutes) {
const hours = minutes / 60;
return Number.isInteger(hours)
? `${hours} h`
: `${hours.toFixed(2).replace(/0$/, "")} h`;
}
function loadDuration(load) {
return Math.max(0, load.end - load.start);
}
function loadEnergy(load, until = DAY) {
if (!load.enabled) return 0;
const overlap = Math.max(
0,
Math.min(load.end, until) - load.start
);
return load.power * overlap / 60;
}
function isActive(load, time = state.cursor) {
return load.enabled && time >= load.start && time < load.end;
}
function totalPower(time = state.cursor) {
return state.loads.reduce(
(sum, load) => sum + (isActive(load, time) ? load.power : 0),
0
);
}
function totalEnergy(until = DAY) {
return state.loads.reduce((sum, load) => sum + loadEnergy(load, until), 0);
}
function selectedLoad() {
return state.loads.find(load => load.id === state.selectedId) || state.loads[0];
}
function timeOptions() {
let html = "";
for (let minute = 0; minute <= DAY; minute += 15) {
html += `<option value="${minute}">${formatClock(minute, true)}</option>`;
}
return html;
}
const optionHTML = timeOptions();
function cardMeta(load) {
const duration = loadDuration(load);
const energy = load.enabled ? load.power * duration / 60 : 0;
return `${formatDuration(duration)} · ${formatNumber(energy)} kWh scheduled`;
}
function renderLoadRows() {
dom.loadCount.textContent = `${state.loads.length} load${state.loads.length === 1 ? "" : "s"}`;
dom.loadList.innerHTML = state.loads.map(load => `
<article
class="load-card ${load.id === state.selectedId ? "selected" : ""} ${load.enabled ? "" : "disabled"}"
data-load-id="${escapeHTML(load.id)}"
style="--load-color:${escapeHTML(load.color)}"
>
<div class="load-top">
<button
class="load-swatch"
type="button"
data-action="focus"
aria-label="Inspect ${escapeHTML(load.name)}"
title="Inspect this load"
></button>
<input
class="name-input"
type="text"
data-field="name"
value="${escapeHTML(load.name)}"
aria-label="Load name"
/>
<label class="toggle" title="Enable or disable load">
<input
type="checkbox"
data-field="enabled"
${load.enabled ? "checked" : ""}
aria-label="Enable ${escapeHTML(load.name)}"
/>
<span></span>
</label>
<button
class="remove-button"
type="button"
data-action="remove"
aria-label="Remove ${escapeHTML(load.name)}"
title="Remove load"
>×</button>
</div>
<div class="load-fields">
<label class="field-label">
Power (kW)
<input
type="number"
data-field="power"
min="0.1"
max="100"
step="0.1"
value="${load.power}"
/>
</label>
<label class="field-label">
Start
<select data-field="start">
${optionHTML}
</select>
</label>
<label class="field-label">
End
<select data-field="end">
${optionHTML}
</select>
</label>
</div>
<div class="load-meta">${cardMeta(load)}</div>
<div class="row-error" hidden></div>
</article>
`).join("");
dom.loadList.querySelectorAll('select[data-field="start"]').forEach(select => {
const load = state.loads.find(item => item.id === select.closest(".load-card").dataset.loadId);
select.value = String(load.start);
});
dom.loadList.querySelectorAll('select[data-field="end"]').forEach(select => {
const load = state.loads.find(item => item.id === select.closest(".load-card").dataset.loadId);
select.value = String(load.end);
});
}
function showToast(message) {
dom.toast.textContent = message;
dom.toast.classList.add("visible");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => {
dom.toast.classList.remove("visible");
}, 2400);
}
dom.loadList.addEventListener("input", event => {
const field = event.target.dataset.field;
if (!field || !["name", "power"].includes(field)) return;
const card = event.target.closest(".load-card");
const load = state.loads.find(item => item.id === card.dataset.loadId);
if (!load) return;
if (field === "name") {
load.name = event.target.value || "Untitled load";
}
if (field === "power") {
const value = Number(event.target.value);
if (Number.isFinite(value)) {
load.power = Math.max(0.1, Math.min(100, value));
}
}
card.querySelector(".load-meta").textContent = cardMeta(load);
updateDynamicUI();
});
dom.loadList.addEventListener("change", event => {
const field = event.target.dataset.field;
const card = event.target.closest(".load-card");
if (!card) return;
const load = state.loads.find(item => item.id === card.dataset.loadId);
if (!load) return;
if (field === "enabled") {
load.enabled = event.target.checked;
card.classList.toggle("disabled", !load.enabled);
updateDynamicUI();
return;
}
if (field === "start" || field === "end") {
const start = Number(card.querySelector('[data-field="start"]').value);
const end = Number(card.querySelector('[data-field="end"]').value);
const error = card.querySelector(".row-error");
if (end <= start) {
error.hidden = false;
error.textContent = "End must be later than start in this single-day model.";
event.target.value = String(field === "start" ? load.start : load.end);
return;
}
error.hidden = true;
load.start = start;
load.end = end;
card.querySelector(".load-meta").textContent = cardMeta(load);
updateDynamicUI();
}
});
dom.loadList.addEventListener("click", event => {
const card = event.target.closest(".load-card");
if (!card) return;
const action = event.target.closest("button")?.dataset.action;
const id = card.dataset.loadId;
if (action === "focus") {
selectLoad(id);
return;
}
if (action === "remove") {
if (state.loads.length <= 1) {
showToast("At least one load is required.");
return;
}
state.loads = state.loads.filter(load => load.id !== id);
if (state.selectedId === id) state.selectedId = state.loads[0].id;
renderLoadRows();
updateDynamicUI();
showToast("Load removed.");
return;
}
if (!event.target.closest("input, select, button")) {
selectLoad(id);
}
});
dom.addLoad.addEventListener("click", () => {
if (state.loads.length >= 8) {
showToast("This demo supports up to eight loads.");
return;
}
const index = state.loads.length;
const id = `load-${Date.now()}`;
state.loads.push({
id,
name: `Synthetic load ${index + 1}`,
power: 1 + (index % 3) * 0.5,
start: 12 * HOUR,
end: 14 * HOUR,
enabled: true,
color: palette[index % palette.length]
});
state.selectedId = id;
renderLoadRows();
updateDynamicUI();
showToast("New synthetic load added.");
});
function selectLoad(id) {
if (!state.loads.some(load => load.id === id)) return;
state.selectedId = id;
renderLoadRows();
updateDynamicUI();
}
function renderMetrics() {
const power = totalPower();
const accumulated = totalEnergy(state.cursor);
const scheduled = totalEnergy(DAY);
const active = state.loads.filter(load => isActive(load)).length;
dom.currentPower.textContent = formatNumber(power);
dom.scheduledEnergy.textContent = formatNumber(scheduled);
dom.accumulatedEnergy.textContent = formatNumber(accumulated);
dom.activeCount.textContent =
`${active} active load${active === 1 ? "" : "s"} at ${formatClock(state.cursor)}`;
dom.clock.textContent = formatClock(state.cursor);
dom.inspectionTime.textContent = `at ${formatClock(state.cursor)}`;
dom.energyCaption.textContent =
`From 00:00 to ${formatClock(state.cursor)} · ${formatNumber(accumulated / scheduled * 100, 0)}% of scheduled energy`;
dom.slider.value = String(Math.round(state.cursor));
dom.playButton.textContent = state.playing ? "❚❚ Pause" : "▶ Play day";
}
function renderComparison() {
const load = selectedLoad();
if (!load) return;
const duration = loadDuration(load) / 60;
const power = load.power;
const baseEnergy = power * duration;
const doubleDurationEnergy = power * duration * 2;
const doublePowerEnergy = power * 2 * duration;
dom.compareTitle.textContent = `Compare: ${load.name}`;
dom.compareBody.innerHTML = `
<tr>
<td>Base</td>
<td>${formatNumber(power)}</td>
<td>${formatNumber(duration, 2)}</td>
<td>${formatNumber(baseEnergy)}</td>
<td>${formatNumber(power)}</td>
</tr>
<tr class="scenario-duration">
<td>2× duration</td>
<td>${formatNumber(power)}</td>
<td>${formatNumber(duration * 2, 2)}</td>
<td>${formatNumber(doubleDurationEnergy)}</td>
<td>${formatNumber(power)}</td>
</tr>
<tr class="scenario-power">
<td>2× power</td>
<td>${formatNumber(power * 2)}</td>
<td>${formatNumber(duration, 2)}</td>
<td>${formatNumber(doublePowerEnergy)}</td>
<td>${formatNumber(power * 2)}</td>
</tr>
`;
dom.comparisonNote.innerHTML = `
<strong>Same energy, different grid impact.</strong>
Here, both changes double energy because
<strong>energy = kW × hours</strong>. Doubling duration keeps peak demand at
<strong>${formatNumber(power)} kW</strong>; doubling power raises peak demand to
<strong>${formatNumber(power * 2)} kW</strong> for the original duration.
`;
}
function niceMaximum(value) {
if (value <= 0) return 1;
const magnitude = 10 ** Math.floor(Math.log10(value));
const normalized = value / magnitude;
const nice = normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;
return nice * magnitude;
}
function chartSVG(values, maximum, unit, color, cursor, fillID) {
const width = 300;
const height = 145;
const left = 36;
const right = 10;
const top = 10;
const bottom = 24;
const plotWidth = width - left - right;
const plotHeight = height - top - bottom;
const x = index => left + index / (values.length - 1) * plotWidth;
const y = value => top + plotHeight - value / maximum * plotHeight;
const line = values.map((value, index) =>
`${index ? "L" : "M"}${x(index).toFixed(2)},${y(value).toFixed(2)}`
).join(" ");
const area = `${line} L${x(values.length - 1)},${top + plotHeight} L${left},${top + plotHeight} Z`;
const cursorX = x(cursor / 15);
const grid = [0, 0.5, 1].map(ratio => {
const gridY = top + plotHeight - ratio * plotHeight;
const value = maximum * ratio;
return `
<line x1="${left}" y1="${gridY}" x2="${width - right}" y2="${gridY}"
stroke="#2b3b42" stroke-width="1" />
<text x="${left - 6}" y="${gridY + 3}" text-anchor="end"
fill="#7f959b" font-size="8">${formatNumber(value, maximum < 5 ? 1 : 0)}</text>
`;
}).join("");
const ticks = [0, 6, 12, 18, 24].map(hour => {
const tickX = left + hour / 24 * plotWidth;
return `
<text x="${tickX}" y="${height - 7}" text-anchor="middle"
fill="#7f959b" font-size="8">${String(hour).padStart(2, "0")}:00</text>
`;
}).join("");
return `
<defs>
<linearGradient id="${fillID}" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="${color}" stop-opacity="0.27" />
<stop offset="100%" stop-color="${color}" stop-opacity="0.015" />
</linearGradient>
</defs>
${grid}
<text x="${left - 6}" y="${top - 1}" text-anchor="end"
fill="#a9bbc0" font-size="8">${unit}</text>
<path d="${area}" fill="url(#${fillID})" />
<path d="${line}" fill="none" stroke="${color}" stroke-width="2"
vector-effect="non-scaling-stroke" />
<line x1="${cursorX}" y1="${top}" x2="${cursorX}" y2="${top + plotHeight}"
stroke="#edf4ef" stroke-width="1" stroke-dasharray="3 3" opacity="0.75" />
${ticks}
`;
}
function renderCharts() {
const powerValues = [];
const energyValues = [];
for (let minute = 0; minute <= DAY; minute += 15) {
powerValues.push(totalPower(minute));
energyValues.push(totalEnergy(minute));
}
const powerMaximum = niceMaximum(Math.max(...powerValues, 1));
const energyMaximum = niceMaximum(Math.max(...energyValues, 1));
dom.powerChart.innerHTML = chartSVG(
powerValues,
powerMaximum,
"kW",
"#4ed9d0",
state.cursor,
"power-fill"
);
dom.energyChart.innerHTML = chartSVG(
energyValues,
energyMaximum,
"kWh",
"#b8f34a",
state.cursor,
"energy-fill"
);
}
function renderTimeline() {
dom.ruler.innerHTML = [0, 3, 6, 9, 12, 15, 18, 21, 24].map(hour => `
<span class="ruler-tick" style="left:${hour / 24 * 100}%">${String(hour).padStart(2, "0")}</span>
`).join("");
dom.lanes.innerHTML = state.loads.map(load => {
const left = load.start / DAY * 100;
const width = loadDuration(load) / DAY * 100;
return `
<div class="timeline-lane" style="--load-color:${escapeHTML(load.color)}">
<div class="lane-name" title="${escapeHTML(load.name)}">${escapeHTML(load.name)}</div>
<div class="lane-track">
<button
class="timeline-bar ${load.enabled ? "" : "disabled"}"
type="button"
data-timeline-id="${escapeHTML(load.id)}"
title="${escapeHTML(load.name)}: ${formatNumber(load.power)} kW, ${formatDuration(loadDuration(load))}"
style="left:${left}%;width:${width}%"
aria-label="Inspect ${escapeHTML(load.name)} schedule"
></button>
</div>
</div>
`;
}).join("");
dom.cursor.style.left = `calc(86px + (100% - 86px) * ${state.cursor / DAY})`;
}
dom.lanes.addEventListener("click", event => {
const bar = event.target.closest("[data-timeline-id]");
if (bar) selectLoad(bar.dataset.timelineId);
});
dom.ruler.addEventListener("pointerdown", event => {
const rect = dom.ruler.getBoundingClientRect();
state.cursor = THREE.MathUtils.clamp(
(event.clientX - rect.left) / rect.width * DAY,
0,
DAY
);
updateDynamicUI();
});
dom.slider.addEventListener("input", () => {
state.cursor = Number(dom.slider.value);
updateDynamicUI();
});
dom.playButton.addEventListener("click", () => {
if (!state.playing && state.cursor >= DAY) state.cursor = 0;
state.playing = !state.playing;
renderMetrics();
});
dom.playbackSpeed.addEventListener("change", () => {
state.speed = Number(dom.playbackSpeed.value);
});
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x111a1f);
scene.fog = new THREE.Fog(0x111a1f, 18, 34);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
dom.scene.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xcde8ef, 0x182027, 2.1);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xffffff, 3.3);
sun.position.set(7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x4ed9d0, 1.25);
rim.position.set(-8, 5, -7);
scene.add(rim);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({ color: 0x10181c, roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.66;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(12.4, 0.55, 8.2),
new THREE.MeshStandardMaterial({ color: 0x26353b, roughness: 0.9 })
);
platform.position.y = -0.38;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const tileGeometry = new THREE.BoxGeometry(0.47, 0.075, 0.47);
const tileMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.88,
metalness: 0.03
});
const tileCountX = 24;
const tileCountZ = 15;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCountX * tileCountZ);
tiles.receiveShadow = true;
const matrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = 0; z < tileCountZ; z++) {
for (let x = 0; x < tileCountX; x++) {
const px = -5.75 + x * 0.5;
const pz = -3.5 + z * 0.5;
matrix.makeTranslation(px, -0.075, pz);
tiles.setMatrixAt(tileIndex, matrix);
const checker = (x + z) % 2 === 0;
tileColor.set(checker ? 0x304047 : 0x29373d);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// A small voxel utility corridor adds depth to the scene.
const utilityMaterial = new THREE.MeshStandardMaterial({
color: 0x34464e,
roughness: 0.75
});
function utilityBox(size, position) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...size),
utilityMaterial
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
utilityBox([0.16, 3.1, 0.16], [-5.4, 1.45, -3.3]);
utilityBox([0.16, 3.1, 0.16], [5.4, 1.45, -3.3]);
utilityBox([10.9, 0.14, 0.14], [0, 2.85, -3.3]);
for (let x = -5; x <= 5; x += 1.25) {
utilityBox([0.05, 0.62, 0.05], [x, 2.48, -3.3]);
}
const stationPositions = [
[-3.7, 0, -1.55],
[0, 0, -1.55],
[3.7, 0, -1.55],
[-3.7, 0, 1.45],
[0, 0, 1.45],
[3.7, 0, 1.45],
[-1.85, 0, 1.45],
[1.85, 0, 1.45]
];
const stationVisuals = new Map();
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x142027,
roughness: 0.72,
metalness: 0.15
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x7ac9d1,
roughness: 0.25,
metalness: 0.35,
emissive: 0x102c33,
emissiveIntensity: 0.35
});
const whiteMaterial = new THREE.MeshStandardMaterial({
color: 0xdce8e6,
roughness: 0.72
});
function stationBox(parent, size, position, material, loadId) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.loadId = loadId;
parent.add(mesh);
return mesh;
}
function createStation(load, index) {
const group = new THREE.Group();
group.position.set(...stationPositions[index]);
scene.add(group);
const accentMaterial = new THREE.MeshStandardMaterial({
color: load.color,
roughness: 0.62,
metalness: 0.12,
emissive: load.color,
emissiveIntensity: 0.03
});
const energyMaterial = new THREE.MeshStandardMaterial({
color: load.color,
roughness: 0.45,
metalness: 0.08,
emissive: load.color,
emissiveIntensity: 0.18
});
const pad = stationBox(
group,
[2.45, 0.16, 1.72],
[0, 0.07, 0],
darkMaterial,
load.id
);
pad.receiveShadow = true;
// Every model is composed only from box-based voxel parts.
if (load.id === "ev") {
stationBox(group, [0.38, 1.65, 0.48], [-0.7, 0.95, -0.15], accentMaterial, load.id);
stationBox(group, [0.42, 0.22, 0.52], [-0.7, 1.87, -0.15], whiteMaterial, load.id);
stationBox(group, [1.15, 0.35, 0.7], [0.18, 0.36, 0.05], accentMaterial, load.id);
stationBox(group, [0.72, 0.34, 0.64], [0.05, 0.63, 0.05], glassMaterial, load.id);
stationBox(group, [0.18, 0.18, 0.72], [0.65, 0.24, 0.05], darkMaterial, load.id);
stationBox(group, [0.18, 0.18, 0.72], [-0.35, 0.24, 0.05], darkMaterial, load.id);
} else if (load.id === "water") {
stationBox(group, [0.82, 0.72, 0.82], [-0.42, 0.51, -0.1], accentMaterial, load.id);
stationBox(group, [0.82, 0.72, 0.82], [0.42, 0.51, -0.1], accentMaterial, load.id);
stationBox(group, [0.82, 0.72, 0.82], [-0.42, 1.23, -0.1], accentMaterial, load.id);
stationBox(group, [0.82, 0.72, 0.82], [0.42, 1.23, -0.1], accentMaterial, load.id);
stationBox(group, [1.72, 0.16, 0.95], [0, 0.25, -0.1], darkMaterial, load.id);
} else if (load.id === "dryer") {
stationBox(group, [1.25, 1.35, 1.05], [-0.25, 0.83, -0.05], accentMaterial, load.id);
stationBox(group, [0.78, 0.72, 0.08], [-0.25, 0.83, 0.51], darkMaterial, load.id);
stationBox(group, [0.52, 0.52, 0.09], [-0.25, 0.83, 0.57], glassMaterial, load.id);
stationBox(group, [0.34, 0.12, 0.08], [-0.25, 1.31, 0.56], whiteMaterial, load.id);
} else if (load.id === "hvac") {
stationBox(group, [1.45, 0.72, 0.88], [-0.3, 0.51, -0.1], accentMaterial, load.id);
for (let i = 0; i < 4; i++) {
stationBox(
group,
[0.82, 0.055, 0.08],
[-0.3, 0.35 + i * 0.13, 0.38],
darkMaterial,
load.id
);
}
stationBox(group, [0.25, 0.52, 0.25], [0.67, 0.41, -0.1], darkMaterial, load.id);
} else if (load.id === "heatpump") {
stationBox(group, [1.0, 0.95, 0.9], [-0.35, 0.63, -0.08], accentMaterial, load.id);
stationBox(group, [0.68, 0.68, 0.08], [-0.35, 0.63, 0.41], darkMaterial, load.id);
stationBox(group, [0.46, 0.46, 0.1], [-0.35, 0.63, 0.47], glassMaterial, load.id);
} else {
stationBox(group, [1.25, 1.08, 0.9], [-0.25, 0.69, -0.05], accentMaterial, load.id);
stationBox(group, [0.55, 0.26, 0.08], [-0.25, 1.08, 0.43], whiteMaterial, load.id);
stationBox(group, [0.72, 0.16, 0.08], [-0.25, 0.55, 0.43], darkMaterial, load.id);
}
const energyBlocks = [];
for (let i = 0; i < 14; i++) {
const block = stationBox(
group,
[0.25, 0.25, 0.25],
[0.88, 0.25 + i * 0.265, 0.18],
energyMaterial,
load.id
);
block.visible = false;
energyBlocks.push(block);
}
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(2.62, 0.08, 1.9)),
new THREE.LineBasicMaterial({
color: 0xf3fff2,
transparent: true,
opacity: 0.9
})
);
outline.position.y = 0.16;
group.add(outline);
const anchor = new THREE.Object3D();
anchor.position.set(0, 2.55, 0);
group.add(anchor);
const label = document.createElement("button");
label.type = "button";
label.className = "voxel-label";
label.style.setProperty("--load-color", load.color);
label.addEventListener("click", () => selectLoad(load.id));
dom.labelLayer.appendChild(label);
stationVisuals.set(load.id, {
group,
accentMaterial,
energyMaterial,
energyBlocks,
outline,
anchor,
label,
active: false,
energy: 0
});
}
state.loads.forEach(createStation);
function updateSceneState() {
const maxIndividualEnergy = Math.max(
1,
...state.loads.map(load => loadEnergy(load, DAY))
);
for (const load of state.loads) {
const visual = stationVisuals.get(load.id);
if (!visual) continue;
visual.active = isActive(load);
visual.energy = loadEnergy(load, state.cursor);
const ratio = THREE.MathUtils.clamp(visual.energy / maxIndividualEnergy, 0, 1);
const visibleBlocks = visual.energy > 0.001
? Math.max(1, Math.ceil(ratio * visual.energyBlocks.length))
: 0;
visual.energyBlocks.forEach((block, index) => {
block.visible = index < visibleBlocks;
});
const selected = load.id === state.selectedId;
visual.outline.visible = selected;
visual.outline.material.opacity = selected ? 0.9 : 0;
visual.label.innerHTML = `
<strong>${escapeHTML(load.name)}</strong>
<span>${visual.active ? `${formatNumber(load.power)} kW active` : "idle"}</span>
<small>${formatNumber(visual.energy)} kWh accumulated</small>
`;
}
}
// Custom camera controls: pointer orbit and wheel zoom.
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
const cameraState = {
yaw: 0.62,
pitch: 0.69,
radius: 15.2
};
function updateCamera() {
const sinPitch = Math.sin(cameraState.pitch);
camera.position.set(
cameraTarget.x + cameraState.radius * sinPitch * Math.sin(cameraState.yaw),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.pitch),
cameraTarget.z + cameraState.radius * sinPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragged = false;
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = { x: event.clientX, y: event.clientY };
dragged = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) dragged = true;
if (dragged) {
cameraState.yaw -= dx * 0.007;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.28,
1.25
);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && !dragged) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
const hit = hits.find(item => item.object.userData.loadId);
if (hit) selectLoad(hit.object.userData.loadId);
}
pointerDown = null;
dragged = false;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
dragged = false;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8.5,
24
);
}, { passive: false });
function resizeScene() {
const width = dom.scene.clientWidth;
const height = dom.scene.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeScene);
resizeObserver.observe(dom.scene);
function updateLabels() {
const width = dom.scene.clientWidth;
const height = dom.scene.clientHeight;
for (const load of state.loads) {
const visual = stationVisuals.get(load.id);
if (!visual) continue;
const world = visual.anchor.getWorldPosition(new THREE.Vector3());
const projected = world.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
visual.label.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
visual.label.style.left = `${x}px`;
visual.label.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// Dynamic UI and animation
// -------------------------------------------------------------------------
function updateDynamicUI() {
renderMetrics();
renderComparison();
renderCharts();
renderTimeline();
updateSceneState();
}
renderLoadRows();
updateDynamicUI();
resizeScene();
updateCamera();
let previousFrame = performance.now();
let lastUIUpdate = 0;
function animate(now) {
requestAnimationFrame(animate);
const elapsedSeconds = Math.min((now - previousFrame) / 1000, 0.1);
previousFrame = now;
if (state.playing) {
state.cursor += elapsedSeconds * state.speed;
if (state.cursor >= DAY) {
state.cursor = DAY;
state.playing = false;
}
if (now - lastUIUpdate > 80) {
updateDynamicUI();
lastUIUpdate = now;
}
}
updateCamera();
const pulse = 0.5 + 0.5 * Math.sin(now * 0.0045);
for (const load of state.loads) {
const visual = stationVisuals.get(load.id);
if (!visual) continue;
visual.accentMaterial.emissiveIntensity = visual.active
? 0.25 + pulse * 0.24
: load.id === state.selectedId
? 0.08
: 0.025;
visual.energyMaterial.emissiveIntensity = visual.active
? 0.32 + pulse * 0.22
: 0.12;
}
renderer.render(scene, camera);
updateLabels();
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```