Prompt specification
Build or customize the Three.js 3D scene "Heating at different pressures comparison" 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: Heating at different pressures comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/heating-at-different-pressures-comparison-x1974
Scene Description Prompt:
Create a standalone cutaway scene in one HTML file using Three.js from cdnjs. Trace two paths through a verified simplified phase map and show their different phase sequences; distinguish a path through state space from a particle trajectory.
Working Three.js Starter (heating-at-different-pressures-comparison-x1974):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CO₂ State Space vs. Particle Trajectory</title>
<style>
:root {
color-scheme: dark;
--bg: #07101a;
--panel: #0c1725;
--panel-2: #101f31;
--line: #24364b;
--text: #eaf1f8;
--muted: #91a5ba;
--a: #ffb454;
--b: #53e3c4;
--solid: #718fd0;
--liquid: #53d0c4;
--gas: #f3ad67;
}
* { 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; }
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
width: 100%;
height: 100%;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 42% 40%, #102137 0%, #07101a 67%);
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
padding: 5px 9px;
border: 1px solid rgba(255,255,255,.12);
border-radius: 6px;
background: rgba(5, 12, 22, .78);
color: #dce8f4;
font-size: 11px;
letter-spacing: .08em;
text-transform: uppercase;
box-shadow: 0 6px 24px rgba(0,0,0,.28);
backdrop-filter: blur(8px);
transition: opacity .12s linear;
}
.world-label strong {
color: white;
font-size: 12px;
letter-spacing: .03em;
}
.world-label.a { border-color: rgba(255,180,84,.55); }
.world-label.b { border-color: rgba(83,227,196,.55); }
.world-label.point { font-size: 10px; letter-spacing: .03em; }
#camera-hint {
position: absolute;
left: 18px;
bottom: 16px;
padding: 8px 11px;
border-radius: 7px;
background: rgba(6,13,23,.72);
border: 1px solid rgba(255,255,255,.09);
color: var(--muted);
font-size: 12px;
pointer-events: none;
backdrop-filter: blur(8px);
}
aside {
position: relative;
z-index: 2;
overflow-y: auto;
padding: 24px 22px 28px;
background:
linear-gradient(180deg, rgba(18,32,49,.98), rgba(9,19,31,.99));
border-left: 1px solid var(--line);
box-shadow: -16px 0 50px rgba(0,0,0,.22);
}
.eyebrow {
color: #75a7cf;
font-size: 11px;
font-weight: 700;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: 25px;
line-height: 1.12;
letter-spacing: -.025em;
}
.intro {
margin: 0 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section {
padding: 17px 0;
border-top: 1px solid var(--line);
}
.section h2 {
margin: 0 0 12px;
font-size: 12px;
letter-spacing: .1em;
text-transform: uppercase;
color: #b9c9d9;
}
.route-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 14px;
}
button {
cursor: pointer;
color: var(--text);
background: #132337;
border: 1px solid #2b4058;
border-radius: 7px;
padding: 9px 10px;
transition: .15s ease;
}
button:hover { border-color: #54718f; }
button:focus-visible { outline: 2px solid #8fc7ef; outline-offset: 2px; }
.route-tabs button[data-route="A"] {
border-left: 3px solid var(--a);
}
.route-tabs button[data-route="B"] {
border-left: 3px solid var(--b);
}
.route-tabs button.active {
background: #21364d;
border-color: #65809d;
}
.slider-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
}
input[type="range"] {
width: 100%;
accent-color: #8fc7ef;
}
.small-button {
padding: 7px 10px;
white-space: nowrap;
font-size: 12px;
}
.progress-label {
display: flex;
justify-content: space-between;
margin: 9px 0 7px;
color: var(--muted);
font-size: 11px;
}
.route-card {
margin-top: 10px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(13,27,42,.72);
}
.route-card.a { border-left: 3px solid var(--a); }
.route-card.b { border-left: 3px solid var(--b); }
.route-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 5px;
font-size: 13px;
font-weight: 700;
}
.route-description {
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.sequence {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
margin-top: 10px;
}
.phase {
padding: 4px 7px;
border-radius: 999px;
font-size: 10px;
font-weight: 700;
letter-spacing: .04em;
text-transform: uppercase;
border: 1px solid currentColor;
}
.phase.solid { color: var(--solid); }
.phase.liquid { color: var(--liquid); }
.phase.gas { color: var(--gas); }
.arrow { color: #60768b; font-size: 12px; }
.current {
margin-top: 9px;
color: var(--muted);
font-size: 11px;
}
.current strong { color: white; }
.distinction {
padding: 13px 14px;
border: 1px solid #35516b;
border-radius: 9px;
background: linear-gradient(135deg, rgba(36,67,94,.72), rgba(12,28,43,.75));
color: #c6d6e4;
font-size: 12px;
line-height: 1.55;
}
.distinction strong { color: white; }
.distinction p { margin: 8px 0 0; }
.check {
display: flex;
gap: 9px;
align-items: flex-start;
margin: 8px 0;
color: #bed0df;
font-size: 12px;
line-height: 1.42;
}
.check-mark {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 17px;
height: 17px;
border-radius: 50%;
color: #05130f;
background: #64dfb7;
font-size: 11px;
font-weight: 900;
}
details {
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
summary {
cursor: pointer;
color: #c8d7e5;
font-weight: 700;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
td, th {
padding: 6px 4px;
border-bottom: 1px solid #25374b;
text-align: left;
}
th { color: #e0eaf3; }
.legend {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 10px;
}
.legend-item {
padding: 7px;
border-radius: 6px;
text-align: center;
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
}
.legend-item.solid { color: #d9e4ff; background: rgba(76,101,155,.48); }
.legend-item.liquid { color: #c6fff6; background: rgba(24,112,116,.52); }
.legend-item.gas { color: #ffe0bf; background: rgba(112,66,42,.55); }
.source-note {
color: #778da2;
font-size: 10px;
line-height: 1.5;
}
#loading {
position: absolute;
inset: 0;
z-index: 4;
display: grid;
place-items: center;
background: #07101a;
color: #9db5c8;
font-size: 13px;
transition: opacity .3s ease;
}
@media (max-width: 900px) {
html, body { overflow: auto; }
#app {
grid-template-columns: 1fr;
grid-template-rows: 62vh auto;
height: auto;
min-height: 100%;
}
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
#camera-hint { font-size: 10px; }
}
</style>
</head>
<body>
<div id="app">
<section id="stage" aria-label="Interactive three-dimensional phase map and particle trajectories">
<div id="labels"></div>
<div id="camera-hint">Drag: orbit · Shift-drag: pan · Wheel: zoom</div>
<div id="loading">Building the verified simplified phase map…</div>
</section>
<aside>
<div class="eyebrow">Cutaway phase-map study</div>
<h1>State space is not a particle trajectory</h1>
<p class="intro">
Two control-parameter paths cross a simplified equilibrium map of carbon
dioxide. The cutaway chambers show what a separate representative particle
path looks like in physical space.
</p>
<div class="section">
<h2>Explore the routes</h2>
<div class="route-tabs">
<button type="button" data-route="A" class="active">Path A</button>
<button type="button" data-route="B">Path B</button>
</div>
<div class="progress-label">
<span id="selected-label">Path A progress</span>
<span id="progress-value">52%</span>
</div>
<div class="slider-row">
<input id="progress" type="range" min="0" max="1000" value="520" />
<button id="play" class="small-button" type="button">Pause</button>
</div>
<div class="route-card a">
<div class="route-title">
<span>Path A — isobaric heating</span>
<span style="color:var(--a)">P = 1.01325 bar</span>
</div>
<div class="route-description">
Heating at the normal sublimation pressure. CO₂ never has a stable
liquid interval along this route.
</div>
<div id="sequence-a" class="sequence"></div>
<div class="current">Current ensemble phase: <strong id="now-a">gas</strong></div>
</div>
<div class="route-card b">
<div class="route-title">
<span>Path B — compress, then heat</span>
<span style="color:var(--b)">P = 50 bar</span>
</div>
<div class="route-description">
First compress the solid at 185 K, then heat at 50 bar. The route
crosses the solid–liquid and liquid–gas boundaries in sequence.
</div>
<div id="sequence-b" class="sequence"></div>
<div class="current">Current ensemble phase: <strong id="now-b">liquid</strong></div>
</div>
</div>
<div class="section">
<h2>Map legend</h2>
<div class="legend">
<div class="legend-item solid">Solid</div>
<div class="legend-item liquid">Liquid</div>
<div class="legend-item gas">Gas</div>
</div>
</div>
<div class="section">
<h2>The essential distinction</h2>
<div class="distinction">
<strong>Colored curves on the slab are paths through state space</strong>
<p>
Their coordinates are thermodynamic controls: temperature and pressure.
They describe the equilibrium phase of the ensemble, not the motion
of a molecule.
</p>
<p>
<strong>Jagged trails in the chambers are particle trajectories</strong>
<p>
Their coordinates are physical positions, r(t) = (x, y, z). One
molecule alone does not define a thermodynamic phase; phase is an
ensemble property.
</p>
</div>
</div>
</div>
<div class="section">
<h2>Verification</h2>
<div id="checks"></div>
</div>
<div class="section">
<details>
<summary>Reference data and simplification</summary>
<p>
CO₂ reference values used: triple point 216.58 K, 5.18 bar; critical
point 304.13 K, 73.8 bar; normal sublimation point 194.695 K at
1.01325 bar. Vapor-pressure anchors are interpolated with a
shape-preserving cubic spline.
</p>
<p>
The solid–liquid boundary is a deliberately simple positive-slope
guide, not a high-pressure CO₂ equation of state. Read that boundary
as a schematic transition ordering, while the triple point, critical
point, sublimation curve, and vapor-pressure curve provide the
quantitative checks.
</p>
<table>
<tr><th>Quantity</th><th>Value</th></tr>
<tr><td>Triple point</td><td>216.58 K / 5.18 bar</td></tr>
<tr><td>Critical point</td><td>304.13 K / 73.8 bar</td></tr>
<tr><td>Normal sublimation</td><td>194.695 K / 1.01325 bar</td></tr>
<tr><td>Sublimation latent heat</td><td>26.05 kJ/mol</td></tr>
<tr><td>Fusion guide</td><td>12 bar/K, schematic</td></tr>
</table>
<p class="source-note">
Reference values are consistent with published NIST/CRC-style CO₂
data. The scene performs its consistency checks locally; it does not
make a live data request.
</p>
</details>
</div>
<div class="section">
<button id="reset-camera" type="button" style="width:100%">Reset camera</button>
</div>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scientific constants and simplified CO2 phase-map functions
// ---------------------------------------------------------------------
const DATA = Object.freeze({
T_MIN: 120,
T_MAX: 330,
LOGP_MIN: -1.2,
LOGP_MAX: 3.2,
T_TRIPLE: 216.58,
P_TRIPLE: 5.18,
T_CRITICAL: 304.13,
P_CRITICAL: 73.8,
T_NORMAL_SUB: 194.695,
P_NORMAL: 1.01325,
L_SUB: 26050, // J/mol
R: 8.314462618, // J/(mol K)
FUSION_SLOPE: 12 // bar/K; intentionally schematic
});
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const lerp = (a, b, t) => a + (b - a) * t;
// Clausius–Clapeyron sublimation line anchored at the triple point.
function pSub(T) {
return DATA.P_TRIPLE * Math.exp(
-DATA.L_SUB / DATA.R *
(1 / T - 1 / DATA.T_TRIPLE)
);
}
function normalSublimationTemperature(P = DATA.P_NORMAL) {
return 1 / (
1 / DATA.T_TRIPLE -
(DATA.R / DATA.L_SUB) * Math.log(P / DATA.P_TRIPLE)
);
}
// Shape-preserving monotone cubic interpolation of ln(P) versus T.
function monotoneInterpolator(xs, ys) {
const n = xs.length;
const h = new Array(n - 1);
const delta = new Array(n - 1);
const m = new Array(n);
for (let i = 0; i < n - 1; i++) {
h[i] = xs[i + 1] - xs[i];
delta[i] = (ys[i + 1] - ys[i]) / h[i];
}
m[0] = delta[0];
m[n - 1] = delta[n - 1];
for (let i = 1; i < n - 1; i++) {
if (delta[i - 1] * delta[i] <= 0) {
m[i] = 0;
} else {
const w1 = 2 * h[i] + h[i - 1];
const w2 = h[i] + 2 * h[i - 1];
m[i] = (w1 + w2) / (w1 / delta[i - 1] + w2 / delta[i]);
}
}
return function evaluate(x) {
if (x <= xs[0]) return ys[0];
if (x >= xs[n - 1]) return ys[n - 1];
let i = 0;
while (i < n - 2 && x > xs[i + 1]) i++;
const t = (x - xs[i]) / h[i];
const t2 = t * t;
const t3 = t2 * t;
return (
(2*t3 - 3*t2 + 1) * ys[i] +
(t3 - 2*t2 + t) * h[i] * m[i] +
(-2*t3 + 3*t2) * ys[i + 1] +
(t3 - t2) * h[i] * m[i + 1]
);
};
}
const vaporLogInterpolator = monotoneInterpolator(
[216.58, 230, 250, 273.15, 280, 290, 300, 304.13],
[5.18, 11.05, 17.85, 34.85, 42.85, 54.25, 67.35, 73.8]
.map(Math.log)
);
function pVap(T) {
return Math.exp(vaporLogInterpolator(T));
}
function pFusion(T) {
return DATA.P_TRIPLE +
DATA.FUSION_SLOPE * (T - DATA.T_TRIPLE);
}
// Equilibrium phase classifier for the simplified map.
function phaseAt(T, P) {
if (T < DATA.T_TRIPLE) {
// Below the triple-point temperature, compression crosses directly
// between the gas and solid fields; there is no liquid field.
return P < pSub(T) ? "gas" : "solid";
}
if (T >= DATA.T_CRITICAL) {
return "gas";
}
if (P < pVap(T)) return "gas";
// T_m(P) is the inverse of the schematic fusion line.
const meltingTemperature =
DATA.T_TRIPLE +
(P - DATA.P_TRIPLE) / DATA.FUSION_SLOPE;
return T < meltingTemperature ? "solid" : "liquid";
}
// ---------------------------------------------------------------------
// Scene, renderer, camera, and direct camera controls
// ---------------------------------------------------------------------
const stage = document.querySelector("#stage");
const labelsRoot = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07101a);
scene.fog = new THREE.FogExp2(0x07101a, 0.025);
const camera = new THREE.PerspectiveCamera(
39,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xc8e4ff, 0x17202d, 1.5));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.3);
keyLight.position.set(-4, 8, 12);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58a9ff, 1.6);
rimLight.position.set(8, 1, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa85c, 25, 14, 2);
warmLight.position.set(5, -2, 6);
scene.add(warmLight);
const cameraState = {
target: new THREE.Vector3(0.15, 0.05, 0.1),
radius: 18.2,
theta: 0.34,
phi: 1.08
};
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.target.set(0.15, 0.05, 0.1);
cameraState.radius = 18.2;
cameraState.theta = 0.34;
cameraState.phi = 1.08;
updateCamera();
}
let pointerDown = false;
let panning = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
panning = event.shiftKey || event.button === 2;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const panScale = cameraState.radius * 0.0014;
cameraState.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(
cameraState.phi - dy * 0.005,
0.28,
1.48
);
}
updateCamera();
});
function endPointer(event) {
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", e => e.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
28
);
updateCamera();
}, { passive: false });
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(stage);
resize();
resetCamera();
// ---------------------------------------------------------------------
// World-space mapping and texture generation
// ---------------------------------------------------------------------
const MAP = {
width: 8,
height: 5.4,
centerX: -1.7,
centerY: 0,
plateZ: 0,
surfaceZ: 0.275,
routeZ: 0.39
};
function mapPosition(T, P, z = MAP.surfaceZ) {
const logP = Math.log10(P);
return new THREE.Vector3(
MAP.centerX +
(T - DATA.T_MIN) /
(DATA.T_MAX - DATA.T_MIN) * MAP.width -
MAP.width / 2,
MAP.centerY +
(logP - DATA.LOGP_MIN) /
(DATA.LOGP_MAX - DATA.LOGP_MIN) * MAP.height -
MAP.height / 2,
z
);
}
function createPhaseTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1000;
canvas.height = 675;
const ctx = canvas.getContext("2d");
const cw = canvas.width;
const ch = canvas.height;
const colors = {
solid: [42, 62, 103],
liquid: [20, 100, 106],
gas: [104, 64, 43]
};
const image = ctx.createImageData(cw, ch);
for (let py = 0; py < ch; py++) {
const logP =
DATA.LOGP_MAX -
py / (ch - 1) *
(DATA.LOGP_MAX - DATA.LOGP_MIN);
const P = Math.pow(10, logP);
for (let px = 0; px < cw; px++) {
const T =
DATA.T_MIN +
px / (cw - 1) *
(DATA.T_MAX - DATA.T_MIN);
const phase = phaseAt(T, P);
const c = colors[phase];
const index = (py * cw + px) * 4;
// A very small deterministic modulation gives the plate texture depth.
const modulation = ((px * 13 + py * 7) % 9) - 4;
image.data[index] = c[0] + modulation;
image.data[index + 1] = c[1] + modulation;
image.data[index + 2] = c[2] + modulation;
image.data[index + 3] = 255;
}
}
ctx.putImageData(image, 0, 0);
const canvasX = T =>
(T - DATA.T_MIN) / (DATA.T_MAX - DATA.T_MIN) * cw;
const canvasY = (T, P) => {
const logP = Math.log10(P);
return (
(1 -
(logP - DATA.LOGP_MIN) /
(DATA.LOGP_MAX - DATA.LOGP_MIN)) * ch
);
};
// Grid.
ctx.save();
ctx.strokeStyle = "rgba(215,235,255,.095)";
ctx.lineWidth = 1;
for (let T = 125; T <= 325; T += 25) {
const x = canvasX(T);
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, ch);
ctx.stroke();
}
for (let logP = -1; logP <= 3; logP += 0.5) {
const y = canvasY(DATA.T_MIN, Math.pow(10, logP));
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(cw, y);
ctx.stroke();
}
ctx.restore();
function strokeCurve(T0, T1, pressureFunction, color, lineWidth) {
ctx.beginPath();
let started = false;
for (let i = 0; i <= 500; i++) {
const T = lerp(T0, T1, i / 500);
const P = pressureFunction(T);
if (
P < Math.pow(10, DATA.LOGP_MIN) ||
P > Math.pow(10, DATA.LOGP_MAX)
) {
started = false;
continue;
}
const x = canvasX(T);
const y = canvasY(T, P);
if (!started) {
ctx.moveTo(x, y);
started = true;
} else {
ctx.lineTo(x, y);
}
}
ctx.strokeStyle = color;
ctx.lineWidth = lineWidth;
ctx.stroke();
}
// Equilibrium boundaries.
strokeCurve(
DATA.T_MIN, DATA.T_TRIPLE,
pSub,
"rgba(221,235,255,.88)",
3
);
strokeCurve(
DATA.T_TRIPLE, DATA.T_CRITICAL,
pVap,
"rgba(255,213,159,.92)",
3.5
);
strokeCurve(
DATA.T_TRIPLE, DATA.T_MAX,
pFusion,
"rgba(178,222,255,.85)",
3
);
// Critical point.
const criticalX = canvasX(DATA.T_CRITICAL);
const criticalY = canvasY(DATA.T_CRITICAL, DATA.P_CRITICAL);
ctx.fillStyle = "#fff3df";
ctx.beginPath();
ctx.arc(criticalX, criticalY, 5, 0, Math.PI * 2);
ctx.fill();
// Triple point.
const tripleX = canvasX(DATA.T_TRIPLE);
const tripleY = canvasY(DATA.T_TRIPLE, DATA.P_TRIPLE);
ctx.fillStyle = "#ffffff";
ctx.beginPath();
ctx.arc(tripleX, tripleY, 5, 0, Math.PI * 2);
ctx.fill();
// Normal sublimation point.
const normalX = canvasX(DATA.T_NORMAL_SUB);
const normalY = canvasY(DATA.T_NORMAL_SUB, DATA.P_NORMAL);
ctx.strokeStyle = "#f4d7a8";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(normalX, normalY, 4.5, 0, Math.PI * 2);
ctx.stroke();
// Region labels.
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 27px system-ui";
ctx.fillStyle = "rgba(224,235,255,.72)";
ctx.fillText("SOLID", canvasX(164), canvasY(164, 100));
ctx.fillStyle = "rgba(190,255,244,.78)";
ctx.fillText("LIQUID", canvasX(261), canvasY(261, 30));
ctx.fillStyle = "rgba(255,222,186,.78)";
ctx.fillText("GAS", canvasX(248), canvasY(248, 2));
ctx.font = "700 18px system-ui";
ctx.fillStyle = "rgba(255,226,190,.65)";
ctx.fillText("GAS / ONE-PHASE FLUID", canvasX(305), canvasY(305, 3));
// Axis labels.
ctx.font = "700 14px system-ui";
ctx.fillStyle = "rgba(220,233,245,.78)";
ctx.textAlign = "center";
for (let T = 150; T <= 300; T += 50) {
ctx.fillText(`${T} K`, canvasX(T), ch - 23);
}
ctx.textAlign = "right";
for (let logP = -1; logP <= 3; logP += 1) {
ctx.fillText(
`10^${logP}`,
cw - 16,
canvasY(DATA.T_MIN, Math.pow(10, logP)) - 10
);
}
ctx.save();
ctx.translate(25, ch / 2);
ctx.rotate(-Math.PI / 2);
ctx.textAlign = "center";
ctx.font = "700 15px system-ui";
ctx.fillText("PRESSURE P / bar (log scale)", 0, 0);
ctx.restore();
ctx.textAlign = "center";
ctx.font = "700 15px system-ui";
ctx.fillText(
"TEMPERATURE T / K",
cw / 2,
ch - 3
);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
texture.needsUpdate = true;
return texture;
}
// ---------------------------------------------------------------------
// Cutaway state-space slab
// ---------------------------------------------------------------------
const W = MAP.width;
const H = MAP.height;
const notchLocalX = 1.44;
const notchHeight = H * 0.31;
const notchTopY = -H / 2 + notchHeight;
const plateShape = new THREE.Shape();
plateShape.moveTo(-W / 2, -H / 2);
plateShape.lineTo(-W / 2, H / 2);
plateShape.lineTo(W / 2, H / 2);
plateShape.lineTo(W / 2, notchTopY);
plateShape.lineTo(notchLocalX, notchTopY);
plateShape.lineTo(notchLocalX, -H / 2);
plateShape.closePath();
const plateGeometry = new THREE.ExtrudeGeometry(plateShape, {
depth: 0.22,
bevelEnabled: true,
bevelSegments: 2,
steps: 1,
bevelSize: 0.035,
bevelThickness: 0.035
});
const plate = new THREE.Mesh(
plateGeometry,
new THREE.MeshStandardMaterial({
color: 0x17263a,
metalness: 0.18,
roughness: 0.68
})
);
plate.position.set(MAP.centerX, MAP.centerY, 0);
scene.add(plate);
const phaseTexture = createPhaseTexture();
function addMapSegment(x0, x1, y0, y1) {
const width = x1 - x0;
const height = y1 - y0;
const geometry = new THREE.PlaneGeometry(width, height);
const positions = geometry.attributes.position;
const uv = geometry.attributes.uv;
for (let i = 0; i < positions.count; i++) {
const localX = positions.getX(i);
const localY = positions.getY(i);
uv.setXY(
i,
(localX + W / 2) / W,
(localY + H / 2) / H
);
}
uv.needsUpdate = true;
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
map: phaseTexture,
transparent: true,
opacity: 0.98
})
);
mesh.position.set(
MAP.centerX + (x0 + x1) / 2,
MAP.centerY + (y0 + y1) / 2,
MAP.surfaceZ
);
scene.add(mesh);
}
addMapSegment(
-W / 2,
notchLocalX,
-H / 2,
H / 2
);
addMapSegment(
notchLocalX,
W / 2,
notchTopY,
H / 2
);
// A thin bright edge emphasizes the actual cutaway.
const cutEdgeGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
MAP.centerX + notchLocalX,
MAP.centerY - H / 2,
0.27
),
new THREE.Vector3(
MAP.centerX + notchLocalX,
MAP.centerY + notchTopY,
0.27
),
new THREE.Vector3(
MAP.centerX + W / 2,
MAP.centerY + notchTopY,
0.27
)
]);
const cutEdge = new THREE.Line(
cutEdgeGeometry,
new THREE.LineBasicMaterial({
color: 0x93b6d0,
transparent: true,
opacity: 0.75
})
);
scene.add(cutEdge);
function addElevatedBoundary(T0, T1, pressureFunction, color) {
const points = [];
for (let i = 0; i <= 300; i++) {
const T = lerp(T0, T1, i / 300);
const P = pressureFunction(T);
if (
P >= Math.pow(10, DATA.LOGP_MIN) &&
P <= Math.pow(10, DATA.LOGP_MAX)
) {
points.push(mapPosition(T, P, 0.305));
}
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.66
})
);
scene.add(line);
}
addElevatedBoundary(
DATA.T_MIN, DATA.T_TRIPLE, pSub, 0xc8daf2
);
addElevatedBoundary(
DATA.T_TRIPLE, DATA.T_CRITICAL, pVap, 0xffd09d
);
addElevatedBoundary(
DATA.T_TRIPLE, DATA.T_MAX, pFusion, 0x8ecbff
);
function addReferencePoint(T, P, color, radius = 0.065) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(radius, 16, 12),
new THREE.MeshBasicMaterial({ color })
);
marker.position.copy(mapPosition(T, P, 0.34));
scene.add(marker);
}
addReferencePoint(DATA.T_TRIPLE, DATA.P_TRIPLE, 0xffffff);
addReferencePoint(DATA.T_CRITICAL, DATA.P_CRITICAL, 0xffe1b7);
addReferencePoint(DATA.T_NORMAL_SUB, DATA.P_NORMAL, 0xffd39d, 0.055);
// ---------------------------------------------------------------------
// Routes through state space
// ---------------------------------------------------------------------
const routes = {
A: {
id: "A",
color: 0xffb454,
points: [
[170, DATA.P_NORMAL],
[300, DATA.P_NORMAL]
],
progress: 0.52
},
B: {
id: "B",
color: 0x53e3c4,
points: [
[185, DATA.P_NORMAL],
[185, 50],
[300, 50]
],
progress: 0.82
}
};
for (const route of Object.values(routes)) {
route.segments = [];
route.totalLength = 0;
for (let i = 0; i < route.points.length - 1; i++) {
const p0 = route.points[i];
const p1 = route.points[i + 1];
const a = mapPosition(p0[0], p0[1], MAP.routeZ);
const b = mapPosition(p1[0], p1[1], MAP.routeZ);
const length = a.distanceTo(b);
route.segments.push({
p0, p1, a, b, length,
startDistance: route.totalLength
});
route.totalLength += length;
}
route.materials = [];
route.arrows = [];
}
function cylinderBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius, radius, length, 14, 1, false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
scene.add(mesh);
return mesh;
}
function addArrow(a, b, fraction, material) {
const point = a.clone().lerp(b, fraction);
const direction = b.clone().sub(a).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.28, 16),
material
);
arrow.position.copy(point);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
scene.add(arrow);
return arrow;
}
for (const route of Object.values(routes)) {
const lineMaterial = new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.95,
depthTest: true
});
const arrowMaterial = new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 1
});
route.materials.push(lineMaterial, arrowMaterial);
for (const segment of route.segments) {
cylinderBetween(
segment.a,
segment.b,
0.035,
lineMaterial
);
route.arrows.push(
addArrow(segment.a, segment.b, 0.62, arrowMaterial)
);
}
const markerMaterial = new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 1
});
route.marker = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 20, 16),
markerMaterial
);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.025, 10, 28),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.85
})
);
route.marker.add(ring);
route.markerRing = ring;
scene.add(route.marker);
}
function sampleRoute(route, u) {
u = clamp(u, 0, 0.999999);
const distance = u * route.totalLength;
const segment = route.segments.find(
s => distance <= s.startDistance + s.length
) || route.segments[route.segments.length - 1];
const local = clamp(
(distance - segment.startDistance) / segment.length,
0,
1
);
return {
T: lerp(segment.p0[0], segment.p1[0], local),
P: lerp(segment.p0[1], segment.p1[1], local),
position: segment.a.clone().lerp(segment.b, local)
};
}
function sequenceForRoute(route) {
const sequence = [];
for (let i = 0; i <= 1200; i++) {
const sample = sampleRoute(route, i / 1200);
const phase = phaseAt(sample.T, sample.P);
if (sequence[sequence.length - 1] !== phase) {
sequence.push(phase);
}
}
return sequence;
}
for (const route of Object.values(routes)) {
route.sequence = sequenceForRoute(route);
}
// ---------------------------------------------------------------------
// Real-space cutaway chambers and representative particle trajectories
// ---------------------------------------------------------------------
const chambers = {};
function makeChamber(routeId, y) {
const route = routes[routeId];
const group = new THREE.Group();
group.position.set(4.55, y, 0);
scene.add(group);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x17283a,
metalness: 0.12,
roughness: 0.8,
transparent: true,
opacity: 0.7
});
const back = new THREE.Mesh(
new THREE.BoxGeometry(2.65, 1.62, 0.055),
wallMaterial
);
back.position.z = -0.56;
group.add(back);
const floor = new THREE.Mesh(
new THREE.BoxGeometry(2.65, 0.055, 1.16),
wallMaterial
);
floor.position.set(0, -0.81, 0);
group.add(floor);
for (const side of [-1, 1]) {
const wall = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 1.62, 1.16),
wallMaterial
);
wall.position.set(side * 1.325, 0, 0);
group.add(wall);
}
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(2.65, 1.62, 1.16)
),
new THREE.LineBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.34
})
);
group.add(edges);
// Small physical-space coordinate triad.
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.12, -0.66, -0.35),
new THREE.Vector3(-0.78, -0.66, -0.35),
new THREE.Vector3(-1.12, -0.66, -0.35),
new THREE.Vector3(-1.12, -0.42, -0.35),
new THREE.Vector3(-1.12, -0.66, -0.35),
new THREE.Vector3(-1.12, -0.66, -0.03)
]);
group.add(new THREE.LineSegments(
axisGeometry,
new THREE.LineBasicMaterial({
color: 0x91a9bd,
transparent: true,
opacity: 0.8
})
));
const particleGeometry = new THREE.SphereGeometry(0.045, 10, 8);
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xbcd0e0,
transparent: true,
opacity: 0.58
});
const particles = [];
for (let i = 0; i < 13; i++) {
const mesh = new THREE.Mesh(
particleGeometry,
particleMaterial
);
const anchor = new THREE.Vector3(
lerp(-1.05, 1.05, (i % 5) / 4),
lerp(-0.57, 0.55, Math.floor(i / 5) / 2),
lerp(-0.38, 0.35, ((i * 7) % 5) / 4)
);
mesh.position.copy(anchor);
group.add(mesh);
particles.push({
mesh,
anchor,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 0.3,
(Math.random() - 0.5) * 0.3,
(Math.random() - 0.5) * 0.2
)
});
}
const tracer = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 18, 14),
new THREE.MeshBasicMaterial({ color: route.color })
);
const tracerHalo = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 16, 12),
new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.2,
depthWrite: false
})
);
tracer.add(tracerHalo);
group.add(tracer);
const MAX_TRAIL = 110;
const trailArray = new Float32Array(MAX_TRAIL * 3);
const trailGeometry = new THREE.BufferGeometry();
trailGeometry.setAttribute(
"position",
new THREE.BufferAttribute(trailArray, 3)
);
trailGeometry.setDrawRange(0, 0);
const trail = new THREE.Line(
trailGeometry,
new THREE.LineBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.95
})
);
group.add(trail);
return {
group,
particles,
tracer,
trail,
trailArray,
trailGeometry,
maxTrail: MAX_TRAIL,
trailPoints: [],
trailTimer: 0,
phase: "solid"
};
}
chambers.A = makeChamber("A", 1.43);
chambers.B = makeChamber("B", -1.43);
function confineParticle(particle, dt) {
const p = particle.mesh.position;
const v = particle.velocity;
const bounds = {
x: 1.17,
y: 0.67,
z: 0.48
};
if (Math.abs(p.x) > bounds.x) {
p.x = Math.sign(p.x) * bounds.x;
v.x *= -0.82;
}
if (Math.abs(p.y) > bounds.y) {
p.y = Math.sign(p.y) * bounds.y;
v.y *= -0.82;
}
if (Math.abs(p.z) > bounds.z) {
p.z = Math.sign(p.z) * bounds.z;
v.z *= -0.82;
}
}
function updateChamber(chamber, phase, dt, elapsed) {
chamber.phase = phase;
for (let i = 0; i < chamber.particles.length; i++) {
const particle = chamber.particles[i];
const p = particle.mesh.position;
const v = particle.velocity;
if (phase === "solid") {
const phaseTime = elapsed * 1.4 + i * 0.8;
p.set(
particle.anchor.x + Math.sin(phaseTime) * 0.012,
particle.anchor.y + Math.cos(phaseTime * 1.3) * 0.012,
particle.anchor.z + Math.sin(phaseTime * 0.7) * 0.008
);
v.set(0, 0, 0);
} else if (phase === "liquid") {
v.x += (Math.random() - 0.5) * 2.0 * dt;
v.y += (Math.random() - 0.5) * 2.0 * dt;
v.z += (Math.random() - 0.5) * 1.3 * dt;
v.multiplyScalar(Math.exp(-1.8 * dt));
p.addScaledVector(v, dt);
} else {
v.x += (Math.random() - 0.5) * 8.0 * dt;
v.y += (Math.random() - 0.5) * 8.0 * dt;
v.z += (Math.random() - 0.5) * 5.0 * dt;
v.multiplyScalar(Math.exp(-0.45 * dt));
const speed = v.length();
if (speed > 2.4) v.multiplyScalar(2.4 / speed);
p.addScaledVector(v, dt);
}
confineParticle(particle, dt);
}
// The highlighted particle is a representative, not a phase definition.
const tracer = chamber.tracer;
const p = tracer.position;
const v = chamber.tracerVelocity ||
(chamber.tracerVelocity = new THREE.Vector3());
if (phase === "solid") {
const anchor = chamber.particles[0].anchor;
v.x += (anchor.x - p.x) * 5.0 * dt;
v.y += (anchor.y - p.y) * 5.0 * dt;
v.z += (anchor.z - p.z) * 5.0 * dt;
v.multiplyScalar(Math.exp(-4.5 * dt));
} else if (phase === "liquid") {
v.x += (Math.random() - 0.5) * 3.2 * dt;
v.y += (Math.random() - 0.5) * 3.2 * dt;
v.z += (Math.random() - 0.5) * 2.2 * dt;
v.multiplyScalar(Math.exp(-1.65 * dt));
} else {
v.x += (Math.random() - 0.5) * 12.0 * dt;
v.y += (Math.random() - 0.5) * 12.0 * dt;
v.z += (Math.random() - 0.5) * 8.0 * dt;
v.multiplyScalar(Math.exp(-0.4 * dt));
const speed = v.length();
if (speed > 2.9) v.multiplyScalar(2.9 / speed);
}
p.addScaledVector(v, dt);
const tracerBounds = {
x: 1.18,
y: 0.68,
z: 0.48
};
if (Math.abs(p.x) > tracerBounds.x) {
p.x = Math.sign(p.x) * tracerBounds.x;
v.x *= -0.85;
}
if (Math.abs(p.y) > tracerBounds.y) {
p.y = Math.sign(p.y) * tracerBounds.y;
v.y *= -0.85;
}
if (Math.abs(p.z) > tracerBounds.z) {
p.z = Math.sign(p.z) * tracerBounds.z;
v.z *= -0.85;
}
chamber.trailTimer += dt;
if (chamber.trailTimer > 0.025) {
chamber.trailTimer = 0;
chamber.trailPoints.push(p.clone());
if (chamber.trailPoints.length > chamber.maxTrail) {
chamber.trailPoints.shift();
}
chamber.trailPoints.forEach((point, i) => {
chamber.trailArray[i * 3] = point.x;
chamber.trailArray[i * 3 + 1] = point.y;
chamber.trailArray[i * 3 + 2] = point.z;
});
chamber.trailGeometry.setDrawRange(
0,
chamber.trailPoints.length
);
chamber.trailGeometry.attributes.position.needsUpdate = true;
}
}
// ---------------------------------------------------------------------
// Projected DOM labels
// ---------------------------------------------------------------------
const worldLabels = [];
function addWorldLabel(html, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
labelsRoot.appendChild(element);
worldLabels.push({ element, position });
return element;
}
addWorldLabel(
"<strong>Thermodynamic state space</strong> · (T, P)",
new THREE.Vector3(MAP.centerX, MAP.centerY + H / 2 + 0.28, 0.4)
);
addWorldLabel(
"<strong>Real-space trajectories</strong> · r(t)",
new THREE.Vector3(4.55, 2.55, 0.5)
);
addWorldLabel(
"<strong>A</strong> · 1.013 bar",
mapPosition(178, DATA.P_NORMAL, 0.48),
"a"
);
addWorldLabel(
"<strong>B</strong> · compress then heat",
mapPosition(185, 50, 0.48),
"b"
);
addWorldLabel(
"particle trail r(t)",
new THREE.Vector3(4.55, 0.12, 0.55),
"a point"
);
addWorldLabel(
"particle trail r(t)",
new THREE.Vector3(4.55, -2.78, 0.55),
"b point"
);
addWorldLabel(
"triple point",
mapPosition(DATA.T_TRIPLE, DATA.P_TRIPLE, 0.42),
"point"
);
addWorldLabel(
"critical point",
mapPosition(DATA.T_CRITICAL, DATA.P_CRITICAL, 0.42),
"point"
);
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const label of worldLabels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// ---------------------------------------------------------------------
// Interface and local verification
// ---------------------------------------------------------------------
let selectedRoute = "A";
let playing = true;
const routeButtons = [...document.querySelectorAll("[data-route]")];
const progressInput = document.querySelector("#progress");
const playButton = document.querySelector("#play");
const progressValue = document.querySelector("#progress-value");
const selectedLabel = document.querySelector("#selected-label");
function renderSequence(element, sequence) {
element.innerHTML = "";
sequence.forEach((phase, index) => {
if (index > 0) {
const arrow = document.createElement("span");
arrow.className = "arrow";
arrow.textContent = "→";
element.appendChild(arrow);
}
const chip = document.createElement("span");
chip.className = `phase ${phase}`;
chip.textContent = phase;
element.appendChild(chip);
});
}
renderSequence(
document.querySelector("#sequence-a"),
routes.A.sequence
);
renderSequence(
document.querySelector("#sequence-b"),
routes.B.sequence
);
function selectRoute(id) {
selectedRoute = id;
routeButtons.forEach(button => {
button.classList.toggle("active", button.dataset.route === id);
});
selectedLabel.textContent = `Path ${id} progress`;
syncControls();
}
function syncControls() {
const route = routes[selectedRoute];
progressInput.value = Math.round(route.progress * 1000);
progressValue.textContent = `${Math.round(route.progress * 100)}%`;
}
routeButtons.forEach(button => {
button.addEventListener("click", () => {
selectRoute(button.dataset.route);
});
});
progressInput.addEventListener("input", () => {
routes[selectedRoute].progress = Number(progressInput.value) / 1000;
progressValue.textContent = `${Math.round(routes[selectedRoute].progress * 100)}%`;
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
document.querySelector("#reset-camera").addEventListener("click", resetCamera);
function check(label, pass, detail) {
const row = document.createElement("div");
row.className = "check";
const mark = document.createElement("span");
mark.className = "check-mark";
mark.textContent = pass ? "✓" : "!";
const text = document.createElement("span");
text.innerHTML = `<strong>${label}</strong><br>${detail}`;
row.append(mark, text);
document.querySelector("#checks").appendChild(row);
}
const computedNormalT = normalSublimationTemperature();
const normalError = Math.abs(computedNormalT - DATA.T_NORMAL_SUB);
let vaporMonotone = true;
let previousP = -Infinity;
for (let T = DATA.T_TRIPLE; T <= DATA.T_CRITICAL; T += 0.25) {
const P = pVap(T);
if (P <= previousP) {
vaporMonotone = false;
break;
}
previousP = P;
}
const expectedA = ["solid", "gas"];
const expectedB = ["solid", "liquid", "gas"];
check(
"Sublimation equation",
normalError < 0.05,
`Computed normal sublimation point ${computedNormalT.toFixed(3)} K; ` +
`reference ${DATA.T_NORMAL_SUB} K. Residual ${normalError.toFixed(3)} K.`
);
check(
"Vapor-pressure curve",
vaporMonotone,
"The interpolated vapor pressure is continuous and strictly increasing " +
"from the triple point to the critical point."
);
check(
"Route A classifier",
JSON.stringify(routes.A.sequence) === JSON.stringify(expectedA),
`Detected sequence: ${routes.A.sequence.join(" → ")}.`
);
check(
"Route B classifier",
JSON.stringify(routes.B.sequence) === JSON.stringify(expectedB),
`Detected sequence: ${routes.B.sequence.join(" → ")}.`
);
check(
"Critical endpoint",
Math.abs(
pVap(DATA.T_CRITICAL) - DATA.P_CRITICAL
) < 0.01,
`Interpolated critical pressure ${pVap(DATA.T_CRITICAL).toFixed(3)} bar; ` +
`reference ${DATA.P_CRITICAL} bar.`
);
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.04);
const elapsed = clock.elapsedTime;
if (playing) {
for (const route of Object.values(routes)) {
route.progress += dt * 0.035;
if (route.progress > 1) route.progress -= 1;
}
syncControls();
}
for (const route of Object.values(routes)) {
const sample = sampleRoute(route, route.progress);
const phase = phaseAt(sample.T, sample.P);
route.current = sample;
route.currentPhase = phase;
route.marker.position.copy(sample.position);
route.marker.position.z = MAP.routeZ + 0.06;
const isSelected = route.id === selectedRoute;
const lineOpacity = isSelected ? 0.98 : 0.46;
const arrowOpacity = isSelected ? 1 : 0.42;
route.materials.forEach((material, index) => {
material.opacity = index === 0 ? lineOpacity : arrowOpacity;
});
route.marker.material.opacity = isSelected ? 1 : 0.5;
route.markerRing.material.opacity = isSelected ? 0.9 : 0.3;
updateChamber(
chambers[route.id],
phase,
dt,
elapsed
);
document.querySelector(`#now-${route.id.toLowerCase()}`).textContent =
phase;
}
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
document.querySelector("#loading").style.opacity = "0";
setTimeout(() => {
document.querySelector("#loading").remove();
}, 320);
</script>
</body>
</html>
```