Prompt specification
Build or customize the Three.js 3D scene "Navigator comparing noon with a ship clock" 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: Navigator comparing noon with a ship clock
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/navigator-comparing-noon-with-a-ship-clock-x2486
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a technical cutaway of a historically referenced navigator's desk. Place a marine chronometer in its protective case, a local-noon observation marker, and a small globe with a reference meridian beside a paper-like angular diagram. Let the user adjust a hypothetical difference between local solar time and the clock's reference time; convert that difference into longitude using the stated simplified rule of fifteen degrees per hour, with a clearly defined east-west sign convention. Link the globe marker and angular diagram to the same value. Source the instrument's period appearance and avoid inventing a particular navigator's log entry. Show an example on either side of the reference meridian, with the clock difference and signed angle changing together across zero.
Working Three.js Starter (navigator-comparing-noon-with-a-ship-clock-x2486):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Navigator's Desk — Meridian Cutaway</title>
<style>
:root {
color-scheme: dark;
--ink: #e8f0f3;
--muted: #9fb1ba;
--panel: rgba(12, 23, 32, 0.88);
--panel-border: rgba(157, 194, 208, 0.22);
--accent: #64d4cf;
--warm: #e8b86d;
--east: #ff896d;
--west: #70b9ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09121a;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, summary { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 42%, transparent 38%, rgba(3, 8, 12, 0.34) 100%),
linear-gradient(180deg, rgba(5, 11, 16, 0.26), transparent 28%);
}
.masthead {
position: fixed;
top: 20px;
left: 22px;
max-width: 520px;
pointer-events: none;
text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 6px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 42px);
font-weight: 500;
line-height: 1;
}
.subtitle {
margin: 0;
color: #b9c8ce;
font-size: 12px;
line-height: 1.5;
}
.panel {
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 14px;
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(15px) saturate(1.15);
-webkit-backdrop-filter: blur(15px) saturate(1.15);
}
.controls {
position: fixed;
top: 122px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 18px;
}
.panel-title {
margin: 0 0 4px;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.04em;
}
.panel-subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 12px;
}
.readout {
min-width: 0;
padding: 11px 12px;
border: 1px solid rgba(174, 206, 218, 0.14);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.readout-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.readout-value {
display: block;
overflow: hidden;
color: #f3f8fa;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 19px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
#longitudeValue { color: var(--accent); }
.range-wrap { margin: 16px 0 9px; }
input[type="range"] {
width: 100%;
height: 24px;
margin: 0;
cursor: ew-resize;
accent-color: var(--accent);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.range-labels .west { color: var(--west); }
.range-labels .east { color: var(--east); }
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin: 14px 0;
}
.preset {
padding: 9px 6px;
border: 1px solid rgba(174, 206, 218, 0.16);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: var(--ink);
cursor: pointer;
transition: 140ms ease;
}
.preset:hover,
.preset:focus-visible {
border-color: rgba(100, 212, 207, 0.65);
background: rgba(100, 212, 207, 0.08);
outline: none;
}
.preset.active {
border-color: var(--accent);
background: rgba(100, 212, 207, 0.13);
}
.preset strong {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.preset span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.equation {
padding: 10px 12px;
border-left: 2px solid var(--warm);
background: rgba(232, 184, 109, 0.06);
color: #d5e0e4;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
line-height: 1.55;
}
.clock-row {
display: flex;
justify-content: space-between;
gap: 12px;
margin: 12px 0;
padding-top: 12px;
border-top: 1px solid rgba(174, 206, 218, 0.12);
font-size: 10px;
}
.clock-row span:first-child { color: var(--muted); }
.clock-row span:last-child {
color: #eef5f7;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: right;
}
.convention {
margin: 0;
color: #aebfc6;
font-size: 10px;
line-height: 1.55;
}
.convention strong { color: #ecf4f6; }
.source-panel {
position: fixed;
top: 20px;
right: 22px;
width: min(330px, calc(100vw - 44px));
padding: 0 14px;
font-size: 11px;
}
.source-panel summary {
padding: 12px 0;
color: #d8e4e8;
font-weight: 750;
cursor: pointer;
list-style: none;
}
.source-panel summary::-webkit-details-marker { display: none; }
.source-panel summary::after {
content: "+";
float: right;
color: var(--accent);
font-size: 17px;
line-height: 13px;
}
.source-panel[open] summary::after { content: "−"; }
.source-panel .source-body {
padding: 0 0 14px;
color: #afc0c7;
line-height: 1.55;
}
.source-panel ol {
margin: 9px 0 0;
padding-left: 18px;
}
.source-panel a {
color: #82d9d5;
text-decoration-color: rgba(130, 217, 213, 0.4);
text-underline-offset: 2px;
}
.source-panel strong { color: #e3edef; }
.camera-hint {
position: fixed;
left: 50%;
bottom: 16px;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(174, 206, 218, 0.15);
border-radius: 999px;
background: rgba(7, 15, 21, 0.76);
color: #9fb1ba;
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
white-space: nowrap;
}
.reset-view {
position: fixed;
right: 22px;
bottom: 18px;
padding: 8px 12px;
border: 1px solid rgba(174, 206, 218, 0.2);
border-radius: 999px;
background: rgba(7, 15, 21, 0.78);
color: #b7c7cd;
font-size: 10px;
cursor: pointer;
}
.reset-view:hover { color: white; border-color: var(--accent); }
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #09121a;
color: #9db4bd;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.masthead {
top: 12px;
left: 14px;
max-width: calc(100vw - 110px);
}
h1 { font-size: 25px; }
.subtitle { font-size: 10px; }
.controls {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 47vh;
overflow: auto;
padding: 14px;
}
.source-panel {
top: 12px;
right: 12px;
width: auto;
max-width: 230px;
}
.source-panel .source-body { max-height: 35vh; overflow: auto; }
.camera-hint {
display: none;
}
.reset-view {
right: 12px;
bottom: calc(47vh + 22px);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="masthead">
<div class="eyebrow">Technical cutaway · Meridian method</div>
<h1>Navigator’s Desk</h1>
<p class="subtitle">
Marine chronometer, local-noon marker, reference globe and angular diagram.
Interpretive reconstruction—not an attributed voyage or log entry.
</p>
</header>
<aside class="controls panel" aria-label="Time and longitude controls">
<h2 class="panel-title">Local solar time − reference clock</h2>
<p class="panel-subtitle">
Positive means local solar time is ahead of the clock and the target
meridian lies east of the reference.
</p>
<div class="readouts">
<div class="readout">
<span class="readout-label">Clock difference Δt</span>
<span class="readout-value" id="hoursValue">+0.00 h</span>
</div>
<div class="readout">
<span class="readout-label">Signed angle Δλ</span>
<span class="readout-value" id="angleValue">0.0°</span>
</div>
<div class="readout" style="grid-column: 1 / -1">
<span class="readout-label">Target longitude from reference</span>
<span class="readout-value" id="longitudeValue">0.0° · REFERENCE</span>
</div>
</div>
<div class="range-wrap">
<input
id="difference"
type="range"
min="-4"
max="4"
step="0.05"
value="0"
aria-label="Hypothetical difference between local solar time and reference clock time"
>
<div class="range-labels">
<span class="west">−4 h · West</span>
<span>0 · Reference</span>
<span class="east">East · +4 h</span>
</div>
</div>
<div class="presets" aria-label="Example presets">
<button class="preset" data-delta="-1">
<strong>−1.00 h</strong>
<span>−15.0° · 15° W</span>
</button>
<button class="preset active" data-delta="0">
<strong>0.00 h</strong>
<span>0.0° · Reference</span>
</button>
<button class="preset" data-delta="1">
<strong>+1.00 h</strong>
<span>+15.0° · 15° E</span>
</button>
</div>
<div class="equation">
Δλ = 15° × Δt<br>
λtarget = λreference + Δλ
</div>
<div class="clock-row">
<span>At target local noon</span>
<span id="referenceClock">Reference clock: 12:00</span>
</div>
<div class="clock-row">
<span>Target apparent solar time</span>
<span>12:00 local</span>
</div>
<p class="convention">
<strong>Sign convention:</strong>
Δt = local apparent solar time − reference clock time.
Thus +Δt is east and −Δt is west.
The reference meridian is set to 0° in this model.
This is a simplified 15°-per-hour rule; it ignores the equation of time,
longitude convergence, and non-solar clock errors.
</p>
</aside>
<details class="source-panel panel">
<summary>Historical basis & sources</summary>
<div class="source-body">
<p>
<strong>Interpretive reconstruction.</strong>
The instrument uses common c. 1830–1880 marine-chronometer features:
a gimballed brass movement box, white dial with subsidiary seconds,
blued and red hands, and a mahogany protective carrying case.
</p>
<p>
The desk arrangement and all displayed readings are original to this
visualization. No particular navigator, voyage, date, quotation, or
log entry is represented.
</p>
<ol>
<li>
<a href="https://www.rmg.co.uk/stories/topics/marine-chronometer"
target="_blank" rel="noopener noreferrer">
Royal Museums Greenwich — Marine chronometer
</a>
</li>
<li>
<a href="https://www.britannica.com/technology/marine-chronometer"
target="_blank" rel="noopener noreferrer">
Encyclopaedia Britannica — Marine chronometer
</a>
</li>
<li>
<a href="https://www.metmuseum.org/art/collection/search?q=marine%20chronometer"
target="_blank" rel="noopener noreferrer">
The Metropolitan Museum of Art — Marine chronometer collection search
</a>
</li>
</ol>
</div>
</details>
<div class="camera-hint">
Drag to orbit · Wheel to zoom · Arrow keys to inspect · Double-click to reset
</div>
<button class="reset-view" id="resetView">Reset view</button>
<div id="loading">Loading the cutaway…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09121a);
scene.fog = new THREE.Fog(0x09121a, 15, 30);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional cutaway of a navigator's desk"
);
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbfd9e8, 0x392619, 1.35);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d2, 3.5);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6ac8d2, 1.8);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
const deskLight = new THREE.PointLight(0xffc982, 12, 9, 2);
deskLight.position.set(-2.2, 4.2, 1.4);
scene.add(deskLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x0b151e,
roughness: 0.92,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x284452, 0x152a34);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// ---------------------------------------------------------------------
// Materials and procedural textures
// ---------------------------------------------------------------------
function seeded(seed) {
let s = seed >>> 0;
return () => {
s = (1664525 * s + 1013904223) >>> 0;
return s / 4294967296;
};
}
function makeWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const rand = seeded(731);
const gradient = ctx.createLinearGradient(0, 0, 0, 512);
gradient.addColorStop(0, "#70432d");
gradient.addColorStop(0.48, "#4e2b20");
gradient.addColorStop(1, "#613725");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1024, 512);
for (let i = 0; i < 460; i++) {
const y = rand() * 512;
const amplitude = 2 + rand() * 12;
const frequency = 0.006 + rand() * 0.02;
const phase = rand() * Math.PI * 2;
const alpha = 0.025 + rand() * 0.09;
const light = rand() > 0.48;
ctx.beginPath();
for (let x = 0; x <= 1024; x += 8) {
const yy = y +
Math.sin(x * frequency + phase) * amplitude +
Math.sin(x * frequency * 0.37 + phase) * amplitude * 0.32;
if (x === 0) ctx.moveTo(x, yy);
else ctx.lineTo(x, yy);
}
ctx.strokeStyle = light
? `rgba(235, 170, 108, ${alpha})`
: `rgba(20, 8, 5, ${alpha + 0.03})`;
ctx.lineWidth = 0.5 + rand() * 1.6;
ctx.stroke();
}
for (let i = 0; i < 900; i++) {
ctx.fillStyle = `rgba(255,220,170,${rand() * 0.035})`;
ctx.fillRect(rand() * 1024, rand() * 512, 1, 1);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.7, 1.1);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeEarthTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const ocean = ctx.createLinearGradient(0, 0, 0, 512);
ocean.addColorStop(0, "#316c83");
ocean.addColorStop(0.5, "#174f6d");
ocean.addColorStop(1, "#0f3d58");
ctx.fillStyle = ocean;
ctx.fillRect(0, 0, 1024, 512);
function land(points, color) {
ctx.beginPath();
points.forEach((p, i) => {
if (i === 0) ctx.moveTo(p[0], p[1]);
else ctx.lineTo(p[0], p[1]);
});
ctx.closePath();
ctx.fillStyle = color;
ctx.fill();
}
land([
[85, 80], [160, 48], [245, 75], [282, 138], [240, 183],
[198, 163], [170, 208], [130, 190], [96, 142]
], "#9d9b72");
land([
[235, 210], [300, 198], [333, 240], [315, 320], [284, 382],
[252, 335], [245, 268]
], "#a6a078");
land([
[475, 80], [535, 53], [585, 77], [610, 122], [580, 150],
[548, 123], [508, 132]
], "#a4a078");
land([
[505, 170], [574, 153], [638, 188], [675, 245], [640, 282],
[598, 259], [574, 320], [538, 295], [527, 235], [493, 205]
], "#b0a77c");
land([
[746, 120], [815, 92], [898, 116], [939, 170], [898, 201],
[849, 188], [812, 237], [767, 201]
], "#97946f");
land([
[806, 274], [871, 258], [928, 291], [914, 353], [872, 395],
[825, 368]
], "#a79f77");
ctx.strokeStyle = "rgba(205,231,235,0.16)";
ctx.lineWidth = 1;
for (let x = 0; x <= 1024; x += 64) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, 512);
ctx.stroke();
}
for (let y = 0; y <= 512; y += 64) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(1024, y);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeDialTexture() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 768;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#ece5cf";
ctx.fillRect(0, 0, 768, 768);
const center = 384;
const radius = 334;
ctx.translate(center, center);
ctx.strokeStyle = "#252d2e";
ctx.lineWidth = 6;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, Math.PI * 2);
ctx.stroke();
ctx.strokeStyle = "#6c736f";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(0, 0, radius - 16, 0, Math.PI * 2);
ctx.stroke();
for (let i = 0; i < 60; i++) {
const a = (i / 60) * Math.PI * 2;
const major = i % 5 === 0;
const inner = radius - (major ? 38 : 20);
ctx.beginPath();
ctx.moveTo(Math.sin(a) * inner, -Math.cos(a) * inner);
ctx.lineTo(Math.sin(a) * (radius - 10), -Math.cos(a) * (radius - 10));
ctx.strokeStyle = major ? "#263033" : "#6d736f";
ctx.lineWidth = major ? 4 : 2;
ctx.stroke();
}
const numerals = ["XII", "I", "II", "III", "IV", "V",
"VI", "VII", "VIII", "IX", "X", "XI"];
ctx.fillStyle = "#263033";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "42px Georgia";
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
const r = radius - 72;
ctx.fillText(numerals[i], Math.sin(a) * r, -Math.cos(a) * r);
}
ctx.strokeStyle = "#7b817d";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(0, 150, 82, 0, Math.PI * 2);
ctx.stroke();
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
ctx.beginPath();
ctx.moveTo(Math.sin(a) * 68, 150 - Math.cos(a) * 68);
ctx.lineTo(Math.sin(a) * 77, 150 - Math.cos(a) * 77);
ctx.stroke();
}
ctx.fillStyle = "#354044";
ctx.font = "bold 23px Georgia";
ctx.fillText("CHRONOMETER", 0, -104);
ctx.font = "17px sans-serif";
ctx.fillText("REFERENCE MERIDIAN", 0, -72);
ctx.font = "14px Georgia";
ctx.fillText("60", 0, 136);
ctx.setTransform(1, 0, 0, 1, 0, 0);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeNoonTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#d9c898";
ctx.fillRect(0, 0, 512, 512);
ctx.translate(256, 256);
ctx.strokeStyle = "#3e4540";
ctx.lineWidth = 4;
ctx.beginPath();
ctx.arc(0, 0, 218, 0, Math.PI * 2);
ctx.stroke();
for (let i = 0; i < 32; i++) {
const a = i / 32 * Math.PI * 2;
const inner = i % 4 === 0 ? 177 : 195;
ctx.beginPath();
ctx.moveTo(Math.sin(a) * inner, -Math.cos(a) * inner);
ctx.lineTo(Math.sin(a) * 208, -Math.cos(a) * 208);
ctx.strokeStyle = "#51594f";
ctx.lineWidth = i % 4 === 0 ? 4 : 2;
ctx.stroke();
}
ctx.fillStyle = "#343d38";
ctx.textAlign = "center";
ctx.font = "bold 30px Georgia";
ctx.fillText("LOCAL", 0, -70);
ctx.fillText("APPARENT", 0, -35);
ctx.font = "bold 34px Georgia";
ctx.fillText("NOON", 0, 62);
ctx.font = "18px sans-serif";
ctx.fillText("OBSERVATION MARK", 0, 102);
ctx.setTransform(1, 0, 0, 1, 0, 0);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const woodTexture = makeWoodTexture();
const materials = {
wood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xc8a58e,
roughness: 0.63,
metalness: 0.03
}),
darkWood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0x8e6756,
roughness: 0.58,
metalness: 0.03
}),
cutWood: new THREE.MeshStandardMaterial({
color: 0xc69a72,
roughness: 0.88
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc89c45,
roughness: 0.26,
metalness: 0.82
}),
darkBrass: new THREE.MeshStandardMaterial({
color: 0x705126,
roughness: 0.38,
metalness: 0.76
}),
iron: new THREE.MeshStandardMaterial({
color: 0x39444b,
roughness: 0.42,
metalness: 0.72
}),
ivory: new THREE.MeshStandardMaterial({
color: 0xe8dfc7,
roughness: 0.7
}),
blueHand: new THREE.MeshStandardMaterial({
color: 0x235a83,
roughness: 0.4,
metalness: 0.3
}),
redHand: new THREE.MeshStandardMaterial({
color: 0xb53b31,
roughness: 0.4,
metalness: 0.25
}),
chalk: new THREE.MeshStandardMaterial({
color: 0xd9e1df,
roughness: 0.9
})
};
function addMesh(geometry, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, x, y, z, parent = scene, edges = false) {
const mesh = addMesh(
new THREE.BoxGeometry(w, h, d),
material,
x, y, z,
parent
);
if (edges) {
const edgeGeometry = new THREE.EdgesGeometry(mesh.geometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xc9a172,
transparent: true,
opacity: 0.35
});
const edgeLines = new THREE.LineSegments(edgeGeometry, edgeMaterial);
mesh.add(edgeLines);
}
return mesh;
}
function addCylinder(radius, height, material, x, y, z, parent = scene, segments = 48) {
return addMesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material,
x, y, z,
parent
);
}
function lineFromPoints(points, color, parent = scene, opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map(p => new THREE.Vector3(...p))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
function makeLabel(text, accent = "#7ed9d4", width = 2.0) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const r = 20;
ctx.beginPath();
ctx.moveTo(r, 4);
ctx.arcTo(764, 4, 764, 124, r);
ctx.arcTo(764, 124, 4, 124, r);
ctx.arcTo(4, 124, 4, 4, r);
ctx.arcTo(4, 4, 764, 4, r);
ctx.closePath();
ctx.fillStyle = "rgba(8,18,26,0.86)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(20, 20, 7, 88);
ctx.fillStyle = "#e8f1f3";
ctx.font = "bold 35px system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(text, 43, 64);
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, width * 128 / 768, 1);
sprite.renderOrder = 20;
return sprite;
}
// ---------------------------------------------------------------------
// Sectioned navigator's desk
// ---------------------------------------------------------------------
const TOP_Y = 1.62;
const desk = new THREE.Group();
scene.add(desk);
// Main top and a front-left top panel leave the front-right section open.
addBox(9.0, 0.32, 3.45, materials.wood, 0, 1.45, -0.975, desk, true);
addBox(5.95, 0.32, 1.95, materials.wood, -1.525, 1.45, 1.725, desk, true);
// Exposed light-colored cut faces.
addBox(0.045, 0.32, 1.95, materials.cutWood, 1.475, 1.45, 1.725, desk);
addBox(3.025, 0.32, 0.045, materials.cutWood, 2.9875, 1.45, 0.765, desk);
// Drawer cavity visible through the cutaway.
addBox(2.78, 0.12, 1.62, materials.darkWood, 2.96, 0.83, 1.70, desk, true);
addBox(0.12, 0.49, 1.62, materials.darkWood, 1.54, 1.075, 1.70, desk, true);
addBox(0.12, 0.49, 1.62, materials.darkWood, 4.38, 1.075, 1.70, desk, true);
addBox(2.72, 0.36, 0.09, materials.darkWood, 2.96, 1.01, 0.87, desk, true);
// Rolled chart and dividers in the exposed drawer.
const chart = addCylinder(0.12, 1.25, materials.ivory, 2.55, 1.02, 1.67, desk);
chart.rotation.z = Math.PI / 2;
addBox(1.2, 0.035, 0.16, materials.chalk, 3.48, 0.92, 1.44, desk);
addBox(1.05, 0.035, 0.12, materials.chalk, 3.45, 0.96, 1.72, desk);
addBox(0.16, 0.035, 0.9, materials.chalk, 3.79, 0.97, 1.59, desk);
// Desk frame, legs and braces.
const legPositions = [
[-4.05, 0.72, -2.15],
[ 4.05, 0.72, -2.15],
[-4.05, 0.72, 2.15],
[ 4.05, 0.72, 2.15]
];
for (const [x, y, z] of legPositions) {
addBox(0.31, 1.30, 0.31, materials.darkWood, x, y, z, desk, true);
}
addBox(7.82, 0.25, 0.18, materials.darkWood, 0, 1.08, -2.15, desk, true);
addBox(7.82, 0.25, 0.18, materials.darkWood, 0, 1.08, 2.15, desk, true);
addBox(0.18, 0.25, 4.1, materials.darkWood, -4.05, 1.08, 0, desk, true);
addBox(0.18, 0.25, 4.1, materials.darkWood, 4.05, 1.08, 0, desk, true);
addBox(7.75, 0.15, 0.15, materials.darkWood, 0, 0.42, -2.15, desk, true);
addBox(7.75, 0.15, 0.15, materials.darkWood, 0, 0.42, 2.15, desk, true);
// Brass corner braces.
const braceMaterial = materials.darkBrass;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const x = sx * 3.88;
const z = sz * 1.98;
addBox(0.52, 0.045, 0.055, braceMaterial, x - sx * 0.18, 1.23, z, desk);
addBox(0.055, 0.045, 0.52, braceMaterial, x, 1.23, z - sz * 0.18, desk);
}
}
// Section hatch marks on the exposed vertical cut.
const hatchPoints = [];
for (let z = 0.86; z < 2.66; z += 0.18) {
hatchPoints.push(
new THREE.Vector3(1.501, 1.31, z),
new THREE.Vector3(1.501, 1.59, Math.min(z + 0.20, 2.69))
);
}
const hatchGeometry = new THREE.BufferGeometry().setFromPoints(hatchPoints);
desk.add(new THREE.LineSegments(
hatchGeometry,
new THREE.LineBasicMaterial({ color: 0x744b32, transparent: true, opacity: 0.55 })
));
// Section outline.
lineFromPoints([
[1.48, 1.615, 0.76], [4.50, 1.615, 0.76],
[4.50, 1.615, 2.70], [1.48, 1.615, 2.70],
[1.48, 1.615, 0.76]
], 0xd7774f, desk, 0.75);
// ---------------------------------------------------------------------
// Marine chronometer in an open protective case
// ---------------------------------------------------------------------
const chronometer = new THREE.Group();
chronometer.position.set(-2.55, TOP_Y, -0.05);
scene.add(chronometer);
// Carrying case base and open lid.
addBox(1.82, 0.20, 1.55, materials.darkWood, 0, 0.11, 0, chronometer, true);
addBox(1.67, 1.30, 0.13, materials.darkWood, 0, 0.84, -0.78, chronometer, true);
addBox(1.43, 1.02, 0.035, materials.wood, 0, 0.84, -0.70, chronometer);
// Brass case edging and corner pieces.
addBox(1.86, 0.045, 0.055, materials.brass, 0, 0.225, 0.79, chronometer);
addBox(1.86, 0.045, 0.055, materials.brass, 0, 0.225, -0.79, chronometer);
addBox(0.055, 0.045, 1.58, materials.brass, -0.91, 0.225, 0, chronometer);
addBox(0.055, 0.045, 1.58, materials.brass, 0.91, 0.225, 0, chronometer);
for (const x of [-0.82, 0.82]) {
addBox(0.16, 0.075, 0.16, materials.brass, x, 0.27, 0.68, chronometer);
addBox(0.16, 0.075, 0.16, materials.brass, x, 0.27, -0.68, chronometer);
}
// Hinges and a small leather latch.
for (const x of [-0.58, 0.58]) {
addCylinder(0.055, 0.26, materials.brass, x, 0.29, -0.72, chronometer, 20)
.rotation.z = Math.PI / 2;
}
addBox(0.22, 0.28, 0.07, materials.darkWood, 0, 1.48, -0.77, chronometer);
addBox(0.13, 0.12, 0.04, materials.brass, 0, 1.45, -0.71, chronometer);
// Gimbal supports.
addBox(0.13, 0.42, 0.13, materials.brass, -0.66, 0.39, 0.02, chronometer);
addBox(0.13, 0.42, 0.13, materials.brass, 0.66, 0.39, 0.02, chronometer);
const gimbalRing = addMesh(
new THREE.TorusGeometry(0.64, 0.035, 12, 72),
materials.brass,
0, 0.49, 0.02,
chronometer
);
gimbalRing.rotation.x = Math.PI / 2;
// Brass movement housing and white enamel dial.
addCylinder(0.57, 0.24, materials.brass, 0, 0.39, 0.02, chronometer, 72);
const dialRing = addMesh(
new THREE.TorusGeometry(0.535, 0.045, 16, 96),
materials.brass,
0, 0.525, 0.02,
chronometer
);
dialRing.rotation.x = Math.PI / 2;
const dialTexture = makeDialTexture();
const dial = addMesh(
new THREE.CircleGeometry(0.493, 96),
new THREE.MeshStandardMaterial({
map: dialTexture,
roughness: 0.42,
metalness: 0.03
}),
0, 0.531, 0.02,
chronometer
);
dial.rotation.x = -Math.PI / 2;
// Clock hands in a local XY plane.
const faceGroup = new THREE.Group();
faceGroup.position.set(0, 0.548, 0.02);
faceGroup.rotation.x = -Math.PI / 2;
chronometer.add(faceGroup);
const hourPivot = new THREE.Group();
const minutePivot = new THREE.Group();
faceGroup.add(hourPivot, minutePivot);
addBox(0.038, 0.285, 0.016, materials.blueHand, 0, 0.115, 0.006, hourPivot);
addBox(0.026, 0.390, 0.014, materials.redHand, 0, 0.165, 0.014, minutePivot);
addCylinder(0.045, 0.025, materials.brass, 0, 0, 0.025, faceGroup, 24);
// Setting square and small winding detail beside the instrument.
addBox(0.27, 0.025, 0.08, materials.brass, 0.69, 0.23, 0.20, chronometer);
addBox(0.08, 0.025, 0.27, materials.brass, 0.79, 0.23, 0.11, chronometer);
// ---------------------------------------------------------------------
// Local-noon observation marker
// ---------------------------------------------------------------------
const noonMarker = new THREE.Group();
noonMarker.position.set(-0.35, TOP_Y, -1.25);
scene.add(noonMarker);
addCylinder(0.53, 0.10, materials.darkBrass, 0, 0.06, 0, noonMarker, 64);
const noonDisc = addMesh(
new THREE.CircleGeometry(0.48, 64),
new THREE.MeshStandardMaterial({
map: makeNoonTexture(),
roughness: 0.85
}),
0, 0.115, 0,
noonMarker
);
noonDisc.rotation.x = -Math.PI / 2;
// Gnomon and the noon shadow line.
addBox(0.035, 0.58, 0.035, materials.brass, 0.10, 0.40, 0.03, noonMarker);
const gnomonBlade = addBox(
0.025, 0.43, 0.23,
materials.brass,
0.16, 0.34, 0.02,
noonMarker
);
gnomonBlade.rotation.x = -0.18;
addBox(0.64, 0.012, 0.024, materials.redHand, -0.22, 0.133, 0.02, noonMarker);
// A stylized beam pointing to the observation mark.
const beamStart = new THREE.Vector3(-0.72, 2.10, -0.44);
const beamEnd = new THREE.Vector3(0.10, 0.13, 0.03);
lineFromPoints([
beamStart.toArray(),
beamEnd.toArray()
], 0xf3c56d, noonMarker, 0.7);
const beamDirection = beamEnd.clone().sub(beamStart);
const beam = addMesh(
new THREE.CylinderGeometry(0.015, 0.11, beamDirection.length(), 20, 1, true),
new THREE.MeshBasicMaterial({
color: 0xffd78b,
transparent: true,
opacity: 0.08,
depthWrite: false,
side: THREE.DoubleSide
}),
0, 0, 0,
noonMarker
);
beam.position.copy(beamStart.clone().add(beamEnd).multiplyScalar(0.5));
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
beamDirection.clone().normalize()
);
// ---------------------------------------------------------------------
// Small globe with reference meridian and linked target marker
// ---------------------------------------------------------------------
const globe = new THREE.Group();
globe.position.set(2.35, TOP_Y, -1.02);
scene.add(globe);
addCylinder(0.56, 0.12, materials.darkBrass, 0, 0.07, 0, globe, 64);
addCylinder(0.12, 0.66, materials.brass, 0, 0.43, 0, globe, 32);
addCylinder(0.29, 0.07, materials.darkBrass, 0, 0.76, 0, globe, 48);
const globeContent = new THREE.Group();
globeContent.position.set(0, 1.45, 0);
globeContent.rotation.z = -0.17;
globe.add(globeContent);
const globeRadius = 0.79;
addMesh(
new THREE.SphereGeometry(globeRadius, 72, 48),
new THREE.MeshStandardMaterial({
map: makeEarthTexture(),
roughness: 0.62,
metalness: 0.03
}),
0, 0, 0,
globeContent
);
// Brass equatorial ring.
const equator = addMesh(
new THREE.TorusGeometry(0.815, 0.018, 10, 96),
materials.brass,
0, 0, 0,
globeContent
);
equator.rotation.x = Math.PI / 2;
// Full brass meridian hoop.
const meridianHoop = addMesh(
new THREE.TorusGeometry(0.845, 0.017, 10, 96),
materials.brass,
0, 0, 0,
globeContent
);
meridianHoop.rotation.y = Math.PI / 2;
function meridianPoints(longitudeDegrees, radius = 0.825) {
const points = [];
const longitude = THREE.MathUtils.degToRad(longitudeDegrees);
for (let i = 0; i <= 80; i++) {
const latitude = -Math.PI / 2 + (i / 80) * Math.PI;
points.push(new THREE.Vector3(
Math.sin(longitude) * Math.cos(latitude) * radius,
Math.sin(latitude) * radius,
Math.cos(longitude) * Math.cos(latitude) * radius
));
}
return points;
}
const referenceMeridian = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(meridianPoints(0)),
new THREE.LineBasicMaterial({ color: 0xffd36f })
);
globeContent.add(referenceMeridian);
let targetMeridian = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(meridianPoints(0, 0.842)),
new THREE.LineBasicMaterial({ color: 0xff8067 })
);
globeContent.add(targetMeridian);
const globeMarker = addMesh(
new THREE.SphereGeometry(0.065, 20, 12),
new THREE.MeshStandardMaterial({
color: 0xff8067,
emissive: 0x4d120a,
roughness: 0.35,
metalness: 0.25
}),
0, 0, 0.85,
globeContent
);
// Small equatorial target pin.
const targetPin = addMesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.17, 12),
materials.brass,
0, 0, 0.88,
globeContent
);
targetPin.rotation.x = Math.PI / 2;
// ---------------------------------------------------------------------
// Paper-like angular diagram
// ---------------------------------------------------------------------
const paperCanvas = document.createElement("canvas");
paperCanvas.width = 1024;
paperCanvas.height = 700;
const paperContext = paperCanvas.getContext("2d");
const paperTexture = new THREE.CanvasTexture(paperCanvas);
paperTexture.colorSpace = THREE.SRGBColorSpace;
paperTexture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const paperGroup = new THREE.Group();
paperGroup.position.set(0.10, TOP_Y + 0.015, 1.34);
paperGroup.rotation.y = -0.08;
scene.add(paperGroup);
const paperShadow = addMesh(
new THREE.PlaneGeometry(3.36, 2.34),
new THREE.MeshBasicMaterial({
color: 0x000000,
transparent: true,
opacity: 0.22,
depthWrite: false
}),
0, 0.012, 0,
paperGroup
);
paperShadow.rotation.x = -Math.PI / 2;
const paper = addMesh(
new THREE.PlaneGeometry(3.24, 2.18),
new THREE.MeshStandardMaterial({
map: paperTexture,
roughness: 0.96,
metalness: 0
}),
0, 0.025, 0,
paperGroup
);
paper.rotation.x = -Math.PI / 2;
// Paper corner weights.
addCylinder(0.075, 0.055, materials.darkBrass, -1.38, 0.055, -0.78, paperGroup, 24);
addCylinder(0.075, 0.055, materials.darkBrass, 1.38, 0.055, 0.78, paperGroup, 24);
// ---------------------------------------------------------------------
// Technical labels
// ---------------------------------------------------------------------
const chronometerLabel = makeLabel(
"GIMBALLED CHRONOMETER",
"#e8b86d",
2.45
);
chronometerLabel.position.set(-2.55, 2.86, -0.18);
scene.add(chronometerLabel);
lineFromPoints([
[-2.55, 2.60, -0.18],
[-2.55, 2.02, -0.18]
], 0xe8b86d, scene, 0.65);
const noonLabel = makeLabel(
"LOCAL APPARENT NOON",
"#f2ca72",
2.35
);
noonLabel.position.set(-0.35, 3.08, -1.45);
scene.add(noonLabel);
lineFromPoints([
[-0.35, 2.84, -1.45],
[-0.35, 2.00, -1.30]
], 0xf2ca72, scene, 0.65);
const globeLabel = makeLabel(
"GLOBE · REFERENCE 0°",
"#7ed9d4",
2.35
);
globeLabel.position.set(2.35, 3.91, -1.03);
scene.add(globeLabel);
lineFromPoints([
[2.35, 3.64, -1.03],
[2.35, 2.86, -1.03]
], 0x7ed9d4, scene, 0.65);
const diagramLabel = makeLabel(
"SIGNED ANGULAR DIAGRAM",
"#ff9a82",
2.55
);
diagramLabel.position.set(0.08, 2.22, 1.37);
scene.add(diagramLabel);
const sectionLabel = makeLabel(
"SECTIONED DESK DRAWER",
"#b9a17c",
2.12
);
sectionLabel.position.set(3.02, 1.60, 2.20);
scene.add(sectionLabel);
// ---------------------------------------------------------------------
// Linked visual and numeric updates
// ---------------------------------------------------------------------
const state = {
deltaHours: 0
};
const differenceInput = document.getElementById("difference");
const hoursValue = document.getElementById("hoursValue");
const angleValue = document.getElementById("angleValue");
const longitudeValue = document.getElementById("longitudeValue");
const referenceClockValue = document.getElementById("referenceClock");
const presetButtons = [...document.querySelectorAll("[data-delta]")];
function signedNumber(value, digits) {
const rounded = Math.abs(value) < 0.5 * Math.pow(10, -digits)
? 0
: value;
if (rounded === 0) return (0).toFixed(digits);
return `${rounded > 0 ? "+" : "−"}${Math.abs(rounded).toFixed(digits)}`;
}
function formatClock(hours) {
const totalMinutes = Math.round(((hours % 24) + 24) % 24 * 60);
const hh = Math.floor(totalMinutes / 60) % 24;
const mm = totalMinutes % 60;
return `${String(hh).padStart(2, "0")}:${String(mm).padStart(2, "0")}`;
}
function updateChronometer(delta) {
// At local apparent noon, the reference clock reads 12:00 - Δt.
const referenceHours = 12 - delta;
const normalized = ((referenceHours % 12) + 12) % 12;
const hourAngle = (normalized / 12) * Math.PI * 2;
const minuteAngle = 0;
hourPivot.rotation.z = -hourAngle;
minutePivot.rotation.z = -minuteAngle;
}
function updateGlobe(delta) {
const longitude = delta * 15;
const points = meridianPoints(longitude, 0.842);
globeContent.remove(targetMeridian);
targetMeridian.geometry.dispose();
targetMeridian = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({ color: 0xff8067 })
);
globeContent.add(targetMeridian);
const radians = THREE.MathUtils.degToRad(longitude);
globeMarker.position.set(
Math.sin(radians) * 0.855,
0,
Math.cos(radians) * 0.855
);
targetPin.position.set(
Math.sin(radians) * 0.885,
0,
Math.cos(radians) * 0.885
);
targetPin.rotation.z = -radians;
}
function drawPaper(delta) {
const ctx = paperContext;
const w = paperCanvas.width;
const h = paperCanvas.height;
const cx = 512;
const cy = 376;
const radius = 238;
const angle = THREE.MathUtils.degToRad(delta * 15);
// Warm paper and subtle fiber.
ctx.fillStyle = "#e8dfc3";
ctx.fillRect(0, 0, w, h);
const rand = seeded(1039 + Math.round((delta + 4) * 100));
for (let i = 0; i < 4200; i++) {
const x = rand() * w;
const y = rand() * h;
const alpha = rand() * 0.055;
ctx.fillStyle = rand() > 0.5
? `rgba(92,67,36,${alpha})`
: `rgba(255,255,255,${alpha})`;
ctx.fillRect(x, y, 1 + rand() * 2, 1);
}
ctx.strokeStyle = "rgba(91, 93, 79, 0.22)";
ctx.lineWidth = 1;
for (let x = 0; x <= w; x += 40) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, h);
ctx.stroke();
}
for (let y = 0; y <= h; y += 40) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(w, y);
ctx.stroke();
}
ctx.strokeStyle = "#4e5148";
ctx.lineWidth = 4;
ctx.strokeRect(24, 24, w - 48, h - 48);
ctx.fillStyle = "#3c443f";
ctx.textAlign = "center";
ctx.font = "bold 29px Georgia";
ctx.fillText("ANGULAR DIFFERENCE AT LOCAL NOON", cx, 65);
ctx.font = "16px sans-serif";
ctx.fillText("λtarget = λreference + 15° × Δt", cx, 93);
// Compass circle.
ctx.strokeStyle = "#5d6258";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
ctx.stroke();
ctx.strokeStyle = "rgba(65,72,65,0.28)";
ctx.lineWidth = 1;
for (const r of [radius * 0.25, radius * 0.5, radius * 0.75]) {
ctx.beginPath();
ctx.arc(cx, cy, r, 0, Math.PI * 2);
ctx.stroke();
}
// Cardinal labels.
ctx.fillStyle = "#3e4841";
ctx.font = "bold 20px Georgia";
ctx.fillText("N / REF 0°", cx, cy - radius - 23);
ctx.fillText("S", cx, cy + radius + 33);
ctx.fillStyle = "#9b4f38";
ctx.fillText("EAST +", cx + radius + 52, cy + 7);
ctx.fillStyle = "#426c91";
ctx.fillText("− WEST", cx - radius - 52, cy + 7);
// Reference meridian.
ctx.strokeStyle = "#b18b35";
ctx.lineWidth = 5;
ctx.setLineDash([12, 8]);
ctx.beginPath();
ctx.moveTo(cx, cy - radius - 16);
ctx.lineTo(cx, cy + radius + 16);
ctx.stroke();
ctx.setLineDash([]);
// Signed wedge and target ray.
const targetX = cx + Math.sin(angle) * radius;
const targetY = cy - Math.cos(angle) * radius;
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.arc(cx, cy, radius * 0.78, -Math.PI / 2, -Math.PI / 2 + angle, angle < 0);
ctx.closePath();
ctx.fillStyle = delta >= 0
? "rgba(205,88,54,0.19)"
: "rgba(61,116,170,0.18)";
ctx.fill();
ctx.strokeStyle = delta >= 0 ? "#c2573d" : "#3f75a4";
ctx.lineWidth = 6;
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.lineTo(targetX, targetY);
ctx.stroke();
ctx.fillStyle = delta >= 0 ? "#c2573d" : "#3f75a4";
ctx.beginPath();
ctx.arc(targetX, targetY, 10, 0, Math.PI * 2);
ctx.fill();
// Angle arc.
ctx.strokeStyle = delta >= 0 ? "#c2573d" : "#3f75a4";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(cx, cy, radius + 22, -Math.PI / 2, -Math.PI / 2 + angle, angle < 0);
ctx.stroke();
// Numeric readouts.
ctx.fillStyle = "#38423c";
ctx.font = "bold 38px ui-monospace, monospace";
ctx.fillText(`Δλ = ${signedNumber(delta * 15, 1)}°`, cx, 622);
ctx.font = "bold 25px ui-monospace, monospace";
ctx.fillText(`Δt = ${signedNumber(delta, 2)} h`, cx, 658);
paperTexture.needsUpdate = true;
}
function updateUI(delta) {
const angle = delta * 15;
const absoluteAngle = Math.abs(angle);
hoursValue.textContent = `${signedNumber(delta, 2)} h`;
angleValue.textContent = `${signedNumber(angle, 1)}°`;
if (Math.abs(angle) < 0.001) {
longitudeValue.textContent = "0.0° · REFERENCE";
} else if (angle > 0) {
longitudeValue.textContent = `${absoluteAngle.toFixed(1)}° E`;
} else {
longitudeValue.textContent = `${absoluteAngle.toFixed(1)}° W`;
}
referenceClockValue.textContent =
`Reference clock: ${formatClock(12 - delta)}`;
presetButtons.forEach(button => {
const value = Number(button.dataset.delta);
button.classList.toggle("active", Math.abs(value - delta) < 0.0001);
});
}
function setDelta(value) {
state.deltaHours = THREE.MathUtils.clamp(value, -4, 4);
const delta = state.deltaHours;
differenceInput.value = delta.toFixed(2);
updateUI(delta);
updateChronometer(delta);
updateGlobe(delta);
drawPaper(delta);
}
differenceInput.addEventListener("input", event => {
setDelta(Number(event.target.value));
});
presetButtons.forEach(button => {
button.addEventListener("click", () => {
setDelta(Number(button.dataset.delta));
});
});
// ---------------------------------------------------------------------
// Camera controls implemented directly, without Three.js add-ons
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-0.42, 1.38, 0.05);
let yaw = 0.69;
let pitch = 0.50;
let radius = 13.2;
let goalYaw = yaw;
let goalPitch = pitch;
let goalRadius = radius;
function resetCamera() {
goalYaw = 0.69;
goalPitch = 0.50;
goalRadius = 13.2;
}
function updateCamera() {
camera.position.set(
cameraTarget.x + radius * Math.cos(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
goalYaw -= dx * 0.0055;
goalPitch = THREE.MathUtils.clamp(
goalPitch + dy * 0.0045,
0.17,
1.22
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
goalRadius = THREE.MathUtils.clamp(
goalRadius * Math.exp(event.deltaY * 0.001),
8.2,
18.5
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
if (event.key === "ArrowLeft") goalYaw += 0.08;
else if (event.key === "ArrowRight") goalYaw -= 0.08;
else if (event.key === "ArrowUp") goalPitch = Math.min(1.22, goalPitch + 0.06);
else if (event.key === "ArrowDown") goalPitch = Math.max(0.17, goalPitch - 0.06);
else if (event.key === "+" || event.key === "=") goalRadius = Math.max(8.2, goalRadius - 0.5);
else if (event.key === "-" || event.key === "_") goalRadius = Math.min(18.5, goalRadius + 0.5);
else handled = false;
if (handled) event.preventDefault();
});
document.getElementById("resetView").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// Initial linked state.
setDelta(0);
updateCamera();
function animate() {
requestAnimationFrame(animate);
yaw = THREE.MathUtils.lerp(yaw, goalYaw, 0.11);
pitch = THREE.MathUtils.lerp(pitch, goalPitch, 0.11);
radius = THREE.MathUtils.lerp(radius, goalRadius, 0.10);
updateCamera();
renderer.render(scene, camera);
}
animate();
document.getElementById("loading").remove();
</script>
</body>
</html>
```