Prompt specification
Build or customize the Three.js 3D scene "Ideal radiation-balance 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: Ideal radiation-balance explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ideal-radiation-balance-explorer-x1512
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: ideal radiation-balance explorer. Provide surface temperature, area, and emissivity controls for a labeled simplified model; calculate emitted power with units and distinguish emission from net heat loss.
Working Three.js Starter (ideal-radiation-balance-explorer-x1512):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Radiation Balance Explorer</title>
<style>
:root {
--bg: #07111d;
--panel: rgba(10, 22, 36, 0.88);
--panel-solid: #0b1725;
--border: rgba(163, 196, 224, 0.16);
--text: #eef6ff;
--muted: #91a6ba;
--orange: #ff8a47;
--orange-bright: #ffb26f;
--blue: #5caeff;
--cyan: #74d8e8;
--green: #68e0b1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 44% 40%, #14273a 0%, #091522 43%, #050b13 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
background:
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
background-size: 64px 64px;
mask-image: radial-gradient(circle at 45% 45%, black, transparent 73%);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
box-shadow: inset 0 0 150px rgba(0, 0, 0, 0.58);
}
.brand {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
max-width: 510px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--orange-bright);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 13px var(--orange);
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
transform: scale(0.75);
}
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 48px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 720;
}
.brand p {
margin: 12px 0 0;
max-width: 440px;
color: #a8bbcd;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
top: 22px;
right: 22px;
bottom: 22px;
z-index: 6;
width: 385px;
overflow-y: auto;
overscroll-behavior: contain;
padding: 21px;
border: 1px solid var(--border);
border-radius: 20px;
background:
linear-gradient(150deg, rgba(23, 43, 63, 0.64), rgba(7, 17, 29, 0.93)),
var(--panel);
box-shadow:
0 28px 80px rgba(0, 0, 0, 0.42),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(20px);
scrollbar-width: thin;
scrollbar-color: #30465b transparent;
}
.panel-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 20px;
}
.panel-kicker {
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 19px;
letter-spacing: -0.025em;
}
.si-badge {
flex: 0 0 auto;
padding: 6px 8px;
border: 1px solid rgba(116, 216, 232, 0.24);
border-radius: 7px;
color: var(--cyan);
background: rgba(116, 216, 232, 0.06);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.control {
margin: 0 0 19px;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 10px;
}
.control-heading label {
color: #d9e7f2;
font-size: 13px;
font-weight: 650;
}
output {
min-width: 96px;
color: var(--text);
font: 700 13px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
output span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
input[type="range"] {
--pct: 50%;
--range-color: var(--orange);
width: 100%;
height: 4px;
margin: 5px 0;
appearance: none;
border-radius: 999px;
background: linear-gradient(
90deg,
var(--range-color) 0%,
var(--range-color) var(--pct),
rgba(139, 164, 187, 0.2) var(--pct),
rgba(139, 164, 187, 0.2) 100%
);
cursor: pointer;
}
input[type="range"].environment {
--range-color: var(--blue);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid #122235;
border-radius: 50%;
background: var(--range-color);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3), 0 0 15px var(--range-color);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #122235;
border-radius: 50%;
background: var(--range-color);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3), 0 0 15px var(--range-color);
}
input[type="range"]:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 7px;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #6f8599;
font: 500 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.divider {
height: 1px;
margin: 20px 0;
background: var(--border);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: #c8d8e5;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span:last-child {
color: #6e8599;
font: 500 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.metric {
position: relative;
margin-bottom: 9px;
padding: 13px 14px 13px 17px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.065);
border-radius: 12px;
background: rgba(255, 255, 255, 0.027);
}
.metric::before {
content: "";
position: absolute;
top: 13px;
bottom: 13px;
left: 0;
width: 3px;
border-radius: 0 5px 5px 0;
background: var(--orange);
box-shadow: 0 0 14px rgba(255, 138, 71, 0.45);
}
.metric.counter::before {
background: var(--blue);
box-shadow: 0 0 14px rgba(92, 174, 255, 0.4);
}
.metric.net::before {
background: var(--green);
box-shadow: 0 0 14px rgba(104, 224, 177, 0.4);
}
.metric.net.gain::before {
background: var(--blue);
box-shadow: 0 0 14px rgba(92, 174, 255, 0.4);
}
.metric-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.metric-label {
color: #aebfd0;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
margin-top: 6px;
font: 720 25px/1.05 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.04em;
}
.metric-formula {
margin-top: 7px;
color: #7890a5;
font: 500 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.explanation {
margin: 12px 0 17px;
padding: 12px 13px;
border-left: 2px solid var(--orange);
border-radius: 0 9px 9px 0;
background: rgba(255, 138, 71, 0.065);
color: #b7c7d6;
font-size: 11px;
line-height: 1.55;
}
.explanation strong {
color: #f4f8fc;
}
.ratio-track {
position: relative;
height: 7px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
overflow: visible;
}
.ratio-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #2e79be, var(--blue));
transition: width 120ms ease;
}
.ratio-divider {
position: absolute;
top: -4px;
left: 0;
width: 2px;
height: 15px;
border-radius: 2px;
background: var(--orange-bright);
box-shadow: 0 0 9px rgba(255, 178, 111, 0.65);
transition: left 120ms ease;
}
.ratio-caption {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: #71889d;
font: 500 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ratio-caption span:nth-child(2) {
color: var(--blue);
}
details {
border-top: 1px solid var(--border);
padding-top: 15px;
}
summary {
color: #aebfd0;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.assumptions {
margin: 12px 0 0;
padding-left: 17px;
color: #849aae;
font-size: 10px;
line-height: 1.7;
}
.assumptions code {
color: #c4d4e1;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.reset-button {
width: 100%;
margin-top: 16px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 9px;
color: #c8d8e5;
background: rgba(255, 255, 255, 0.035);
font: 700 10px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 160ms ease;
}
.reset-button:hover {
color: white;
border-color: rgba(255, 138, 71, 0.4);
background: rgba(255, 138, 71, 0.08);
}
.legend {
position: fixed;
bottom: 28px;
left: 30px;
z-index: 5;
display: flex;
gap: 18px;
align-items: center;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(5, 13, 23, 0.55);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #9db0c1;
font-size: 10px;
font-weight: 650;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 9px var(--orange);
}
.legend-dot.blue {
background: var(--blue);
box-shadow: 0 0 9px var(--blue);
}
.camera-hint {
position: fixed;
bottom: 31px;
left: 50%;
z-index: 4;
color: rgba(163, 183, 201, 0.55);
font: 500 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translateX(-50%);
pointer-events: none;
}
.scene-label {
position: fixed;
z-index: 4;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.scene-label.model-label {
min-width: 172px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
background: rgba(7, 17, 29, 0.83);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
}
.scene-label.model-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -18px;
width: 1px;
height: 18px;
background: linear-gradient(var(--orange), transparent);
}
.label-kicker {
display: block;
margin-bottom: 4px;
color: var(--orange-bright);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
color: #eff7ff;
font: 700 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.scene-label small {
display: block;
margin-top: 3px;
color: #8096a9;
font-size: 9px;
}
.ray-label {
padding: 6px 9px;
border-radius: 999px;
color: var(--orange-bright);
background: rgba(41, 22, 14, 0.75);
border: 1px solid rgba(255, 138, 71, 0.23);
font: 750 9px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.ray-label.blue {
color: #8cc5ff;
background: rgba(10, 32, 57, 0.78);
border-color: rgba(92, 174, 255, 0.25);
}
.status-label {
padding: 7px 11px;
border-radius: 8px;
color: var(--green);
border: 1px solid rgba(104, 224, 177, 0.25);
background: rgba(7, 31, 26, 0.78);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.status-label.gain {
color: #8cc5ff;
border-color: rgba(92, 174, 255, 0.25);
background: rgba(8, 28, 49, 0.8);
}
.status-label.balanced {
color: var(--cyan);
border-color: rgba(116, 216, 232, 0.25);
background: rgba(7, 29, 35, 0.8);
}
@media (max-width: 850px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 49vh;
padding: 17px;
border-radius: 16px;
}
.legend {
top: 105px;
bottom: auto;
left: 18px;
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.camera-hint {
display: none;
}
.scene-label.model-label {
transform: translate(-50%, -100%) scale(0.86);
}
}
@media (max-height: 700px) and (min-width: 851px) {
.panel {
top: 10px;
right: 10px;
bottom: 10px;
}
.brand {
top: 18px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel radiation-balance model"></canvas>
<div class="vignette"></div>
<header class="brand">
<div class="eyebrow">
<span class="live-dot"></span>
Ideal radiation-balance explorer
</div>
<h1>Gray-body<br />surface lab</h1>
<p>
Explore how temperature, area, and emissivity change thermal emission—and
how surrounding radiation changes the net heat balance.
</p>
</header>
<aside class="panel" aria-label="Radiation model controls and results">
<div class="panel-header">
<div>
<div class="panel-kicker">Simplified physical model</div>
<h2>Surface conditions</h2>
</div>
<div class="si-badge">SI</div>
</div>
<div class="control">
<div class="control-heading">
<label for="temperature">Surface temperature</label>
<output id="temperatureOut" for="temperature"></output>
</div>
<input
id="temperature"
type="range"
min="220"
max="500"
step="1"
value="330"
/>
<div class="range-ends">
<span>220 K</span>
<span>500 K</span>
</div>
</div>
<div class="control">
<div class="control-heading">
<label for="area">Surface area</label>
<output id="areaOut" for="area"></output>
</div>
<input
id="area"
type="range"
min="1"
max="100"
step="1"
value="24"
/>
<div class="range-ends">
<span>1 m²</span>
<span>100 m²</span>
</div>
</div>
<div class="control">
<div class="control-heading">
<label for="emissivity">Surface emissivity</label>
<output id="emissivityOut" for="emissivity"></output>
</div>
<input
id="emissivity"
type="range"
min="0.05"
max="1"
step="0.01"
value="0.87"
/>
<div class="range-ends">
<span>0.05 · low ε</span>
<span>1.00 · black body</span>
</div>
</div>
<div class="control">
<div class="control-heading">
<label for="environment">Surroundings temperature</label>
<output id="environmentOut" for="environment"></output>
</div>
<input
id="environment"
class="environment"
type="range"
min="220"
max="400"
step="1"
value="288"
/>
<div class="range-ends">
<span>220 K</span>
<span>400 K</span>
</div>
</div>
<div class="divider"></div>
<div class="section-title">
<span>Radiation balance</span>
<span>σ = 5.670374419×10⁻⁸</span>
</div>
<div class="metric">
<div class="metric-top">
<div class="metric-label">Gross emitted power</div>
</div>
<div class="metric-value" id="emitValue" aria-live="polite">—</div>
<div class="metric-formula" id="emitDetails"></div>
</div>
<div class="metric counter">
<div class="metric-top">
<div class="metric-label">Absorbed counter-radiation</div>
</div>
<div class="metric-value" id="counterValue">—</div>
<div class="metric-formula" id="counterDetails"></div>
</div>
<div class="metric net" id="netMetric">
<div class="metric-top">
<div class="metric-label" id="netTitle">Net radiative heat loss</div>
</div>
<div class="metric-value" id="netValue" aria-live="polite">—</div>
<div class="metric-formula" id="netDetails"></div>
</div>
<div class="explanation">
<strong>Emission is not net heat loss.</strong>
Gross emission is the power radiated by the surface. Net heat loss also
subtracts the thermal radiation absorbed from the surroundings. Positive
net values cool the surface; negative values warm it.
</div>
<div class="section-title">
<span>Counter-radiation / emission</span>
<span id="counterPercent">—</span>
</div>
<div class="ratio-track">
<div class="ratio-fill" id="counterFill"></div>
<div class="ratio-divider" id="ratioDivider"></div>
</div>
<div class="ratio-caption">
<span>0%</span>
<span id="counterCaption">incoming fraction</span>
<span>100%</span>
</div>
<details>
<summary>Model equations & assumptions</summary>
<ul class="assumptions">
<li>
Gross emission:
<code>P<sub>emit</sub> = εσAT<sub>s</sub>⁴</code>
</li>
<li>
Surroundings counter-radiation:
<code>P<sub>in</sub> = εσAT<sub>∞</sub>⁴</code>
</li>
<li>
Net radiative heat loss:
<code>P<sub>net</sub> = εσA(T<sub>s</sub>⁴ − T<sub>∞</sub>⁴)</code>
</li>
<li>
Stefan–Boltzmann constant:
<code>σ = 5.670374419×10⁻⁸ W m⁻² K⁻⁴</code>
</li>
<li>
Temperatures are absolute temperatures in kelvin. The surface is an
opaque gray body with unit view factor to the surroundings.
</li>
<li>
Convection, conduction, convection from internal sources, spectral
effects, and solar absorption are intentionally excluded.
</li>
<li>
The voxel footprint communicates the variables visually and is not
drawn to physical scale.
</li>
</ul>
</details>
<button class="reset-button" id="resetButton" type="button">
Reset model & camera
</button>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="legend-dot"></span>
Thermal emission
</div>
<div class="legend-item">
<span class="legend-dot blue"></span>
Surroundings radiation
</div>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom · double-click to reset</div>
<div class="scene-label model-label" id="surfaceLabel">
<span class="label-kicker">Voxel surface</span>
<strong id="surfaceLabelValue"></strong>
<small id="surfaceLabelArea"></small>
</div>
<div class="scene-label ray-label" id="emissionLabel">
Gross emission
</div>
<div class="scene-label ray-label blue" id="incomingLabel">
Incoming radiation
</div>
<div class="scene-label status-label" id="statusLabel">
Net cooling
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const canvas = $("scene");
const controls = {
temperature: $("temperature"),
area: $("area"),
emissivity: $("emissivity"),
environment: $("environment")
};
const defaults = {
temperature: 330,
area: 24,
emissivity: 0.87,
environment: 288
};
const SIGMA = 5.670374419e-8;
const state = {
temperature: defaults.temperature,
area: defaults.area,
emissivity: defaults.emissivity,
environment: defaults.environment
};
// Renderer and scene.
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111d, 0.024);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
yaw: 0.68,
pitch: 0.57,
distance: 10.5,
targetYaw: 0.68,
targetPitch: 0.57,
targetDistance: 10.5
};
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
const hemisphere = new THREE.HemisphereLight(0xb9d5f5, 0x121722, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2df, 3.2);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x579fff, 1.25);
rimLight.position.set(-5, 4, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xff743a, 4, 10, 2);
warmFill.position.set(0, 1.8, 0);
scene.add(warmFill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 60, 0x31516b, 0x183047);
grid.position.y = -0.01;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(16, 40, 24),
new THREE.MeshBasicMaterial({
color: 0x3977b8,
transparent: true,
opacity: 0.025,
side: THREE.BackSide,
depthWrite: false
})
);
scene.add(atmosphere);
const horizon = new THREE.Mesh(
new THREE.RingGeometry(3.1, 3.115, 128),
new THREE.MeshBasicMaterial({
color: 0x4d9bdf,
transparent: true,
opacity: 0.2,
side: THREE.DoubleSide,
depthWrite: false
})
);
horizon.rotation.x = -Math.PI / 2;
horizon.position.y = 0.005;
scene.add(horizon);
let voxelGroup = new THREE.Group();
scene.add(voxelGroup);
let voxelMaterials = [];
let modelWidth = 1;
let modelDepth = 1;
const statusRing = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.018, 6, 128),
new THREE.MeshBasicMaterial({
color: 0x68e0b1,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
statusRing.rotation.x = Math.PI / 2;
statusRing.position.y = 0.025;
scene.add(statusRing);
const emissionArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 0.55, 0),
2.3,
0xff8a47,
0.3,
0.17
);
scene.add(emissionArrow);
const incomingArrow = new THREE.ArrowHelper(
new THREE.Vector3(0.55, -0.78, 0.3).normalize(),
new THREE.Vector3(-2.6, 4.0, -1.5),
3.7,
0x5caeff,
0.32,
0.18
);
scene.add(incomingArrow);
// Procedural radiation fields.
const OUT_COUNT = 72;
const IN_COUNT = 48;
const outPositions = new Float32Array(OUT_COUNT * 6);
const outColors = new Float32Array(OUT_COUNT * 6);
const inPositions = new Float32Array(IN_COUNT * 6);
const inColors = new Float32Array(IN_COUNT * 6);
const outGeometry = new THREE.BufferGeometry();
outGeometry.setAttribute(
"position",
new THREE.BufferAttribute(outPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
outGeometry.setAttribute("color", new THREE.BufferAttribute(outColors, 3));
const inGeometry = new THREE.BufferGeometry();
inGeometry.setAttribute(
"position",
new THREE.BufferAttribute(inPositions, 3).setUsage(THREE.DynamicDrawUsage)
);
inGeometry.setAttribute("color", new THREE.BufferAttribute(inColors, 3));
const outgoingMaterial = new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.75,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const incomingMaterial = new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.64,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const outgoingLines = new THREE.LineSegments(outGeometry, outgoingMaterial);
const incomingLines = new THREE.LineSegments(inGeometry, incomingMaterial);
outgoingLines.frustumCulled = false;
incomingLines.frustumCulled = false;
scene.add(outgoingLines, incomingLines);
const outgoingBases = [];
const incomingTargets = [];
const incomingSources = [];
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
function thermalColor(kelvin) {
const t = THREE.MathUtils.clamp((kelvin - 220) / 280, 0, 1);
const hue = 0.59 - t * 0.55;
return new THREE.Color().setHSL(hue, 0.78, 0.48);
}
function disposeObject(root) {
const geometries = new Set();
const materials = new Set();
root.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
const list = Array.isArray(object.material)
? object.material
: [object.material];
list.forEach((material) => materials.add(material));
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
scene.remove(root);
}
function refreshRayTargets() {
const random = seededRandom(87431 + state.area * 97);
outgoingBases.length = 0;
incomingTargets.length = 0;
incomingSources.length = 0;
for (let i = 0; i < OUT_COUNT; i++) {
outgoingBases.push({
x: (random() - 0.5) * modelWidth * 0.9,
z: (random() - 0.5) * modelDepth * 0.9,
phase: random()
});
}
for (let i = 0; i < IN_COUNT; i++) {
const target = new THREE.Vector3(
(random() - 0.5) * modelWidth * 0.95,
0.43,
(random() - 0.5) * modelDepth * 0.95
);
const angle = random() * Math.PI * 2;
const radius = 1.9 + random() * 1.8;
const source = target.clone().add(
new THREE.Vector3(
Math.cos(angle) * radius,
2.5 + random() * 1.8,
Math.sin(angle) * radius
)
);
incomingTargets.push(target);
incomingSources.push(source);
}
const hot = new THREE.Color(0xffa15c);
const hotFade = new THREE.Color(0x3b160a);
for (let i = 0; i < OUT_COUNT; i++) {
const offset = i * 6;
hot.toArray(outColors, offset);
hotFade.toArray(outColors, offset + 3);
}
const cold = new THREE.Color(0x72baff);
const coldFade = new THREE.Color(0x10243e);
for (let i = 0; i < IN_COUNT; i++) {
const offset = i * 6;
cold.toArray(inColors, offset);
coldFade.toArray(inColors, offset + 3);
}
outGeometry.attributes.color.needsUpdate = true;
inGeometry.attributes.color.needsUpdate = true;
}
function updateThermalMaterials() {
if (!voxelMaterials.length) return;
const glow = thermalColor(state.temperature);
const t = THREE.MathUtils.clamp(
(state.temperature - 220) / 280,
0,
1
);
voxelMaterials.forEach((material, index) => {
const base = glow.clone().offsetHSL(0, 0, (index - 1) * 0.045);
material.color.copy(base);
material.emissive.copy(glow);
material.emissiveIntensity = 0.12 + t * 0.38;
});
warmFill.color.copy(glow);
warmFill.intensity = 1.5 + t * 4.2;
}
function buildVoxels() {
disposeObject(voxelGroup);
voxelGroup = new THREE.Group();
voxelMaterials = [];
const count = state.area;
const columns = Math.max(1, Math.round(Math.sqrt(count)));
const rows = Math.ceil(count / columns);
const cell = 0.31;
const pitch = 0.42;
modelWidth = (columns - 1) * pitch + cell;
modelDepth = (rows - 1) * pitch + cell;
const glow = thermalColor(state.temperature);
const t = THREE.MathUtils.clamp(
(state.temperature - 220) / 280,
0,
1
);
for (let i = 0; i < 3; i++) {
const base = glow.clone().offsetHSL(0, 0, (i - 1) * 0.045);
voxelMaterials.push(
new THREE.MeshStandardMaterial({
color: base,
emissive: glow,
emissiveIntensity: 0.12 + t * 0.38,
roughness: 0.7,
metalness: 0.025
})
);
}
const cubeGeometry = new THREE.BoxGeometry(cell, 0.38, cell);
const edgeGeometry = new THREE.EdgesGeometry(cubeGeometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xb7d4e8,
transparent: true,
opacity: 0.22
});
for (let i = 0; i < count; i++) {
const column = i % columns;
const row = Math.floor(i / columns);
const x = (column - (columns - 1) / 2) * pitch;
const z = (row - (rows - 1) / 2) * pitch;
const cube = new THREE.Mesh(
cubeGeometry,
voxelMaterials[(column + row) % voxelMaterials.length]
);
cube.position.set(x, 0.19, z);
cube.castShadow = true;
cube.receiveShadow = true;
voxelGroup.add(cube);
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
edges.position.copy(cube.position);
voxelGroup.add(edges);
}
const baseGeometry = new THREE.BoxGeometry(
modelWidth + 0.2,
0.045,
modelDepth + 0.2
);
const base = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x14283a,
roughness: 0.75,
metalness: 0.15
})
);
base.position.y = 0.0225;
base.receiveShadow = true;
voxelGroup.add(base);
const baseEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(baseGeometry),
new THREE.LineBasicMaterial({
color: 0x4d7898,
transparent: true,
opacity: 0.42
})
);
baseEdges.position.copy(base.position);
voxelGroup.add(baseEdges);
statusRing.scale.set(modelWidth * 0.61, modelDepth * 0.61, 1);
scene.add(voxelGroup);
refreshRayTargets();
}
function formatPower(watts) {
const absolute = Math.abs(watts);
const sign = watts < 0 ? "−" : "";
if (absolute >= 1e6) {
return `${sign}${(absolute / 1e6).toFixed(2)} MW`;
}
if (absolute >= 1e3) {
return `${sign}${(absolute / 1e3).toFixed(2)} kW`;
}
return `${sign}${absolute.toFixed(1)} W`;
}
function formatFlux(wattsPerSquareMeter) {
const absolute = Math.abs(wattsPerSquareMeter);
const sign = wattsPerSquareMeter < 0 ? "−" : "";
if (absolute >= 1000) {
return `${sign}${(absolute / 1000).toFixed(2)} kW/m²`;
}
return `${sign}${absolute.toFixed(1)} W/m²`;
}
function setRangeFill(input) {
const minimum = Number(input.min);
const maximum = Number(input.max);
const value = Number(input.value);
const percentage = ((value - minimum) / (maximum - minimum)) * 100;
input.style.setProperty("--pct", `${percentage}%`);
}
function updateInterface() {
const t = state.temperature;
const environment = state.environment;
$("temperatureOut").innerHTML =
`${t} K<span>${(t - 273.15).toFixed(1)} °C</span>`;
$("areaOut").innerHTML =
`${state.area} m²<span>${state.area} square metres</span>`;
$("emissivityOut").innerHTML =
`${state.emissivity.toFixed(2)}<span>dimensionless</span>`;
$("environmentOut").innerHTML =
`${environment} K<span>${(environment - 273.15).toFixed(1)} °C</span>`;
Object.values(controls).forEach(setRangeFill);
controls.temperature.setAttribute(
"aria-valuetext",
`${t} kelvin, ${(t - 273.15).toFixed(1)} degrees Celsius`
);
controls.area.setAttribute("aria-valuetext", `${state.area} square meters`);
controls.emissivity.setAttribute(
"aria-valuetext",
`emissivity ${state.emissivity.toFixed(2)}`
);
controls.environment.setAttribute(
"aria-valuetext",
`${environment} kelvin surroundings`
);
const emitted =
state.emissivity *
SIGMA *
state.area *
Math.pow(t, 4);
const counterRadiation =
state.emissivity *
SIGMA *
state.area *
Math.pow(environment, 4);
const net = emitted - counterRadiation;
const netFlux =
state.emissivity *
SIGMA *
(Math.pow(t, 4) - Math.pow(environment, 4));
$("emitValue").textContent = formatPower(emitted);
$("emitDetails").textContent =
`P_emit = εσAT_s⁴ · ${formatFlux(emitted / state.area)} × ${state.area} m²`;
$("counterValue").textContent = formatPower(counterRadiation);
$("counterDetails").textContent =
`P_in = εσAT_∞⁴ · ${formatFlux(counterRadiation / state.area)} × ${state.area} m²`;
$("netValue").textContent = formatPower(net);
$("netMetric").classList.toggle("gain", net < 0);
const isBalanced = Math.abs(net) < 1;
$("netTitle").textContent = isBalanced
? "Net radiative balance"
: net > 0
? "Net radiative heat loss"
: "Net radiative heat gain";
$("netDetails").textContent = isBalanced
? "P_net = εσA(T_s⁴ − T_∞⁴) · radiation is balanced"
: net > 0
? `P_net = P_emit − P_in · ${formatFlux(netFlux)} net to surroundings`
: `P_net = P_emit − P_in · ${formatFlux(Math.abs(netFlux))} net into the surface`;
const ratio = (counterRadiation / emitted) * 100;
const visibleRatio = Math.min(100, Math.max(0, ratio));
$("counterFill").style.width = `${visibleRatio}%`;
$("ratioDivider").style.left = `${visibleRatio}%`;
$("counterPercent").textContent = `${ratio.toFixed(0)}%`;
$("counterCaption").textContent = `${ratio.toFixed(0)}% incoming`;
const statusLabel = $("statusLabel");
statusLabel.classList.toggle("gain", net < 0);
statusLabel.classList.toggle("balanced", isBalanced);
statusLabel.textContent = isBalanced
? "Radiation balanced"
: net > 0
? "Net cooling"
: "Net warming";
const ringColor = isBalanced ? 0x74d8e8 : net > 0 ? 0xff8a47 : 0x5caeff;
statusRing.material.color.setHex(ringColor);
const emissionArrowLength = THREE.MathUtils.clamp(
0.7 + Math.sqrt(emitted / 20000) * 1.65,
0.7,
3.0
);
const incomingArrowLength = THREE.MathUtils.clamp(
0.7 + Math.sqrt(counterRadiation / 20000) * 1.65,
0.7,
3.0
);
emissionArrow.setLength(emissionArrowLength, 0.3, 0.17);
incomingArrow.setLength(incomingArrowLength, 0.32, 0.18);
$("surfaceLabelValue").textContent =
`T ${t} K · ε ${state.emissivity.toFixed(2)}`;
$("surfaceLabelArea").textContent =
`${state.area} m² opaque gray surface`;
}
function updateModel(rebuild = false) {
state.temperature = Number(controls.temperature.value);
state.area = Number(controls.area.value);
state.emissivity = Number(controls.emissivity.value);
state.environment = Number(controls.environment.value);
if (rebuild) buildVoxels();
updateThermalMaterials();
updateInterface();
}
Object.entries(controls).forEach(([name, input]) => {
input.addEventListener("input", () => {
updateModel(name === "area");
});
});
// Direct camera controls: orbit, wheel zoom, and pointer pinch zoom.
const pointers = new Map();
let pinchDistance = 0;
function currentPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
pinchDistance = currentPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.targetYaw -= dx * 0.006;
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch + dy * 0.005,
0.12,
1.38
);
} else if (pointers.size === 2) {
const nextDistance = currentPinchDistance();
cameraState.targetDistance = THREE.MathUtils.clamp(
cameraState.targetDistance - (nextDistance - pinchDistance) * 0.018,
5.2,
18
);
pinchDistance = nextDistance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? currentPinchDistance() : 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetDistance = THREE.MathUtils.clamp(
cameraState.targetDistance + event.deltaY * 0.008,
5.2,
18
);
},
{ passive: false }
);
function resetCamera() {
cameraState.targetYaw = 0.68;
cameraState.targetPitch = 0.57;
cameraState.targetDistance = window.innerWidth < 850 ? 12.3 : 10.5;
}
canvas.addEventListener("dblclick", resetCamera);
$("resetButton").addEventListener("click", () => {
controls.temperature.value = defaults.temperature;
controls.area.value = defaults.area;
controls.emissivity.value = defaults.emissivity;
controls.environment.value = defaults.environment;
updateModel(true);
resetCamera();
});
function positionCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 10);
cameraState.yaw +=
(cameraState.targetYaw - cameraState.yaw) * smoothing;
cameraState.pitch +=
(cameraState.targetPitch - cameraState.pitch) * smoothing;
cameraState.distance +=
(cameraState.targetDistance - cameraState.distance) * smoothing;
const horizontal =
cameraState.distance * Math.cos(cameraState.pitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraState.yaw),
cameraTarget.y + cameraState.distance * Math.sin(cameraState.pitch),
cameraTarget.z + horizontal * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
}
const projected = new THREE.Vector3();
function placeLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.18 &&
Math.abs(projected.y) < 1.18;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateRadiationFields(time) {
const temperatureFactor = THREE.MathUtils.clamp(
(state.temperature - 220) / 280,
0,
1
);
const visibleOutgoing = Math.floor(
7 + 65 * state.emissivity * Math.pow(temperatureFactor, 0.55)
);
outGeometry.setDrawRange(0, visibleOutgoing * 2);
for (let i = 0; i < visibleOutgoing; i++) {
const base = outgoingBases[i];
const distance = ((time * 0.24 + base.phase) % 1) * 4.1;
const offset = i * 6;
outPositions[offset] = base.x + distance * 0.035;
outPositions[offset + 1] = 0.45 + distance;
outPositions[offset + 2] = base.z + distance * 0.018;
outPositions[offset + 3] = base.x + (distance + 0.62) * 0.035;
outPositions[offset + 4] = 0.45 + distance + 0.62;
outPositions[offset + 5] = base.z + (distance + 0.62) * 0.018;
}
outGeometry.attributes.position.needsUpdate = true;
const visibleIncoming = 34;
inGeometry.setDrawRange(0, visibleIncoming * 2);
for (let i = 0; i < visibleIncoming; i++) {
const source = incomingSources[i];
const target = incomingTargets[i];
const phase = (i * 0.61803398875) % 1;
const progress = (time * 0.17 + phase) % 1;
const direction = target.clone().sub(source).normalize();
const position = source.clone().lerp(target, progress);
const offset = i * 6;
inPositions[offset] = position.x;
inPositions[offset + 1] = position.y;
inPositions[offset + 2] = position.z;
inPositions[offset + 3] = position.x + direction.x * 0.58;
inPositions[offset + 4] = position.y + direction.y * 0.58;
inPositions[offset + 5] = position.z + direction.z * 0.58;
}
inGeometry.attributes.position.needsUpdate = true;
}
function updateLabels() {
placeLabel($("surfaceLabel"), 0, 0.64, 0);
placeLabel($("emissionLabel"), 0, 3.45, 0);
placeLabel($("incomingLabel"), -2.35, 3.55, -1.2);
placeLabel($("statusLabel"), 0, 0.1, modelDepth * 0.5 + 0.75);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
updateModel(true);
resetCamera();
cameraState.yaw = cameraState.targetYaw;
cameraState.pitch = cameraState.targetPitch;
cameraState.distance = cameraState.targetDistance;
positionCamera(1);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
positionCamera(delta);
updateRadiationFields(time);
statusRing.material.opacity = 0.57 + Math.sin(time * 2.2) * 0.12;
voxelMaterials.forEach((material, index) => {
const t = THREE.MathUtils.clamp(
(state.temperature - 220) / 280,
0,
1
);
material.emissiveIntensity =
0.12 +
t * 0.38 +
Math.sin(time * 1.6 + index * 0.6) * 0.025;
});
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```