Prompt specification
Build or customize the Three.js 3D scene "Toy radiative-balance parameter 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: Toy radiative-balance parameter explorer
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/toy-radiative-balance-parameter-explorer-x1220
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the greenhouse effect and radiation balance. Provide solar input and effective outgoing-response controls in a labeled simplified energy model; graph its qualitative equilibrium response and clearly avoid claiming a full climate prediction. Low-poly.
Working Three.js Starter (toy-radiative-balance-parameter-explorer-x1220):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Greenhouse Effect — Illustrative Radiation Balance</title>
<style>
:root {
color-scheme: dark;
--bg: #06111f;
--panel: rgba(9, 24, 42, 0.84);
--panel-border: rgba(154, 202, 232, 0.2);
--text: #eaf5ff;
--muted: #9db5c9;
--cyan: #66d8ee;
--yellow: #ffd166;
--coral: #ff806f;
--green: #74dfad;
--amber: #ffc36b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 5;
top: 20px;
left: 22px;
max-width: min(530px, calc(100vw - 44px));
pointer-events: none;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.65);
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 3vw, 2.55rem);
line-height: 1.05;
letter-spacing: -0.035em;
}
.hero p {
max-width: 520px;
margin: 10px 0 0;
color: #c1d2df;
font-size: 0.92rem;
line-height: 1.45;
}
.panel {
position: fixed;
z-index: 10;
width: 330px;
padding: 17px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(20, 48, 73, 0.68), rgba(6, 19, 34, 0.9)),
var(--panel);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(16px) saturate(120%);
-webkit-backdrop-filter: blur(16px) saturate(120%);
}
#controls {
top: 132px;
left: 22px;
}
#analysis {
top: 132px;
right: 22px;
width: 390px;
}
.panel h2 {
margin: 0;
font-size: 1.03rem;
letter-spacing: -0.015em;
}
.panel-subtitle {
margin: 5px 0 16px;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.4;
}
.section-label {
display: flex;
align-items: center;
gap: 8px;
margin: 17px 0 12px;
color: #d8e9f6;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.section-label::after {
content: "";
height: 1px;
flex: 1;
background: rgba(255, 255, 255, 0.1);
}
.control {
margin: 0 0 17px;
}
.control-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 7px;
}
.control-heading label {
color: #dcecf7;
font-size: 0.82rem;
font-weight: 650;
}
output {
color: var(--cyan);
font-size: 0.79rem;
font-weight: 800;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.control-note {
margin: 6px 0 0;
color: #8fa9bc;
font-size: 0.69rem;
line-height: 1.35;
}
input[type="range"] {
--pct: 50%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
-webkit-appearance: none;
background:
linear-gradient(
90deg,
var(--range-color, var(--cyan)) 0 var(--pct),
rgba(255, 255, 255, 0.13) var(--pct) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 2px solid #eaf8ff;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: var(--range-color, var(--cyan));
box-shadow: 0 0 0 4px rgba(102, 216, 238, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #eaf8ff;
border-radius: 50%;
background: var(--range-color, var(--cyan));
box-shadow: 0 0 0 4px rgba(102, 216, 238, 0.12);
}
#solar {
--range-color: var(--yellow);
}
#trap {
--range-color: var(--cyan);
}
#response {
--range-color: var(--coral);
}
.equation {
margin-top: 16px;
padding: 12px 13px;
border: 1px solid rgba(102, 216, 238, 0.15);
border-radius: 12px;
background: rgba(4, 13, 24, 0.46);
color: #d9ecf8;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 0.73rem;
line-height: 1.65;
}
.equation strong {
color: white;
font-weight: 700;
}
.model-warning {
margin: 13px 0 0;
padding: 10px 11px;
border-left: 3px solid var(--amber);
border-radius: 7px;
background: rgba(255, 188, 92, 0.08);
color: #e8d4b4;
font-size: 0.69rem;
line-height: 1.45;
}
.results {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 8px;
margin-bottom: 12px;
}
.result {
min-width: 0;
padding: 10px 8px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
text-align: center;
}
.result span {
display: block;
color: var(--muted);
font-size: 0.61rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.result strong {
display: block;
margin-top: 4px;
color: white;
font-size: 0.91rem;
font-variant-numeric: tabular-nums;
}
.chart-wrap {
position: relative;
height: 245px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 13px;
background: rgba(2, 10, 20, 0.42);
}
#chart {
width: 100%;
height: 100%;
display: block;
}
.chart-caption {
margin: 8px 2px 0;
color: var(--muted);
font-size: 0.69rem;
line-height: 1.4;
}
.balance {
margin-top: 16px;
}
.balance-row {
display: grid;
grid-template-columns: 75px 1fr 61px;
gap: 8px;
align-items: center;
margin: 8px 0;
color: #c8d9e6;
font-size: 0.69rem;
}
.balance-row strong {
color: white;
text-align: right;
font-variant-numeric: tabular-nums;
}
.bar-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.bar {
height: 100%;
width: 50%;
border-radius: inherit;
transition: width 180ms ease;
}
#incomingBar {
background: linear-gradient(90deg, #d99e2e, var(--yellow));
}
#outgoingBar {
background: linear-gradient(90deg, #d85151, var(--coral));
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding: 9px 11px;
border: 1px solid rgba(116, 223, 173, 0.24);
border-radius: 10px;
background: rgba(116, 223, 173, 0.07);
color: #bdeed6;
font-size: 0.72rem;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px rgba(116, 223, 173, 0.8);
}
.disclaimer {
margin: 13px 0 0;
color: #9fb4c6;
font-size: 0.68rem;
line-height: 1.48;
}
.disclaimer strong {
color: var(--amber);
}
.legend {
position: fixed;
z-index: 6;
right: 24px;
bottom: 20px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: 390px;
pointer-events: none;
}
.legend-item,
.scene-label {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 999px;
background: rgba(6, 17, 31, 0.68);
color: #dcebf5;
font-size: 0.68rem;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.yellow {
color: var(--yellow);
}
.cyan {
color: var(--cyan);
}
.coral {
color: var(--coral);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
transform: translate(-50%, -50%);
opacity: 0;
white-space: nowrap;
}
.scene-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 11px currentColor;
}
.camera-help {
position: fixed;
z-index: 6;
left: 24px;
bottom: 20px;
color: rgba(211, 228, 241, 0.72);
font-size: 0.68rem;
pointer-events: none;
}
#resetView {
position: fixed;
z-index: 15;
left: 22px;
bottom: 52px;
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 999px;
background: rgba(7, 22, 39, 0.75);
color: #dcecf8;
font-size: 0.7rem;
cursor: pointer;
}
#resetView:hover {
border-color: rgba(102, 216, 238, 0.55);
color: white;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font-size: 0.86rem;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 950px) {
.hero {
max-width: 430px;
}
.hero p {
display: none;
}
#controls {
top: auto;
bottom: 16px;
width: 300px;
max-height: 48vh;
overflow-y: auto;
}
#analysis {
top: 108px;
right: 16px;
width: 340px;
}
.camera-help,
#resetView,
.legend {
display: none;
}
}
@media (max-width: 650px) {
.hero {
top: 14px;
left: 15px;
}
h1 {
font-size: 1.45rem;
}
#analysis {
top: 85px;
right: 10px;
width: calc(100vw - 20px);
max-height: 42vh;
overflow-y: auto;
}
#controls {
left: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 39vh;
}
.results {
grid-template-columns: 1fr 1fr 1fr;
}
.scene-label {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive low-poly planet showing incoming solar radiation, atmospheric greenhouse trapping, and outgoing longwave radiation"
></canvas>
<header class="hero">
<p class="eyebrow">Radiation balance teaching model</p>
<h1>The Greenhouse Effect, in Balance</h1>
<p>
Shortwave sunlight enters. Longwave heat leaves, with part of it trapped and
returned by the atmosphere. Move the controls to explore the simplified model.
</p>
</header>
<div id="labels" aria-hidden="true">
<div id="incomingLabel" class="scene-label yellow">Incoming shortwave</div>
<div id="atmosphereLabel" class="scene-label cyan">Atmospheric trapping</div>
<div id="outgoingLabel" class="scene-label coral">Outgoing longwave</div>
</div>
<aside id="controls" class="panel" aria-label="Model controls">
<h2>Simplified energy model</h2>
<p class="panel-subtitle">
A deliberately small model showing how temperature and radiative response
interact at equilibrium.
</p>
<div class="section-label">Solar input</div>
<div class="control">
<div class="control-heading">
<label for="solar">Absorbed solar input, S</label>
<output id="solarValue" for="solar">240 W/m²</output>
</div>
<input
id="solar"
type="range"
min="80"
max="400"
step="5"
value="240"
/>
<p class="control-note">
Shortwave energy reaching the top of the model atmosphere.
</p>
</div>
<div class="section-label">Effective outgoing response</div>
<div class="control">
<div class="control-heading">
<label for="trap">Atmospheric trapping, g</label>
<output id="trapValue" for="trap">25%</output>
</div>
<input
id="trap"
type="range"
min="0"
max="0.8"
step="0.01"
value="0.25"
/>
<p class="control-note">
Fractional reduction of reference outgoing radiation caused by the effective
greenhouse layer.
</p>
</div>
<div class="control">
<div class="control-heading">
<label for="response">Radiative response, λ</label>
<output id="responseValue" for="response">4.0 W/m²/°C</output>
</div>
<input
id="response"
type="range"
min="1"
max="12"
step="0.5"
value="4"
/>
<p class="control-note">
Change in effective outgoing longwave per 1 °C surface-temperature change.
</p>
</div>
<div class="equation" aria-live="polite">
<div><strong>Balance:</strong> S = O₀(1 − g) + λ(T − T₀)</div>
<div><strong>Equilibrium:</strong> T* = T₀ + [S − O₀(1 − g)] / λ</div>
<div id="equationValues" style="margin-top: 6px; color: #8fb3c8">
O₀ = 240 W/m² · T₀ = 15 °C
</div>
</div>
<p class="model-warning">
Parameters are illustrative rather than calibrated. Stronger trapping generally
requires a warmer surface to restore the same outgoing flux.
</p>
</aside>
<aside id="analysis" class="panel" aria-label="Equilibrium graph and radiation balance">
<h2>Qualitative equilibrium response</h2>
<p class="panel-subtitle">
The horizontal line is solar input. The sloped line is effective outgoing
longwave radiation. Their intersection is the model equilibrium.
</p>
<div class="results">
<div class="result">
<span>Solar in</span>
<strong id="incomingValue">240 W/m²</strong>
</div>
<div class="result">
<span>Outgoing</span>
<strong id="outgoingValue">240 W/m²</strong>
</div>
<div class="result">
<span>Equilibrium T*</span>
<strong id="equilibriumValue">30.0 °C</strong>
</div>
</div>
<div class="chart-wrap">
<canvas
id="chart"
role="img"
aria-label="Qualitative graph of incoming and outgoing radiation versus surface temperature"
></canvas>
</div>
<p class="chart-caption">
Moving the solar slider shifts the incoming line. Moving trapping or response
changes the outgoing line.
</p>
<div class="balance">
<div class="balance-row">
<span>Incoming</span>
<div class="bar-track"><div id="incomingBar" class="bar"></div></div>
<strong id="incomingBarValue">240</strong>
</div>
<div class="balance-row">
<span>Outgoing</span>
<div class="bar-track"><div id="outgoingBar" class="bar"></div></div>
<strong id="outgoingBarValue">240</strong>
</div>
</div>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">Balanced at the computed equilibrium temperature</span>
</div>
<p class="disclaimer">
<strong>Not a climate prediction.</strong> This schematic omits atmospheric
circulation, clouds, ocean heat uptake, ice albedo, water vapor, aerosols,
carbon-cycle feedbacks, and climate inertia. It is a qualitative teaching
model, not a forecast or a calibrated simulation.
</p>
</aside>
<button id="resetView" type="button">Reset camera</button>
<div class="camera-help">Drag to orbit · scroll to zoom · double-click to reset</div>
<div class="legend" aria-hidden="true">
<div class="legend-item yellow">
<span class="swatch"></span> Solar shortwave
</div>
<div class="legend-item cyan">
<span class="swatch"></span> Atmospheric layer
</div>
<div class="legend-item coral">
<span class="swatch"></span> Longwave radiation
</div>
</div>
<div id="loading">Building the low-poly scene…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and model state
// -------------------------------------------------------------------------
const $ = (id) => document.getElementById(id);
const canvas = $("scene");
const chartCanvas = $("chart");
const chartContext = chartCanvas.getContext("2d");
const OUTGOING_REFERENCE = 240; // W/m²
const TEMPERATURE_REFERENCE = 15; // °C
const model = {
solar: 240,
trapping: 0.25,
response: 4
};
const controls = {
solar: $("solar"),
trapping: $("trap"),
response: $("response")
};
function equilibriumTemperature() {
const effectiveReferenceOutgoing =
OUTGOING_REFERENCE * (1 - model.trapping);
return (
TEMPERATURE_REFERENCE +
(model.solar - effectiveReferenceOutgoing) / model.response
);
}
function effectiveOutgoing(temperature) {
return (
OUTGOING_REFERENCE * (1 - model.trapping) +
model.response * (temperature - TEMPERATURE_REFERENCE)
);
}
function setRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--pct", `${percent}%`);
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(0x06111f, 1);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
yaw: 0.62,
pitch: 0.22,
distance: 11.2
};
function updateCamera() {
const { yaw, pitch, distance } = cameraState;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
Math.sin(yaw) * horizontal,
Math.sin(pitch) * distance + 0.15,
Math.cos(yaw) * horizontal
);
camera.lookAt(0, 0.1, 0);
}
updateCamera();
const ambientLight = new THREE.HemisphereLight(0xbadfff, 0x102035, 1.45);
scene.add(ambientLight);
const sunlight = new THREE.DirectionalLight(0xffe0a1, 2.4);
sunlight.position.set(-6, 7, 5);
scene.add(sunlight);
const rimLight = new THREE.DirectionalLight(0x4bd8f2, 1.2);
rimLight.position.set(5, 2, -6);
scene.add(rimLight);
// Stars.
{
const positions = [];
const colors = [];
for (let i = 0; i < 280; i++) {
const radius = 15 + Math.random() * 12;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
const brightness = 0.48 + Math.random() * 0.45;
colors.push(
brightness * 0.75,
brightness * 0.88,
brightness
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
const stars = new THREE.Points(
geometry,
new THREE.PointsMaterial({
size: 0.055,
sizeAttenuation: true,
vertexColors: true,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
scene.add(stars);
}
// Stylized low-poly sun.
const sun = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.58, 0),
new THREE.MeshBasicMaterial({ color: 0xffd166 })
);
sun.position.set(-7.2, 1.3, -1.2);
scene.add(sun);
const sunGlow = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.78, 1),
new THREE.MeshBasicMaterial({
color: 0xffc04f,
transparent: true,
opacity: 0.09,
depthWrite: false
})
);
sunGlow.position.copy(sun.position);
scene.add(sunGlow);
// Planet.
const surfaceGroup = new THREE.Group();
scene.add(surfaceGroup);
const earthMaterial = new THREE.MeshStandardMaterial({
color: 0x2a7198,
roughness: 0.94,
metalness: 0,
flatShading: true
});
const earth = new THREE.Mesh(
new THREE.IcosahedronGeometry(2.05, 2),
earthMaterial
);
surfaceGroup.add(earth);
function sphericalPoint(longitude, latitude, radius = 2.105) {
const lon = THREE.MathUtils.degToRad(longitude);
const lat = THREE.MathUtils.degToRad(latitude);
return new THREE.Vector3(
radius * Math.cos(lat) * Math.cos(lon),
radius * Math.sin(lat),
radius * Math.cos(lat) * Math.sin(lon)
);
}
function addLandPolygon(polygon) {
const centerLongitude =
polygon.reduce((sum, point) => sum + point[0], 0) / polygon.length;
const centerLatitude =
polygon.reduce((sum, point) => sum + point[1], 0) / polygon.length;
const center = sphericalPoint(centerLongitude, centerLatitude, 2.115);
const vertices = [];
for (let i = 0; i < polygon.length; i++) {
const a = sphericalPoint(
polygon[i][0],
polygon[i][1],
2.115
);
const b = sphericalPoint(
polygon[(i + 1) % polygon.length][0],
polygon[(i + 1) % polygon.length][1],
2.115
);
vertices.push(
center.x, center.y, center.z,
a.x, a.y, a.z,
b.x, b.y, b.z
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.computeVertexNormals();
const land = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x7ca75d,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
surfaceGroup.add(land);
}
[
[
[-168, 66], [-135, 72], [-105, 58], [-82, 28],
[-108, 18], [-132, 42]
],
[
[-82, 12], [-52, 5], [-58, -20], [-72, -53],
[-81, -26]
],
[
[-11, 36], [0, 59], [30, 70], [51, 49], [29, 34]
],
[
[-18, 36], [16, 37], [42, 15], [29, -15],
[15, -35], [-5, -10]
],
[
[34, 35], [45, 66], [100, 73], [151, 58],
[131, 35], [89, 20], [64, 8]
],
[
[112, -12], [145, -10], [153, -38], [119, -43]
],
[
[-54, 82], [-24, 78], [-20, 61], [-47, 59]
]
].forEach(addLandPolygon);
// Atmospheric shell and triangular cage.
const atmosphereGeometry = new THREE.IcosahedronGeometry(2.38, 2);
const atmosphereMaterial = new THREE.MeshBasicMaterial({
color: 0x62d8ee,
transparent: true,
opacity: 0.09,
depthWrite: false,
side: THREE.DoubleSide
});
const atmosphere = new THREE.Mesh(
atmosphereGeometry,
atmosphereMaterial
);
scene.add(atmosphere);
const atmosphereEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(atmosphereGeometry, 15),
new THREE.LineBasicMaterial({
color: 0x75e5f5,
transparent: true,
opacity: 0.17,
depthWrite: false
})
);
scene.add(atmosphereEdges);
// A pair of thin orbital-looking rings helps read the layer as a shell.
const ringMaterial = new THREE.LineBasicMaterial({
color: 0x66d8ee,
transparent: true,
opacity: 0.2,
depthWrite: false
});
function makeRing(radius, tiltX, tiltZ) {
const points = [];
for (let i = 0; i < 48; i++) {
const angle = (i / 48) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0
)
);
}
const ring = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
ringMaterial
);
ring.rotation.x = tiltX;
ring.rotation.z = tiltZ;
scene.add(ring);
return ring;
}
const ringA = makeRing(2.42, 1.22, 0.12);
const ringB = makeRing(2.42, 0.28, 1.08);
// Incoming parallel solar beams.
const incomingDirection = new THREE.Vector3(1, -0.07, 0.015).normalize();
const incomingRays = [];
const incomingOrigins = [
[-6.25, 1.25, -0.75],
[-6.35, 0.52, 0.38],
[-6.25, -0.25, -0.48],
[-6.35, -0.96, 0.62]
];
for (const origin of incomingOrigins) {
const arrow = new THREE.ArrowHelper(
incomingDirection,
new THREE.Vector3(...origin),
4.15,
0xffd166,
0.3,
0.19
);
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.line.material.depthWrite = false;
arrow.cone.material.depthWrite = false;
scene.add(arrow);
incomingRays.push(arrow);
}
// Outgoing longwave beams and downwelling atmospheric radiation.
const outgoingDirections = [
new THREE.Vector3(0.18, 0.92, 0.35).normalize(),
new THREE.Vector3(-0.28, 0.84, 0.47).normalize(),
new THREE.Vector3(0.53, 0.74, 0.40).normalize(),
new THREE.Vector3(-0.48, 0.72, 0.49).normalize(),
new THREE.Vector3(0.10, 0.79, -0.60).normalize()
];
const outgoingRays = [];
for (const direction of outgoingDirections) {
const start = direction.clone().multiplyScalar(2.08);
const middle = direction.clone().multiplyScalar(2.53);
const end = direction.clone().multiplyScalar(4.65);
const absorbedArrow = new THREE.ArrowHelper(
direction,
start,
middle.distanceTo(start),
0xff806f,
0.16,
0.12
);
const escapeArrow = new THREE.ArrowHelper(
direction,
middle,
end.distanceTo(middle),
0xff806f,
0.30,
0.20
);
const tangent = new THREE.Vector3()
.crossVectors(direction, new THREE.Vector3(0, 1, 0))
.normalize()
.multiplyScalar(0.11);
const returnArrow = new THREE.ArrowHelper(
direction.clone().negate(),
middle.clone().add(tangent),
0.43,
0xff625c,
0.13,
0.11
);
for (const arrow of [absorbedArrow, escapeArrow, returnArrow]) {
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.line.material.depthWrite = false;
arrow.cone.material.depthWrite = false;
scene.add(arrow);
}
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.085, 0),
new THREE.MeshBasicMaterial({
color: 0xff806f,
transparent: true,
opacity: 0.85
})
);
marker.position.copy(middle);
scene.add(marker);
outgoingRays.push({
absorbedArrow,
escapeArrow,
returnArrow,
marker
});
}
// -------------------------------------------------------------------------
// DOM labels projected from 3D positions
// -------------------------------------------------------------------------
const projectedLabels = [
{
element: $("incomingLabel"),
position: new THREE.Vector3(-4.35, 1.25, 0.35)
},
{
element: $("atmosphereLabel"),
position: new THREE.Vector3(1.25, 2.78, 0.7)
},
{
element: $("outgoingLabel"),
position: new THREE.Vector3(0.4, 4.35, 0.1)
}
];
const projectionVector = new THREE.Vector3();
function updateProjectedLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of projectedLabels) {
projectionVector.copy(label.position).project(camera);
const visible =
projectionVector.z > -1 &&
projectionVector.z < 1;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projectionVector.x * 0.5 + 0.5) * width;
const y = (-projectionVector.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "0.92";
}
}
// -------------------------------------------------------------------------
// Qualitative graph
// -------------------------------------------------------------------------
function drawChart() {
const rect = chartCanvas.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.max(1, Math.round(rect.width));
const height = Math.max(1, Math.round(rect.height));
chartCanvas.width = Math.round(width * dpr);
chartCanvas.height = Math.round(height * dpr);
chartContext.setTransform(dpr, 0, 0, dpr, 0, 0);
chartContext.clearRect(0, 0, width, height);
const margin = {
left: 47,
right: 18,
top: 24,
bottom: 43
};
const plotWidth = width - margin.left - margin.right;
const plotHeight = height - margin.top - margin.bottom;
const fluxMaximum = 420;
const baseOutgoing =
OUTGOING_REFERENCE * (1 - model.trapping);
const temperatureAtZero = TEMPERATURE_REFERENCE +
(0 - baseOutgoing) / model.response;
const temperatureAtMaximum = TEMPERATURE_REFERENCE +
(fluxMaximum - baseOutgoing) / model.response;
const equilibrium = equilibriumTemperature();
let temperatureMinimum = Math.min(
-20,
Math.floor((temperatureAtZero - 10) / 10) * 10
);
let temperatureMaximum = Math.max(
80,
Math.ceil((temperatureAtMaximum + 10) / 10) * 10
);
temperatureMinimum = Math.min(
temperatureMinimum,
Math.floor((equilibrium - 15) / 10) * 10
);
temperatureMaximum = Math.max(
temperatureMaximum,
Math.ceil((equilibrium + 15) / 10) * 10
);
const x = (temperature) =>
margin.left +
((temperature - temperatureMinimum) /
(temperatureMaximum - temperatureMinimum)) *
plotWidth;
const y = (flux) =>
margin.top +
((fluxMaximum - flux) / fluxMaximum) * plotHeight;
// Plot background.
chartContext.fillStyle = "rgba(3, 11, 22, 0.72)";
chartContext.fillRect(
margin.left,
margin.top,
plotWidth,
plotHeight
);
// Grid and axes.
chartContext.lineWidth = 1;
for (let flux = 0; flux <= 400; flux += 100) {
const py = y(flux);
chartContext.strokeStyle = "rgba(171, 207, 230, 0.10)";
chartContext.beginPath();
chartContext.moveTo(margin.left, py);
chartContext.lineTo(margin.left + plotWidth, py);
chartContext.stroke();
chartContext.fillStyle = "#7993a8";
chartContext.font = "10px system-ui";
chartContext.textAlign = "right";
chartContext.textBaseline = "middle";
chartContext.fillText(String(flux), margin.left - 7, py);
}
for (let i = 0; i <= 4; i++) {
const temperature =
temperatureMinimum +
((temperatureMaximum - temperatureMinimum) * i) / 4;
const px = x(temperature);
chartContext.strokeStyle = "rgba(171, 207, 230, 0.08)";
chartContext.beginPath();
chartContext.moveTo(px, margin.top);
chartContext.lineTo(px, margin.top + plotHeight);
chartContext.stroke();
chartContext.fillStyle = "#7993a8";
chartContext.font = "10px system-ui";
chartContext.textAlign = "center";
chartContext.textBaseline = "top";
chartContext.fillText(
`${Math.round(temperature)}°`,
px,
margin.top + plotHeight + 8
);
}
// Shade the balance relation.
chartContext.save();
chartContext.beginPath();
chartContext.rect(
margin.left,
margin.top,
plotWidth,
plotHeight
);
chartContext.clip();
chartContext.beginPath();
chartContext.moveTo(x(temperatureMinimum), y(model.solar));
chartContext.lineTo(
x(temperatureMinimum),
y(effectiveOutgoing(temperatureMinimum))
);
chartContext.lineTo(
x(temperatureMaximum),
y(effectiveOutgoing(temperatureMaximum))
);
chartContext.lineTo(x(temperatureMaximum), y(model.solar));
chartContext.closePath();
chartContext.fillStyle = "rgba(102, 216, 238, 0.055)";
chartContext.fill();
// Outgoing relation.
chartContext.beginPath();
chartContext.moveTo(
x(temperatureMinimum),
y(effectiveOutgoing(temperatureMinimum))
);
chartContext.lineTo(
x(temperatureMaximum),
y(effectiveOutgoing(temperatureMaximum))
);
chartContext.strokeStyle = "#ff806f";
chartContext.lineWidth = 2.5;
chartContext.stroke();
// Incoming relation.
chartContext.beginPath();
chartContext.moveTo(margin.left, y(model.solar));
chartContext.lineTo(margin.left + plotWidth, y(model.solar));
chartContext.strokeStyle = "#ffd166";
chartContext.lineWidth = 2.5;
chartContext.stroke();
chartContext.restore();
// Axes.
chartContext.strokeStyle = "rgba(207, 230, 244, 0.38)";
chartContext.lineWidth = 1;
chartContext.beginPath();
chartContext.moveTo(margin.left, margin.top);
chartContext.lineTo(margin.left, margin.top + plotHeight);
chartContext.lineTo(margin.left + plotWidth, margin.top + plotHeight);
chartContext.stroke();
// Equilibrium point.
const equilibriumX = x(equilibrium);
const equilibriumY = y(model.solar);
chartContext.beginPath();
chartContext.arc(
equilibriumX,
equilibriumY,
6,
0,
Math.PI * 2
);
chartContext.fillStyle = "#ffffff";
chartContext.fill();
chartContext.strokeStyle = "#74dfad";
chartContext.lineWidth = 3;
chartContext.stroke();
// Dashed guide to temperature axis.
chartContext.setLineDash([3, 4]);
chartContext.strokeStyle = "rgba(116, 223, 173, 0.62)";
chartContext.lineWidth = 1;
chartContext.beginPath();
chartContext.moveTo(equilibriumX, equilibriumY);
chartContext.lineTo(equilibriumX, margin.top + plotHeight);
chartContext.stroke();
chartContext.setLineDash([]);
// Labels inside the graph.
chartContext.font = "600 10px system-ui";
chartContext.textAlign = "left";
chartContext.textBaseline = "bottom";
chartContext.fillStyle = "#ffd166";
chartContext.fillText(
`Incoming S = ${model.solar.toFixed(0)}`,
margin.left + 8,
y(model.solar) - 5
);
chartContext.fillStyle = "#ff806f";
chartContext.fillText(
"Effective outgoing O(T)",
margin.left + 8,
margin.top + 13
);
const labelOnLeft = equilibriumX > margin.left + plotWidth * 0.58;
chartContext.textAlign = labelOnLeft ? "right" : "left";
chartContext.fillStyle = "#dff8ed";
chartContext.fillText(
`T* = ${equilibrium.toFixed(1)}°C`,
equilibriumX + (labelOnLeft ? -9 : 9),
equilibriumY - 9
);
chartContext.fillStyle = "#8da8bb";
chartContext.font = "10px system-ui";
chartContext.textAlign = "center";
chartContext.textBaseline = "bottom";
chartContext.fillText(
"Surface temperature",
margin.left + plotWidth / 2,
height - 3
);
chartContext.save();
chartContext.translate(12, margin.top + plotHeight / 2);
chartContext.rotate(-Math.PI / 2);
chartContext.textAlign = "center";
chartContext.textBaseline = "middle";
chartContext.fillText("Radiative flux (W/m²)", 0, 0);
chartContext.restore();
}
// -------------------------------------------------------------------------
// UI and 3D synchronization
// -------------------------------------------------------------------------
const coldColor = new THREE.Color(0x477fc4);
const neutralColor = new THREE.Color(0x2b8b83);
const warmColor = new THREE.Color(0xe78a4d);
const visualTemperatureColor = new THREE.Color();
function updateScene() {
const equilibrium = equilibriumTemperature();
const outgoingAtEquilibrium = effectiveOutgoing(equilibrium);
// Surface color communicates temperature without claiming a calibrated scale.
if (equilibrium < TEMPERATURE_REFERENCE) {
visualTemperatureColor.copy(coldColor).lerp(
neutralColor,
THREE.MathUtils.clamp(
(equilibrium + 30) / 45,
0,
1
)
);
} else {
visualTemperatureColor.copy(neutralColor).lerp(
warmColor,
THREE.MathUtils.clamp(
(equilibrium - TEMPERATURE_REFERENCE) / 70,
0,
1
)
);
}
earthMaterial.color.copy(visualTemperatureColor);
atmosphereMaterial.opacity =
0.045 + model.trapping * 0.19;
atmosphereMaterial.color
.set(0x62d8ee)
.lerp(new THREE.Color(0xff9a7b), model.trapping * 0.34);
atmosphereEdges.material.opacity =
0.09 + model.trapping * 0.27;
ringMaterial.opacity = 0.12 + model.trapping * 0.24;
const incomingOpacity = 0.35 + (model.solar / 400) * 0.65;
const escapeOpacity = Math.max(
0.34,
0.95 - model.trapping * 0.62
);
const returnOpacity = model.trapping < 0.01
? 0
: 0.08 + model.trapping * 0.82;
for (const ray of incomingRays) {
ray.line.material.opacity = incomingOpacity;
ray.cone.material.opacity = incomingOpacity;
}
const outgoingLength =
1.72 + THREE.MathUtils.clamp(outgoingAtEquilibrium / 400, 0, 1) * 0.65;
for (const ray of outgoingRays) {
ray.absorbedArrow.line.material.opacity = 0.43;
ray.absorbedArrow.cone.material.opacity = 0.43;
ray.escapeArrow.setLength(
outgoingLength,
0.3,
0.2
);
ray.escapeArrow.line.material.opacity = escapeOpacity;
ray.escapeArrow.cone.material.opacity = escapeOpacity;
ray.returnArrow.visible = model.trapping > 0.01;
ray.returnArrow.line.material.opacity = returnOpacity;
ray.returnArrow.cone.material.opacity = returnOpacity;
ray.marker.material.opacity = 0.38 + returnOpacity * 0.5;
}
sunlight.intensity = 1.65 + (model.solar / 400) * 1.05;
}
function updateUI() {
const equilibrium = equilibriumTemperature();
const outgoing = effectiveOutgoing(equilibrium);
$("solarValue").textContent = `${model.solar.toFixed(0)} W/m²`;
$("trapValue").textContent = `${Math.round(model.trapping * 100)}%`;
$("responseValue").textContent =
`${model.response.toFixed(1)} W/m²/°C`;
$("incomingValue").textContent = `${model.solar.toFixed(0)} W/m²`;
$("outgoingValue").textContent = `${outgoing.toFixed(0)} W/m²`;
$("equilibriumValue").textContent = `${equilibrium.toFixed(1)} °C`;
$("incomingBarValue").textContent = model.solar.toFixed(0);
$("outgoingBarValue").textContent = outgoing.toFixed(0);
$("incomingBar").style.width =
`${THREE.MathUtils.clamp(model.solar / 400, 0, 1) * 100}%`;
$("outgoingBar").style.width =
`${THREE.MathUtils.clamp(outgoing / 400, 0, 1) * 100}%`;
$("equationValues").textContent =
`O₀ = 240 W/m² · T₀ = 15 °C · O(T₀) = ` +
`${(OUTGOING_REFERENCE * (1 - model.trapping)).toFixed(0)} W/m²`;
setRangeFill(controls.solar);
setRangeFill(controls.trapping);
setRangeFill(controls.response);
updateScene();
drawChart();
}
controls.solar.addEventListener("input", (event) => {
model.solar = Number(event.target.value);
updateUI();
});
controls.trapping.addEventListener("input", (event) => {
model.trapping = Number(event.target.value);
updateUI();
});
controls.response.addEventListener("input", (event) => {
model.response = Number(event.target.value);
updateUI();
});
// -------------------------------------------------------------------------
// Custom camera controls: no external examples/addons
// -------------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function resetCamera() {
cameraState.yaw = 0.62;
cameraState.pitch = 0.22;
cameraState.distance = 11.2;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.005,
-0.45,
1.05
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.008,
6.7,
17
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
$("resetView").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
drawChart();
});
if ("ResizeObserver" in window) {
new ResizeObserver(drawChart).observe(chartCanvas.parentElement);
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
updateUI();
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateProjectedLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```