Prompt specification
Build or customize the Three.js 3D scene "Coastal Energy Learning Park" 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: Coastal Energy Learning Park
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coastal-energy-learning-park-x3999
Scene Description Prompt:
Build an original educational park comparing wind and solar modules under synthetic weather. Use transparent toy conversion rules and show unavailable generation periods explicitly. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (coastal-energy-learning-park-x3999):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Wind / Sun Commons — Educational Energy Park</title>
<style>
:root {
--ink: #102b35;
--muted: #54717b;
--paper: rgba(249, 253, 250, 0.90);
--line: rgba(16, 43, 53, 0.12);
--wind: #159d78;
--wind-soft: #d9f4e9;
--solar: #e59a28;
--solar-soft: #fff0cf;
--danger: #d94d48;
--danger-soft: #ffe4df;
--shadow: 0 18px 50px rgba(24, 52, 59, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9d7e6;
color: var(--ink);
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"] {
accent-color: var(--ink);
}
button {
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(12, 40, 52, 0.08), transparent 22%),
linear-gradient(0deg, rgba(12, 40, 52, 0.11), transparent 30%);
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.15);
-webkit-backdrop-filter: blur(16px) saturate(1.15);
}
.brand {
position: fixed;
z-index: 5;
top: 18px;
left: 18px;
width: min(410px, calc(100vw - 390px));
padding: 18px 20px 16px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #41616a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--solar);
box-shadow: 13px 0 0 var(--wind);
margin-right: 13px;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
.brand p {
margin: 9px 0 13px;
max-width: 355px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.brand-footer {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.pill {
display: inline-flex;
align-items: center;
gap: 6px;
min-height: 27px;
padding: 5px 9px;
border-radius: 999px;
background: rgba(16, 43, 53, 0.075);
color: #395a64;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.pill.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--wind);
box-shadow: 0 0 0 4px rgba(21, 157, 120, 0.13);
}
#panelToggle {
position: fixed;
z-index: 30;
display: none;
top: 12px;
right: 12px;
padding: 10px 13px;
border: 0;
border-radius: 12px;
color: white;
background: #173b43;
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 800;
}
.lab {
position: fixed;
z-index: 20;
top: 18px;
right: 18px;
width: 330px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border-radius: 20px;
scrollbar-width: thin;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 16px;
}
.panel-title h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.02em;
}
.panel-title span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.field { margin: 14px 0; }
.field-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
font-size: 11px;
font-weight: 800;
}
.field-head output {
color: #244d58;
font-variant-numeric: tabular-nums;
}
select {
width: 100%;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
outline: none;
background: rgba(255, 255, 255, 0.88);
color: var(--ink);
font-size: 12px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
cursor: pointer;
}
.range-scale {
display: flex;
justify-content: space-between;
color: #759099;
font-size: 9px;
font-weight: 700;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.button {
min-height: 39px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
color: var(--ink);
font-size: 11px;
font-weight: 800;
transition: transform 120ms ease, background 120ms ease;
}
.button:hover {
transform: translateY(-1px);
background: #f2f8f4;
}
.button.primary {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.button.primary:hover { background: #214b56; }
.rules {
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.rules-title {
margin: 0 0 9px;
color: #48656e;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.rule {
display: grid;
grid-template-columns: 52px 1fr;
gap: 9px;
align-items: start;
margin: 8px 0;
}
.rule b {
display: inline-block;
padding: 4px 6px;
border-radius: 6px;
color: white;
font-size: 9px;
letter-spacing: 0.08em;
text-align: center;
}
.rule.wind b { background: var(--wind); }
.rule.solar b { background: var(--solar); }
.rule code {
display: block;
color: #264c56;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 700;
line-height: 1.45;
}
.rule small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.model-note {
margin: 12px 0 0;
padding: 10px 11px;
border-radius: 10px;
background: #eef5f3;
color: #59727a;
font-size: 10px;
line-height: 1.45;
}
.dashboard {
position: fixed;
z-index: 10;
left: 18px;
bottom: 18px;
width: min(820px, calc(100vw - 390px));
min-width: 570px;
padding: 15px;
border-radius: 20px;
pointer-events: none;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr 0.88fr;
gap: 9px;
}
.metric {
min-width: 0;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.72);
}
.metric-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.source {
display: flex;
align-items: center;
gap: 7px;
font-size: 11px;
font-weight: 900;
white-space: nowrap;
}
.source i {
width: 9px;
height: 9px;
border-radius: 3px;
}
#windMetric .source i { background: var(--wind); }
#solarMetric .source i { background: var(--solar); }
.status {
padding: 4px 6px;
border-radius: 5px;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
white-space: nowrap;
}
.status.available {
background: var(--wind-soft);
color: #087658;
}
.status.unavailable {
background: var(--danger-soft);
color: #b53c38;
}
.value-row {
display: flex;
align-items: baseline;
gap: 5px;
margin-top: 5px;
}
.value-row strong {
font-size: 27px;
line-height: 1;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.value-row span {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.bar {
height: 6px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: #e7eeeb;
}
.bar span {
display: block;
width: var(--fill, 0%);
height: 100%;
border-radius: inherit;
transition: width 180ms ease;
}
#windBar { background: var(--wind); }
#solarBar { background: var(--solar); }
.meta {
margin-top: 6px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
line-height: 1.3;
text-overflow: ellipsis;
white-space: nowrap;
}
.comparison {
display: flex;
flex-direction: column;
justify-content: center;
padding: 10px 12px;
border-radius: 13px;
background: #eaf3ef;
color: #2e5660;
font-size: 10px;
line-height: 1.4;
}
.comparison b {
display: block;
margin-bottom: 3px;
color: #163e48;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-wrap {
margin-top: 11px;
padding-top: 9px;
border-top: 1px solid var(--line);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 3px;
}
.timeline-head strong {
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-head span {
color: var(--muted);
font-size: 9px;
}
#timeline {
display: block;
width: 100%;
height: 108px;
}
.timeline-legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
align-items: center;
margin-top: -2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 15px;
height: 7px;
border-radius: 2px;
}
.swatch.wind { background: var(--wind); }
.swatch.solar { background: var(--solar); }
.swatch.off {
border: 1px solid rgba(217, 77, 72, 0.5);
background:
repeating-linear-gradient(
135deg,
rgba(217, 77, 72, 0.22) 0,
rgba(217, 77, 72, 0.22) 3px,
white 3px,
white 6px
);
}
.hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 17px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
background: rgba(17, 46, 55, 0.68);
color: rgba(255, 255, 255, 0.9);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
opacity: 0;
transition: opacity 180ms ease;
}
.hint.show { opacity: 1; }
@media (max-width: 980px) {
.brand {
width: calc(100vw - 24px);
max-width: 410px;
}
.brand p { display: none; }
#panelToggle { display: block; }
.lab {
top: 58px;
right: 12px;
width: min(330px, calc(100vw - 24px));
max-height: calc(100vh - 70px);
transform: translateX(calc(100% + 24px));
transition: transform 180ms ease;
}
body.panel-open .lab {
transform: translateX(0);
}
.dashboard {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
min-width: 0;
}
.hint { display: none; }
}
@media (max-width: 620px) {
.brand {
top: 12px;
left: 12px;
padding: 14px 15px;
}
.brand h1 { font-size: 25px; }
.brand p { display: none; }
.brand-footer .pill:first-child { display: none; }
.dashboard { padding: 10px; }
.metrics {
grid-template-columns: 1fr 1fr;
}
.comparison {
grid-column: 1 / -1;
min-height: 44px;
}
.metric { padding: 10px; }
.value-row strong { font-size: 23px; }
.meta { white-space: normal; }
#timeline { height: 96px; }
.timeline-head span { display: none; }
}
@media (max-height: 680px) and (min-width: 981px) {
.brand p { display: none; }
.dashboard { padding: 11px; }
#timeline { height: 88px; }
.lab { padding: 14px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel educational energy park"></canvas>
<div class="vignette"></div>
<header class="brand glass">
<div class="eyebrow">Educational energy park</div>
<h1>Wind / Sun Commons</h1>
<p>
Move daylight and synthetic weather through the park. Compare equal-sized
wind and solar modules, and see exactly when each source is unavailable.
</p>
<div class="brand-footer">
<span class="pill live" id="sceneState">12:00 · Synthetic weather</span>
<span class="pill">4 × 1 MW each</span>
<span class="pill">Not a forecast</span>
</div>
</header>
<button id="panelToggle" aria-expanded="false" aria-controls="labPanel">
☰ Weather lab
</button>
<aside class="lab glass" id="labPanel">
<div class="panel-title">
<h2>Synthetic weather lab</h2>
<span>Live model</span>
</div>
<div class="field">
<div class="field-head">
<label for="preset">Weather scenario</label>
</div>
<select id="preset">
<option value="clear">Clear and breezy</option>
<option value="overcast">Soft overcast</option>
<option value="gusty">Gusty afternoon</option>
<option value="storm">Storm front</option>
<option value="custom" disabled>Custom weather</option>
</select>
</div>
<div class="field">
<div class="field-head">
<label for="hour">Park time</label>
<output id="hourOut" for="hour">12:00</output>
</div>
<input id="hour" type="range" min="0" max="24" step="0.05" value="12" />
<div class="range-scale">
<span>00:00</span>
<span>06:00</span>
<span>12:00</span>
<span>18:00</span>
<span>24:00</span>
</div>
</div>
<div class="field">
<div class="field-head">
<label for="cloud">Cloud cover</label>
<output id="cloudOut" for="cloud">12%</output>
</div>
<input id="cloud" type="range" min="0" max="100" step="1" value="12" />
<div class="range-scale">
<span>Clear</span>
<span>Fully covered</span>
</div>
</div>
<div class="field">
<div class="field-head">
<label for="wind">Wind speed</label>
<output id="windOut" for="wind">8.0 m/s</output>
</div>
<input id="wind" type="range" min="0" max="20" step="0.1" value="8" />
<div class="range-scale">
<span>Calm</span>
<span>20 m/s</span>
</div>
</div>
<div class="button-row">
<button class="button primary" id="play">▶ Run 24 hours</button>
<button class="button" id="resetView">Reset camera</button>
</div>
<section class="rules">
<h3 class="rules-title">Transparent toy conversion rules</h3>
<div class="rule wind">
<b>WIND</b>
<div>
<code>P = clamp((v − 3) / 9, 0, 1) × 1 MW</code>
<small>
Below 3 m/s the module is unavailable. It ramps linearly to 1 MW at
12 m/s and stays capped. No storm cut-out is modeled.
</small>
</div>
</div>
<div class="rule solar">
<b>SOLAR</b>
<div>
<code>I = D × (1 − 0.75C) kW/m²</code>
<small>
D is the 06:00–18:00 daylight curve; C is cloud fraction.
P = I × 1 MW when I ≥ 0.08 kW/m².
</small>
</div>
</div>
<p class="model-note">
Each side has four identical 1 MW modules. Red hatching and red park
signs mean that generation is unavailable, not merely that output is low.
</p>
</section>
</aside>
<section class="dashboard glass" aria-label="Live comparison dashboard">
<div class="metrics">
<article class="metric" id="windMetric">
<div class="metric-head">
<span class="source"><i></i>Wind field</span>
<span class="status available" id="windStatus">Available</span>
</div>
<div class="value-row">
<strong id="windPower">0.00</strong>
<span>MW farm</span>
</div>
<div class="bar"><span id="windBar"></span></div>
<div class="meta" id="windMeta">0.00 MW per module · 4 modules</div>
</article>
<article class="metric" id="solarMetric">
<div class="metric-head">
<span class="source"><i></i>Solar field</span>
<span class="status available" id="solarStatus">Available</span>
</div>
<div class="value-row">
<strong id="solarPower">0.00</strong>
<span>MW farm</span>
</div>
<div class="bar"><span id="solarBar"></span></div>
<div class="meta" id="solarMeta">0.00 MW per module · 4 modules</div>
</article>
<div class="comparison">
<b>Park insight</b>
<span id="comparisonText">Compare the two equal-capacity fields.</span>
</div>
</div>
<div class="timeline-wrap">
<div class="timeline-head">
<strong>24-hour toy outlook</strong>
<span id="timelineScenario">Clear and breezy · MW per 1 MW module</span>
</div>
<canvas id="timeline" aria-label="Wind and solar generation timeline"></canvas>
<div class="timeline-legend">
<span class="legend-item"><i class="swatch wind"></i>Wind generation</span>
<span class="legend-item"><i class="swatch solar"></i>Solar generation</span>
<span class="legend-item"><i class="swatch off"></i>Unavailable period</span>
<span class="legend-item">Vertical marker = current time</span>
</div>
</div>
</section>
<div class="hint" id="hint">Drag to orbit · Scroll to zoom · Arrow keys change time</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model state and synthetic weather
// -------------------------------------------------------------------------
const $ = (id) => document.getElementById(id);
const PROFILES = {
clear: {
name: "Clear and breezy",
cloud: Array(24).fill(12),
wind: [
4, 4, 4, 5, 5, 6, 7, 8, 8, 7, 6, 6,
5, 5, 6, 6, 5, 5, 4, 4, 4, 3, 3, 3
]
},
overcast: {
name: "Soft overcast",
cloud: Array.from({ length: 24 }, (_, i) => 68 + Math.round(10 * Math.sin(i / 3))),
wind: [
3, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8,
7, 7, 8, 9, 8, 7, 6, 5, 4, 4, 3, 3
]
},
gusty: {
name: "Gusty afternoon",
cloud: Array.from({ length: 24 }, (_, i) => 24 + Math.round(10 * Math.sin(i / 4 + 1))),
wind: [
5, 6, 7, 9, 12, 14, 16, 15, 13, 12, 14, 16,
15, 13, 11, 12, 10, 8, 7, 6, 5, 5, 4, 4
]
},
storm: {
name: "Storm front",
cloud: Array.from({ length: 24 }, (_, i) => 88 + Math.round(9 * Math.sin(i / 2))),
wind: [
8, 9, 11, 13, 15, 17, 18, 16, 15, 14, 16, 17,
15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 7, 7
]
}
};
const state = {
hour: 12,
preset: "clear",
custom: false,
cloud: 12,
wind: 8,
playing: false
};
const clamp = (n, min, max) => Math.max(min, Math.min(max, n));
function weatherAt(hour) {
if (state.custom) {
return { cloud: state.cloud, wind: state.wind };
}
const profile = PROFILES[state.preset];
const index = Math.floor(((hour % 24) + 24) % 24);
return {
cloud: profile.cloud[index],
wind: profile.wind[index]
};
}
function calculateAt(hour) {
const weather = weatherAt(hour);
const daylight =
hour > 6 && hour < 18
? Math.sin(Math.PI * (hour - 6) / 12)
: 0;
const irradiance =
daylight * (1 - 0.75 * weather.cloud / 100);
const windAvailable = weather.wind >= 3;
const windPerModule = windAvailable
? clamp((weather.wind - 3) / 9, 0, 1)
: 0;
const solarAvailable = daylight > 0 && irradiance >= 0.08;
const solarPerModule = solarAvailable ? irradiance : 0;
let solarReason = `${irradiance.toFixed(2)} kW/m² effective light`;
if (daylight <= 0) solarReason = "Night · no sunlight";
else if (!solarAvailable) solarReason = "Too little light after cloud loss";
let windReason = "Ramping between cut-in and rated speed";
if (!windAvailable) windReason = "Below 3 m/s cut-in";
else if (weather.wind >= 12) windReason = "At or above 12 m/s · capped at 1 MW";
return {
weather,
daylight,
irradiance,
wind: {
available: windAvailable,
perModule: windPerModule,
total: windPerModule * 4,
reason: windReason
},
solar: {
available: solarAvailable,
perModule: solarPerModule,
total: solarPerModule * 4,
reason: solarReason
}
};
}
function formatHour(hour) {
const whole = Math.floor(Math.min(hour, 24));
const minutes = Math.round((hour - whole) * 60);
return `${String(whole).padStart(2, "0")}:${String(minutes % 60).padStart(2, "0")}`;
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const canvas = $("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fd8ed);
scene.fog = new THREE.Fog(0x9fd8ed, 48, 95);
const camera = new THREE.OrthographicCamera(-25, 25, 18, -18, 0.1, 160);
const cameraTarget = new THREE.Vector3(0, 2.1, 0);
const cameraState = {
yaw: 0.56,
pitch: 0.62,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xe9f8ff, 0x516347, 1.7);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xfff0cf, 2.8);
sunLight.position.set(-10, 25, -12);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(1536, 1536);
sunLight.shadow.camera.left = -25;
sunLight.shadow.camera.right = 25;
sunLight.shadow.camera.top = 25;
sunLight.shadow.camera.bottom = -25;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 70;
sunLight.shadow.bias = -0.0004;
scene.add(sunLight);
scene.add(sunLight.target);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
const materials = {
soil: standard(0x8a6d4d),
path: standard(0xd9c49b),
windPlot: standard(0x80a86e),
solarPlot: standard(0x6f916b),
white: standard(0xf2f4e9),
dark: standard(0x29474e),
roof: standard(0x285f59),
frame: standard(0x52666a, { metalness: 0.25 }),
wood: standard(0x76523c),
leaf: standard(0x4f8b61),
leafLight: standard(0x76a86c),
trunk: standard(0x6e4b37),
water: standard(0x4ba8bc, { roughness: 0.3, metalness: 0.1 }),
solarCell: standard(0x245f82, {
roughness: 0.34,
metalness: 0.2,
emissive: 0x0c2b4b,
emissiveIntensity: 0.35
}),
screen: standard(0x1a4a55, {
emissive: 0x3cd0d5,
emissiveIntensity: 0.65,
roughness: 0.4
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Main diorama base and voxel grass tiles.
addBox(scene, [36, 1, 26], [0, -0.57, 0], materials.soil);
const tileGeometry = new THREE.BoxGeometry(1.92, 0.12, 1.92);
const tileMaterial = standard(0xffffff, { vertexColors: true });
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, 216);
const dummy = new THREE.Object3D();
let tileIndex = 0;
for (let x = -17; x <= 17; x += 2) {
for (let z = -11; z <= 11; z += 2) {
dummy.position.set(x, 0.025, z);
dummy.rotation.y = ((x * 13 + z * 7) % 4) * 0.01;
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const color = new THREE.Color();
color.setHSL(
0.255 + ((x + z) % 5) * 0.003,
0.27,
0.48 + (((x * z + 91) % 7) / 100)
);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// Paths and field plots.
addBox(scene, [3.2, 0.08, 24], [0, 0.12, 0], materials.path, false);
addBox(scene, [34, 0.08, 2], [0, 0.13, 9.7], materials.path, false);
addBox(scene, [11.8, 0.07, 20], [-10.3, 0.12, -0.6], materials.windPlot, false);
addBox(scene, [11.8, 0.07, 20], [10.3, 0.12, -0.6], materials.solarPlot, false);
// Perimeter fence.
const fenceMaterial = materials.white;
for (let x = -16; x <= 16; x += 3) {
addBox(scene, [0.22, 1.25, 0.22], [x, 0.7, -12], fenceMaterial);
}
addBox(scene, [33, 0.16, 0.16], [0, 1.0, -12], fenceMaterial);
addBox(scene, [33, 0.16, 0.16], [0, 0.55, -12], fenceMaterial);
for (let z = -11; z <= 10; z += 3) {
addBox(scene, [0.22, 1.25, 0.22], [-17, 0.7, z], fenceMaterial);
addBox(scene, [0.22, 1.25, 0.22], [17, 0.7, z], fenceMaterial);
}
addBox(scene, [0.16, 0.16, 22], [-17, 1, -0.5], fenceMaterial);
addBox(scene, [0.16, 0.16, 22], [17, 1, -0.5], fenceMaterial);
// Voxel trees.
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.1, z);
tree.scale.setScalar(scale);
addBox(tree, [0.5, 2.2, 0.5], [0, 1.1, 0], materials.trunk);
addBox(tree, [2.1, 1.7, 1.8], [0, 2.65, 0], materials.leaf);
addBox(tree, [1.35, 1.25, 1.45], [-0.5, 3.65, 0.1], materials.leafLight);
addBox(tree, [1.25, 1.1, 1.3], [0.65, 3.55, -0.15], materials.leaf);
scene.add(tree);
}
[
[-15.7, -10], [-15.8, -6], [-15.7, 4], [-15.8, 8],
[15.7, -10], [15.7, -6], [15.8, 3], [15.7, 7],
[-7, -10.8], [-3, -10.8], [3, -10.8], [7, -10.8]
].forEach(([x, z], i) => createTree(x, z, 0.8 + (i % 3) * 0.12));
// Small pond.
addBox(scene, [4.6, 0.13, 3.1], [13.7, 0.16, 10.4], materials.water, false);
addBox(scene, [5.1, 0.18, 0.35], [13.7, 0.2, 12], materials.wood);
addBox(scene, [5.1, 0.18, 0.35], [13.7, 0.2, 8.8], materials.wood);
addBox(scene, [0.35, 0.18, 3.5], [11.3, 0.2, 10.4], materials.wood);
addBox(scene, [0.35, 0.18, 3.5], [16.1, 0.2, 10.4], materials.wood);
// Central weather lab kiosk.
const kiosk = new THREE.Group();
kiosk.position.set(0, 0.12, -2.5);
scene.add(kiosk);
addBox(kiosk, [3.8, 0.28, 3.8], [0, 0.16, 0], materials.path);
addBox(kiosk, [3.1, 2.5, 3.1], [0, 1.55, 0], materials.white);
addBox(kiosk, [3.7, 0.35, 3.7], [0, 3.0, 0], materials.roof);
addBox(kiosk, [2.1, 1.05, 0.14], [0, 1.75, 1.59], materials.screen);
addBox(kiosk, [0.14, 1.75, 0.14], [-1.45, 1.8, 1.59], materials.roof);
addBox(kiosk, [0.14, 1.75, 0.14], [1.45, 1.8, 1.59], materials.roof);
const screenCanvas = document.createElement("canvas");
screenCanvas.width = 512;
screenCanvas.height = 256;
const screenCtx = screenCanvas.getContext("2d");
screenCtx.fillStyle = "#153d48";
screenCtx.fillRect(0, 0, 512, 256);
screenCtx.fillStyle = "#7ce5dc";
screenCtx.font = "800 38px system-ui";
screenCtx.textAlign = "center";
screenCtx.fillText("WEATHER LAB", 256, 88);
screenCtx.fillStyle = "#e9fff8";
screenCtx.font = "700 24px system-ui";
screenCtx.fillText("TRY A NEW SKY", 256, 145);
screenCtx.fillStyle = "#f2bd50";
for (let i = 0; i < 5; i++) {
screenCtx.fillRect(166 + i * 43, 183, 28, 18);
}
const screenTexture = new THREE.CanvasTexture(screenCanvas);
screenTexture.colorSpace = THREE.SRGBColorSpace;
const screenFace = new THREE.Mesh(
new THREE.PlaneGeometry(1.92, 0.88),
new THREE.MeshBasicMaterial({ map: screenTexture })
);
screenFace.position.set(0, 1.75, 1.67);
kiosk.add(screenFace);
// Roof weather station.
addBox(kiosk, [0.15, 2.4, 0.15], [0, 4.25, 0], materials.dark);
const anemometer = new THREE.Group();
anemometer.position.set(0, 5.35, 0);
kiosk.add(anemometer);
addBox(anemometer, [1.8, 0.12, 0.12], [0, 0, 0], materials.dark);
addBox(anemometer, [0.4, 0.4, 0.4], [0.9, 0, 0], materials.solar);
// Benches and tiny park visitors.
function createBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0.1, z);
bench.rotation.y = rotation;
addBox(bench, [2.2, 0.18, 0.62], [0, 0.8, 0], materials.wood);
addBox(bench, [2.2, 0.7, 0.16], [0, 1.2, -0.25], materials.wood);
addBox(bench, [0.15, 0.8, 0.5], [-0.8, 0.4, 0], materials.dark);
addBox(bench, [0.15, 0.8, 0.5], [0.8, 0.4, 0], materials.dark);
scene.add(bench);
}
createBench(2.7, 5.1, Math.PI / 2);
createBench(-2.7, 6.2, -Math.PI / 2);
function createVisitor(x, z, shirtColor) {
const visitor = new THREE.Group();
visitor.position.set(x, 0.16, z);
const shirt = standard(shirtColor);
addBox(visitor, [0.48, 0.85, 0.4], [0, 1.15, 0], shirt);
addBox(visitor, [0.42, 0.42, 0.42], [0, 1.82, 0], standard(0xd9a77f));
addBox(visitor, [0.18, 0.65, 0.2], [-0.14, 0.32, 0], materials.dark);
addBox(visitor, [0.18, 0.65, 0.2], [0.14, 0.32, 0], materials.dark);
scene.add(visitor);
}
createVisitor(1.3, 0.8, 0xe5a23b);
createVisitor(-1.2, 1.4, 0x329b7a);
// Status beacon materials.
const windBeaconMaterial = standard(0x159d78, {
emissive: 0x159d78,
emissiveIntensity: 1.1
});
const solarBeaconMaterial = standard(0x159d78, {
emissive: 0x159d78,
emissiveIntensity: 1.1
});
// Four wind turbines.
const turbineRotors = [];
function createTurbine(x, z) {
const turbine = new THREE.Group();
turbine.position.set(x, 0.12, z);
scene.add(turbine);
addBox(turbine, [2.1, 0.35, 2.1], [0, 0.2, 0], materials.path);
addBox(turbine, [0.72, 6.45, 0.72], [0, 3.45, 0], materials.white);
for (let y = 1; y < 6.5; y += 1.25) {
addBox(turbine, [0.83, 0.13, 0.83], [0, y, 0], materials.frame);
}
addBox(turbine, [1.65, 0.72, 1.05], [0, 6.95, 0], materials.white);
const rotor = new THREE.Group();
rotor.position.set(0, 6.98, -0.66);
turbine.add(rotor);
addBox(rotor, [0.66, 0.66, 0.54], [0, 0, 0], materials.frame);
for (let i = 0; i < 3; i++) {
const blade = new THREE.Group();
blade.rotation.z = i * Math.PI * 2 / 3;
rotor.add(blade);
addBox(blade, [0.43, 3.15, 0.23], [0, 1.72, 0], materials.white);
addBox(blade, [0.5, 0.25, 0.28], [0, 0.35, 0], materials.frame);
}
addBox(turbine, [0.3, 0.38, 0.3], [0.65, 7.65, 0], windBeaconMaterial);
turbineRotors.push(rotor);
}
[-7, -2.5, 2, 6.5].forEach((z) => createTurbine(-11, z));
// Four equal-capacity solar modules, each represented by three panel tables.
[-7, -2.5, 2, 6.5].forEach((z) => {
const module = new THREE.Group();
module.position.set(10, 0.12, z);
scene.add(module);
[-2.7, 0, 2.7].forEach((px) => {
const panel = new THREE.Group();
panel.position.set(px, 0, 0);
panel.rotation.x = -0.45;
module.add(panel);
addBox(panel, [2.5, 0.16, 1.55], [0, 0.9, 0], materials.frame);
for (const cx of [-0.59, 0.59]) {
for (const cz of [-0.37, 0.37]) {
addBox(panel, [1.08, 0.055, 0.66], [cx, 1.01, cz], materials.solarCell);
}
}
});
for (const px of [-3.4, -1.35, 1.35, 3.4]) {
addBox(module, [0.14, 0.95, 0.14], [px, 0.48, 0], materials.frame);
}
addBox(module, [0.18, 1.05, 0.18], [4.05, 0.55, 0], materials.frame);
addBox(module, [0.38, 0.38, 0.38], [4.05, 1.25, 0], solarBeaconMaterial);
});
// Voxel clouds.
const cloudMaterial = new THREE.MeshBasicMaterial({
color: 0xf6fbf7,
transparent: true,
opacity: 0.78
});
const clouds = [];
function createCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
addBox(cloud, [3.1, 1.2, 1.2], [0, 0, 0], cloudMaterial, false);
addBox(cloud, [1.6, 1.6, 1.4], [-1.2, 0.5, 0], cloudMaterial, false);
addBox(cloud, [1.7, 1.9, 1.3], [1.1, 0.55, 0], cloudMaterial, false);
addBox(cloud, [1.5, 1.0, 1.1], [0.2, 1.25, 0], cloudMaterial, false);
scene.add(cloud);
clouds.push(cloud);
}
createCloud(-15, 13, -12, 1.0);
createCloud(-3, 15, -13, 0.75);
createCloud(10, 12.5, -12, 1.1);
createCloud(20, 14.5, -11, 0.7);
// Voxel sun and moon.
const sun = addBox(
scene,
[2.1, 2.1, 2.1],
[-10, 16, -13],
new THREE.MeshBasicMaterial({ color: 0xffd260 }),
false
);
const moon = addBox(
scene,
[1.55, 1.55, 1.55],
[10, 16, -13],
new THREE.MeshBasicMaterial({ color: 0xe8f2df }),
false
);
// Wind streak particles.
const particleCount = 42;
const particleGeometry = new THREE.BoxGeometry(0.48, 0.07, 0.07);
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xf0ffff,
transparent: true,
opacity: 0.35,
depthWrite: false
});
const windParticles = new THREE.InstancedMesh(
particleGeometry,
particleMaterial,
particleCount
);
windParticles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(windParticles);
const particlePositions = Array.from({ length: particleCount }, () => ({
x: -18 + Math.random() * 36,
y: 1.2 + Math.random() * 7,
z: -11 + Math.random() * 22
}));
const particleDummy = new THREE.Object3D();
// -------------------------------------------------------------------------
// In-scene canvas labels
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function createFarmLabel(x, z, title) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 700;
labelCanvas.height = 200;
const ctx = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(x, 1.75, z);
sprite.scale.set(7.8, 2.23, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return {
canvas: labelCanvas,
ctx,
texture,
sprite,
title,
lastKey: "",
draw(status, detail, available, accent) {
const key = `${status}|${detail}|${available}`;
if (key === this.lastKey) return;
this.lastKey = key;
ctx.clearRect(0, 0, 700, 200);
ctx.fillStyle = available ? "rgba(249,253,250,0.95)" : "rgba(255,236,230,0.96)";
roundedRect(ctx, 7, 7, 686, 186, 25);
ctx.fill();
ctx.strokeStyle = available ? "rgba(16,43,53,0.17)" : "rgba(217,77,72,0.58)";
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = accent;
roundedRect(ctx, 23, 24, 12, 152, 6);
ctx.fill();
ctx.textAlign = "left";
ctx.fillStyle = "#49656d";
ctx.font = "800 25px system-ui";
ctx.fillText(this.title.toUpperCase(), 55, 56);
ctx.fillStyle = available ? "#08785a" : "#c43e3a";
ctx.font = "900 48px system-ui";
ctx.fillText(status, 55, 116);
ctx.fillStyle = "#526e76";
ctx.font = "700 23px system-ui";
ctx.fillText(detail, 55, 158);
this.texture.needsUpdate = true;
}
};
}
const windLabel = createFarmLabel(-10.3, 13.3, "Wind field · 4 × 1 MW");
const solarLabel = createFarmLabel(10.3, 13.3, "Solar field · 4 × 1 MW");
// -------------------------------------------------------------------------
// Camera controls implemented directly in this file
// -------------------------------------------------------------------------
function updateCamera() {
const radius = 48;
const horizontal = Math.cos(cameraState.pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraState.yaw) * horizontal,
cameraTarget.y + Math.sin(cameraState.pitch) * radius,
cameraTarget.z + Math.cos(cameraState.yaw) * horizontal
);
camera.zoom = cameraState.zoom;
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(17.2, 21 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
drawTimeline();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
$("hint").classList.add("show");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = clamp(cameraState.pitch + dy * 0.0045, 0.35, 1.15);
updateCamera();
});
function endDrag() {
dragging = false;
window.setTimeout(() => $("hint").classList.remove("show"), 1300);
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = clamp(cameraState.zoom * Math.exp(-event.deltaY * 0.001), 0.65, 1.75);
updateCamera();
},
{ passive: false }
);
$("resetView").addEventListener("click", () => {
cameraState.yaw = 0.56;
cameraState.pitch = 0.62;
cameraState.zoom = 1;
updateCamera();
});
// -------------------------------------------------------------------------
// UI and 24-hour timeline
// -------------------------------------------------------------------------
const ui = {
preset: $("preset"),
hour: $("hour"),
hourOut: $("hourOut"),
cloud: $("cloud"),
cloudOut: $("cloudOut"),
wind: $("wind"),
windOut: $("windOut"),
play: $("play"),
windPower: $("windPower"),
windStatus: $("windStatus"),
windMeta: $("windMeta"),
windBar: $("windBar"),
solarPower: $("solarPower"),
solarStatus: $("solarStatus"),
solarMeta: $("solarMeta"),
solarBar: $("solarBar"),
comparison: $("comparisonText"),
sceneState: $("sceneState"),
timelineScenario: $("timelineScenario")
};
function hatchRect(ctx, x, y, width, height) {
ctx.save();
ctx.beginPath();
ctx.rect(x, y, width, height);
ctx.clip();
ctx.fillStyle = "rgba(217,77,72,0.13)";
ctx.fillRect(x, y, width, height);
ctx.strokeStyle = "rgba(217,77,72,0.58)";
ctx.lineWidth = 1.3;
for (let offset = -height; offset < width + height; offset += 7) {
ctx.beginPath();
ctx.moveTo(x + offset, y + height);
ctx.lineTo(x + offset + height, y);
ctx.stroke();
}
ctx.restore();
}
function drawTimeline() {
const timeline = $("timeline");
const rect = timeline.getBoundingClientRect();
if (!rect.width || !rect.height) return;
const dpr = Math.min(window.devicePixelRatio, 2);
const pixelWidth = Math.round(rect.width * dpr);
const pixelHeight = Math.round(rect.height * dpr);
if (timeline.width !== pixelWidth || timeline.height !== pixelHeight) {
timeline.width = pixelWidth;
timeline.height = pixelHeight;
}
const ctx = timeline.getContext("2d");
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, rect.width, rect.height);
const width = rect.width;
const height = rect.height;
const left = 53;
const right = width - 12;
const plotWidth = right - left;
const hourWidth = plotWidth / 24;
const tracks = [
{ label: "WIND", y: 26, h: 20, color: "#159d78", key: "wind" },
{ label: "SOLAR", y: 62, h: 20, color: "#e59a28", key: "solar" }
];
ctx.font = "800 9px system-ui";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
for (const track of tracks) {
ctx.fillStyle = "#58727b";
ctx.fillText(track.label, 0, track.y + track.h / 2);
for (let hour = 0; hour < 24; hour++) {
const x = left + hour * hourWidth;
const result = calculateAt(hour + 0.5);
const source = result[track.key];
const available = source.available;
const value = source.perModule;
ctx.fillStyle = available ? "rgba(38,117,96,0.10)" : "rgba(217,77,72,0.06)";
ctx.fillRect(x, track.y, hourWidth + 0.5, track.h);
if (!available) {
hatchRect(ctx, x, track.y, hourWidth + 0.5, track.h);
} else {
const barHeight = value * track.h;
ctx.fillStyle = track.color;
ctx.globalAlpha = 0.82;
ctx.fillRect(x, track.y + track.h - barHeight, hourWidth + 0.5, barHeight);
ctx.globalAlpha = 1;
if (value < 0.015) {
ctx.fillRect(x, track.y + track.h - 2, hourWidth + 0.5, 2);
}
}
}
}
// Hour ticks and labels.
ctx.strokeStyle = "rgba(16,43,53,0.13)";
ctx.fillStyle = "#668089";
ctx.lineWidth = 1;
ctx.textAlign = "center";
ctx.textBaseline = "top";
for (const hour of [0, 6, 12, 18, 24]) {
const x = left + (hour / 24) * plotWidth;
ctx.beginPath();
ctx.moveTo(x, 22);
ctx.lineTo(x, 84);
ctx.stroke();
ctx.fillText(String(hour).padStart(2, "0"), x, 89);
}
// Current-time marker.
const markerX = left + (state.hour / 24) * plotWidth;
ctx.strokeStyle = "#173d47";
ctx.lineWidth = 1.8;
ctx.beginPath();
ctx.moveTo(markerX, 19);
ctx.lineTo(markerX, 86);
ctx.stroke();
ctx.fillStyle = "#173d47";
ctx.beginPath();
ctx.moveTo(markerX - 4, 17);
ctx.lineTo(markerX + 4, 17);
ctx.lineTo(markerX, 22);
ctx.closePath();
ctx.fill();
}
function updateUI() {
const result = calculateAt(state.hour);
const weather = result.weather;
const scenarioName = state.custom ? "Custom synthetic weather" : PROFILES[state.preset].name;
ui.preset.value = state.custom ? "custom" : state.preset;
ui.hour.value = state.hour;
ui.hourOut.textContent = formatHour(state.hour);
ui.cloud.value = weather.cloud;
ui.cloudOut.textContent = `${Math.round(weather.cloud)}%`;
ui.wind.value = weather.wind;
ui.windOut.textContent = `${weather.wind.toFixed(1)} m/s`;
ui.windPower.textContent = result.wind.total.toFixed(2);
ui.solarPower.textContent = result.solar.total.toFixed(2);
ui.windStatus.textContent = result.wind.available ? "Available" : "Unavailable";
ui.windStatus.className = `status ${result.wind.available ? "available" : "unavailable"}`;
ui.solarStatus.textContent = result.solar.available ? "Available" : "Unavailable";
ui.solarStatus.className = `status ${result.solar.available ? "available" : "unavailable"}`;
ui.windMeta.textContent =
`${result.wind.perModule.toFixed(2)} MW/module · ${result.wind.reason}`;
ui.solarMeta.textContent =
`${result.solar.perModule.toFixed(2)} MW/module · ${result.solar.reason}`;
ui.windBar.style.setProperty("--fill", `${result.wind.perModule * 100}%`);
ui.solarBar.style.setProperty("--fill", `${result.solar.perModule * 100}%`);
const total = result.wind.total + result.solar.total;
ui.sceneState.textContent =
`${formatHour(state.hour)} · ${total.toFixed(2)} MW total`;
if (result.wind.available && result.solar.available) {
const difference = result.solar.total - result.wind.total;
if (Math.abs(difference) < 0.015) {
ui.comparison.textContent = "Wind and solar are matched at this moment.";
} else if (difference > 0) {
ui.comparison.textContent = `Solar leads by ${difference.toFixed(2)} MW across the two fields.`;
} else {
ui.comparison.textContent = `Wind leads by ${Math.abs(difference).toFixed(2)} MW across the two fields.`;
}
} else if (result.solar.available) {
ui.comparison.textContent = "Only solar is available; wind is below its cut-in speed.";
} else if (result.wind.available) {
ui.comparison.textContent = "Only wind is available; sunlight is unavailable right now.";
} else {
ui.comparison.textContent = "Both fields are unavailable, so the park has no toy generation.";
}
ui.timelineScenario.textContent =
`${scenarioName} · MW per 1 MW module`;
windLabel.draw(
result.wind.available ? "AVAILABLE" : "UNAVAILABLE",
result.wind.available
? `${result.wind.perModule.toFixed(2)} MW per module`
: result.wind.reason,
result.wind.available,
"#159d78"
);
solarLabel.draw(
result.solar.available ? "AVAILABLE" : "UNAVAILABLE",
result.solar.available
? `${result.solar.perModule.toFixed(2)} MW per module`
: result.solar.reason,
result.solar.available,
"#e59a28"
);
drawTimeline();
}
// -------------------------------------------------------------------------
// Interaction
// -------------------------------------------------------------------------
ui.preset.addEventListener("change", () => {
if (ui.preset.value === "custom") return;
state.preset = ui.preset.value;
state.custom = false;
updateUI();
});
ui.hour.addEventListener("input", () => {
state.hour = Number(ui.hour.value);
updateUI();
});
ui.cloud.addEventListener("input", () => {
state.custom = true;
state.cloud = Number(ui.cloud.value);
updateUI();
});
ui.wind.addEventListener("input", () => {
state.custom = true;
state.wind = Number(ui.wind.value);
updateUI();
});
ui.play.addEventListener("click", () => {
state.playing = !state.playing;
if (state.playing) state.hour = 0;
ui.play.textContent = state.playing ? "❚❚ Pause cycle" : "▶ Run 24 hours";
ui.play.setAttribute("aria-pressed", String(state.playing));
updateUI();
});
$("panelToggle").addEventListener("click", () => {
const open = document.body.classList.toggle("panel-open");
$("panelToggle").setAttribute("aria-expanded", String(open));
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (["INPUT", "SELECT", "BUTTON"].includes(tag)) return;
if (event.key === "ArrowRight") {
state.hour = (state.hour + 0.25) % 24;
updateUI();
}
if (event.key === "ArrowLeft") {
state.hour = (state.hour - 0.25 + 24) % 24;
updateUI();
}
if (event.code === "Space") {
event.preventDefault();
ui.play.click();
}
});
// -------------------------------------------------------------------------
// Environmental animation
// -------------------------------------------------------------------------
const nightColor = new THREE.Color(0x071a32);
const dayColor = new THREE.Color(0x9fd8ed);
const duskColor = new THREE.Color(0xe4a07c);
const temporarySky = new THREE.Color();
function updateEnvironment(dt, time) {
const result = calculateAt(state.hour);
const daylight = result.daylight;
const hour = state.hour % 24;
temporarySky.copy(nightColor).lerp(dayColor, daylight);
const nearDawn = hour > 4.5 && hour < 8;
const nearDusk = hour > 16 && hour < 19.5;
if (nearDawn || nearDusk) {
const strength = nearDawn
? Math.sin(Math.PI * (hour - 4.5) / 3.5) * 0.48
: Math.sin(Math.PI * (hour - 16) / 3.5) * 0.55;
temporarySky.lerp(duskColor, strength);
}
scene.background.copy(temporarySky);
scene.fog.color.copy(temporarySky);
hemisphere.intensity = 0.48 + daylight * 1.35;
sunLight.intensity = 0.15 + daylight * 2.8;
if (hour > 6 && hour < 18) {
const progress = (hour - 6) / 12;
sun.visible = true;
moon.visible = false;
sun.position.set(
-17 + progress * 34,
7 + Math.sin(progress * Math.PI) * 10,
-13
);
sunLight.position.copy(sun.position).multiplyScalar(1.3);
} else {
sun.visible = false;
moon.visible = true;
const progress = hour < 6 ? hour / 6 : (hour - 18) / 6;
moon.position.set(
-16 + progress * 32,
8 + Math.sin(progress * Math.PI) * 7,
-13
);
sunLight.position.set(moon.position.x, 20, 8);
}
const windSpeed = result.weather.wind;
for (const rotor of turbineRotors) {
rotor.rotation.z += dt * (0.12 + windSpeed * 0.13);
}
anemometer.rotation.y += dt * (0.2 + windSpeed * 0.32);
for (const cloud of clouds) {
cloud.position.x += dt * (0.35 + windSpeed * 0.08);
if (cloud.position.x > 23) cloud.position.x = -23;
}
cloudMaterial.opacity = 0.45 + daylight * 0.32;
const solarGlow = daylight * (1 - result.weather.cloud / 100);
materials.solarCell.emissiveIntensity = 0.08 + solarGlow * 0.95;
const windColor = result.wind.available ? 0x159d78 : 0xd94d48;
windBeaconMaterial.color.setHex(windColor);
windBeaconMaterial.emissive.setHex(windColor);
windBeaconMaterial.emissiveIntensity = result.wind.available
? 1.1
: 0.65 + Math.sin(time * 8) * 0.45;
const solarColor = result.solar.available ? 0xe5a33a : 0xd94d48;
solarBeaconMaterial.color.setHex(solarColor);
solarBeaconMaterial.emissive.setHex(solarColor);
solarBeaconMaterial.emissiveIntensity = result.solar.available
? 1.1
: 0.65 + Math.sin(time * 8 + 1) * 0.45;
particleMaterial.opacity = windSpeed >= 3
? 0.18 + Math.min(windSpeed, 18) * 0.025
: 0.06;
for (let i = 0; i < particleCount; i++) {
const particle = particlePositions[i];
particle.x += dt * (1.2 + windSpeed * 0.72);
if (particle.x > 19) particle.x = -19;
particleDummy.position.set(particle.x, particle.y, particle.z);
particleDummy.scale.set(
0.45 + Math.min(windSpeed, 18) * 0.06,
1,
1
);
particleDummy.updateMatrix();
windParticles.setMatrixAt(i, particleDummy.matrix);
}
windParticles.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
let lastUIUpdate = 0;
function animate(now) {
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (state.playing) {
state.hour = (state.hour + dt * 0.45) % 24;
}
if (now - lastUIUpdate > 90) {
updateUI();
lastUIUpdate = now;
}
updateEnvironment(dt, now / 1000);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", resize);
if ("ResizeObserver" in window) {
new ResizeObserver(drawTimeline).observe($("timeline"));
}
resize();
updateUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```