Prompt specification
Build or customize the Three.js 3D scene "Inclined Moon Orbit Misses Most Alignments" 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: Inclined Moon Orbit Misses Most Alignments
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inclined-moon-orbit-misses-most-alignments-x3774
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring eclipse alignment, shadows, and orbital inclination. Create a schematic planet-moon system with a visibly inclined orbit. Show why alignment near orbital nodes matters, labeling exaggerated distances and sizes. A 3D cutaway view.
Working Three.js Starter (inclined-moon-orbit-misses-most-alignments-x3774):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sun–Planet–Moon Eclipse Geometry</title>
<style>
:root {
color-scheme: dark;
--bg: #050914;
--panel: rgba(8, 15, 31, 0.82);
--border: rgba(137, 185, 255, 0.18);
--text: #eef5ff;
--muted: #91a6c7;
--cyan: #60e6ff;
--amber: #ffc65c;
--green: #72ffc1;
--pink: #ff73bd;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.scene-tag {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(137, 185, 255, 0.25);
border-radius: 6px;
background: rgba(4, 10, 24, 0.74);
color: #eaf4ff;
font-size: 10px;
font-weight: 700;
line-height: 1;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(8px);
}
.scene-tag::before {
content: "";
position: absolute;
top: 50%;
left: -10px;
width: 9px;
height: 1px;
background: currentColor;
opacity: 0.55;
}
.scene-tag.cyan {
color: var(--cyan);
border-color: rgba(96, 230, 255, 0.34);
}
.scene-tag.amber {
color: var(--amber);
border-color: rgba(255, 198, 92, 0.36);
}
.scene-tag.pink {
color: var(--pink);
border-color: rgba(255, 115, 189, 0.35);
}
.title-block {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
max-width: 510px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 39px);
font-weight: 680;
line-height: 1.04;
letter-spacing: -0.035em;
text-transform: uppercase;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.025em;
}
.panel {
position: fixed;
top: 22px;
right: 22px;
z-index: 5;
width: min(345px, calc(100vw - 44px));
padding: 17px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
box-shadow:
0 20px 55px rgba(0, 0, 0, 0.36),
inset 0 1px rgba(255, 255, 255, 0.03);
backdrop-filter: blur(16px);
}
.panel h2 {
margin: 0 0 5px;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel-intro {
margin: 0 0 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.status-card {
margin-bottom: 13px;
padding: 12px;
border: 1px solid rgba(255, 198, 92, 0.23);
border-radius: 9px;
background: rgba(255, 198, 92, 0.045);
transition:
border-color 180ms ease,
background 180ms ease;
}
.status-card[data-state="eclipse"] {
border-color: rgba(114, 255, 193, 0.4);
background: rgba(114, 255, 193, 0.065);
}
.status-card[data-state="miss"] {
border-color: rgba(255, 115, 189, 0.35);
background: rgba(255, 115, 189, 0.055);
}
.status-heading {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 198, 92, 0.7);
}
[data-state="eclipse"] .status-dot {
background: var(--green);
box-shadow: 0 0 14px rgba(114, 255, 193, 0.75);
}
[data-state="miss"] .status-dot {
background: var(--pink);
box-shadow: 0 0 14px rgba(255, 115, 189, 0.7);
}
.status-detail {
margin-top: 7px;
color: #aebed6;
font-size: 11px;
line-height: 1.45;
}
.checks {
display: grid;
gap: 7px;
margin-bottom: 13px;
}
.check {
display: grid;
grid-template-columns: 17px 1fr auto;
align-items: center;
gap: 7px;
color: #7f94b3;
font-size: 10px;
}
.check-icon {
display: grid;
width: 16px;
height: 16px;
place-items: center;
border: 1px solid rgba(143, 166, 200, 0.25);
border-radius: 50%;
color: #7185a4;
font-size: 9px;
}
.check.pass {
color: #d8e7fb;
}
.check.pass .check-icon {
border-color: rgba(114, 255, 193, 0.45);
background: rgba(114, 255, 193, 0.08);
color: var(--green);
}
.check-value {
color: #9eb2ce;
font-variant-numeric: tabular-nums;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 13px;
}
.metric {
padding: 9px;
border: 1px solid rgba(137, 185, 255, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.018);
}
.metric-label {
color: #758aa9;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
margin-top: 4px;
color: #dbe9fb;
font-size: 12px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.legend {
display: grid;
gap: 7px;
padding-top: 12px;
border-top: 1px solid rgba(137, 185, 255, 0.11);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #8ea3c1;
font-size: 10px;
line-height: 1.3;
}
.swatch {
width: 20px;
height: 3px;
flex: 0 0 auto;
border-radius: 3px;
}
.swatch.orbit {
background: var(--cyan);
}
.swatch.reference {
height: 0;
border-top: 1px dashed #8194b1;
}
.swatch.corridor {
background: var(--amber);
}
.swatch.planet {
width: 10px;
height: 10px;
border-radius: 50%;
background: linear-gradient(135deg, #307fa8, #ed7d31);
}
.controls {
position: fixed;
bottom: 24px;
left: 50%;
z-index: 5;
display: flex;
align-items: center;
gap: 14px;
width: min(760px, calc(100vw - 44px));
padding: 12px 14px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
transform: translateX(-50%);
box-shadow: 0 18px 45px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(16px);
}
.inclination-control {
min-width: 190px;
flex: 1 1 220px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #9eb2ce;
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
output {
color: var(--cyan);
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
appearance: none;
border-radius: 4px;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) 58%,
rgba(255, 255, 255, 0.13) 58%,
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid #07111f;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(96, 230, 255, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #07111f;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(96, 230, 255, 0.55);
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
padding: 8px 10px;
border: 1px solid rgba(137, 185, 255, 0.2);
border-radius: 7px;
background: rgba(137, 185, 255, 0.065);
color: #c9d9ee;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(96, 230, 255, 0.55);
background: rgba(96, 230, 255, 0.11);
color: #eefaff;
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: rgba(114, 255, 193, 0.38);
background: rgba(114, 255, 193, 0.09);
color: var(--green);
}
button.pink {
border-color: rgba(255, 115, 189, 0.28);
color: #ffadd6;
}
.scale-note {
position: fixed;
right: 24px;
bottom: 25px;
z-index: 4;
max-width: 255px;
padding: 10px 12px;
border-left: 2px solid var(--amber);
background: rgba(5, 10, 23, 0.72);
color: #8ea2bf;
font-size: 9px;
line-height: 1.5;
letter-spacing: 0.025em;
pointer-events: none;
}
.scale-note strong {
display: block;
margin-bottom: 3px;
color: var(--amber);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.camera-hint {
position: fixed;
bottom: 27px;
left: 26px;
z-index: 4;
color: #667d9d;
font-size: 9px;
line-height: 1.55;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 900px) {
.title-block {
top: 18px;
left: 18px;
max-width: 42vw;
}
.panel {
top: 16px;
right: 16px;
width: 310px;
padding: 14px;
}
.panel-intro,
.legend {
display: none;
}
.scale-note {
display: none;
}
.controls {
bottom: 15px;
width: calc(100vw - 30px);
flex-direction: column;
align-items: stretch;
gap: 10px;
}
.inclination-control {
flex-basis: auto;
}
.camera-hint {
display: none;
}
}
@media (max-width: 650px) {
.title-block {
max-width: calc(100vw - 36px);
}
h1 {
font-size: 21px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 146px;
width: 260px;
max-height: 245px;
overflow: auto;
}
.checks,
.metrics {
display: none;
}
.status-detail {
font-size: 10px;
}
.button-row {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive 3D eclipse alignment diagram"></canvas>
<div id="labels"></div>
<header class="title-block">
<div class="eyebrow">Heliocentric snapshot / 3D geometry</div>
<h1>Sun–Planet–Moon<br />Eclipse Alignment</h1>
<div class="subtitle">
Inclined lunar orbit, orbital nodes, real shadow mapping, and a cutaway planet
</div>
</header>
<aside class="panel">
<h2>Why the node matters</h2>
<p class="panel-intro">
A solar eclipse requires the Moon to cross the ecliptic near a node,
while also lying on the Sun–planet axis. The shaded strip is the
eclipse corridor.
</p>
<div id="statusCard" class="status-card" data-state="eclipse">
<div class="status-heading">
<span class="status-dot"></span>
<span id="statusTitle">Eclipse alignment</span>
</div>
<div id="statusDetail" class="status-detail">
The Moon is at the Sun-facing node and lies inside the shadow corridor.
</div>
</div>
<div class="checks">
<div id="checkNode" class="check pass">
<span class="check-icon">✓</span>
<span>Near an orbital node</span>
<span id="nodeValue" class="check-value">0.0°</span>
</div>
<div id="checkAxis" class="check pass">
<span class="check-icon">✓</span>
<span>On the Sun–planet axis</span>
<span id="axisValue" class="check-value">0.0°</span>
</div>
<div id="checkSide" class="check pass">
<span class="check-icon">✓</span>
<span>On the Sun-facing side</span>
<span id="sideValue" class="check-value">YES</span>
</div>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">Distance from node</div>
<div id="nodeMetric" class="metric-value">0.0°</div>
</div>
<div class="metric">
<div class="metric-label">Ecliptic latitude</div>
<div id="latitudeMetric" class="metric-value">0.0°</div>
</div>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch orbit"></span>
Inclined lunar orbit and orbital plane
</div>
<div class="legend-item">
<span class="swatch reference"></span>
Zero-inclination comparison path
</div>
<div class="legend-item">
<span class="swatch corridor"></span>
Eclipse corridor and node markers
</div>
<div class="legend-item">
<span class="swatch planet"></span>
Cutaway: crust, mantle, and core
</div>
</div>
</aside>
<div class="controls">
<div class="inclination-control">
<label class="control-label" for="inclination">
<span>Orbital inclination</span>
<output id="inclinationValue" for="inclination">14°</output>
</label>
<input
id="inclination"
type="range"
min="0"
max="24"
step="1"
value="14"
/>
</div>
<div class="button-row">
<button id="eclipseButton" class="primary">Eclipse at node</button>
<button id="missButton" class="pink">Off-node miss</button>
<button id="playButton">▶ Animate orbit</button>
<button id="resetButton">Reset view</button>
</div>
</div>
<div class="camera-hint">
DRAG TO ORBIT · WHEEL TO ZOOM · RIGHT-DRAG TO PAN<br />
DOUBLE-CLICK TO RESET · SPACE TO ANIMATE
</div>
<div class="scale-note">
<strong>Illustrative scale</strong>
Planet and Moon sizes are enlarged; distances are compressed.
The geometry is schematic, not a physical size or distance model.
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x050914, 1);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x050914, 0.0075);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const world = new THREE.Group();
scene.add(world);
const ORBIT_RADIUS = 10.2;
const PLANET_RADIUS = 4.2;
const MOON_RADIUS = 1.55;
const ORBIT_SEGMENTS = 256;
let inclination = THREE.MathUtils.degToRad(14);
let orbitalPhase = Math.PI;
let isPlaying = false;
const clock = new THREE.Clock();
// ------------------------------------------------------------
// Procedural textures
// ------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makePlanetTexture() {
const random = seededRandom(4127);
const c = document.createElement("canvas");
c.width = 1024;
c.height = 512;
const ctx = c.getContext("2d");
const ocean = ctx.createLinearGradient(0, 0, 0, c.height);
ocean.addColorStop(0, "#123b66");
ocean.addColorStop(0.48, "#176c99");
ocean.addColorStop(1, "#10365c");
ctx.fillStyle = ocean;
ctx.fillRect(0, 0, c.width, c.height);
for (let i = 0; i < 64; i++) {
const x = random() * c.width;
const y = random() * c.height;
const rx = 18 + random() * 92;
const ry = 9 + random() * 42;
ctx.save();
ctx.translate(x, y);
ctx.rotate((random() - 0.5) * 1.1);
ctx.scale(rx, ry);
const land = ctx.createRadialGradient(0, 0, 0.1, 0, 0, 1);
land.addColorStop(0, i % 4 === 0 ? "#b69c64" : "#4e936a");
land.addColorStop(0.55, i % 4 === 0 ? "#7e8653" : "#337558");
land.addColorStop(1, "rgba(33, 101, 78, 0)");
ctx.fillStyle = land;
ctx.beginPath();
ctx.arc(0, 0, 1, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
ctx.globalAlpha = 0.28;
ctx.strokeStyle = "#eef7ff";
ctx.lineCap = "round";
for (let i = 0; i < 36; i++) {
const x = random() * c.width;
const y = random() * c.height;
const length = 25 + random() * 130;
ctx.lineWidth = 2 + random() * 7;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.bezierCurveTo(
x + length * 0.3,
y - 14,
x + length * 0.7,
y + 15,
x + length,
y
);
ctx.stroke();
}
ctx.globalAlpha = 1;
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeMoonTexture() {
const random = seededRandom(9201);
const c = document.createElement("canvas");
c.width = 512;
c.height = 256;
const ctx = c.getContext("2d");
const image = ctx.createImageData(c.width, c.height);
for (let i = 0; i < image.data.length; i += 4) {
const noise = (random() - 0.5) * 25;
image.data[i] = 164 + noise;
image.data[i + 1] = 164 + noise;
image.data[i + 2] = 157 + noise;
image.data[i + 3] = 255;
}
ctx.putImageData(image, 0, 0);
for (let i = 0; i < 48; i++) {
const x = random() * c.width;
const y = random() * c.height;
const radius = 2 + random() * 14;
const crater = ctx.createRadialGradient(
x - radius * 0.2,
y - radius * 0.2,
0,
x,
y,
radius
);
crater.addColorStop(0, "rgba(80,78,76,0.42)");
crater.addColorStop(0.7, "rgba(102,100,96,0.35)");
crater.addColorStop(1, "rgba(215,212,202,0.12)");
ctx.fillStyle = crater;
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeGlowTexture() {
const c = document.createElement("canvas");
c.width = 256;
c.height = 256;
const ctx = c.getContext("2d");
const gradient = ctx.createRadialGradient(128, 128, 0, 128, 128, 128);
gradient.addColorStop(0, "rgba(255,255,255,0.7)");
gradient.addColorStop(0.22, "rgba(120,220,255,0.32)");
gradient.addColorStop(0.58, "rgba(50,130,255,0.08)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// ------------------------------------------------------------
// Lighting and background
// ------------------------------------------------------------
const ambient = new THREE.AmbientLight(0x7896c8, 0.45);
scene.add(ambient);
const hemisphere = new THREE.HemisphereLight(0x9bc9ff, 0x15101a, 0.7);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffedc5, 3.25);
sunlight.position.set(-30, 0, 0);
sunlight.target.position.set(0, 0, 0);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -18;
sunlight.shadow.camera.right = 18;
sunlight.shadow.camera.top = 18;
sunlight.shadow.camera.bottom = -18;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 70;
sunlight.shadow.bias = -0.00035;
sunlight.shadow.normalBias = 0.025;
scene.add(sunlight, sunlight.target);
const cameraFill = new THREE.PointLight(0x67baff, 42, 40, 2);
cameraFill.position.set(-8, 8, 14);
scene.add(cameraFill);
const coreLight = new THREE.PointLight(0xff6828, 30, 13, 2);
coreLight.position.set(0, -0.3, 0);
scene.add(coreLight);
function createStars() {
const random = seededRandom(117);
const count = 850;
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const theta = random() * Math.PI * 2;
const u = random() * 2 - 1;
const radius = 42 + random() * 42;
const horizontal = Math.sqrt(1 - u * u);
positions[i * 3] = radius * horizontal * Math.cos(theta);
positions[i * 3 + 1] = radius * u;
positions[i * 3 + 2] = radius * horizontal * Math.sin(theta);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
const material = new THREE.PointsMaterial({
color: 0xb8d5ff,
size: 0.085,
sizeAttenuation: true,
transparent: true,
opacity: 0.72,
depthWrite: false,
fog: false
});
const stars = new THREE.Points(geometry, material);
scene.add(stars);
return stars;
}
const stars = createStars();
// ------------------------------------------------------------
// Ecliptic/reference plane
// ------------------------------------------------------------
const grid = new THREE.GridHelper(
34,
34,
0x376899,
0x1d3550
);
grid.position.y = -0.08;
const gridMaterials = Array.isArray(grid.material)
? grid.material
: [grid.material];
gridMaterials.forEach((material) => {
material.transparent = true;
material.opacity = 0.28;
material.depthWrite = false;
});
scene.add(grid);
const referenceDisk = new THREE.Mesh(
new THREE.CircleGeometry(14.5, 128),
new THREE.MeshBasicMaterial({
color: 0x5b86b8,
transparent: true,
opacity: 0.025,
side: THREE.DoubleSide,
depthWrite: false
})
);
referenceDisk.rotation.x = -Math.PI / 2;
referenceDisk.position.y = -0.095;
scene.add(referenceDisk);
// The inclined orbital plane is a translucent disk whose normal
// changes as the inclination slider moves.
const inclinedDiskGeometry = new THREE.BufferGeometry();
const inclinedDiskPositions = new Float32Array((ORBIT_SEGMENTS + 1) * 3);
const inclinedDiskIndices = [];
for (let i = 1; i < ORBIT_SEGMENTS; i++) {
inclinedDiskIndices.push(0, i, i + 1);
}
inclinedDiskGeometry.setAttribute(
"position",
new THREE.BufferAttribute(inclinedDiskPositions, 3)
);
inclinedDiskGeometry.setIndex(inclinedDiskIndices);
const inclinedDisk = new THREE.Mesh(
inclinedDiskGeometry,
new THREE.MeshBasicMaterial({
color: 0x48d8ff,
transparent: true,
opacity: 0.032,
side: THREE.DoubleSide,
depthWrite: false
})
);
inclinedDisk.frustumCulled = false;
scene.add(inclinedDisk);
// Zero-inclination comparison path.
const referenceCirclePoints = [];
for (let i = 0; i <= ORBIT_SEGMENTS; i++) {
const theta = (i / ORBIT_SEGMENTS) * Math.PI * 2;
referenceCirclePoints.push(
new THREE.Vector3(
ORBIT_RADIUS * Math.cos(theta),
0.015,
ORBIT_RADIUS * Math.sin(theta)
)
);
}
const referenceCircle = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(referenceCirclePoints),
new THREE.LineDashedMaterial({
color: 0x8397b4,
dashSize: 0.28,
gapSize: 0.2,
transparent: true,
opacity: 0.48
})
);
referenceCircle.computeLineDistances();
scene.add(referenceCircle);
// The actual inclined orbit.
const orbitPoints = [];
for (let i = 0; i <= ORBIT_SEGMENTS; i++) {
const theta = (i / ORBIT_SEGMENTS) * Math.PI * 2;
orbitPoints.push(new THREE.Vector3());
}
const actualOrbit = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(orbitPoints),
new THREE.LineBasicMaterial({
color: 0x60e6ff,
transparent: true,
opacity: 0.88
})
);
scene.add(actualOrbit);
function orbitPoint(theta, target = new THREE.Vector3()) {
return target.set(
ORBIT_RADIUS * Math.cos(theta),
-ORBIT_RADIUS * Math.sin(theta) * Math.sin(inclination),
ORBIT_RADIUS * Math.sin(theta) * Math.cos(inclination)
);
}
function updateOrbitGeometry() {
for (let i = 0; i <= ORBIT_SEGMENTS; i++) {
const theta = (i / ORBIT_SEGMENTS) * Math.PI * 2;
orbitPoint(theta, orbitPoints[i]);
}
actualOrbit.geometry.setFromPoints(orbitPoints);
const w = new THREE.Vector3(
0,
-Math.sin(inclination),
Math.cos(inclination)
);
inclinedDiskPositions[0] = 0;
inclinedDiskPositions[1] = 0;
inclinedDiskPositions[2] = 0;
for (let i = 0; i <= ORBIT_SEGMENTS; i++) {
const theta = (i / ORBIT_SEGMENTS) * Math.PI * 2;
const index = (i + 1) * 3;
inclinedDiskPositions[index] =
ORBIT_RADIUS * Math.cos(theta);
inclinedDiskPositions[index + 1] =
ORBIT_RADIUS * Math.sin(theta) * w.y;
inclinedDiskPositions[index + 2] =
ORBIT_RADIUS * Math.sin(theta) * w.z;
}
inclinedDiskGeometry.attributes.position.needsUpdate = true;
inclinedDiskGeometry.computeVertexNormals();
inclinedDiskGeometry.computeBoundingSphere();
}
// Node markers: the inclined orbit crosses y=0 at x = ±R.
const nodeMaterial = new THREE.MeshStandardMaterial({
color: 0xffc65c,
emissive: 0xff8d22,
emissiveIntensity: 1.8,
roughness: 0.35,
metalness: 0.15
});
const nodes = [];
for (const x of [-ORBIT_RADIUS, ORBIT_RADIUS]) {
const node = new THREE.Mesh(
new THREE.OctahedronGeometry(0.24),
nodeMaterial
);
node.position.set(x, 0, 0);
world.add(node);
nodes.push(node);
}
// The eclipse corridor is centered on the Sun–planet line.
const corridor = new THREE.Mesh(
new THREE.BoxGeometry(14, 0.025, 2.15),
new THREE.MeshBasicMaterial({
color: 0xffbf4f,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
corridor.position.set(-10.8, -0.035, 0);
world.add(corridor);
const sunlightAxis = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-20, 0, 0),
new THREE.Vector3(-4.12, 0, 0)
]),
new THREE.LineDashedMaterial({
color: 0xffce69,
dashSize: 0.48,
gapSize: 0.26,
transparent: true,
opacity: 0.72
})
);
sunlightAxis.computeLineDistances();
world.add(sunlightAxis);
const sunlightArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-17.5, 2.1, -3.3),
7,
0xffc65c,
0.65,
0.3
);
world.add(sunlightArrow);
// ------------------------------------------------------------
// Cutaway planet
// ------------------------------------------------------------
const planetGroup = new THREE.Group();
world.add(planetGroup);
// A 74-degree wedge is removed from the camera-facing side.
const missingPhiStart = 0.25;
const missingPhiEnd = 1.55;
const shellPhiStart = missingPhiEnd;
const shellPhiLength = Math.PI * 2 - (missingPhiEnd - missingPhiStart);
const crustMaterial = new THREE.MeshStandardMaterial({
map: makePlanetTexture(),
color: 0xffffff,
roughness: 0.86,
metalness: 0.03,
side: THREE.DoubleSide
});
const mantleMaterial = new THREE.MeshStandardMaterial({
color: 0xd96d2e,
emissive: 0x421405,
emissiveIntensity: 0.32,
roughness: 0.68,
side: THREE.DoubleSide
});
const coreMaterial = new THREE.MeshStandardMaterial({
color: 0xff7b21,
emissive: 0xff2d00,
emissiveIntensity: 2.15,
roughness: 0.4
});
const innerCoreMaterial = new THREE.MeshBasicMaterial({
color: 0xffe19a
});
const shell = new THREE.Mesh(
new THREE.SphereGeometry(
PLANET_RADIUS,
96,
64,
shellPhiStart,
shellPhiLength,
0,
Math.PI
),
crustMaterial
);
shell.castShadow = true;
shell.receiveShadow = true;
planetGroup.add(shell);
const mantle = new THREE.Mesh(
new THREE.SphereGeometry(
3.55,
80,
52,
shellPhiStart,
shellPhiLength,
0,
Math.PI
),
mantleMaterial
);
mantle.receiveShadow = true;
planetGroup.add(mantle);
const core = new THREE.Mesh(
new THREE.SphereGeometry(2.25, 72, 48),
coreMaterial
);
planetGroup.add(core);
const innerCore = new THREE.Mesh(
new THREE.SphereGeometry(1.12, 48, 32),
innerCoreMaterial
);
planetGroup.add(innerCore);
function makeHalfAnnulus(innerRadius, outerRadius, phi) {
const positions = [];
const indices = [];
const segments = 64;
const u = new THREE.Vector3(-Math.cos(phi), 0, Math.sin(phi));
const v = new THREE.Vector3(0, 1, 0);
for (let i = 0; i <= segments; i++) {
const angle = -Math.PI / 2 + (i / segments) * Math.PI;
const innerQ = innerRadius * Math.cos(angle);
const innerY = innerRadius * Math.sin(angle);
const outerQ = outerRadius * Math.cos(angle);
const outerY = outerRadius * Math.sin(angle);
positions.push(
u.x * innerQ, v.y * innerY, u.z * innerQ,
u.x * outerQ, v.y * outerY, u.z * outerQ
);
if (i < segments) {
const base = i * 2;
indices.push(base, base + 2, base + 1);
indices.push(base + 1, base + 2, base + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeHalfDisc(radius, phi) {
const geometry = new THREE.CircleGeometry(
radius,
64,
-Math.PI / 2,
Math.PI
);
const position = geometry.attributes.position;
const u = new THREE.Vector3(-Math.cos(phi), 0, Math.sin(phi));
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
position.setXYZ(i, u.x * x, y, u.z * x);
}
position.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
const cutCrustMaterial = new THREE.MeshStandardMaterial({
color: 0x397d9d,
roughness: 0.8,
side: THREE.DoubleSide
});
const cutMantleMaterial = new THREE.MeshStandardMaterial({
color: 0xe77d32,
roughness: 0.58,
emissive: 0x3b1003,
emissiveIntensity: 0.25,
side: THREE.DoubleSide
});
const cutCoreMaterial = new THREE.MeshStandardMaterial({
color: 0xffad43,
emissive: 0xff4d0a,
emissiveIntensity: 1.25,
roughness: 0.4,
side: THREE.DoubleSide
});
for (const phi of [missingPhiStart, missingPhiEnd]) {
const crustFace = new THREE.Mesh(
makeHalfAnnulus(3.55, PLANET_RADIUS, phi),
cutCrustMaterial
);
crustFace.receiveShadow = true;
planetGroup.add(crustFace);
const mantleFace = new THREE.Mesh(
makeHalfAnnulus(2.25, 3.55, phi),
cutMantleMaterial
);
planetGroup.add(mantleFace);
const coreFace = new THREE.Mesh(
makeHalfDisc(2.25, phi),
cutCoreMaterial
);
planetGroup.add(coreFace);
}
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(PLANET_RADIUS * 1.055, 64, 40),
new THREE.MeshBasicMaterial({
color: 0x58c9ff,
transparent: true,
opacity: 0.12,
side: THREE.BackSide,
depthWrite: false
})
);
planetGroup.add(atmosphere);
const planetGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeGlowTexture(),
color: 0x4fb9ff,
transparent: true,
opacity: 0.17,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
planetGlow.scale.set(12, 12, 1);
planetGroup.add(planetGlow);
// ------------------------------------------------------------
// Moon, shadow cone, and projection guide
// ------------------------------------------------------------
const moon = new THREE.Mesh(
new THREE.SphereGeometry(MOON_RADIUS, 64, 40),
new THREE.MeshStandardMaterial({
map: makeMoonTexture(),
color: 0xffffff,
roughness: 1,
metalness: 0
})
);
moon.castShadow = true;
moon.receiveShadow = true;
world.add(moon);
const umbra = new THREE.Mesh(
new THREE.CylinderGeometry(
0.28,
MOON_RADIUS * 1.02,
1,
48,
1,
true
),
new THREE.MeshBasicMaterial({
color: 0x000000,
transparent: true,
opacity: 0.58,
side: THREE.DoubleSide,
depthWrite: false
})
);
umbra.rotation.z = -Math.PI / 2;
umbra.renderOrder = 2;
world.add(umbra);
const penumbra = new THREE.Mesh(
new THREE.CylinderGeometry(3.0, 3.2, 1, 48, 1, true),
new THREE.MeshBasicMaterial({
color: 0x879bc5,
transparent: true,
opacity: 0.065,
side: THREE.DoubleSide,
depthWrite: false
})
);
penumbra.rotation.z = -Math.PI / 2;
penumbra.renderOrder = 1;
world.add(penumbra);
// A visible footprint supplements the actual shadow map.
const footprint = new THREE.Mesh(
new THREE.CircleGeometry(0.98, 48),
new THREE.MeshBasicMaterial({
color: 0x010207,
transparent: true,
opacity: 0.56,
depthWrite: false,
side: THREE.DoubleSide
})
);
footprint.rotation.y = -Math.PI / 2;
footprint.position.set(-4.225, 0, 0);
footprint.renderOrder = 3;
world.add(footprint);
const projectedMarker = new THREE.Mesh(
new THREE.RingGeometry(0.11, 0.19, 32),
new THREE.MeshBasicMaterial({
color: 0xff73bd,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false
})
);
projectedMarker.rotation.x = -Math.PI / 2;
world.add(projectedMarker);
const offsetLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]),
new THREE.LineDashedMaterial({
color: 0xff73bd,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.8
})
);
world.add(offsetLine);
// ------------------------------------------------------------
// HTML labels projected from 3D anchors
// ------------------------------------------------------------
const sceneTags = [];
function createTag(text, className, anchor, offset = [0, 0]) {
const element = document.createElement("div");
element.className = `scene-tag ${className || ""}`;
element.textContent = text;
labelsLayer.appendChild(element);
const tag = { element, anchor, offset };
sceneTags.push(tag);
return tag;
}
const moonTag = createTag(
"Moon",
"cyan",
() => moon.position,
[24, -30]
);
const nodeTag = createTag(
"Orbital node",
"amber",
() => new THREE.Vector3(-ORBIT_RADIUS, 0.15, 0),
[-35, -30]
);
const corridorTag = createTag(
"Eclipse corridor",
"amber",
() => new THREE.Vector3(-7.4, 0, 0),
[0, 30]
);
const sunTag = createTag(
"Sun off-frame →",
"amber",
() => new THREE.Vector3(-15.8, 2.1, -3.3),
[-35, -16]
);
const umbraTag = createTag(
"Umbra",
"",
() => new THREE.Vector3(moon.position.x + 2.5, moon.position.y + 0.7, moon.position.z),
[28, 8]
);
const planetTag = createTag(
"Planet · cutaway",
"",
() => new THREE.Vector3(-0.8, -3.1, 1.7),
[-68, 13]
);
const coreTag = createTag(
"Core",
"pink",
() => new THREE.Vector3(0.1, -0.35, 0.5),
[30, 22]
);
const eclipticTag = createTag(
"Ecliptic / reference plane",
"",
() => new THREE.Vector3(6.6, -0.02, -6.8),
[15, 19]
);
const inclinationTag = createTag(
"14° orbital plane",
"cyan",
() => orbitPoint(Math.PI * 0.56),
[42, -20]
);
function updateTags() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const tag of sceneTags) {
const anchor =
typeof tag.anchor === "function"
? tag.anchor()
: tag.anchor;
const projected = anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
tag.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width + tag.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + tag.offset[1];
tag.element.style.left = `${x}px`;
tag.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Dynamic eclipse status
// ------------------------------------------------------------
const statusCard = document.querySelector("#statusCard");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const checkNode = document.querySelector("#checkNode");
const checkAxis = document.querySelector("#checkAxis");
const checkSide = document.querySelector("#checkSide");
const nodeValue = document.querySelector("#nodeValue");
const axisValue = document.querySelector("#axisValue");
const sideValue = document.querySelector("#sideValue");
const nodeMetric = document.querySelector("#nodeMetric");
const latitudeMetric = document.querySelector("#latitudeMetric");
function setCheck(element, passes) {
element.classList.toggle("pass", passes);
element.querySelector(".check-icon").textContent = passes ? "✓" : "×";
}
function updateMoonAndStatus() {
orbitPoint(orbitalPhase, moon.position);
const nodeDelta = Math.abs(
Math.atan2(
Math.sin(orbitalPhase - Math.PI),
Math.cos(orbitalPhase - Math.PI)
)
);
const nodeDegrees = THREE.MathUtils.radToDeg(nodeDelta);
const latitude = THREE.MathUtils.radToDeg(
Math.asin(THREE.MathUtils.clamp(moon.position.y / ORBIT_RADIUS, -1, 1))
);
const axisSeparation = THREE.MathUtils.radToDeg(
Math.acos(
THREE.MathUtils.clamp(-moon.position.x / ORBIT_RADIUS, -1, 1)
)
);
const nearNode = nodeDegrees < 8;
const onAxis = axisSeparation < 15;
const sunFacing = moon.position.x < 0;
setCheck(checkNode, nearNode);
setCheck(checkAxis, onAxis);
setCheck(checkSide, sunFacing);
nodeValue.textContent = `${nodeDegrees.toFixed(1)}°`;
axisValue.textContent = `${axisSeparation.toFixed(1)}°`;
sideValue.textContent = sunFacing ? "YES" : "NO";
nodeMetric.textContent = `${nodeDegrees.toFixed(1)}°`;
latitudeMetric.textContent = `${Math.abs(latitude).toFixed(1)}° ${
latitude >= 0 ? "above" : "below"
}`;
let state = "miss";
let title = "Off-node shadow miss";
let detail =
"The Moon is above or below the ecliptic corridor, so its shadow misses the planet.";
if (!sunFacing) {
title = "No solar eclipse here";
detail =
"The Moon is on the planet's far side relative to the off-frame Sun.";
} else if (nearNode && axisSeparation < 2.2) {
state = "eclipse";
title = "Eclipse alignment";
detail =
"The Moon is at the Sun-facing node and lies on the Sun–planet axis.";
} else if (nearNode) {
state = "partial";
title = "Near-node partial alignment";
detail =
"The node is close, but the Moon still has a measurable height above or below the axis.";
}
statusCard.dataset.state = state;
statusTitle.textContent = title;
statusDetail.textContent = detail;
// Shadow cone: sunlight travels in the +X direction.
const towardPlanet = moon.position.x < -4.1;
umbra.visible = towardPlanet;
penumbra.visible = towardPlanet;
if (towardPlanet) {
const length = -3.85 - moon.position.x;
umbra.scale.set(1, length, 1);
umbra.position.set(
moon.position.x + length * 0.5,
moon.position.y,
moon.position.z
);
penumbra.scale.set(1, length + 0.5, 1);
penumbra.position.set(
moon.position.x + (length + 0.5) * 0.5,
moon.position.y,
moon.position.z
);
}
// The projected position shows the Moon's displacement from the plane.
projectedMarker.position.set(
moon.position.x,
0.025,
moon.position.z
);
const offsetLength = Math.abs(moon.position.y);
projectedMarker.visible = offsetLength > 0.035;
offsetLine.visible = projectedMarker.visible;
if (projectedMarker.visible) {
const positions = offsetLine.geometry.attributes.position;
positions.setXYZ(0, moon.position.x, moon.position.y, moon.position.z);
positions.setXYZ(1, moon.position.x, 0.025, moon.position.z);
positions.needsUpdate = true;
offsetLine.computeLineDistances();
}
// Stylized footprint, visible only when the shadow can reach the planet.
const footprintStrength = THREE.MathUtils.clamp(
1 - axisSeparation / 18,
0,
1
);
footprint.visible = sunFacing && footprintStrength > 0.01;
footprint.material.opacity = 0.58 * footprintStrength;
footprint.scale.setScalar(0.55 + footprintStrength * 0.45);
}
// ------------------------------------------------------------
// Custom camera controls — no addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-1.5, 0, 0);
const desiredTarget = cameraTarget.clone();
let cameraTheta = 2.12;
let cameraPhi = 1.12;
let cameraRadius = 24;
let desiredTheta = cameraTheta;
let desiredPhi = cameraPhi;
let desiredRadius = cameraRadius;
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-9 * dt);
cameraTheta = THREE.MathUtils.lerp(cameraTheta, desiredTheta, smoothing);
cameraPhi = THREE.MathUtils.lerp(cameraPhi, desiredPhi, smoothing);
cameraRadius = THREE.MathUtils.lerp(cameraRadius, desiredRadius, smoothing);
cameraTarget.lerp(desiredTarget, smoothing);
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.cos(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.sin(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
desiredTarget.set(-1.5, 0, 0);
desiredTheta = 2.12;
desiredPhi = 1.12;
desiredRadius = 24;
}
let pointer = null;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointer = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
button: event.button
};
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer || pointer.id !== event.pointerId) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.button === 0) {
desiredTheta -= dx * 0.006;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - dy * 0.005,
0.22,
Math.PI - 0.22
);
} else if (pointer.button === 2) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const panScale = desiredRadius * 0.0013;
desiredTarget
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -8, 8);
desiredTarget.y = THREE.MathUtils.clamp(desiredTarget.y, -5, 5);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -8, 8);
}
});
function endPointer(event) {
if (pointer && pointer.id === event.pointerId) {
pointer = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.012,
12,
43
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
const inclinationSlider = document.querySelector("#inclination");
const inclinationValue = document.querySelector("#inclinationValue");
const eclipseButton = document.querySelector("#eclipseButton");
const missButton = document.querySelector("#missButton");
const playButton = document.querySelector("#playButton");
const resetButton = document.querySelector("#resetButton");
function updateInclination() {
inclination = THREE.MathUtils.degToRad(
Number(inclinationSlider.value)
);
const degrees = Number(inclinationSlider.value);
inclinationValue.textContent = `${degrees}°`;
inclinationTag.element.textContent = `${degrees}° orbital plane`;
const fraction = degrees / 24;
inclinationSlider.style.background = `linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) ${fraction * 100}%,
rgba(255,255,255,0.13) ${fraction * 100}%,
rgba(255,255,255,0.13) 100%
)`;
updateOrbitGeometry();
updateMoonAndStatus();
}
inclinationSlider.addEventListener("input", updateInclination);
eclipseButton.addEventListener("click", () => {
orbitalPhase = Math.PI;
isPlaying = false;
playButton.textContent = "▶ Animate orbit";
updateMoonAndStatus();
});
missButton.addEventListener("click", () => {
if (inclination < THREE.MathUtils.degToRad(8)) {
inclinationSlider.value = "14";
updateInclination();
}
orbitalPhase = Math.PI - 0.42;
isPlaying = false;
playButton.textContent = "▶ Animate orbit";
updateMoonAndStatus();
});
playButton.addEventListener("click", () => {
isPlaying = !isPlaying;
playButton.textContent = isPlaying ? "❚❚ Pause orbit" : "▶ Animate orbit";
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "e") {
eclipseButton.click();
}
if (event.key.toLowerCase() === "m") {
missButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateOrbitGeometry();
updateInclination();
updateMoonAndStatus();
updateCamera(1);
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (isPlaying) {
orbitalPhase =
(orbitalPhase + dt * 0.105) % (Math.PI * 2);
updateMoonAndStatus();
}
moon.rotation.y += dt * 0.045;
stars.rotation.y += dt * 0.002;
nodeMaterial.emissiveIntensity =
1.65 + Math.sin(performance.now() * 0.0022) * 0.25;
updateCamera(dt);
updateTags();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```