Prompt specification
Build or customize the Three.js 3D scene "Ice-packed rail crates across a synthetic journey" 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: Ice-packed rail crates across a synthetic journey
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ice-packed-rail-crates-across-a-synthetic-journey-x2528
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring historical refrigeration and food cold chains. Compare two period-referenced ice-packed rail crates over one synthetic journey. Let users change insulation thickness and initial ice mass, then plot remaining ice using explicitly supplied thermal assumptions. Voxel style.
Working Three.js Starter (ice-packed-rail-crates-across-a-synthetic-journey-x2528):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ice Rail Lab — Historical Cold-Chain Comparison</title>
<style>
:root {
color-scheme: dark;
--bg: #080c12;
--panel: #101722;
--panel-2: #141e2a;
--line: #263546;
--text: #e9f0f7;
--muted: #91a4b7;
--early: #f2a65a;
--late: #58d7df;
--ambient: #a88bff;
--green: #8be08b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
border: 1px solid var(--line);
color: var(--text);
background: #182331;
cursor: pointer;
}
button:hover {
border-color: #526b82;
background: #1c2a3a;
}
.app {
display: flex;
flex-direction: column;
height: 100vh;
min-height: 650px;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
min-height: 76px;
padding: 14px 22px;
border-bottom: 1px solid var(--line);
background:
linear-gradient(90deg, rgba(88, 215, 223, 0.06), transparent 38%),
#0c121b;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 40px;
height: 40px;
flex: 0 0 40px;
border: 2px solid var(--late);
box-shadow: 5px 5px 0 #16383f;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--late);
}
.brand-mark::before {
width: 4px;
height: 28px;
top: 4px;
left: 16px;
}
.brand-mark::after {
width: 28px;
height: 4px;
top: 16px;
left: 4px;
}
.eyebrow {
margin: 0 0 3px;
color: var(--late);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 25px);
line-height: 1.05;
letter-spacing: -0.025em;
}
.top-note {
max-width: 520px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
text-align: right;
}
.workspace {
display: grid;
grid-template-columns: 300px minmax(390px, 1fr) 340px;
flex: 1;
min-height: 0;
}
.panel {
min-width: 0;
background: var(--panel);
}
.controls-panel,
.chart-panel {
overflow-y: auto;
scrollbar-color: #33475c transparent;
scrollbar-width: thin;
}
.controls-panel {
border-right: 1px solid var(--line);
}
.chart-panel {
border-left: 1px solid var(--line);
}
.panel-pad {
padding: 18px;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-label .unit {
color: #6f8499;
font-size: 9px;
}
.journey-card {
margin-bottom: 15px;
padding: 14px;
border: 1px solid var(--line);
background: linear-gradient(145deg, #172330, #111923);
}
.route {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 11px;
color: #dce8f3;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
.route-arrow {
color: var(--late);
}
.time-readout {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 3px 0 7px;
}
.time-readout strong {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 27px;
letter-spacing: -0.05em;
}
.time-readout span {
color: var(--muted);
font-size: 11px;
}
input[type="range"] {
width: 100%;
height: 20px;
margin: 0;
accent-color: var(--late);
cursor: pointer;
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 10px;
}
.button-row button {
min-height: 35px;
padding: 7px 11px;
border-radius: 0;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
}
#playButton {
border-color: #2b7076;
background: #16353b;
color: #b9fbff;
}
.period-card {
position: relative;
margin-bottom: 12px;
padding: 15px 14px 13px;
border: 1px solid var(--line);
background: #121b26;
overflow: hidden;
}
.period-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--accent);
}
.period-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
.period-heading h2 {
margin: 0;
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 17px;
letter-spacing: -0.03em;
}
.period-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.period-chip {
flex: 0 0 auto;
padding: 4px 6px;
border: 1px solid color-mix(in srgb, var(--accent), transparent 45%);
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.09em;
}
.control {
margin-top: 13px;
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 5px;
}
.control-top label {
color: #c5d1dc;
font-size: 11px;
font-weight: 650;
}
.control-value {
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
text-align: right;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: #61768a;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
}
.period-status {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid #243241;
color: var(--muted);
font-size: 10px;
}
.period-status strong {
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.fine-print {
margin: 11px 0 0;
color: #72879b;
font-size: 9px;
line-height: 1.55;
}
.scene-panel {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 34%, #182738 0, #0c131d 48%, #080d14 100%);
}
.scene-panel canvas.webgl {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.scene-top {
position: absolute;
z-index: 2;
top: 17px;
left: 17px;
right: 17px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
pointer-events: none;
}
.scene-title {
padding: 11px 13px;
border: 1px solid rgba(119, 151, 178, 0.27);
background: rgba(8, 14, 22, 0.76);
backdrop-filter: blur(8px);
}
.scene-title strong {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-title span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.camera-hint {
padding: 7px 9px;
border: 1px solid rgba(119, 151, 178, 0.2);
background: rgba(8, 14, 22, 0.68);
color: #8299ad;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.scene-metrics {
position: absolute;
z-index: 2;
right: 17px;
bottom: 17px;
left: 17px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
pointer-events: none;
}
.scene-metric {
padding: 12px 13px;
border: 1px solid rgba(119, 151, 178, 0.28);
border-top: 2px solid var(--accent);
background: rgba(8, 14, 22, 0.82);
backdrop-filter: blur(9px);
}
.scene-metric span {
display: block;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-metric strong {
display: block;
margin: 4px 0 2px;
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 22px;
letter-spacing: -0.04em;
}
.scene-metric small {
color: #91a4b7;
font-size: 9px;
}
.loading {
position: absolute;
z-index: 5;
inset: 0;
display: grid;
place-items: center;
background: #0b1119;
color: var(--late);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.chart-panel .panel-pad {
padding-bottom: 28px;
}
.chart-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.chart-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.02em;
}
.chart-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.chart-badge {
flex: 0 0 auto;
padding: 4px 6px;
border: 1px solid var(--line);
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
font-weight: 800;
}
#iceChart {
display: block;
width: 100%;
height: 275px;
border: 1px solid var(--line);
background: #0c131c;
cursor: crosshair;
touch-action: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 13px;
margin: 10px 0 16px;
color: var(--muted);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 18px;
height: 3px;
background: var(--color);
}
.legend-line.dashed {
height: 0;
border-top: 2px dashed var(--color);
background: transparent;
}
.readout-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 17px;
}
.readout {
padding: 10px;
border: 1px solid var(--line);
background: #121b26;
}
.readout span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.readout strong {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
}
details {
border: 1px solid var(--line);
background: #0d151e;
}
summary {
padding: 12px;
color: #c9d7e3;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
cursor: pointer;
}
.assumptions {
padding: 0 12px 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.assumptions p {
margin: 8px 0;
}
.formula {
display: block;
margin: 9px 0;
padding: 9px;
border-left: 2px solid var(--late);
background: #111c27;
color: #c8f8fb;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.65;
overflow-wrap: anywhere;
}
.assumption-list {
margin: 8px 0 0;
padding-left: 16px;
}
.assumption-list li {
margin-bottom: 6px;
}
.ambient-key {
margin-top: 10px;
padding: 9px;
border: 1px dashed #3b405d;
color: #b9addf;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
line-height: 1.7;
}
@media (max-width: 1120px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
}
.workspace {
grid-template-columns: 285px minmax(0, 1fr);
}
.scene-panel {
min-height: 690px;
}
.chart-panel {
grid-column: 1 / -1;
border-top: 1px solid var(--line);
border-left: 0;
}
#iceChart {
height: 330px;
}
}
@media (max-width: 720px) {
.topbar {
align-items: flex-start;
padding: 13px 15px;
}
.top-note {
display: none;
}
.workspace {
display: flex;
flex-direction: column;
}
.controls-panel {
border-right: 0;
}
.scene-panel {
min-height: 570px;
}
.chart-panel {
border-left: 0;
}
.scene-top {
flex-direction: column;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Historical cold-chain simulator</p>
<h1>Ice Rail Lab</h1>
</div>
</div>
<p class="top-note">
Two period-referenced ice-packed rail crates share one synthetic,
72-hour Chicago–Buffalo–New York journey with no re-icing.
</p>
</header>
<main class="workspace">
<aside class="panel controls-panel">
<div class="panel-pad">
<div class="section-label">
<span>Journey</span>
<span class="unit">72 H / NO RE-ICING</span>
</div>
<section class="journey-card">
<div class="route">
<span>CHI</span>
<span class="route-arrow">→</span>
<span>BUF</span>
<span class="route-arrow">→</span>
<span>NYC</span>
</div>
<div class="time-readout">
<strong id="timeReadout">00.0 h</strong>
<span id="phaseReadout">Chicago departure</span>
</div>
<input
id="journeyTime"
type="range"
min="0"
max="72"
step="0.1"
value="0"
aria-label="Journey time in hours"
/>
<div class="range-ends">
<span>DEPART</span>
<span>ARRIVE</span>
</div>
<div class="button-row">
<button id="playButton" type="button">▶ RUN JOURNEY</button>
<button id="resetButton" type="button">RESET</button>
</div>
</section>
<div class="section-label">
<span>Crate parameters</span>
<span class="unit">LIVE MODEL</span>
</div>
<section
class="period-card"
style="--accent: var(--early)"
>
<div class="period-heading">
<div>
<h2>1870s reference</h2>
<p>Early refrigerated-rail / sawdust-and-ice archetype</p>
</div>
<span class="period-chip">A</span>
</div>
<div class="control">
<div class="control-top">
<label for="earlyIce">Initial ice mass</label>
<output id="earlyIceValue" class="control-value"></output>
</div>
<input
id="earlyIce"
type="range"
min="40"
max="300"
step="5"
value="120"
/>
<div class="range-ends">
<span>40 LB</span>
<span>300 LB</span>
</div>
</div>
<div class="control">
<div class="control-top">
<label for="earlyThickness">Insulation thickness</label>
<output id="earlyThicknessValue" class="control-value"></output>
</div>
<input
id="earlyThickness"
type="range"
min="0.75"
max="7"
step="0.25"
value="2"
/>
<div class="range-ends">
<span>0.75 IN</span>
<span>7 IN</span>
</div>
</div>
<div class="period-status">
<span>At cursor</span>
<strong id="earlyStatus">54.4 kg remaining</strong>
</div>
</section>
<section
class="period-card"
style="--accent: var(--late)"
>
<div class="period-heading">
<div>
<h2>1890s reference</h2>
<p>More developed insulated ice-express archetype</p>
</div>
<span class="period-chip">B</span>
</div>
<div class="control">
<div class="control-top">
<label for="lateIce">Initial ice mass</label>
<output id="lateIceValue" class="control-value"></output>
</div>
<input
id="lateIce"
type="range"
min="40"
max="300"
step="5"
value="180"
/>
<div class="range-ends">
<span>40 LB</span>
<span>300 LB</span>
</div>
</div>
<div class="control">
<label for="lateThickness">Insulation thickness</label>
<div class="control-top">
<span></span>
<output id="lateThicknessValue" class="control-value"></output>
</div>
<input
id="lateThickness"
type="range"
min="0.75"
max="7"
step="0.25"
value="4.5"
/>
<div class="range-ends">
<span>0.75 IN</span>
<span>7 IN</span>
</div>
</div>
<div class="period-status">
<span>At cursor</span>
<strong id="lateStatus">81.6 kg remaining</strong>
</div>
</section>
<p class="fine-print">
Period labels describe visual and operational archetypes, not
exact archaeological reconstructions. Geometry and thermal
constants are intentionally synthetic.
</p>
</div>
</aside>
<section class="scene-panel" id="viewport" aria-label="Voxel rail scene">
<div class="loading" id="loading">Building voxel rail scene…</div>
<div class="scene-top">
<div class="scene-title">
<strong>Shared synthetic journey</strong>
<span id="scenePhase">Chicago departure · no re-icing</span>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom</div>
</div>
<div class="scene-metrics">
<div class="scene-metric" style="--accent: var(--early)">
<span>1870s ice reserve</span>
<strong id="sceneEarlyMass">54.4 kg</strong>
<small id="sceneEarlyHeat">Heat load: 0 W</small>
</div>
<div class="scene-metric" style="--accent: var(--late)">
<span>1890s ice reserve</span>
<strong id="sceneLateMass">81.6 kg</strong>
<small id="sceneLateHeat">Heat load: 0 W</small>
</div>
</div>
</section>
<aside class="panel chart-panel">
<div class="panel-pad">
<div class="chart-heading">
<div>
<h2>Remaining ice</h2>
<p>Live comparison at the journey cursor</p>
</div>
<span class="chart-badge">0–72 H</span>
</div>
<canvas id="iceChart" aria-label="Remaining ice mass chart"></canvas>
<div class="legend">
<div class="legend-item">
<span class="legend-line" style="--color: var(--early)"></span>
<span>1870s crate</span>
</div>
<div class="legend-item">
<span class="legend-line" style="--color: var(--late)"></span>
<span>1890s crate</span>
</div>
<div class="legend-item">
<span class="legend-line dashed" style="--color: var(--ambient)"></span>
<span>Ambient °C, right axis</span>
</div>
</div>
<div class="section-label">
<span>Cursor readout</span>
<span class="unit">CLICK CHART TO SCRUB</span>
</div>
<div class="readout-grid">
<div class="readout">
<span>1870s remaining</span>
<strong id="chartEarlyMass">54.4 kg</strong>
</div>
<div class="readout">
<span>1890s remaining</span>
<strong id="chartLateMass">81.6 kg</strong>
</div>
<div class="readout">
<span>1870s empty at</span>
<strong id="chartEarlyDry">—</strong>
</div>
<div class="readout">
<span>1890s empty at</span>
<strong id="chartLateDry">—</strong>
</div>
</div>
<details open>
<summary>EXPLICIT THERMAL ASSUMPTIONS</summary>
<div class="assumptions">
<p>
The chart uses a lumped, steady heat-inflow model while ice
remains. Both crates are held at 0 °C until their ice is
exhausted.
</p>
<code class="formula">
Rtotal = Rcase + t / k<br />
U = 1 / Rtotal<br />
Q̇ = U · A · (Tambient − 0 °C)<br />
dm/dt = −Q̇ / Lfusion
</code>
<ul class="assumption-list">
<li>
External crate dimensions:
1.20 × 0.90 × 0.80 m.
</li>
<li>
Total exposed surface area, including all six faces:
<strong>A = 5.52 m²</strong>.
</li>
<li>
Effective insulation conductivity:
<strong>k = 0.035 W/(m·K)</strong>.
</li>
<li>
Non-insulated case resistance:
<strong>Rcase = 0.12 m²·K/W</strong>.
</li>
<li>
Ice latent heat of fusion:
<strong>334,000 J/kg</strong>.
</li>
<li>
Pound-to-kilogram conversion:
<strong>1 lb = 0.45359237 kg</strong>.
</li>
<li>
Synthetic ambient schedule:
18 °C for 0–6 h; 25 °C for 6–18 h; 27 °C for
18–24 h; 20 °C for 24–42 h; 25 °C for 42–54 h;
27 °C for 54–60 h; 24 °C for 60–72 h.
</li>
<li>
No re-icing, track heat, solar radiation, explicit airflow,
crate moisture migration, liquid-water heat capacity,
or product heat load is included.
</li>
</ul>
<div class="ambient-key">
AMBIENT PROFILE / HOUR<br />
00–06: 18°C 06–18: 25°C 18–24: 27°C<br />
24–42: 20°C 42–54: 25°C 54–60: 27°C<br />
60–72: 24°C
</div>
</div>
</details>
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model
// -------------------------------------------------------------------------
const PHYS = Object.freeze({
durationHours: 72,
crateWidth: 1.20,
crateHeight: 0.90,
crateDepth: 0.80,
area:
2 *
(
1.20 * 0.90 +
1.20 * 0.80 +
0.90 * 0.80
),
caseResistance: 0.12,
insulationConductivity: 0.035,
latentHeat: 334000,
poundsToKg: 0.45359237,
stepHours: 0.25
});
const AMBIENT_SEGMENTS = [
{ start: 0, end: 6, celsius: 18 },
{ start: 6, end: 18, celsius: 25 },
{ start: 18, end: 24, celsius: 27 },
{ start: 24, end: 42, celsius: 20 },
{ start: 42, end: 54, celsius: 25 },
{ start: 54, end: 60, celsius: 27 },
{ start: 60, end: 72, celsius: 24 }
];
const COLORS = {
early: "#f2a65a",
late: "#58d7df",
ambient: "#a88bff"
};
const configs = {
early: {
iceLb: 120,
insulationIn: 2.0
},
late: {
iceLb: 180,
insulationIn: 4.5
}
};
let journeyHours = 0;
let playing = false;
let earlySeries = [];
let lateSeries = [];
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function ambientAt(hour) {
const h = clamp(hour, 0, PHYS.durationHours);
for (const segment of AMBIENT_SEGMENTS) {
if (h >= segment.start && h < segment.end) {
return segment.celsius;
}
}
return AMBIENT_SEGMENTS[AMBIENT_SEGMENTS.length - 1].celsius;
}
function heatLoadWatts(config, hour) {
const insulationMeters = config.insulationIn * 0.0254;
const resistance =
PHYS.caseResistance +
insulationMeters / PHYS.insulationConductivity;
const conductance = 1 / resistance;
return conductance * PHYS.area * ambientAt(hour);
}
function simulate(config) {
let massKg = config.iceLb * PHYS.poundsToKg;
const points = [{ hour: 0, massKg }];
for (
let hour = PHYS.stepHours;
hour <= PHYS.durationHours + 0.0001;
hour += PHYS.stepHours
) {
const midpoint = hour - PHYS.stepHours * 0.5;
const heatWatts = heatLoadWatts(config, midpoint);
const meltedKg =
(heatWatts * 3600 * PHYS.stepHours) /
PHYS.latentHeat;
massKg = Math.max(0, massKg - meltedKg);
points.push({ hour, massKg });
}
return points;
}
function massAt(series, hour) {
if (!series.length) return 0;
const position = clamp(hour, 0, PHYS.durationHours) / PHYS.stepHours;
const lowerIndex = Math.floor(position);
const upperIndex = Math.min(series.length - 1, lowerIndex + 1);
const fraction = position - lowerIndex;
return (
series[lowerIndex].massKg +
(series[upperIndex].massKg - series[lowerIndex].massKg) * fraction
);
}
function emptyAt(series) {
const empty = series.find(point => point.massKg <= 0.0001);
return empty ? empty.hour : null;
}
function phaseAt(hour) {
if (hour < 6) return "Chicago departure";
if (hour < 18) return "Chicago → Buffalo";
if (hour < 24) return "Buffalo dwell";
if (hour < 54) return "Buffalo → New York";
if (hour < 60) return "New York dwell";
return "New York arrival";
}
// -------------------------------------------------------------------------
// DOM references
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const loading = document.getElementById("loading");
const journeyInput = document.getElementById("journeyTime");
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const earlyIceInput = document.getElementById("earlyIce");
const earlyThicknessInput = document.getElementById("earlyThickness");
const lateIceInput = document.getElementById("lateIce");
const lateThicknessInput = document.getElementById("lateThickness");
const earlyIceValue = document.getElementById("earlyIceValue");
const earlyThicknessValue = document.getElementById("earlyThicknessValue");
const lateIceValue = document.getElementById("lateIceValue");
const lateThicknessValue = document.getElementById("lateThicknessValue");
const earlyStatus = document.getElementById("earlyStatus");
const lateStatus = document.getElementById("lateStatus");
const sceneEarlyMass = document.getElementById("sceneEarlyMass");
const sceneLateMass = document.getElementById("sceneLateMass");
const sceneEarlyHeat = document.getElementById("sceneEarlyHeat");
const sceneLateHeat = document.getElementById("sceneLateHeat");
const chartEarlyMass = document.getElementById("chartEarlyMass");
const chartLateMass = document.getElementById("chartLateMass");
const chartEarlyDry = document.getElementById("chartEarlyDry");
const chartLateDry = document.getElementById("chartLateDry");
const timeReadout = document.getElementById("timeReadout");
const phaseReadout = document.getElementById("phaseReadout");
const scenePhase = document.getElementById("scenePhase");
const chart = document.getElementById("iceChart");
const chartContext = chart.getContext("2d");
let chartLayout = null;
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1119);
scene.fog = new THREE.Fog(0x0b1119, 10, 25);
const camera = new THREE.PerspectiveCamera(
42,
1,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.className = "webgl";
viewport.prepend(renderer.domElement);
const ambientLight = new THREE.HemisphereLight(0xbadfff, 0x372617, 2.1);
scene.add(ambientLight);
const keyLight = new THREE.DirectionalLight(0xfff1da, 3.2);
keyLight.position.set(4, 8, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58d7df, 1.5);
rimLight.position.set(-5, 4, -6);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0x17212c,
roughness: 1,
flatShading: true
}),
track: new THREE.MeshStandardMaterial({
color: 0x3b4650,
roughness: 0.8,
metalness: 0.45,
flatShading: true
}),
sleeper: new THREE.MeshStandardMaterial({
color: 0x3e2b22,
roughness: 0.95,
flatShading: true
}),
wagon: new THREE.MeshStandardMaterial({
color: 0x263646,
roughness: 0.7,
metalness: 0.4,
flatShading: true
}),
metalDark: new THREE.MeshStandardMaterial({
color: 0x17212b,
roughness: 0.55,
metalness: 0.72,
flatShading: true
}),
earlyWood: new THREE.MeshStandardMaterial({
color: 0x70432b,
roughness: 0.92,
flatShading: true
}),
earlyWoodLight: new THREE.MeshStandardMaterial({
color: 0x9b633a,
roughness: 0.88,
flatShading: true
}),
lateWood: new THREE.MeshStandardMaterial({
color: 0xa46d3d,
roughness: 0.86,
flatShading: true
}),
lateWoodLight: new THREE.MeshStandardMaterial({
color: 0xc08a52,
roughness: 0.84,
flatShading: true
}),
insulation: new THREE.MeshStandardMaterial({
color: 0xc0a66c,
roughness: 1,
flatShading: true
}),
ice: new THREE.MeshStandardMaterial({
color: 0x8ceaf2,
emissive: 0x164854,
emissiveIntensity: 0.65,
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.9,
flatShading: true
}),
cargo: new THREE.MeshStandardMaterial({
color: 0xb7aa83,
roughness: 0.95,
flatShading: true
}),
cargoAlt: new THREE.MeshStandardMaterial({
color: 0x8d7651,
roughness: 0.95,
flatShading: true
})
};
function addBox(
parent,
sizeX,
sizeY,
sizeZ,
positionX,
positionY,
positionZ,
material,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sizeX, sizeY, sizeZ);
mesh.position.set(positionX, positionY, positionZ);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function makeTextSprite(lines, accent, width = 2.3) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(8, 14, 22, 0.90)";
context.fillRect(8, 8, 496, 128);
context.strokeStyle = accent;
context.lineWidth = 5;
context.strokeRect(8, 8, 496, 128);
context.fillStyle = accent;
context.fillRect(8, 8, 10, 128);
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "bold 30px monospace";
const lineHeight = 38;
const startY = canvas.height / 2 -
((lines.length - 1) * lineHeight) / 2;
lines.forEach((line, index) => {
context.fillStyle = index === 0 ? accent : "#dce7f0";
context.fillText(line, 265, startY + index * lineHeight);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 144 / 512, 1);
sprite.renderOrder = 10;
return sprite;
}
// Ground, rail bed, sleepers and rails.
addBox(
scene,
28, 0.18, 13,
0, -0.14, 0,
materials.ground,
false,
true
);
for (let x = -11; x <= 11; x += 0.72) {
addBox(
scene,
0.22, 0.09, 2.15,
x, 0.0, 0,
materials.sleeper,
false,
true
);
}
addBox(scene, 24, 0.12, 0.10, 0, 0.10, -0.73, materials.track);
addBox(scene, 24, 0.12, 0.10, 0, 0.10, 0.73, materials.track);
// Flatcar.
const flatcar = new THREE.Group();
scene.add(flatcar);
addBox(
flatcar,
6.4, 0.22, 1.45,
0, 0.31, 0,
materials.wagon
);
addBox(
flatcar,
6.45, 0.08, 0.12,
0, 0.46, -0.72,
materials.metalDark
);
addBox(
flatcar,
6.45, 0.08, 0.12,
0, 0.46, 0.72,
materials.metalDark
);
for (const x of [-2.35, -1.75, 1.75, 2.35]) {
for (const z of [-0.73, 0.73]) {
addBox(
flatcar,
0.34, 0.28, 0.18,
x, 0.20, z,
materials.metalDark
);
addBox(
flatcar,
0.12, 0.12, 0.20,
x, 0.20, z,
materials.track
);
}
}
// Distant voxel skyline.
const skyline = [
[-10, 1.4, 0.9], [-8.8, 2.2, 1.1], [-7.2, 1.1, 0.8],
[-5.9, 2.8, 1.2], [-4.5, 1.7, 0.9], [-3.4, 3.5, 1.4],
[-1.8, 2.0, 1.0], [-0.2, 2.7, 1.1], [1.2, 1.5, 0.9],
[2.5, 3.1, 1.3], [4.0, 2.1, 1.0], [5.5, 2.6, 1.2],
[7.0, 1.3, 0.8], [8.5, 2.9, 1.4], [10, 1.7, 1.0]
];
for (const [x, height, width] of skyline) {
addBox(
scene,
width, height, 0.8,
x, height / 2, -7.0,
materials.ground,
false,
false
);
}
// Route markers.
const stationSprites = [];
function createStation(x, name, accent) {
const station = new THREE.Group();
station.position.set(x, 0, -3.7);
scene.add(station);
addBox(
station,
0.12, 1.10, 0.12,
0, 0.55, 0,
materials.metalDark
);
addBox(
station,
0.65, 0.08, 0.08,
0, 1.08, 0,
materials.track
);
const sprite = makeTextSprite([name], accent, 1.55);
sprite.position.set(0, 1.43, 0);
station.add(sprite);
const glow = addBox(
station,
0.12, 0.12, 0.12,
0, 1.16, 0,
new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 1.5,
roughness: 0.4
}),
false,
false
);
stationSprites.push({ sprite, glow });
}
createStation(-4.3, "CHICAGO", COLORS.early);
createStation(0, "BUFFALO", "#e9edf2");
createStation(4.3, "NEW YORK", COLORS.late);
for (let x = -4.1; x < 4.2; x += 0.38) {
addBox(
scene,
0.28, 0.035, 0.09,
x, 0.03, -3.1,
materials.track,
false,
true
);
}
// -------------------------------------------------------------------------
// Voxel crates
// -------------------------------------------------------------------------
function createCrate(config, variant) {
const group = new THREE.Group();
group.position.set(
variant === "early" ? -1.35 : 1.35,
0.49,
0
);
scene.add(group);
const width = PHYS.crateWidth;
const height = PHYS.crateHeight;
const depth = PHYS.crateDepth;
const wood = variant === "early"
? materials.earlyWood
: materials.lateWood;
const woodLight = variant === "early"
? materials.earlyWoodLight
: materials.lateWoodLight;
// Base and corner posts.
addBox(group, width, 0.13, depth, 0, 0.065, 0, woodLight);
addBox(group, width, 0.09, 0.10, 0, 0.14, -depth / 2, wood);
addBox(group, width, 0.09, 0.10, 0, 0.14, depth / 2, wood);
for (const x of [-width / 2 + 0.06, width / 2 - 0.06]) {
for (const z of [-depth / 2 + 0.06, depth / 2 - 0.06]) {
addBox(
group,
0.12, height, 0.12,
x, height / 2, z,
woodLight
);
}
}
// Horizontal slats on the front and back.
for (const y of [0.22, 0.42, 0.62, 0.81]) {
for (const z of [-depth / 2, depth / 2]) {
addBox(
group,
width - 0.12, 0.14, 0.09,
0, y, z,
wood
);
}
}
// Slats on the sides.
for (const y of [0.22, 0.42, 0.62, 0.81]) {
for (const x of [-width / 2, width / 2]) {
addBox(
group,
0.09, 0.14, depth - 0.12,
x, y, 0,
woodLight
);
}
}
// Iron or steel bands.
const strapPositions = variant === "early"
? [-0.34, 0.34]
: [-0.46, -0.16, 0.16, 0.46];
for (const x of strapPositions) {
for (const z of [-depth / 2 - 0.058, depth / 2 + 0.058]) {
addBox(
group,
0.065, height * 0.91, 0.035,
x, height * 0.48, z,
materials.metalDark
);
}
}
// Food parcels beneath the ice.
for (const [x, z, material] of [
[-0.25, -0.18, materials.cargo],
[0.25, -0.18, materials.cargoAlt],
[-0.25, 0.18, materials.cargoAlt],
[0.25, 0.18, materials.cargo]
]) {
addBox(
group,
0.34, 0.17, 0.28,
x, 0.225, z,
material
);
}
// Ice is rendered as individual voxel blocks.
const iceBlocks = [];
for (let layer = 2; layer >= 0; layer--) {
for (let xIndex = 0; xIndex < 4; xIndex++) {
for (let zIndex = 0; zIndex < 3; zIndex++) {
const x = -0.36 + xIndex * 0.24;
const z = -0.24 + zIndex * 0.24;
const y = 0.41 + layer * 0.19;
const block = addBox(
group,
0.215, 0.215, 0.215,
x, y, z,
materials.ice
);
block.userData.baseY = y;
iceBlocks.push(block);
}
}
}
// Visible insulation edge bands. Their thickness follows the slider.
const insulationBands = [];
const bandDefinitions = [
{
axis: "z",
size: [width * 0.80, 0.075, 1],
base: [0, 0.39, depth / 2],
sign: 1
},
{
axis: "z",
size: [width * 0.80, 0.075, 1],
base: [0, 0.39, -depth / 2],
sign: -1
},
{
axis: "x",
size: [1, 0.075, depth * 0.78],
base: [width / 2, 0.39, 0],
sign: 1
},
{
axis: "x",
size: [1, 0.075, depth * 0.78],
base: [-width / 2, 0.39, 0],
sign: -1
}
];
for (const definition of bandDefinitions) {
const band = addBox(
group,
definition.size[0],
definition.size[1],
definition.size[2],
definition.base[0],
definition.base[1],
definition.base[2],
materials.insulation
);
band.userData = definition;
insulationBands.push(band);
}
const accent = variant === "early" ? COLORS.early : COLORS.late;
const label = makeTextSprite(
[
variant === "early" ? "1870s REFERENCE" : "1890s REFERENCE",
variant === "early" ? "EARLY ICE RAIL" : "INSULATED ICE EXPRESS"
],
accent,
2.35
);
label.position.set(0, 1.50, 0);
group.add(label);
return { group, iceBlocks, insulationBands, config };
}
const earlyCrate = createCrate(configs.early, "early");
const lateCrate = createCrate(configs.late, "late");
function updateCrate(crate, config, hour) {
const initialMass = config.iceLb * PHYS.poundsToKg;
const remaining = massAt(
crate === earlyCrate ? earlySeries : lateSeries,
hour
);
const ratio = clamp(remaining / Math.max(initialMass, 0.001), 0, 1);
const count = crate.iceBlocks.length;
const visibleCount = Math.ceil(ratio * count);
crate.iceBlocks.forEach((block, index) => {
block.visible = index < visibleCount;
if (!block.visible) return;
const partial = index === visibleCount - 1
? clamp(ratio * count - index, 0.08, 1)
: 1;
block.scale.y = 0.215 * partial;
block.position.y =
block.userData.baseY - 0.1075 * (1 - partial);
});
const insulationMeters = config.insulationIn * 0.0254;
for (const band of crate.insulationBands) {
const definition = band.userData;
if (definition.axis === "z") {
band.scale.set(
definition.size[0],
definition.size[1],
insulationMeters
);
band.position.z =
definition.base[2] + definition.sign * insulationMeters / 2;
} else {
band.scale.set(
insulationMeters,
definition.size[1],
definition.size[2]
);
band.position.x =
definition.base[0] + definition.sign * insulationMeters / 2;
}
}
return remaining;
}
// -------------------------------------------------------------------------
// Direct camera controls: no external controls addon
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.68,
targetTheta: 0.68,
phi: 1.02,
targetPhi: 1.02,
radius: 8.8,
targetRadius: 8.8
};
const cameraTarget = new THREE.Vector3(0, 0.83, 0);
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.targetTheta -= deltaX * 0.006;
cameraState.targetPhi = clamp(
cameraState.targetPhi - deltaY * 0.005,
0.42,
1.42
);
});
function endCameraDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endCameraDrag);
renderer.domElement.addEventListener("pointercancel", endCameraDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.targetRadius = clamp(
cameraState.targetRadius + event.deltaY * 0.006,
5.4,
15
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraState.targetTheta = 0.68;
cameraState.targetPhi = 1.02;
cameraState.targetRadius = 8.8;
});
function updateCamera() {
cameraState.theta +=
(cameraState.targetTheta - cameraState.theta) * 0.09;
cameraState.phi +=
(cameraState.targetPhi - cameraState.phi) * 0.09;
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * 0.09;
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y +
cameraState.radius * cosPhi,
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeRenderer).observe(viewport);
resizeRenderer();
// -------------------------------------------------------------------------
// Chart
// -------------------------------------------------------------------------
function resizeChart() {
const rectangle = chart.getBoundingClientRect();
const ratio = Math.min(window.devicePixelRatio || 1, 2);
chart.width = Math.max(1, Math.round(rectangle.width * ratio));
chart.height = Math.max(1, Math.round(rectangle.height * ratio));
drawChart();
}
function drawChart() {
if (!chart.width || !chart.height) return;
const ratio = Math.min(window.devicePixelRatio || 1, 2);
const context = chartContext;
context.setTransform(ratio, 0, 0, ratio, 0, 0);
const width = chart.width / ratio;
const height = chart.height / ratio;
context.clearRect(0, 0, width, height);
context.fillStyle = "#0c131c";
context.fillRect(0, 0, width, height);
const margin = {
left: 43,
right: 39,
top: 22,
bottom: 31
};
const plotWidth = width - margin.left - margin.right;
const plotHeight = height - margin.top - margin.bottom;
const maximumMass = Math.max(
configs.early.iceLb * PHYS.poundsToKg,
configs.late.iceLb * PHYS.poundsToKg
) * 1.08;
const xAt = hour =>
margin.left + (hour / PHYS.durationHours) * plotWidth;
const yAt = mass =>
margin.top + plotHeight -
(mass / maximumMass) * plotHeight;
const ambientY = celsius =>
margin.top + plotHeight -
((celsius - 15) / (30 - 15)) * plotHeight;
chartLayout = { margin, plotWidth, plotHeight, xAt };
// Grid.
context.strokeStyle = "#243140";
context.lineWidth = 1;
for (let index = 0; index <= 4; index++) {
const y =
margin.top + (plotHeight * index) / 4;
context.beginPath();
context.moveTo(margin.left, y);
context.lineTo(width - margin.right, y);
context.stroke();
}
for (let hour = 0; hour <= 72; hour += 12) {
const x = xAt(hour);
context.beginPath();
context.moveTo(x, margin.top);
context.lineTo(x, margin.top + plotHeight);
context.stroke();
}
// Station dwell markers.
context.strokeStyle = "rgba(232, 238, 244, 0.20)";
context.setLineDash([3, 4]);
for (const hour of [24, 54, 60]) {
const x = xAt(hour);
context.beginPath();
context.moveTo(x, margin.top);
context.lineTo(x, margin.top + plotHeight);
context.stroke();
}
context.setLineDash([]);
// Filled areas.
function drawMassSeries(series, color) {
if (!series.length) return;
const gradient = context.createLinearGradient(
0,
margin.top,
0,
margin.top + plotHeight
);
gradient.addColorStop(0, color + "38");
gradient.addColorStop(1, color + "03");
context.beginPath();
context.moveTo(xAt(series[0].hour), yAt(series[0].massKg));
for (const point of series) {
context.lineTo(xAt(point.hour), yAt(point.massKg));
}
context.lineTo(
xAt(PHYS.durationHours),
margin.top + plotHeight
);
context.lineTo(
xAt(0),
margin.top + plotHeight
);
context.closePath();
context.fillStyle = gradient;
context.fill();
context.beginPath();
context.moveTo(xAt(series[0].hour), yAt(series[0].massKg));
for (const point of series) {
context.lineTo(xAt(point.hour), yAt(point.massKg));
}
context.strokeStyle = color;
context.lineWidth = 2.6;
context.lineJoin = "round";
context.stroke();
}
drawMassSeries(earlySeries, COLORS.early);
drawMassSeries(lateSeries, COLORS.late);
// Ambient temperature line.
context.beginPath();
for (let hour = 0; hour <= PHYS.durationHours; hour += 0.5) {
const x = xAt(hour);
const y = ambientY(ambientAt(hour));
if (hour === 0) context.moveTo(x, y);
else context.lineTo(x, y);
}
context.strokeStyle = COLORS.ambient;
context.lineWidth = 1.5;
context.setLineDash([5, 4]);
context.stroke();
context.setLineDash([]);
// Journey cursor.
const cursorX = xAt(journeyHours);
context.strokeStyle = "rgba(233, 240, 247, 0.60)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(cursorX, margin.top);
context.lineTo(cursorX, margin.top + plotHeight);
context.stroke();
for (const [series, color] of [
[earlySeries, COLORS.early],
[lateSeries, COLORS.late]
]) {
const mass = massAt(series, journeyHours);
context.beginPath();
context.arc(
cursorX,
yAt(mass),
3.5,
0,
Math.PI * 2
);
context.fillStyle = color;
context.fill();
context.strokeStyle = "#0c131c";
context.lineWidth = 1.5;
context.stroke();
}
// Axes and labels.
context.font = "9px monospace";
context.fillStyle = "#8297aa";
context.strokeStyle = "#405064";
context.lineWidth = 1;
context.beginPath();
context.moveTo(margin.left, margin.top);
context.lineTo(margin.left, margin.top + plotHeight);
context.lineTo(width - margin.right, margin.top + plotHeight);
context.stroke();
context.textAlign = "right";
context.textBaseline = "middle";
for (let index = 0; index <= 4; index++) {
const mass = maximumMass * (1 - index / 4);
const y = margin.top + (plotHeight * index) / 4;
context.fillText(mass.toFixed(0), margin.left - 7, y);
}
context.textAlign = "left";
for (let index = 0; index <= 4; index++) {
const celsius = 30 - index * 3.75;
const y = margin.top + (plotHeight * index) / 4;
context.fillText(
celsius.toFixed(0),
width - margin.right + 7,
y
);
}
context.textAlign = "center";
context.textBaseline = "top";
for (let hour = 0; hour <= 72; hour += 12) {
context.fillText(
`${hour}h`,
xAt(hour),
margin.top + plotHeight + 9
);
}
context.textAlign = "left";
context.fillStyle = "#91a4b7";
context.fillText("ICE / kg", 7, 5);
context.textAlign = "right";
context.fillStyle = "#b9addf";
context.fillText("AIR / °C", width - 4, 5);
}
// Chart scrubbing.
let scrubbingChart = false;
function scrubChart(event) {
if (!chartLayout) return;
const rectangle = chart.getBoundingClientRect();
const localX = event.clientX - rectangle.left;
const { margin, plotWidth } = chartLayout;
const fraction = clamp(
(localX - margin.left) / plotWidth,
0,
1
);
journeyHours = fraction * PHYS.durationHours;
playing = false;
updatePlayButton();
updateReadouts();
drawChart();
}
chart.addEventListener("pointerdown", event => {
scrubbingChart = true;
chart.setPointerCapture(event.pointerId);
scrubChart(event);
});
chart.addEventListener("pointermove", event => {
if (scrubbingChart) scrubChart(event);
});
chart.addEventListener("pointerup", event => {
scrubbingChart = false;
if (chart.hasPointerCapture(event.pointerId)) {
chart.releasePointerCapture(event.pointerId);
}
});
chart.addEventListener("pointercancel", () => {
scrubbingChart = false;
});
new ResizeObserver(resizeChart).observe(chart);
resizeChart();
// -------------------------------------------------------------------------
// Controls and readouts
// -------------------------------------------------------------------------
function updateInputLabels() {
earlyIceValue.textContent =
`${configs.early.iceLb} lb · ` +
`${(configs.early.iceLb * PHYS.poundsToKg).toFixed(1)} kg`;
earlyThicknessValue.textContent =
`${configs.early.insulationIn.toFixed(2)} in · ` +
`${Math.round(configs.early.insulationIn * 25.4)} mm`;
lateIceValue.textContent =
`${configs.late.iceLb} lb · ` +
`${(configs.late.iceLb * PHYS.poundsToKg).toFixed(1)} kg`;
lateThicknessValue.textContent =
`${configs.late.insulationIn.toFixed(2)} in · ` +
`${Math.round(configs.late.insulationIn * 25.4)} mm`;
}
function updateReadouts() {
const earlyMass = massAt(earlySeries, journeyHours);
const lateMass = massAt(lateSeries, journeyHours);
const earlyHeat = heatLoadWatts(configs.early, journeyHours);
const lateHeat = heatLoadWatts(configs.late, journeyHours);
const earlyDry = emptyAt(earlySeries);
const lateDry = emptyAt(lateSeries);
timeReadout.textContent = `${journeyHours.toFixed(1).padStart(4, "0")} h`;
phaseReadout.textContent = phaseAt(journeyHours);
scenePhase.textContent = `${phaseAt(journeyHours)} · no re-icing`;
earlyStatus.textContent = `${earlyMass.toFixed(1)} kg remaining`;
lateStatus.textContent = `${lateMass.toFixed(1)} kg remaining`;
sceneEarlyMass.textContent = `${earlyMass.toFixed(1)} kg`;
sceneLateMass.textContent = `${lateMass.toFixed(1)} kg`;
sceneEarlyHeat.textContent = `Heat load: ${Math.round(earlyHeat)} W`;
sceneLateHeat.textContent = `Heat load: ${Math.round(lateHeat)} W`;
chartEarlyMass.textContent = `${earlyMass.toFixed(1)} kg`;
chartLateMass.textContent = `${lateMass.toFixed(1)} kg`;
chartEarlyDry.textContent =
earlyDry === null ? "> 72 h" : `${earlyDry.toFixed(1)} h`;
chartLateDry.textContent =
lateDry === null ? "> 72 h" : `${lateDry.toFixed(1)} h`;
journeyInput.value = journeyHours;
}
function refreshModel() {
configs.early.iceLb = Number(earlyIceInput.value);
configs.early.insulationIn = Number(earlyThicknessInput.value);
configs.late.iceLb = Number(lateIceInput.value);
configs.late.insulationIn = Number(lateThicknessInput.value);
earlySeries = simulate(configs.early);
lateSeries = simulate(configs.late);
updateInputLabels();
updateReadouts();
drawChart();
}
earlyIceInput.addEventListener("input", refreshModel);
earlyThicknessInput.addEventListener("input", refreshModel);
lateIceInput.addEventListener("input", refreshModel);
lateThicknessInput.addEventListener("input", refreshModel);
journeyInput.addEventListener("input", () => {
journeyHours = Number(journeyInput.value);
playing = false;
updatePlayButton();
updateReadouts();
drawChart();
});
function updatePlayButton() {
playButton.textContent = playing
? "❚❚ PAUSE JOURNEY"
: "▶ RUN JOURNEY";
}
playButton.addEventListener("click", () => {
if (journeyHours >= PHYS.durationHours) {
journeyHours = 0;
}
playing = !playing;
updatePlayButton();
});
resetButton.addEventListener("click", () => {
journeyHours = 0;
playing = false;
updatePlayButton();
updateReadouts();
drawChart();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let lastReadoutUpdate = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
journeyHours = Math.min(
PHYS.durationHours,
journeyHours + delta * 1.35
);
if (journeyHours >= PHYS.durationHours) {
playing = false;
updatePlayButton();
}
}
updateCamera();
updateCrate(earlyCrate, configs.early, journeyHours);
updateCrate(lateCrate, configs.late, journeyHours);
const activeStation =
journeyHours < 18 ? 0 :
journeyHours < 54 ? 1 : 2;
stationSprites.forEach((station, index) => {
station.sprite.material.opacity = index === activeStation ? 1 : 0.46;
station.glow.scale.setScalar(index === activeStation ? 1.3 : 0.75);
station.glow.material.emissiveIntensity =
index === activeStation ? 2.2 : 0.35;
});
if (clock.elapsedTime - lastReadoutUpdate > 0.08) {
updateReadouts();
drawChart();
lastReadoutUpdate = clock.elapsedTime;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
refreshModel();
loading.remove();
animate();
</script>
</body>
</html>
```