Prompt specification
Build or customize the Three.js 3D scene "Plan fictional resupply under stated storage limits" 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: Plan fictional resupply under stated storage limits
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plan-fictional-resupply-under-stated-storage-limits-x2580
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts maritime resupply around the Cape of Good Hope. Let users choose stops for a hypothetical vessel with explicit water and food capacities. Keep the logistics exercise separate from claims about the motives or treatment of historical populations. Low-poly.
Working Three.js Starter (plan-fictional-resupply-under-stated-storage-limits-x2580):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cape Resupply — Low-Poly Planning Sandbox</title>
<style>
:root {
--ink: #102d38;
--muted: #58727b;
--panel: rgba(247, 251, 250, 0.93);
--line: rgba(16, 45, 56, 0.14);
--teal: #087f78;
--teal-dark: #05635e;
--orange: #ed7d31;
--red: #b64242;
--green: #27865b;
--shadow: 0 14px 40px rgba(10, 35, 44, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b7d6de;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 16px;
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
#controlsPanel {
top: 14px;
left: 14px;
width: 350px;
max-height: calc(100vh - 28px);
overflow: auto;
padding: 18px;
}
#stopsPanel {
top: 14px;
right: 14px;
width: 318px;
max-height: calc(100vh - 28px);
overflow: auto;
padding: 16px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
h1 {
margin-bottom: 7px;
font-size: 24px;
line-height: 1.05;
letter-spacing: -0.035em;
}
h2 {
margin-bottom: 8px;
font-size: 16px;
}
.intro {
margin-bottom: 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.notice {
margin: 0 0 15px;
padding: 10px 11px;
border-left: 3px solid var(--orange);
border-radius: 7px;
background: rgba(237, 125, 49, 0.09);
color: #59483c;
font-size: 11px;
line-height: 1.45;
}
fieldset {
margin: 0 0 15px;
padding: 0;
border: 0;
}
legend {
width: 100%;
margin-bottom: 9px;
padding: 0 0 7px;
border-bottom: 1px solid var(--line);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.input-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
label.field {
display: block;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
label.field span {
display: block;
margin-bottom: 4px;
}
input[type="number"] {
width: 100%;
height: 35px;
padding: 6px 8px;
border: 1px solid rgba(16, 45, 56, 0.18);
border-radius: 8px;
outline: none;
background: rgba(255, 255, 255, 0.8);
color: var(--ink);
font: inherit;
font-size: 13px;
}
input[type="number"]:focus {
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(8, 127, 120, 0.1);
}
.check-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.check-row input {
accent-color: var(--teal);
}
.status {
margin: 9px 0 12px;
padding: 10px 11px;
border-radius: 9px;
background: rgba(39, 134, 91, 0.11);
color: #216542;
font-size: 12px;
font-weight: 750;
}
.status.short {
background: rgba(182, 66, 66, 0.12);
color: var(--red);
}
.status.neutral {
background: rgba(16, 45, 56, 0.07);
color: var(--muted);
}
.metric {
margin-bottom: 11px;
}
.metric-title {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
font-size: 11px;
font-weight: 750;
}
.metric-title span:last-child {
color: var(--muted);
font-weight: 650;
text-align: right;
}
.bar {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: rgba(16, 45, 56, 0.1);
}
.bar > div {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--teal);
transition: width 180ms ease;
}
.bar.food > div {
background: var(--orange);
}
.summary-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 12px 0;
}
.summary-card {
padding: 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
}
.summary-card small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.summary-card strong {
font-size: 12px;
line-height: 1.35;
}
details {
margin-top: 10px;
border-top: 1px solid var(--line);
padding-top: 9px;
}
summary {
cursor: pointer;
color: var(--muted);
font-size: 11px;
font-weight: 800;
text-transform: uppercase;
}
.leg-table {
width: 100%;
margin-top: 8px;
border-collapse: collapse;
font-size: 10px;
}
.leg-table th {
padding: 5px 4px;
border-bottom: 1px solid var(--line);
color: var(--muted);
text-align: left;
}
.leg-table td {
padding: 6px 4px;
border-bottom: 1px solid rgba(16, 45, 56, 0.08);
vertical-align: top;
}
.leg-table td:nth-child(2),
.leg-table td:nth-child(3),
.leg-table th:nth-child(2),
.leg-table th:nth-child(3) {
text-align: right;
white-space: nowrap;
}
.panel-note {
margin: 12px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#stopsPanel h2 {
display: flex;
align-items: center;
justify-content: space-between;
}
#stopsPanel h2 small {
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.stop-list {
display: grid;
gap: 7px;
margin-top: 11px;
}
.stop-row {
display: grid;
grid-template-columns: 26px minmax(0, 1fr) 25px 25px;
align-items: center;
gap: 5px;
min-height: 53px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.56);
}
.stop-row.start {
background: rgba(8, 127, 120, 0.08);
border-color: rgba(8, 127, 120, 0.2);
}
.stop-row input {
width: 16px;
height: 16px;
accent-color: var(--teal);
}
.stop-copy {
min-width: 0;
}
.stop-copy strong {
display: block;
overflow: hidden;
color: var(--ink);
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.stop-copy small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.stop-type {
color: var(--teal) !important;
font-weight: 750;
}
.icon-button {
width: 24px;
height: 24px;
padding: 0;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(255, 255, 255, 0.75);
color: var(--ink);
cursor: pointer;
font-size: 12px;
line-height: 1;
}
.icon-button:hover:not(:disabled) {
border-color: var(--teal);
color: var(--teal);
}
.icon-button:disabled {
opacity: 0.28;
cursor: default;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px;
margin-top: 12px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: flex;
align-items: center;
gap: 4px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
}
.dot.orange {
background: var(--orange);
}
.dot.gray {
background: #88979b;
}
#voyagePanel {
left: 50%;
bottom: 14px;
display: grid;
grid-template-columns: auto minmax(180px, 1fr) auto;
align-items: center;
gap: 13px;
width: min(690px, calc(100vw - 28px));
padding: 11px 13px;
transform: translateX(-50%);
}
button.primary,
button.secondary {
height: 35px;
padding: 0 13px;
border-radius: 8px;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 800;
}
button.primary {
border: 1px solid var(--teal-dark);
background: var(--teal);
color: white;
}
button.primary:hover {
background: var(--teal-dark);
}
button.secondary {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.75);
color: var(--ink);
}
#progress {
width: 100%;
accent-color: var(--teal);
}
#voyageStatus {
min-width: 145px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
text-align: right;
}
#mapHint {
position: fixed;
z-index: 4;
left: 380px;
bottom: 18px;
padding: 7px 10px;
border-radius: 7px;
background: rgba(16, 45, 56, 0.72);
color: white;
font-size: 9px;
pointer-events: none;
}
@media (max-width: 820px) {
#controlsPanel {
top: 8px;
left: 8px;
width: min(330px, calc(100vw - 16px));
max-height: 48vh;
}
#stopsPanel {
top: auto;
right: 8px;
bottom: 68px;
width: min(310px, calc(100vw - 16px));
max-height: 43vh;
}
#voyagePanel {
bottom: 8px;
grid-template-columns: auto 1fr;
}
#voyageStatus {
display: none;
}
#mapHint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="controlsPanel" class="panel">
<div class="eyebrow">Maritime logistics sandbox</div>
<h1>Cape Resupply</h1>
<p class="intro">
Choose a route around the Cape of Good Hope, then test whether the
vessel’s water and food stores can support the voyage.
</p>
<div class="notice">
<strong>Planning exercise only.</strong> Stops, refill assumptions,
port availability, and capacities are hypothetical abstractions.
This scene makes no claim about historical motives, encounters, labor,
or the treatment of Indigenous and other populations.
</div>
<fieldset>
<legend>Vessel and consumption</legend>
<div class="input-grid">
<label class="field">
<span>Crew</span>
<input id="crew" type="number" min="1" step="1" value="12">
</label>
<label class="field">
<span>Speed (knots)</span>
<input id="speed" type="number" min="1" step="0.5" value="12">
</label>
<label class="field">
<span>Water capacity (L)</span>
<input id="waterCapacity" type="number" min="0" step="10" value="420">
</label>
<label class="field">
<span>Food capacity (kg)</span>
<input id="foodCapacity" type="number" min="0" step="5" value="120">
</label>
<label class="field">
<span>Water per person/day (L)</span>
<input id="waterRate" type="number" min="0" step="0.5" value="12">
</label>
<label class="field">
<span>Food per person/day (kg)</span>
<input id="foodRate" type="number" min="0" step="0.5" value="4">
</label>
<label class="field">
<span>Safety reserve (%)</span>
<input id="reserve" type="number" min="0" max="200" step="5" value="20">
</label>
</div>
<label class="check-row">
<input id="refill" type="checkbox" checked>
<span>
Refill water and food to full capacity at each selected supply stop.
Cape Agulhas is treated only as a waypoint.
</span>
</label>
</fieldset>
<div id="status" class="status neutral">Choose at least one stop.</div>
<div class="summary-grid">
<div class="summary-card">
<small>Route</small>
<strong id="routeTotal">0 km · 0 h</strong>
</div>
<div class="summary-card">
<small>Peak interval</small>
<strong id="peakInterval">No interval</strong>
</div>
</div>
<div class="metric">
<div class="metric-title">
<span>Water requirement</span>
<span id="waterText">0 L of 420 L</span>
</div>
<div class="bar"><div id="waterBar"></div></div>
</div>
<div class="metric">
<div class="metric-title">
<span>Food requirement</span>
<span id="foodText">0 kg of 120 kg</span>
</div>
<div class="bar food"><div id="foodBar"></div></div>
</div>
<details>
<summary>Voyage legs</summary>
<table class="leg-table">
<thead>
<tr>
<th>Leg</th>
<th>Distance</th>
<th>Time</th>
</tr>
</thead>
<tbody id="legRows"></tbody>
</table>
</details>
<p class="panel-note">
Reserve is applied as a percentage margin to the calculated consumption
of the longest unsupplied interval. Geographic distances are approximate.
</p>
</section>
<section id="stopsPanel" class="panel">
<h2>
Route stops
<small>Selected in listed order</small>
</h2>
<p class="intro">
Use the arrows to reorder stops. Clicking a map marker also toggles a stop.
</p>
<div id="stopList" class="stop-list"></div>
<div class="legend">
<span><i class="dot"></i> Supply candidate</span>
<span><i class="dot orange"></i> Waypoint</span>
<span><i class="dot gray"></i> Not selected</span>
</div>
<p class="panel-note">
Geographic names provide orientation only. “Offshore Alpha” is entirely
fictional. No real port capacity or historical trading arrangement is
represented.
</p>
</section>
<section id="voyagePanel" class="panel">
<button id="playButton" class="primary" type="button">Play voyage</button>
<input id="progress" type="range" min="0" max="1" step="0.1" value="0">
<div id="voyageStatus">Vessel at Cape Town</div>
<button id="resetButton" class="secondary" type="button">Reset</button>
</section>
<div id="mapHint">
Drag: rotate · Shift/right-drag: pan · Wheel: zoom
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scenario data
// -------------------------------------------------------------------------
const START = {
id: "start",
name: "Cape Town",
sub: "Fixed departure point",
lon: 18.42,
lat: -33.92,
type: "start"
};
const stops = [
{
id: "simons",
name: "Simon's Town",
sub: "Supply candidate",
lon: 18.44,
lat: -34.19,
type: "supply",
selected: true
},
{
id: "agulhas",
name: "Cape Agulhas",
sub: "Waypoint; no refill",
lon: 20.00,
lat: -34.83,
type: "waypoint",
selected: true
},
{
id: "gqeberha",
name: "Gqeberha",
sub: "Supply candidate",
lon: 25.61,
lat: -33.96,
type: "supply",
selected: true
},
{
id: "eastlondon",
name: "East London",
sub: "Supply candidate",
lon: 27.91,
lat: -33.02,
type: "supply",
selected: false
},
{
id: "durban",
name: "Durban",
sub: "Supply candidate",
lon: 31.02,
lat: -29.87,
type: "supply",
selected: true
},
{
id: "alpha",
name: "Offshore Alpha",
sub: "Fictional transfer point",
lon: 22.40,
lat: -37.00,
type: "supply",
selected: false
}
];
const $ = (selector) => document.querySelector(selector);
const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
function selectedStops() {
return stops.filter((stop) => stop.selected);
}
function mapPosition(lon, lat) {
return new THREE.Vector3(lon * 70, 0, -lat * 70);
}
function haversineKm(a, b) {
const toRad = Math.PI / 180;
const dLat = (b.lat - a.lat) * toRad;
const dLon = (b.lon - a.lon) * toRad;
const lat1 = a.lat * toRad;
const lat2 = b.lat * toRad;
const value =
Math.sin(dLat / 2) ** 2 +
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) ** 2;
return 6371 * 2 * Math.atan2(Math.sqrt(value), Math.sqrt(1 - value));
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(421);
// -------------------------------------------------------------------------
// Renderer, scene, lights
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d7df);
scene.fog = new THREE.Fog(0xb8d7df, 2350, 4200);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
1,
6000
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
$("#scene").appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xdff6ff, 0x796a48, 2.15));
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(950, 1550, 1050);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -1500;
sun.shadow.camera.right = 1500;
sun.shadow.camera.top = 1300;
sun.shadow.camera.bottom = -1300;
sun.shadow.camera.near = 100;
sun.shadow.camera.far = 3500;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x78b7ce, 0.7);
fill.position.set(-700, 700, 1400);
scene.add(fill);
// -------------------------------------------------------------------------
// Low-poly ocean and land
// -------------------------------------------------------------------------
function buildOcean() {
const geometry = new THREE.PlaneGeometry(2550, 1950, 32, 24);
geometry.rotateX(-Math.PI / 2);
geometry.translate(1600, 0, 2180);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const z = positions.getZ(i);
const wave =
Math.sin(x * 0.014 + z * 0.006) * 1.7 +
Math.cos(z * 0.019 - x * 0.003) * 1.2 +
Math.sin((x + z) * 0.031) * 0.55;
positions.setY(i, wave);
}
const faceted = geometry.toNonIndexed();
geometry.dispose();
const colors = [];
const color = new THREE.Color();
for (let i = 0; i < faceted.attributes.position.count; i += 3) {
const shade = 0.49 + random() * 0.035;
color.setHSL(0.535 + random() * 0.012, 0.48, shade);
for (let j = 0; j < 3; j++) {
colors.push(color.r, color.g, color.b);
}
}
faceted.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
faceted.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.83,
metalness: 0.03,
flatShading: true,
side: THREE.DoubleSide
});
const ocean = new THREE.Mesh(faceted, material);
ocean.receiveShadow = true;
scene.add(ocean);
}
const coastContour = [
[14.0, -22.0],
[14.6, -25.0],
[15.5, -28.5],
[17.2, -32.2],
[18.2, -33.8],
[18.4, -34.4],
[19.2, -34.55],
[20.0, -34.83],
[22.0, -34.95],
[23.5, -34.4],
[25.0, -34.1],
[25.8, -34.0],
[27.0, -33.4],
[28.3, -32.4],
[29.8, -31.2],
[31.0, -30.0],
[32.4, -28.8],
[31.8, -26.8],
[31.0, -25.4],
[30.0, -24.8],
[28.0, -25.4],
[26.0, -24.5],
[24.0, -23.0],
[22.0, -22.0],
[18.0, -22.0]
];
function terrainHeight(x, z) {
return (
7 +
Math.sin(x * 0.011 + z * 0.008) * 4 +
Math.cos(z * 0.018) * 3 +
random() * 5
);
}
function buildLand() {
const contour = coastContour.map(
([lon, lat]) => new THREE.Vector2(lon * 70, lat * 70)
);
const triangles = THREE.ShapeUtils.triangulateShape(contour, []);
const positions = [];
const colors = [];
const baseColor = new THREE.Color();
for (const triangle of triangles) {
baseColor.setHSL(
0.235 + random() * 0.035,
0.28 + random() * 0.09,
0.33 + random() * 0.055
);
for (const index of triangle) {
const point = contour[index];
const x = point.x;
const z = -point.y;
positions.push(x, terrainHeight(x, z), z);
colors.push(baseColor.r, baseColor.g, baseColor.b);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const land = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
flatShading: true,
side: THREE.DoubleSide
})
);
land.receiveShadow = true;
land.castShadow = true;
scene.add(land);
// A dark low-poly coastal skirt.
const skirtPositions = [];
for (let i = 0; i < coastContour.length; i++) {
const next = (i + 1) % coastContour.length;
const a = coastContour[i];
const b = coastContour[next];
const ax = a[0] * 70;
const az = -a[1] * 70;
const bx = b[0] * 70;
const bz = -b[1] * 70;
skirtPositions.push(
ax, 7, az,
ax, -4, az,
bx, -4, bz,
ax, 7, az,
bx, -4, bz,
bx, 7, bz
);
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(skirtPositions, 3)
);
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({
color: 0x79664b,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
scene.add(skirt);
const mountainData = [
[16.8, -25.8, 42, 92],
[19.0, -27.6, 50, 115],
[21.6, -28.8, 42, 88],
[24.1, -28.4, 56, 126],
[26.7, -29.4, 44, 98],
[28.2, -27.2, 38, 82],
[29.4, -25.9, 44, 104],
[18.6, -30.0, 35, 72],
[22.4, -24.6, 34, 70]
];
for (const [lon, lat, radius, height] of mountainData) {
const geometry = new THREE.ConeGeometry(radius, height, 5);
const material = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(
0.19 + random() * 0.04,
0.18,
0.31 + random() * 0.06
),
roughness: 1,
flatShading: true
});
const mountain = new THREE.Mesh(geometry, material);
mountain.position.set(lon * 70, height * 0.5 + 7, -lat * 70);
mountain.rotation.y = random() * Math.PI;
mountain.castShadow = true;
mountain.receiveShadow = true;
scene.add(mountain);
}
}
function makeLabel(text, options = {}) {
const {
color = "#173b46",
background = "rgba(248,252,250,0.91)",
width = 150,
height = 27,
fontSize = 23
} = options;
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = background;
context.strokeStyle = "rgba(16,45,56,0.18)";
context.lineWidth = 3;
context.beginPath();
context.roundRect(3, 3, 634, 106, 20);
context.fill();
context.stroke();
context.fillStyle = color;
context.font = `700 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 320, 58);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
function buildGridAndLabels() {
const gridMaterial = new THREE.LineBasicMaterial({
color: 0xd6f0ef,
transparent: true,
opacity: 0.2
});
for (let lon = 15; lon <= 33; lon += 2) {
const points = [];
for (let lat = -38.5; lat <= -22.4; lat += 0.5) {
points.push(mapPosition(lon, lat).setY(3.8));
}
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
gridMaterial
)
);
}
for (let lat = -25; lat >= -38; lat -= 2.5) {
const points = [];
for (let lon = 13.5; lon <= 33; lon += 0.5) {
points.push(mapPosition(lon, lat).setY(3.8));
}
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
gridMaterial
)
);
}
const capeLabel = makeLabel("CAPE OF GOOD HOPE", {
width: 220,
height: 35,
fontSize: 27,
color: "#314d3e"
});
capeLabel.position.copy(mapPosition(18.7, -34.35)).setY(92);
scene.add(capeLabel);
const atlantic = makeLabel("ATLANTIC OCEAN", {
width: 205,
height: 31,
fontSize: 25,
color: "#2b6876"
});
atlantic.position.copy(mapPosition(15.8, -31.8)).setY(30);
scene.add(atlantic);
const indian = makeLabel("INDIAN OCEAN", {
width: 195,
height: 31,
fontSize: 25,
color: "#2b6876"
});
indian.position.copy(mapPosition(30.3, -34.7)).setY(30);
scene.add(indian);
}
// -------------------------------------------------------------------------
// Markers
// -------------------------------------------------------------------------
const markerMap = new Map();
const markerPickMeshes = [];
function markerColor(type) {
if (type === "start") return 0x176f9b;
if (type === "waypoint") return 0xed7d31;
return 0x087f78;
}
function createMarker(stop) {
const group = new THREE.Group();
group.position.copy(mapPosition(stop.lon, stop.lat));
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(2.2, 2.2, 42, 6),
new THREE.MeshStandardMaterial({
color: 0xf4f5ec,
roughness: 0.7,
flatShading: true
})
);
pole.position.y = 21;
pole.castShadow = true;
group.add(pole);
const core = new THREE.Mesh(
new THREE.OctahedronGeometry(13, 0),
new THREE.MeshStandardMaterial({
color: markerColor(stop.type),
roughness: 0.55,
flatShading: true
})
);
core.position.y = 48;
core.castShadow = true;
core.userData.stopId = stop.id;
group.add(core);
markerPickMeshes.push(core);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(18, 2.4, 6, 24),
new THREE.MeshBasicMaterial({
color: markerColor(stop.type),
transparent: true,
opacity: 0.8
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 6;
group.add(ring);
const label = makeLabel(stop.name, {
width: stop.type === "start" ? 135 : 145,
height: 27,
fontSize: 22
});
label.position.y = 79;
group.add(label);
scene.add(group);
markerMap.set(stop.id, { group, core, ring, label, stop });
}
function updateMarkerStates() {
for (const stop of stops) {
const marker = markerMap.get(stop.id);
if (!marker) continue;
const active = stop.selected;
const color = active
? markerColor(stop.type)
: 0x87979a;
marker.core.material.color.setHex(color);
marker.ring.material.color.setHex(color);
marker.ring.material.opacity = active ? 0.82 : 0.25;
marker.core.scale.setScalar(active ? 1 : 0.78);
}
}
// -------------------------------------------------------------------------
// Low-poly vessel
// -------------------------------------------------------------------------
function createHullGeometry() {
const top = [
[-7, 5, -34],
[7, 5, -34],
[9, 5, 22],
[0, 5, 40],
[-9, 5, 22]
];
const bottom = top.map(([x, y, z]) => [x * 0.63, -4, z * 0.92]);
const positions = [];
const indices = [];
// Deck fan.
for (let i = 0; i < top.length; i++) {
const next = (i + 1) % top.length;
indices.push(0, i + 1, next + 1);
}
top.forEach((point) => positions.push(...point));
const base = top.length;
for (let i = 0; i < top.length; i++) {
const next = (i + 1) % top.length;
indices.push(
base + i,
base + next,
next,
base + i,
next,
i
);
}
bottom.forEach((point) => positions.push(...point));
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createVessel() {
const vessel = new THREE.Group();
const hull = new THREE.Mesh(
createHullGeometry(),
new THREE.MeshStandardMaterial({
color: 0x153f52,
roughness: 0.65,
flatShading: true,
side: THREE.DoubleSide
})
);
hull.castShadow = true;
vessel.add(hull);
const deck = new THREE.Mesh(
new THREE.BoxGeometry(15, 2, 30),
new THREE.MeshStandardMaterial({
color: 0xd9c79c,
roughness: 0.85,
flatShading: true
})
);
deck.position.set(0, 7, 5);
deck.castShadow = true;
vessel.add(deck);
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(11, 11, 13),
new THREE.MeshStandardMaterial({
color: 0xf1eee2,
roughness: 0.7,
flatShading: true
})
);
cabin.position.set(0, 12, 11);
cabin.castShadow = true;
vessel.add(cabin);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x4a9fb2,
emissive: 0x153b43,
emissiveIntensity: 0.35,
roughness: 0.4,
flatShading: true
});
for (const side of [-1, 1]) {
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.7, 3.5, 7),
windowMaterial
);
windowMesh.position.set(side * 5.6, 13, 11);
vessel.add(windowMesh);
}
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(1.1, 1.4, 32, 6),
new THREE.MeshStandardMaterial({
color: 0xe7e2d5,
roughness: 0.7,
flatShading: true
})
);
mast.position.set(0, 26, 4);
mast.castShadow = true;
vessel.add(mast);
const containerColors = [0xe77735, 0x3e8f83, 0xd9b64e];
for (let i = 0; i < 3; i++) {
const container = new THREE.Mesh(
new THREE.BoxGeometry(10, 7, 13),
new THREE.MeshStandardMaterial({
color: containerColors[i],
roughness: 0.82,
flatShading: true
})
);
container.position.set(0, 12, -8 - i * 0);
container.position.x = i === 1 ? 0 : 0;
container.position.z = -13 + (i % 2) * 13;
container.castShadow = true;
vessel.add(container);
}
const flag = new THREE.Mesh(
new THREE.ConeGeometry(4, 12, 3),
new THREE.MeshStandardMaterial({
color: 0xed7d31,
roughness: 0.8,
flatShading: true
})
);
flag.rotation.z = -Math.PI / 2;
flag.position.set(7, 35, 4);
vessel.add(flag);
vessel.scale.setScalar(1.18);
scene.add(vessel);
return vessel;
}
// -------------------------------------------------------------------------
// Route rendering
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const state = {
legs: [],
routePoints: [],
routeKm: [],
totalKm: 0,
progressKm: 0,
playing: false
};
function disposeRoute() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
}
}
function buildRoute() {
disposeRoute();
const selected = selectedStops();
const points = [START, ...selected];
state.routePoints = points.map((stop) =>
mapPosition(stop.lon, stop.lat)
);
state.routeKm = [];
for (let i = 0; i < points.length - 1; i++) {
const distance = haversineKm(points[i], points[i + 1]);
state.routeKm.push(distance);
const start = state.routePoints[i];
const end = state.routePoints[i + 1];
const direction = end.clone().sub(start);
const length = direction.length();
if (length < 0.001) continue;
const routeSegment = new THREE.Mesh(
new THREE.CylinderGeometry(2.8, 2.8, length, 6),
new THREE.MeshBasicMaterial({
color: 0xf39a43,
transparent: true,
opacity: 0.88
})
);
routeSegment.position.copy(start).add(end).multiplyScalar(0.5);
routeSegment.position.y = 8;
routeSegment.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
routeSegment.userData.isRoute = true;
routeGroup.add(routeSegment);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(8, 19, 3),
new THREE.MeshBasicMaterial({ color: 0xffc06c })
);
arrow.position.copy(start).lerp(end, 0.56);
arrow.position.y = 12;
arrow.quaternion.copy(routeSegment.quaternion);
routeGroup.add(arrow);
}
state.totalKm = state.routeKm.reduce((sum, value) => sum + value, 0);
state.progressKm = 0;
state.playing = false;
$("#progress").max = Math.max(1, state.totalKm);
$("#progress").value = 0;
$("#playButton").textContent = "Play voyage";
updateVessel();
}
// -------------------------------------------------------------------------
// Logistics calculations
// -------------------------------------------------------------------------
function readSettings() {
return {
crew: Math.max(1, Number($("#crew").value) || 1),
speed: Math.max(0.1, Number($("#speed").value) || 0.1),
waterCapacity: Math.max(0, Number($("#waterCapacity").value) || 0),
foodCapacity: Math.max(0, Number($("#foodCapacity").value) || 0),
waterRate: Math.max(0, Number($("#waterRate").value) || 0),
foodRate: Math.max(0, Number($("#foodRate").value) || 0),
reserve: Math.max(0, Number($("#reserve").value) || 0),
refill: $("#refill").checked
};
}
function calculatePlan() {
const settings = readSettings();
const selected = selectedStops();
const sequence = [START, ...selected];
const legs = [];
for (let i = 0; i < sequence.length - 1; i++) {
const from = sequence[i];
const to = sequence[i + 1];
const distance = haversineKm(from, to);
const hours = distance / (settings.speed * 1.852);
const days = hours / 24;
const water = settings.waterRate * settings.crew * days;
const food = settings.foodRate * settings.crew * days;
legs.push({
from,
to,
distance,
hours,
days,
water,
food,
refill: settings.refill && to.type === "supply"
});
}
const cycles = [];
let cycleWater = 0;
let cycleFood = 0;
let cycleDistance = 0;
let cycleFrom = START.name;
for (const leg of legs) {
cycleWater += leg.water;
cycleFood += leg.food;
cycleDistance += leg.distance;
if (leg.refill) {
cycles.push({
water: cycleWater,
food: cycleFood,
distance: cycleDistance,
from: cycleFrom,
to: leg.to.name
});
cycleWater = 0;
cycleFood = 0;
cycleDistance = 0;
cycleFrom = leg.to.name;
}
}
if (cycleWater > 0 || cycleFood > 0 || cycleDistance > 0) {
cycles.push({
water: cycleWater,
food: cycleFood,
distance: cycleDistance,
from: cycleFrom,
to: legs.length ? legs[legs.length - 1].to.name : START.name
});
}
const peakWater = cycles.reduce(
(max, cycle) => Math.max(max, cycle.water),
0
);
const peakFood = cycles.reduce(
(max, cycle) => Math.max(max, cycle.food),
0
);
const reserveMultiplier = 1 + settings.reserve / 100;
const requiredWater = peakWater * reserveMultiplier;
const requiredFood = peakFood * reserveMultiplier;
const peakCycle = cycles.reduce(
(best, cycle) => (!best || cycle.distance > best.distance ? cycle : best),
null
);
const totalDistance = legs.reduce((sum, leg) => sum + leg.distance, 0);
const totalHours = legs.reduce((sum, leg) => sum + leg.hours, 0);
return {
settings,
legs,
cycles,
peakWater,
peakFood,
requiredWater,
requiredFood,
peakCycle,
totalDistance,
totalHours
};
}
function renderSummary(plan) {
const {
settings,
legs,
peakCycle,
requiredWater,
requiredFood,
totalDistance,
totalHours
} = plan;
const waterShort = Math.max(0, requiredWater - settings.waterCapacity);
const foodShort = Math.max(0, requiredFood - settings.foodCapacity);
const status = $("#status");
if (!legs.length) {
status.className = "status neutral";
status.textContent = "Choose at least one stop to calculate a voyage.";
} else if (waterShort > 0 || foodShort > 0) {
const shortages = [];
if (waterShort > 0) {
shortages.push(`${Math.ceil(waterShort)} L more water`);
}
if (foodShort > 0) {
shortages.push(`${Math.ceil(foodShort)} kg more food`);
}
status.className = "status short";
status.textContent = `Capacity short: ${shortages.join(" and ")}.`;
} else {
status.className = "status";
status.textContent = "Feasible with the selected reserve.";
}
$("#routeTotal").textContent =
`${Math.round(totalDistance).toLocaleString()} km · ` +
`${totalHours.toFixed(1)} h`;
if (peakCycle) {
$("#peakInterval").textContent =
`${settings.refill ? "Peak refill interval" : "Cumulative voyage"}: ` +
`${Math.round(peakCycle.distance).toLocaleString()} km`;
} else {
$("#peakInterval").textContent = "No interval";
}
const waterCapacity = Math.max(1, settings.waterCapacity);
const foodCapacity = Math.max(1, settings.foodCapacity);
$("#waterText").textContent =
`${Math.ceil(requiredWater).toLocaleString()} L of ` +
`${settings.waterCapacity.toLocaleString()} L`;
$("#foodText").textContent =
`${Math.ceil(requiredFood).toLocaleString()} kg of ` +
`${settings.foodCapacity.toLocaleString()} kg`;
$("#waterBar").style.width =
`${clamp((requiredWater / waterCapacity) * 100, 0, 100)}%`;
$("#foodBar").style.width =
`${clamp((requiredFood / foodCapacity) * 100, 0, 100)}%`;
$("#waterBar").style.background =
waterShort > 0 ? "var(--red)" : "var(--teal)";
$("#foodBar").style.background =
foodShort > 0 ? "var(--red)" : "var(--orange)";
$("#legRows").innerHTML = legs.length
? legs
.map((leg) => `
<tr>
<td>
${leg.from.name} → ${leg.to.name}
${leg.refill ? "<br><span style='color:#087f78'>Refill</span>" : ""}
</td>
<td>${Math.round(leg.distance).toLocaleString()} km</td>
<td>${leg.hours.toFixed(1)} h</td>
</tr>
`)
.join("")
: `<tr><td colspan="3">No legs selected.</td></tr>`;
}
// -------------------------------------------------------------------------
// Stop list
// -------------------------------------------------------------------------
function renderStopList() {
const list = $("#stopList");
const selectedOrder = new Map(
selectedStops().map((stop, index) => [stop.id, index + 1])
);
const startRow = `
<div class="stop-row start">
<input type="checkbox" checked disabled aria-label="Cape Town fixed start">
<div class="stop-copy">
<strong>Cape Town</strong>
<small class="stop-type">Fixed departure point</small>
</div>
<span></span>
<span></span>
</div>
`;
const stopRows = stops
.map((stop, index) => {
const order = selectedOrder.get(stop.id);
return `
<div class="stop-row">
<input
type="checkbox"
data-id="${stop.id}"
${stop.selected ? "checked" : ""}
aria-label="Include ${stop.name}"
>
<div class="stop-copy">
<strong>${stop.name}</strong>
<small class="${stop.type === "waypoint" ? "" : "stop-type"}">
${stop.type === "waypoint" ? "Waypoint" : "Supply candidate"}
${order ? ` · #${order}` : ""}
</small>
</div>
<button
class="icon-button"
data-action="up"
data-id="${stop.id}"
${index === 0 ? "disabled" : ""}
aria-label="Move ${stop.name} earlier"
>▲</button>
<button
class="icon-button"
data-action="down"
data-id="${stop.id}"
${index === stops.length - 1 ? "disabled" : ""}
aria-label="Move ${stop.name} later"
>▼</button>
</div>
`;
})
.join("");
list.innerHTML = startRow + stopRows;
}
function moveStop(id, direction) {
const index = stops.findIndex((stop) => stop.id === id);
const target = index + direction;
if (index < 0 || target < 0 || target >= stops.length) return;
[stops[index], stops[target]] = [stops[target], stops[index]];
renderStopList();
recalculate();
}
// -------------------------------------------------------------------------
// Voyage animation
// -------------------------------------------------------------------------
const vessel = createVessel();
const clock = new THREE.Clock();
function updateVessel() {
if (!state.routePoints.length) {
vessel.position.copy(mapPosition(START.lon, START.lat));
vessel.position.y = 10;
return;
}
let remaining = clamp(state.progressKm, 0, state.totalKm);
let segmentIndex = 0;
while (
segmentIndex < state.routeKm.length - 1 &&
remaining > state.routeKm[segmentIndex]
) {
remaining -= state.routeKm[segmentIndex];
segmentIndex++;
}
const segmentDistance = state.routeKm[segmentIndex] || 1;
const fraction = clamp(remaining / segmentDistance, 0, 1);
const start = state.routePoints[segmentIndex];
const end = state.routePoints[segmentIndex + 1] || start;
const position = start.clone().lerp(end, fraction);
const direction = end.clone().sub(start);
if (direction.lengthSq() > 0.0001) {
const yaw = Math.atan2(-direction.x, -direction.z);
vessel.rotation.y = yaw;
}
vessel.position.copy(position);
vessel.position.y = 10 + Math.sin(clock.elapsedTime * 2.4) * 0.7;
}
function updateVoyageStatus() {
const progress = $("#progress");
const status = $("#voyageStatus");
progress.value = state.progressKm;
if (!state.legs.length) {
status.textContent = "Vessel at Cape Town";
return;
}
if (state.progressKm <= 0.01) {
status.textContent = "Vessel at Cape Town";
return;
}
if (state.progressKm >= state.totalKm - 0.01) {
const last = state.legs[state.legs.length - 1];
status.textContent = `Arrived at ${last.to.name}`;
return;
}
let accumulated = 0;
for (const leg of state.legs) {
accumulated += leg.distance;
if (state.progressKm <= accumulated) {
status.textContent =
`${leg.from.name} → ${leg.to.name} · ` +
`${Math.round(leg.distance).toLocaleString()} km`;
break;
}
}
}
function resetVoyage() {
state.progressKm = 0;
state.playing = false;
$("#playButton").textContent = "Play voyage";
$("#progress").value = 0;
updateVessel();
updateVoyageStatus();
}
function recalculate() {
const plan = calculatePlan();
state.legs = plan.legs;
renderSummary(plan);
updateMarkerStates();
buildRoute();
}
$("#playButton").addEventListener("click", () => {
if (!state.totalKm) return;
if (state.progressKm >= state.totalKm - 0.01) {
state.progressKm = 0;
}
state.playing = !state.playing;
$("#playButton").textContent = state.playing ? "Pause voyage" : "Play voyage";
});
$("#resetButton").addEventListener("click", resetVoyage);
$("#progress").addEventListener("input", (event) => {
state.progressKm = Number(event.target.value);
state.playing = false;
$("#playButton").textContent = "Play voyage";
updateVessel();
updateVoyageStatus();
});
document.querySelectorAll(
"#crew, #speed, #waterCapacity, #foodCapacity, #waterRate, #foodRate, #reserve, #refill"
).forEach((element) => {
element.addEventListener("input", recalculate);
element.addEventListener("change", recalculate);
});
$("#stopList").addEventListener("change", (event) => {
if (!event.target.matches("input[type='checkbox']")) return;
const stop = stops.find((item) => item.id === event.target.dataset.id);
if (!stop) return;
stop.selected = event.target.checked;
renderStopList();
recalculate();
});
$("#stopList").addEventListener("click", (event) => {
const button = event.target.closest("button[data-action]");
if (!button) return;
const direction = button.dataset.action === "up" ? -1 : 1;
moveStop(button.dataset.id, direction);
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, and marker picking
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(1570, 0, 2200),
spherical: new THREE.Spherical(1580, 0.91, 0.86),
pointerId: null,
dragging: false,
panning: false,
moved: false,
lastX: 0,
lastY: 0
};
camera.position.copy(controls.target).add(
new THREE.Vector3().setFromSpherical(controls.spherical)
);
camera.lookAt(controls.target);
function applyCamera() {
const offset = new THREE.Vector3().setFromSpherical(controls.spherical);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickMarker(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(markerPickMeshes, false)[0];
if (!hit) return;
const stop = stops.find((item) => item.id === hit.object.userData.stopId);
if (!stop) return;
stop.selected = !stop.selected;
renderStopList();
recalculate();
}
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
if (controls.pointerId !== null) return;
controls.pointerId = event.pointerId;
controls.dragging = true;
controls.panning = event.button === 2 || event.shiftKey;
controls.moved = false;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging || event.pointerId !== controls.pointerId) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
controls.moved = true;
}
if (controls.panning) {
const scale = controls.spherical.radius * 0.0012;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
controls.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
controls.target.y = 0;
const offset = camera.position.clone().sub(controls.target);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
} else {
controls.spherical.theta -= dx * 0.005;
controls.spherical.phi = clamp(
controls.spherical.phi - dy * 0.005,
0.22,
1.45
);
applyCamera();
}
});
function endPointer(event) {
if (event.pointerId !== controls.pointerId) return;
if (!controls.moved && event.button === 0) {
pickMarker(event);
}
controls.pointerId = null;
controls.dragging = false;
controls.panning = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.spherical.radius = clamp(
controls.spherical.radius * Math.exp(event.deltaY * 0.001),
340,
3200
);
applyCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Initialization and render loop
// -------------------------------------------------------------------------
buildOcean();
buildLand();
buildGridAndLabels();
createMarker(START);
stops.forEach(createMarker);
renderStopList();
recalculate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing && state.totalKm > 0) {
const visualSpeed = Math.max(35, state.totalKm / 18);
state.progressKm = Math.min(
state.totalKm,
state.progressKm + visualSpeed * delta
);
if (state.progressKm >= state.totalKm) {
state.playing = false;
$("#playButton").textContent = "Play voyage";
}
updateVoyageStatus();
}
updateVessel();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```