Prompt specification
Build or customize the Three.js 3D scene "Thermal storage parameter playground" 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: Thermal storage parameter playground
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/thermal-storage-parameter-playground-x1472
Scene Description Prompt:
Allow changing mass, heat capacity, and input power in an insulated lumped model; display temperature over time and explicitly distinguish stored energy from instantaneous temperature. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (thermal-storage-parameter-playground-x1472):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<title>Insulated Lumped Thermal Model</title>
<style>
:root {
--bg: #071019;
--panel: rgba(14, 26, 39, 0.88);
--panel-strong: #101d2b;
--panel-soft: #0a1521;
--line: rgba(154, 187, 214, 0.16);
--text: #edf6ff;
--muted: #8ea5b9;
--cyan: #66d9ff;
--orange: #ffad61;
--green: #76e3aa;
--danger: #ff7383;
--radius: 18px;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-width: 320px;
min-height: 100vh;
color: var(--text);
background:
radial-gradient(circle at 15% 0%, rgba(42, 108, 143, 0.18), transparent 34rem),
radial-gradient(circle at 90% 20%, rgba(255, 128, 66, 0.10), transparent 30rem),
var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select,
input[type="number"] {
color: var(--text);
}
button {
cursor: pointer;
}
.app {
width: min(1500px, calc(100% - 32px));
margin: 0 auto;
padding: 24px 0 40px;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
margin-bottom: 20px;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
}
.brand-mark {
position: relative;
display: grid;
width: 46px;
height: 46px;
place-items: center;
border: 1px solid rgba(102, 217, 255, 0.35);
border-radius: 14px;
background: rgba(102, 217, 255, 0.08);
box-shadow: inset 0 0 22px rgba(102, 217, 255, 0.06);
}
.brand-mark::before {
width: 17px;
height: 23px;
content: "";
border: 2px solid var(--cyan);
border-radius: 7px 7px 10px 10px;
transform: rotate(180deg);
}
.brand-mark::after {
position: absolute;
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 13px var(--orange);
}
.eyebrow {
margin: 0 0 3px;
color: var(--cyan);
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.35rem, 2vw, 1.85rem);
letter-spacing: -0.035em;
}
.live-badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: rgba(8, 17, 27, 0.7);
font-size: 0.78rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.live-badge::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px var(--green);
}
.live-badge.paused::before {
background: var(--orange);
box-shadow: 0 0 10px var(--orange);
}
.layout {
display: grid;
grid-template-columns: 330px minmax(0, 1fr);
gap: 18px;
align-items: start;
}
.panel {
overflow: hidden;
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(16px);
}
.controls-panel {
position: sticky;
top: 18px;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 18px 20px;
border-bottom: 1px solid var(--line);
}
.panel-header h2,
.section-title h2 {
margin: 0;
font-size: 0.95rem;
letter-spacing: -0.01em;
}
.panel-header span,
.section-title span {
color: var(--muted);
font-size: 0.74rem;
}
.control-body {
padding: 20px;
}
.control {
margin-bottom: 24px;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.control-head label {
color: #d9e8f5;
font-size: 0.82rem;
font-weight: 700;
}
.number-wrap {
display: flex;
align-items: center;
gap: 6px;
}
.number-wrap input {
width: 82px;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
background: rgba(4, 12, 20, 0.72);
text-align: right;
font-size: 0.82rem;
font-variant-numeric: tabular-nums;
}
.number-wrap input:focus {
border-color: rgba(102, 217, 255, 0.65);
box-shadow: 0 0 0 3px rgba(102, 217, 255, 0.08);
}
.number-wrap span {
min-width: 48px;
color: var(--muted);
font-size: 0.71rem;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(90deg, var(--cyan), rgba(102, 217, 255, 0.12));
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid #dff7ff;
border-radius: 50%;
background: #37bde8;
box-shadow: 0 0 0 4px rgba(102, 217, 255, 0.10);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #dff7ff;
border-radius: 50%;
background: #37bde8;
box-shadow: 0 0 0 4px rgba(102, 217, 255, 0.10);
}
#powerRange {
background: linear-gradient(90deg, var(--orange), rgba(255, 173, 97, 0.12));
}
#powerRange::-webkit-slider-thumb {
background: #ed873b;
box-shadow: 0 0 0 4px rgba(255, 173, 97, 0.10);
}
#powerRange::-moz-range-thumb {
background: #ed873b;
box-shadow: 0 0 0 4px rgba(255, 173, 97, 0.10);
}
.range-limits {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: #61798e;
font-size: 0.66rem;
}
.control-help {
margin: 7px 0 0;
color: var(--muted);
font-size: 0.72rem;
line-height: 1.5;
}
.divider {
height: 1px;
margin: 21px 0;
background: var(--line);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.button {
min-height: 40px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
font-size: 0.78rem;
font-weight: 760;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.button:hover {
border-color: rgba(102, 217, 255, 0.45);
background: rgba(102, 217, 255, 0.08);
}
.button:active {
transform: translateY(1px);
}
.button.primary {
border-color: rgba(102, 217, 255, 0.34);
color: #07121b;
background: var(--cyan);
}
.button.primary:hover {
background: #8ce5ff;
}
.speed-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 12px;
color: var(--muted);
font-size: 0.75rem;
}
.speed-row select {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 8px;
outline: none;
background: var(--panel-soft);
}
.model-note {
margin-top: 18px;
padding: 13px;
border: 1px solid rgba(102, 217, 255, 0.15);
border-radius: 12px;
background: rgba(102, 217, 255, 0.045);
color: var(--muted);
font-size: 0.71rem;
line-height: 1.55;
}
.model-note strong {
color: var(--text);
}
.workspace {
display: grid;
gap: 18px;
min-width: 0;
}
.visual-panel {
padding: 18px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 0 2px 14px;
}
.stage {
position: relative;
height: 530px;
overflow: hidden;
border: 1px solid rgba(151, 190, 220, 0.12);
border-radius: 15px;
background: #09131e;
}
#sceneCanvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#sceneCanvas:active {
cursor: grabbing;
}
.stage-overlay {
position: absolute;
pointer-events: none;
}
.stage-overlay.top-left {
top: 17px;
left: 18px;
}
.stage-overlay.bottom-left {
bottom: 17px;
left: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100% - 120px);
}
.hud-title {
margin-bottom: 5px;
font-size: 0.85rem;
font-weight: 800;
}
.hud-subtitle {
color: var(--muted);
font-size: 0.7rem;
}
.hud-chip {
padding: 7px 9px;
border: 1px solid rgba(152, 191, 220, 0.16);
border-radius: 8px;
color: #b9cddd;
background: rgba(6, 14, 23, 0.68);
font-size: 0.68rem;
backdrop-filter: blur(8px);
}
.hud-chip b {
color: var(--text);
}
.dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 5px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 8px var(--green);
}
.stage-controls {
position: absolute;
right: 14px;
bottom: 14px;
display: flex;
gap: 6px;
}
.icon-button {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 1px solid rgba(152, 191, 220, 0.18);
border-radius: 9px;
color: #d9e8f5;
background: rgba(6, 14, 23, 0.76);
font-size: 1rem;
backdrop-filter: blur(8px);
}
.icon-button:hover {
border-color: rgba(102, 217, 255, 0.5);
}
.metric-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
margin-top: 12px;
}
.metric {
min-width: 0;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(5, 13, 21, 0.48);
}
.metric-label {
display: block;
margin-bottom: 8px;
color: var(--muted);
font-size: 0.63rem;
font-weight: 800;
letter-spacing: 0.10em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: var(--text);
font-size: clamp(1.05rem, 2vw, 1.55rem);
font-weight: 800;
letter-spacing: -0.035em;
text-overflow: ellipsis;
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.metric-value.temperature {
color: var(--orange);
}
.metric-value.energy {
color: var(--cyan);
}
.metric-sub {
display: block;
margin-top: 5px;
color: #70879a;
font-size: 0.66rem;
line-height: 1.35;
}
.charts-panel {
padding: 18px;
}
.chart-grid {
display: grid;
grid-template-columns: 1.35fr 1fr;
gap: 12px;
}
.chart-card {
min-width: 0;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(5, 13, 21, 0.43);
}
.chart-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.chart-heading h3 {
margin: 0 0 4px;
font-size: 0.8rem;
}
.chart-heading p {
margin: 0;
color: var(--muted);
font-size: 0.67rem;
}
.chart-unit {
color: var(--cyan);
font-size: 0.68rem;
font-weight: 800;
white-space: nowrap;
}
.chart-card.energy-chart .chart-unit {
color: var(--orange);
}
.chart-canvas {
display: block;
width: 100%;
height: 205px;
}
.equation-strip {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10px 20px;
margin-top: 12px;
padding: 13px 15px;
border: 1px solid rgba(102, 217, 255, 0.13);
border-radius: 12px;
background: rgba(102, 217, 255, 0.035);
color: var(--muted);
font-size: 0.71rem;
line-height: 1.5;
}
.equation-strip strong {
color: var(--text);
}
code {
color: var(--cyan);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 0.76rem;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1100px) {
.layout {
grid-template-columns: 1fr;
}
.controls-panel {
position: static;
}
.control-body {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0 24px;
}
.control-body .divider,
.control-body .actions,
.control-body .model-note {
grid-column: 1 / -1;
}
}
@media (max-width: 760px) {
.app {
width: min(100% - 20px, 1500px);
padding-top: 16px;
}
.topbar {
align-items: flex-start;
}
.live-badge {
display: none;
}
.control-body {
grid-template-columns: 1fr;
}
.control-body .divider,
.control-body .actions,
.control-body .model-note {
grid-column: auto;
}
.stage {
height: 430px;
}
.metric-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.chart-grid {
grid-template-columns: 1fr;
}
.chart-canvas {
height: 190px;
}
}
@media (max-width: 480px) {
.visual-panel,
.charts-panel {
padding: 10px;
}
.metric {
padding: 11px;
}
.stage {
height: 390px;
}
}
</style>
</head>
<body>
<main class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Adiabatic · Lumped capacitance</p>
<h1>Insulated Thermal Cell</h1>
</div>
</div>
<div class="live-badge" id="liveBadge">Live model</div>
</header>
<div class="layout">
<aside class="panel controls-panel" aria-label="Model parameters">
<div class="panel-header">
<h2>Model parameters</h2>
<span>SI units</span>
</div>
<div class="control-body">
<div class="control">
<div class="control-head">
<label for="massNumber">Mass</label>
<div class="number-wrap">
<input id="massNumber" type="number" min="0.5" max="20" step="0.1" value="2.5">
<span>kg</span>
</div>
</div>
<input id="massRange" type="range" min="0.5" max="20" step="0.1" value="2.5"
aria-label="Mass in kilograms">
<div class="range-limits"><span>0.5 kg</span><span>20 kg</span></div>
</div>
<div class="control">
<div class="control-head">
<label for="capacityNumber">Specific heat capacity</label>
<div class="number-wrap">
<input id="capacityNumber" type="number" min="100" max="5000" step="10" value="900">
<span>J/(kg·K)</span>
</div>
</div>
<input id="capacityRange" type="range" min="100" max="5000" step="10" value="900"
aria-label="Specific heat capacity in joules per kilogram kelvin">
<div class="range-limits"><span>100</span><span>5,000</span></div>
</div>
<div class="control">
<div class="control-head">
<label for="powerNumber">Input power</label>
<div class="number-wrap">
<input id="powerNumber" type="number" min="0" max="10000" step="50" value="1500">
<span>W</span>
</div>
</div>
<input id="powerRange" type="range" min="0" max="10000" step="50" value="1500"
aria-label="Input power in watts">
<div class="range-limits"><span>0 W</span><span>10 kW</span></div>
<p class="control-help">Power changes the rate of energy accumulation.</p>
</div>
<div class="control">
<div class="control-head">
<label for="initialTemp">Initial temperature</label>
<div class="number-wrap">
<input id="initialTemp" type="number" min="-50" max="150" step="0.5" value="20">
<span>°C</span>
</div>
</div>
<p class="control-help">Applied when the model is reset.</p>
</div>
<div class="divider"></div>
<div class="actions">
<div class="button-row">
<button class="button primary" id="pauseButton" type="button">Pause</button>
<button class="button" id="resetButton" type="button">Reset model</button>
</div>
<div class="speed-row">
<label for="speedSelect">Simulation speed</label>
<select id="speedSelect">
<option value="1">1× real time</option>
<option value="5">5× real time</option>
<option value="20">20× real time</option>
</select>
</div>
</div>
<div class="model-note">
<strong>State distinction:</strong> stored energy <code>E</code> is the accumulated
state. Temperature <code>T</code> is instantaneous and derived from
<code>T = E / (m cₚ)</code> using a 0 °C energy datum.
</div>
</div>
</aside>
<div class="workspace">
<section class="panel visual-panel" aria-labelledby="visualTitle">
<div class="section-title">
<div>
<h2 id="visualTitle">Low-poly thermal cell</h2>
<span>Drag to orbit · scroll or use buttons to zoom</span>
</div>
<span id="modelTime">00:00.0</span>
</div>
<div class="stage">
<canvas id="sceneCanvas" aria-label="Interactive 3D insulated thermal cell"></canvas>
<div class="stage-overlay top-left">
<div class="hud-title">Insulated lumped system</div>
<div class="hud-subtitle">No conductive, convective, or radiative loss terms</div>
</div>
<div class="stage-overlay bottom-left">
<div class="hud-chip"><span class="dot"></span><b id="scenePower">1.50 kW</b> input</div>
<div class="hud-chip">Total capacity <b id="sceneCapacity">2.25 kJ/K</b></div>
<div class="hud-chip">ΔT/dt <b id="sceneRate">0.667 K/s</b></div>
</div>
<div class="stage-controls">
<button class="icon-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="icon-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="icon-button" id="resetView" type="button" aria-label="Reset camera view">⌂</button>
</div>
</div>
<div class="metric-grid">
<div class="metric">
<span class="metric-label">Instantaneous temperature</span>
<span class="metric-value temperature" id="temperatureValue">20.0 °C</span>
<span class="metric-sub">Derived state: T = E / C</span>
</div>
<div class="metric">
<span class="metric-label">Stored energy</span>
<span class="metric-value energy" id="energyValue">45.00 kJ</span>
<span class="metric-sub">Relative to a 0 °C datum</span>
</div>
<div class="metric">
<span class="metric-label">Total heat capacity</span>
<span class="metric-value" id="capacityValue">2.25 kJ/K</span>
<span class="metric-sub">C = m · cₚ</span>
</div>
<div class="metric">
<span class="metric-label">Temperature rate</span>
<span class="metric-value" id="rateValue">+0.667 K/s</span>
<span class="metric-sub">dT/dt = P / C</span>
</div>
</div>
</section>
<section class="panel charts-panel" aria-labelledby="historyTitle">
<div class="section-title">
<div>
<h2 id="historyTitle">State histories</h2>
<span>Temperature and stored energy are plotted separately</span>
</div>
<span>Model time</span>
</div>
<div class="chart-grid">
<article class="chart-card">
<div class="chart-heading">
<div>
<h3>Temperature over time</h3>
<p>Instantaneous response of the lumped body</p>
</div>
<span class="chart-unit">°C</span>
</div>
<canvas class="chart-canvas" id="temperatureChart"
role="img" aria-label="Temperature history chart"></canvas>
</article>
<article class="chart-card energy-chart">
<div class="chart-heading">
<div>
<h3>Stored energy over time</h3>
<p>Accumulated input energy, relative to 0 °C</p>
</div>
<span class="chart-unit">kJ</span>
</div>
<canvas class="chart-canvas" id="energyChart"
role="img" aria-label="Stored energy history chart"></canvas>
</article>
</div>
<div class="equation-strip">
<span><strong>Adiabatic balance:</strong> <code>dE/dt = Pᵢₙ</code></span>
<span><strong>Temperature:</strong> <code>T = E / (m cₚ) + 0 °C</code></span>
<span>Mass and heat-capacity edits change <code>C</code> without editing stored energy.</span>
</div>
</section>
</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
// -------------------------------------------------------------------------
// Lumped thermal model
//
// E is stored energy relative to a 0 °C datum:
// E = m * cp * T_Celsius
// The insulated balance contains no loss term:
// dE/dt = P_in
// Temperature is instantaneous and derived:
// T = E / (m * cp)
// -------------------------------------------------------------------------
const model = {
mass: 2.5,
cp: 900,
power: 1500,
initialTemperature: 20,
capacity: 2250,
energy: 45000,
time: 0,
running: true,
speed: 1,
accumulator: 0,
lastSample: 0
};
const SIMULATION_STEP = 1 / 60;
const SAMPLE_INTERVAL = 0.1;
const MAX_HISTORY = 20000;
let history = [];
function temperature() {
return model.energy / model.capacity;
}
function updateCapacity() {
model.capacity = model.mass * model.cp;
}
function recordSample() {
history.push({
time: model.time,
temperature: temperature(),
energy: model.energy
});
if (history.length > MAX_HISTORY) {
history.shift();
}
model.lastSample = model.time;
}
function resetModel() {
updateCapacity();
model.energy = model.capacity * model.initialTemperature;
model.time = 0;
model.accumulator = 0;
model.lastSample = 0;
history = [];
recordSample();
updateUI();
drawCharts();
}
// -------------------------------------------------------------------------
// Parameter controls
// -------------------------------------------------------------------------
function bindPair(rangeId, numberId, min, max, onChange) {
const range = $(rangeId);
const number = $(numberId);
range.addEventListener("input", () => {
const value = parseFloat(range.value);
number.value = value;
onChange(value);
updateUI();
});
number.addEventListener("change", () => {
let value = parseFloat(number.value);
if (!Number.isFinite(value)) {
value = parseFloat(range.value);
}
value = Math.min(max, Math.max(min, value));
number.value = value;
range.value = value;
onChange(value);
updateUI();
});
}
bindPair("massRange", "massNumber", 0.5, 20, (value) => {
model.mass = value;
updateCapacity();
// Stored energy is intentionally not changed. Only the mapping from
// energy to instantaneous temperature changes.
});
bindPair("capacityRange", "capacityNumber", 100, 5000, (value) => {
model.cp = value;
updateCapacity();
});
bindPair("powerRange", "powerNumber", 0, 10000, (value) => {
model.power = value;
});
$("initialTemp").addEventListener("change", (event) => {
let value = parseFloat(event.target.value);
if (!Number.isFinite(value)) {
value = 20;
}
value = Math.min(150, Math.max(-50, value));
event.target.value = value;
model.initialTemperature = value;
});
$("pauseButton").addEventListener("click", () => {
model.running = !model.running;
updateUI();
});
$("resetButton").addEventListener("click", resetModel);
$("speedSelect").addEventListener("change", (event) => {
model.speed = parseFloat(event.target.value);
});
// -------------------------------------------------------------------------
// Three.js low-poly scene
// -------------------------------------------------------------------------
const canvas = $("sceneCanvas");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09131e);
scene.fog = new THREE.Fog(0x09131e, 12, 26);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const orbit = {
azimuth: 0.64,
elevation: 0.40,
distance: 8.2,
target: new THREE.Vector3(0, 1.48, 0)
};
function updateCamera() {
const horizontalDistance = Math.cos(orbit.elevation) * orbit.distance;
camera.position.set(
Math.sin(orbit.azimuth) * horizontalDistance,
orbit.target.y + Math.sin(orbit.elevation) * orbit.distance,
Math.cos(orbit.azimuth) * horizontalDistance
);
camera.lookAt(orbit.target);
}
updateCamera();
// Custom pointer orbit and wheel zoom; no external controls are imported.
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
orbit.azimuth -= deltaX * 0.007;
orbit.elevation = THREE.MathUtils.clamp(
orbit.elevation + deltaY * 0.006,
0.16,
1.12
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance + event.deltaY * 0.006,
5.1,
14
);
updateCamera();
}, { passive: false });
$("zoomIn").addEventListener("click", () => {
orbit.distance = Math.max(5.1, orbit.distance - 0.7);
updateCamera();
});
$("zoomOut").addEventListener("click", () => {
orbit.distance = Math.min(14, orbit.distance + 0.7);
updateCamera();
});
$("resetView").addEventListener("click", () => {
orbit.azimuth = 0.64;
orbit.elevation = 0.40;
orbit.distance = 8.2;
updateCamera();
});
const hemisphere = new THREE.HemisphereLight(0xb8e8ff, 0x142033, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.5);
keyLight.position.set(5, 8, 4);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5dcfff, 2.2);
rimLight.position.set(-5, 3, -4);
scene.add(rimLight);
const thermalLight = new THREE.PointLight(0xff7a42, 2.5, 8, 2);
thermalLight.position.set(0, 1.65, 0);
scene.add(thermalLight);
const floor = new THREE.Mesh(
new THREE.CircleGeometry(15, 32),
new THREE.MeshStandardMaterial({
color: 0x09121c,
roughness: 0.95,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(16, 16, 0x31516a, 0x1a3042);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.25;
scene.add(grid);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.65, 1.9, 0.34, 16),
new THREE.MeshStandardMaterial({
color: 0x172635,
roughness: 0.72,
metalness: 0.25,
flatShading: true
})
);
pedestal.position.y = 0.17;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.48, 1.55, 0.16, 12),
new THREE.MeshStandardMaterial({
color: 0x2b4354,
roughness: 0.38,
metalness: 0.62,
flatShading: true
})
);
base.position.y = 0.42;
base.castShadow = true;
scene.add(base);
const vessel = new THREE.Group();
scene.add(vessel);
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0x8dd9f4,
roughness: 0.25,
metalness: 0.12,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false
});
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(1.2, 1.2, 2.24, 12, 1, true),
shellMaterial
);
shell.position.y = 1.69;
vessel.add(shell);
const ribMaterial = new THREE.MeshStandardMaterial({
color: 0x74b9d5,
roughness: 0.42,
metalness: 0.48,
transparent: true,
opacity: 0.38
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const rib = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 2.28, 0.08),
ribMaterial
);
rib.position.set(
Math.sin(angle) * 1.215,
1.69,
Math.cos(angle) * 1.215
);
rib.rotation.y = angle;
vessel.add(rib);
}
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x83cbdf,
roughness: 0.3,
metalness: 0.72,
flatShading: true
});
for (const y of [0.56, 2.82]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.21, 0.075, 6, 12),
ringMaterial
);
ring.position.y = y;
ring.rotation.x = Math.PI / 2;
ring.castShadow = true;
vessel.add(ring);
}
const coldColor = new THREE.Color(0x4ac9ff);
const hotColor = new THREE.Color(0xff653c);
const coreMaterial = new THREE.MeshStandardMaterial({
color: coldColor,
emissive: coldColor,
emissiveIntensity: 0.35,
roughness: 0.42,
metalness: 0.12,
flatShading: true
});
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.78, 1),
coreMaterial
);
core.position.y = 1.67;
core.scale.y = 1.25;
core.castShadow = true;
vessel.add(core);
const coilMaterial = new THREE.MeshStandardMaterial({
color: 0xff8a48,
emissive: 0xff5b28,
emissiveIntensity: 0.5,
roughness: 0.32,
metalness: 0.55,
flatShading: true
});
for (const y of [0.88, 1.25, 1.62, 1.99, 2.36]) {
const coil = new THREE.Mesh(
new THREE.TorusGeometry(0.73, 0.052, 5, 12),
coilMaterial
);
coil.position.y = y;
coil.rotation.x = Math.PI / 2;
vessel.add(coil);
}
const sensorMaterial = new THREE.MeshStandardMaterial({
color: 0x71e5ff,
emissive: 0x29c9ff,
emissiveIntensity: 0.65,
roughness: 0.25,
metalness: 0.5
});
const sensor = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.28, 0.12),
sensorMaterial
);
sensor.position.set(0, 2.38, 1.22);
vessel.add(sensor);
const particleGeometry = new THREE.TetrahedronGeometry(0.065);
const particles = [];
for (let i = 0; i < 28; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0xffa35c,
emissive: 0xff6d33,
emissiveIntensity: 0.55,
roughness: 0.45,
metalness: 0.15,
flatShading: true
});
const mesh = new THREE.Mesh(particleGeometry, material);
const angle = (i / 28) * Math.PI * 2;
mesh.position.set(
Math.cos(angle) * (0.72 + (i % 3) * 0.08),
0.85 + (i % 7) * 0.25,
Math.sin(angle) * (0.72 + (i % 3) * 0.08)
);
vessel.add(mesh);
particles.push({
mesh,
angle,
radius: 0.72 + (i % 3) * 0.08,
phase: (i / 28 + (i % 4) * 0.11) % 1
});
}
const inletMaterial = new THREE.MeshStandardMaterial({
color: 0xffb05e,
emissive: 0xff6d2e,
emissiveIntensity: 1.2,
transparent: true,
opacity: 0.85,
roughness: 0.38,
metalness: 0.2,
flatShading: true
});
const inletArrows = [];
for (let i = 0; i < 3; i++) {
const arrow = new THREE.Group();
const angle = (i / 3) * Math.PI * 2 + 0.4;
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.38, 6),
inletMaterial
);
shaft.position.y = 0.19;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.3, 6),
inletMaterial
);
head.position.y = -0.13;
head.rotation.z = Math.PI;
arrow.add(shaft, head);
arrow.position.set(
Math.sin(angle) * 1.62,
3.3,
Math.cos(angle) * 1.62
);
scene.add(arrow);
inletArrows.push({ group: arrow, phase: i * 1.7 });
}
function resizeRenderer() {
const bounds = canvas.getBoundingClientRect();
renderer.setSize(bounds.width, bounds.height, false);
camera.aspect = bounds.width / Math.max(1, bounds.height);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(canvas.parentElement);
resizeRenderer();
let particleClock = 0;
function updateScene(realDelta) {
const currentTemperature = temperature();
const thermalFraction = THREE.MathUtils.clamp((currentTemperature + 20) / 180, 0, 1);
const powerFraction = THREE.MathUtils.clamp(model.power / 5000, 0, 1);
coreMaterial.color.copy(coldColor).lerp(hotColor, thermalFraction);
coreMaterial.emissive.copy(coldColor).lerp(hotColor, thermalFraction);
coreMaterial.emissiveIntensity = 0.2 + thermalFraction * 1.5;
coilMaterial.emissiveIntensity =
0.18 + powerFraction * 1.7 + thermalFraction * 0.45;
thermalLight.color.copy(coldColor).lerp(hotColor, thermalFraction);
thermalLight.intensity = 0.7 + thermalFraction * 3.0 + powerFraction * 1.2;
shellMaterial.color.copy(coldColor).lerp(hotColor, thermalFraction * 0.55);
const pulse = 1 + Math.sin(particleClock * 3.1) * 0.025 * (0.2 + thermalFraction);
core.scale.set(0.98 + thermalFraction * 0.07, 1.25 * pulse, 0.98 + thermalFraction * 0.07);
if (model.running) {
particleClock += realDelta * Math.min(model.speed, 4);
}
for (const particle of particles) {
const angle = particle.angle + particleClock * (0.12 + powerFraction * 0.32);
const rise = (particle.phase + particleClock * (0.025 + powerFraction * 0.055)) % 1;
particle.mesh.position.set(
Math.cos(angle) * particle.radius,
0.82 + rise * 1.76,
Math.sin(angle) * particle.radius
);
particle.mesh.rotation.x += realDelta * 1.2;
particle.mesh.rotation.y += realDelta * 1.6;
particle.mesh.material.emissiveIntensity =
0.18 + thermalFraction * 0.9 + powerFraction * 0.3;
}
inletMaterial.opacity = 0.18 + powerFraction * 0.72;
inletMaterial.emissiveIntensity = 0.3 + powerFraction * 1.8;
for (const inlet of inletArrows) {
const movement = model.running
? Math.sin(particleClock * 2.2 + inlet.phase) * 0.08
: 0;
inlet.group.position.y = 3.3 + movement;
}
}
// -------------------------------------------------------------------------
// UI formatting
// -------------------------------------------------------------------------
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remaining = seconds - minutes * 60;
return `${String(minutes).padStart(2, "0")}:${remaining.toFixed(1).padStart(4, "0")}`;
}
function formatRate(value) {
if (Math.abs(value) >= 1000) {
return `${(value / 1000).toFixed(2)}k K/s`;
}
return `${value.toFixed(3)} K/s`;
}
function updateUI() {
const currentTemperature = temperature();
const rate = model.capacity > 0 ? model.power / model.capacity : 0;
$("temperatureValue").textContent = `${currentTemperature.toFixed(1)} °C`;
$("energyValue").textContent = `${(model.energy / 1000).toFixed(2)} kJ`;
$("capacityValue").textContent = `${(model.capacity / 1000).toFixed(2)} kJ/K`;
$("rateValue").textContent = `${rate >= 0 ? "+" : ""}${formatRate(rate)}`;
$("modelTime").textContent = formatTime(model.time);
$("scenePower").textContent = `${(model.power / 1000).toFixed(2)} kW`;
$("sceneCapacity").textContent = `${(model.capacity / 1000).toFixed(2)} kJ/K`;
$("sceneRate").textContent = formatRate(rate);
$("pauseButton").textContent = model.running ? "Pause" : "Resume";
const badge = $("liveBadge");
badge.classList.toggle("paused", !model.running);
badge.textContent = !model.running
? "Model paused"
: model.power > 0
? "Live · heating"
: "Live · no power input";
}
// -------------------------------------------------------------------------
// Canvas plots
// -------------------------------------------------------------------------
function prepareCanvas(plotCanvas) {
const rect = plotCanvas.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.max(1, Math.floor(rect.width));
const height = Math.max(1, Math.floor(rect.height));
const pixelWidth = Math.floor(width * dpr);
const pixelHeight = Math.floor(height * dpr);
if (plotCanvas.width !== pixelWidth || plotCanvas.height !== pixelHeight) {
plotCanvas.width = pixelWidth;
plotCanvas.height = pixelHeight;
}
const context = plotCanvas.getContext("2d");
context.setTransform(dpr, 0, 0, dpr, 0, 0);
context.clearRect(0, 0, width, height);
return { context, width, height };
}
function compactNumber(value) {
const absolute = Math.abs(value);
if (absolute >= 1000000) return `${(value / 1000000).toFixed(1)}M`;
if (absolute >= 1000) return `${(value / 1000).toFixed(1)}k`;
if (absolute >= 100) return value.toFixed(0);
if (absolute >= 10) return value.toFixed(1);
return value.toFixed(2);
}
function drawPlot(plotCanvas, accessor, color, includeZero) {
const { context, width, height } = prepareCanvas(plotCanvas);
const padding = { left: 52, right: 15, top: 15, bottom: 33 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
if (chartWidth <= 0 || chartHeight <= 0 || history.length === 0) return;
let minimum = Infinity;
let maximum = -Infinity;
for (const sample of history) {
const value = accessor(sample);
minimum = Math.min(minimum, value);
maximum = Math.max(maximum, value);
}
if (includeZero) {
minimum = Math.min(minimum, 0);
maximum = Math.max(maximum, 0);
}
if (minimum === maximum) {
const offset = Math.max(1, Math.abs(minimum) * 0.05);
minimum -= offset;
maximum += offset;
} else {
const paddingY = (maximum - minimum) * 0.12;
minimum -= paddingY;
maximum += paddingY;
}
if (includeZero && minimum >= 0) {
minimum = 0;
}
const xMaximum = Math.max(30, model.time * 1.06);
const mapX = (time) => padding.left + (time / xMaximum) * chartWidth;
const mapY = (value) =>
padding.top + chartHeight - ((value - minimum) / (maximum - minimum)) * chartHeight;
context.font = "10px system-ui, sans-serif";
context.textBaseline = "middle";
// Horizontal grid and Y-axis labels.
for (let i = 0; i <= 4; i++) {
const ratio = i / 4;
const y = padding.top + chartHeight * ratio;
const value = maximum - (maximum - minimum) * ratio;
context.beginPath();
context.moveTo(padding.left, y);
context.lineTo(width - padding.right, y);
context.strokeStyle = "rgba(151, 184, 210, 0.10)";
context.lineWidth = 1;
context.stroke();
context.fillStyle = "#70879a";
context.textAlign = "right";
context.fillText(compactNumber(value), padding.left - 8, y);
}
// Vertical grid and time labels.
for (let i = 0; i <= 3; i++) {
const ratio = i / 3;
const x = padding.left + chartWidth * ratio;
const time = xMaximum * ratio;
context.beginPath();
context.moveTo(x, padding.top);
context.lineTo(x, padding.top + chartHeight);
context.strokeStyle = "rgba(151, 184, 210, 0.075)";
context.stroke();
context.fillStyle = "#70879a";
context.textAlign = i === 0 ? "left" : i === 3 ? "right" : "center";
context.textBaseline = "top";
context.fillText(`${time.toFixed(time < 10 ? 1 : 0)}s`, x, padding.top + chartHeight + 9);
}
// Filled area.
const gradient = context.createLinearGradient(0, padding.top, 0, padding.top + chartHeight);
gradient.addColorStop(0, `${color}38`);
gradient.addColorStop(1, `${color}00`);
context.beginPath();
context.moveTo(mapX(history[0].time), padding.top + chartHeight);
for (const sample of history) {
context.lineTo(mapX(sample.time), mapY(accessor(sample)));
}
context.lineTo(
mapX(history[history.length - 1].time),
padding.top + chartHeight
);
context.closePath();
context.fillStyle = gradient;
context.fill();
// Main line.
context.beginPath();
history.forEach((sample, index) => {
const x = mapX(sample.time);
const y = mapY(accessor(sample));
if (index === 0) context.moveTo(x, y);
else context.lineTo(x, y);
});
context.strokeStyle = color;
context.lineWidth = 2;
context.lineJoin = "round";
context.lineCap = "round";
context.stroke();
// Current-value marker.
const last = history[history.length - 1];
const lastX = mapX(last.time);
const lastY = mapY(accessor(last));
context.beginPath();
context.arc(lastX, lastY, 3.5, 0, Math.PI * 2);
context.fillStyle = color;
context.fill();
context.beginPath();
context.arc(lastX, lastY, 6.5, 0, Math.PI * 2);
context.strokeStyle = `${color}55`;
context.lineWidth = 2;
context.stroke();
}
function drawCharts() {
drawPlot(
$("temperatureChart"),
(sample) => sample.temperature,
"#ffad61",
false
);
drawPlot(
$("energyChart"),
(sample) => sample.energy / 1000,
"#66d9ff",
true
);
}
// -------------------------------------------------------------------------
// Animation and fixed-step simulation
// -------------------------------------------------------------------------
let previousFrame = performance.now();
let previousUIUpdate = 0;
let previousChartUpdate = 0;
function animate(now) {
const realDelta = Math.min((now - previousFrame) / 1000, 0.1);
previousFrame = now;
if (model.running) {
model.accumulator += realDelta * model.speed;
let steps = 0;
while (model.accumulator >= SIMULATION_STEP && steps < 240) {
// Insulated: all input power is retained as stored energy.
model.energy += model.power * SIMULATION_STEP;
model.time += SIMULATION_STEP;
model.accumulator -= SIMULATION_STEP;
steps++;
if (model.time - model.lastSample >= SAMPLE_INTERVAL) {
recordSample();
}
}
}
updateScene(realDelta);
if (now - previousUIUpdate > 80) {
updateUI();
previousUIUpdate = now;
}
if (now - previousChartUpdate > 150) {
drawCharts();
previousChartUpdate = now;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resetModel();
requestAnimationFrame(animate);
</script>
</body>
</html>
```