Prompt specification
Build or customize the Three.js 3D scene "Ellipse With Focus and Equal-Time Sectors" 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: Ellipse With Focus and Equal-Time Sectors
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ellipse-with-focus-and-equal-time-sectors-x3801
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring elliptical orbits and changing orbital speed. Model an ellipse with the attracting focus and several equal-time orbital sectors. Show that the focus is not generally the geometric center. A 3D cutaway view.
Working Three.js Starter (ellipse-with-focus-and-equal-time-sectors-x3801):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kepler's Second Law — 3D Elliptical Cutaway</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 15, 30, 0.82);
--border: rgba(148, 163, 184, 0.22);
--muted: #94a3b8;
--text: #e5edf8;
--gold: #ffd166;
--cyan: #67e8f9;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #030712;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(4, 10, 22, 0.82));
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.42),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #334155 transparent;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 36px);
line-height: 1.06;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 16px;
color: #b8c5d8;
font-size: 14px;
line-height: 1.55;
}
.equation {
margin: 14px 0;
padding: 12px 14px;
border: 1px solid rgba(103, 232, 249, 0.18);
border-radius: 12px;
background: rgba(14, 116, 144, 0.09);
color: #d9fbff;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
text-align: center;
}
.note {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.note strong {
color: #dbeafe;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
margin: 16px 0;
}
.metric {
min-width: 0;
padding: 10px;
border: 1px solid rgba(148, 163, 184, 0.13);
border-radius: 11px;
background: rgba(15, 23, 42, 0.48);
}
.metric-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: #f8fafc;
font-size: 17px;
font-variant-numeric: tabular-nums;
text-overflow: ellipsis;
white-space: nowrap;
}
.section-title {
margin: 17px 0 9px;
color: #cbd5e1;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.sector-row {
display: grid;
grid-template-columns: 17px 1fr 76px;
align-items: center;
gap: 8px;
min-height: 24px;
margin: 4px 0;
color: #94a3b8;
font-size: 10px;
font-variant-numeric: tabular-nums;
transition: color 150ms ease;
}
.sector-row.current {
color: #f8fafc;
}
.sector-dot {
width: 9px;
height: 9px;
margin-left: 3px;
border-radius: 50%;
box-shadow: 0 0 9px currentColor;
}
.bar-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(148, 163, 184, 0.11);
}
.bar {
height: 100%;
border-radius: inherit;
opacity: 0.78;
}
.sector-row.current .bar {
opacity: 1;
box-shadow: 0 0 12px currentColor;
}
.arc-length {
text-align: right;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 17px;
}
button {
flex: 1;
padding: 9px 12px;
border: 1px solid rgba(148, 163, 184, 0.22);
border-radius: 10px;
background: rgba(30, 41, 59, 0.8);
color: #e2e8f0;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(103, 232, 249, 0.5);
background: rgba(14, 116, 144, 0.28);
}
button:active {
transform: translateY(1px);
}
#help {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(4, 10, 22, 0.72);
color: #94a3b8;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(12px);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #030712;
color: #67e8f9;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 700px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 45vh;
padding: 15px;
border-radius: 14px;
}
h1 {
font-size: 25px;
}
.subtitle {
margin-bottom: 10px;
}
.metrics {
margin: 10px 0;
}
#help {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive 3D illustration of an elliptical orbit"></div>
<section class="panel" aria-label="Explanation and live orbital measurements">
<div class="eyebrow">Oblique 3D cutaway</div>
<h1>Equal time.<br>Unequal arc length.</h1>
<p class="subtitle">
The eight colored sectors each represent the same elapsed time.
Their swept areas are equal, but the planet covers a longer orbital
arc when moving rapidly near the attracting focus.
</p>
<div class="equation">
dA/dt = L/2 = constant
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Sector time</span>
<span class="metric-value" id="sector-time">—</span>
</div>
<div class="metric">
<span class="metric-label">Sector area</span>
<span class="metric-value" id="sector-area">—</span>
</div>
<div class="metric">
<span class="metric-label">Focus offset</span>
<span class="metric-value" id="focus-offset">—</span>
</div>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Current speed</span>
<span class="metric-value" id="speed">—</span>
</div>
<div class="metric">
<span class="metric-label">Focus distance</span>
<span class="metric-value" id="radius">—</span>
</div>
<div class="metric">
<span class="metric-label">Current sector</span>
<span class="metric-value" id="current-sector">—</span>
</div>
</div>
<div class="section-title">Equal Δt · varying orbital arc</div>
<div id="sector-bars"></div>
<p class="note">
<strong>F</strong> is the attracting focus and <strong>C</strong> is the
geometric center. For an ellipse their separation is
<strong>c = ae</strong>, so the focus is generally not the center.
</p>
<div class="buttons">
<button id="pause" type="button">Pause motion</button>
<button id="reset" type="button">Reset camera</button>
</div>
</section>
<div id="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="loading">Building orbital cutaway…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Orbital model
// ------------------------------------------------------------
const A = 4.2; // semimajor axis
const ECCENTRICITY = 0.62; // eccentricity
const B = A * Math.sqrt(1 - ECCENTRICITY * ECCENTRICITY);
const CENTER_X = -A * ECCENTRICITY; // focus is at the world origin
const SECTOR_COUNT = 8;
const PERIOD = 18; // seconds
const MEAN_MOTION = 2 * Math.PI / PERIOD;
const colors = [
0xf59e0b,
0xfb7185,
0xa78bfa,
0x60a5fa,
0x22d3ee,
0x34d399,
0xfacc15,
0xfb923c
];
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x030712);
scene.fog = new THREE.FogExp2(0x030712, 0.017);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
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;
stage.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0x9bb8ff, 0x101827, 1.65));
const keyLight = new THREE.DirectionalLight(0xdbeafe, 2.4);
keyLight.position.set(5, -8, 11);
scene.add(keyLight);
const focusLight = new THREE.PointLight(0xffaa44, 34, 11, 2);
focusLight.position.set(0, 0, 0.55);
scene.add(focusLight);
const world = new THREE.Group();
scene.add(world);
// ------------------------------------------------------------
// Deterministic star field
// ------------------------------------------------------------
let seed = 928374;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const starPositions = [];
for (let i = 0; i < 850; i++) {
const radius = 18 + random() * 28;
const theta = random() * Math.PI * 2;
const u = random() * 2 - 1;
const s = Math.sqrt(1 - u * u);
starPositions.push(
radius * s * Math.cos(theta),
radius * u,
radius * s * Math.sin(theta)
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xb9d8ff,
size: 0.055,
transparent: true,
opacity: 0.7,
depthWrite: false
})
);
scene.add(stars);
// ------------------------------------------------------------
// Kepler equation and ellipse helpers
// ------------------------------------------------------------
function solveKepler(meanAnomaly) {
let E = meanAnomaly;
for (let i = 0; i < 9; i++) {
const error =
E - ECCENTRICITY * Math.sin(E) - meanAnomaly;
const derivative =
1 - ECCENTRICITY * Math.cos(E);
E -= error / derivative;
}
return E;
}
function ellipsePoint(E, z = 0) {
return new THREE.Vector3(
A * (Math.cos(E) - ECCENTRICITY),
B * Math.sin(E),
z
);
}
function makeEllipseShape(cx, rx, ry) {
const shape = new THREE.Shape();
for (let i = 0; i <= 160; i++) {
const angle = i / 160 * Math.PI * 2;
const x = cx + rx * Math.cos(angle);
const y = ry * Math.sin(angle);
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
return shape;
}
function lineFromPoints(points, material) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
return new THREE.Line(geometry, material);
}
// ------------------------------------------------------------
// Dark lower slab: gives the colored sectors a cutaway depth
// ------------------------------------------------------------
const baseGeometry = new THREE.ExtrudeGeometry(
makeEllipseShape(CENTER_X, A, B),
{
depth: 0.11,
bevelEnabled: false,
steps: 1
}
);
const base = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x091426,
roughness: 0.72,
metalness: 0.2
})
);
base.position.z = -0.16;
world.add(base);
// Outer orbit rim
const rimPoints = [];
for (let i = 0; i <= 512; i++) {
rimPoints.push(ellipsePoint(i / 512 * Math.PI * 2, 0.105));
}
const rim = lineFromPoints(
rimPoints,
new THREE.LineBasicMaterial({
color: 0xe0f2fe,
transparent: true,
opacity: 0.82
})
);
world.add(rim);
// ------------------------------------------------------------
// Equal-time sectors
// ------------------------------------------------------------
const sectorMeshes = [];
const sectorEdges = [];
const sectorRows = [];
const sectorArcLengths = [];
const barContainer = document.getElementById("sector-bars");
const startAnomalies = [];
for (let k = 0; k < SECTOR_COUNT; k++) {
const startM = k / SECTOR_COUNT * Math.PI * 2;
const endM = (k + 1) / SECTOR_COUNT * Math.PI * 2;
const startE = solveKepler(startM);
const endE = solveKepler(endM);
startAnomalies.push(startE);
const shape = new THREE.Shape();
const firstPoint = ellipsePoint(startE);
shape.moveTo(0, 0);
shape.lineTo(firstPoint.x, firstPoint.y);
const arcPoints = [new THREE.Vector3(0, 0, 0.105)];
arcPoints.push(
new THREE.Vector3(firstPoint.x, firstPoint.y, 0.105)
);
let arcLength = 0;
let previous = firstPoint;
const subdivisions = 64;
for (let j = 1; j <= subdivisions; j++) {
const E = startE + (endE - startE) * j / subdivisions;
const point = ellipsePoint(E);
arcLength += point.distanceTo(previous);
previous = point;
shape.lineTo(point.x, point.y);
arcPoints.push(new THREE.Vector3(point.x, point.y, 0.105));
}
shape.closePath();
sectorArcLengths.push(arcLength);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.115,
bevelEnabled: false,
steps: 1
});
const color = new THREE.Color(colors[k]);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.035,
transparent: true,
opacity: 0.27,
roughness: 0.55,
metalness: 0.06,
side: THREE.DoubleSide,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.z = -0.045;
mesh.renderOrder = 2 + k;
world.add(mesh);
sectorMeshes.push(mesh);
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.48
});
const edge = lineFromPoints(arcPoints, edgeMaterial);
edge.renderOrder = 15;
world.add(edge);
sectorEdges.push(edge);
// Small boundary marker at each equal-time boundary.
const boundaryMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 12, 8),
new THREE.MeshBasicMaterial({ color })
);
boundaryMarker.position.copy(firstPoint);
boundaryMarker.position.z = 0.16;
world.add(boundaryMarker);
}
// Add radius-to-focus closing edges for the final sector.
const finalEnd = ellipsePoint(solveKepler(Math.PI * 2));
const finalEdge = lineFromPoints(
[
new THREE.Vector3(finalEnd.x, finalEnd.y, 0.105),
new THREE.Vector3(0, 0, 0.105)
],
new THREE.LineBasicMaterial({
color: colors[SECTOR_COUNT - 1],
transparent: true,
opacity: 0.48
})
);
world.add(finalEdge);
// ------------------------------------------------------------
// Major axis and focus-to-center dimension
// ------------------------------------------------------------
const pericenterX = A * (1 - ECCENTRICITY);
const apocenterX = -A * (1 + ECCENTRICITY);
const majorAxis = lineFromPoints(
[
new THREE.Vector3(apocenterX, 0, 0.13),
new THREE.Vector3(pericenterX, 0, 0.13)
],
new THREE.LineDashedMaterial({
color: 0x64748b,
dashSize: 0.14,
gapSize: 0.11,
transparent: true,
opacity: 0.52
})
);
majorAxis.computeLineDistances();
world.add(majorAxis);
const focusDistanceLine = lineFromPoints(
[
new THREE.Vector3(CENTER_X, 0, 0.21),
new THREE.Vector3(0, 0, 0.21)
],
new THREE.LineDashedMaterial({
color: 0xffd166,
dashSize: 0.13,
gapSize: 0.08,
transparent: true,
opacity: 0.95
})
);
focusDistanceLine.computeLineDistances();
world.add(focusDistanceLine);
const tickMaterial = new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.9
});
const ticks = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(CENTER_X, -0.17, 0.21),
new THREE.Vector3(CENTER_X, 0.17, 0.21),
new THREE.Vector3(0, -0.17, 0.21),
new THREE.Vector3(0, 0.17, 0.21)
]),
tickMaterial
);
world.add(ticks);
// Geometric center marker and ring.
const centerMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 24, 16),
new THREE.MeshBasicMaterial({ color: 0xcbd5e1 })
);
centerMarker.position.set(CENTER_X, 0, 0.2);
world.add(centerMarker);
const centerRingPoints = [];
for (let i = 0; i <= 64; i++) {
const angle = i / 64 * Math.PI * 2;
centerRingPoints.push(
new THREE.Vector3(
CENTER_X + 0.27 * Math.cos(angle),
0.27 * Math.sin(angle),
0.2
)
);
}
world.add(
lineFromPoints(
centerRingPoints,
new THREE.LineBasicMaterial({
color: 0xe2e8f0,
transparent: true,
opacity: 0.9
})
)
);
// Attracting focus.
const focus = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 32, 20),
new THREE.MeshBasicMaterial({ color: 0xffc857 })
);
focus.position.set(0, 0, 0.24);
world.add(focus);
// ------------------------------------------------------------
// Procedural labels and glow textures
// ------------------------------------------------------------
function makeLabel(text, textColor = "#e5edf8") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(4, 10, 22, 0.84)";
context.strokeStyle = "rgba(148, 163, 184, 0.38)";
context.lineWidth = 3;
context.beginPath();
context.roundRect(5, 5, 758, 150, 30);
context.fill();
context.stroke();
context.fillStyle = textColor;
context.font = "700 36px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 384, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 30;
return sprite;
}
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128, 128, 0,
128, 128, 128
);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.12, "rgba(255,210,100,0.95)");
gradient.addColorStop(0.35, "rgba(255,155,45,0.35)");
gradient.addColorStop(1, "rgba(255,120,20,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const glow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeGlowTexture(),
color: 0xffffff,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
glow.position.set(0, 0, 0.2);
glow.scale.set(2.2, 2.2, 1);
glow.renderOrder = 25;
world.add(glow);
const focusLabel = makeLabel("ATTRACTING FOCUS F", "#ffd166");
focusLabel.position.set(0, -0.72, 0.72);
focusLabel.scale.set(3.05, 0.64, 1);
world.add(focusLabel);
const centerLabel = makeLabel("GEOMETRIC CENTER C", "#dbeafe");
centerLabel.position.set(CENTER_X, 0.72, 0.72);
centerLabel.scale.set(3.35, 0.64, 1);
world.add(centerLabel);
const offsetLabel = makeLabel("c = ae", "#ffd166");
offsetLabel.position.set(CENTER_X * 0.5, -0.43, 0.67);
offsetLabel.scale.set(1.65, 0.48, 1);
world.add(offsetLabel);
const periLabel = makeLabel("PERIAPSIS · FASTER", "#fef3c7");
periLabel.position.set(pericenterX - 0.1, 0.72, 0.6);
periLabel.scale.set(2.8, 0.53, 1);
world.add(periLabel);
const apoLabel = makeLabel("APOAPSIS · SLOWER", "#cbd5e1");
apoLabel.position.set(apocenterX + 0.35, 0.72, 0.6);
apoLabel.scale.set(2.8, 0.53, 1);
world.add(apoLabel);
// ------------------------------------------------------------
// Moving body, velocity arrow, and equal-time trail
// ------------------------------------------------------------
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 28, 18),
new THREE.MeshStandardMaterial({
color: 0xe0f2fe,
emissive: 0x22d3ee,
emissiveIntensity: 1.35,
roughness: 0.25,
metalness: 0.1
})
);
body.position.z = 0.31;
world.add(body);
const bodyLight = new THREE.PointLight(0x22d3ee, 4.5, 3.4, 2);
world.add(bodyLight);
const velocityArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
1,
0x67e8f9,
0.22,
0.12
);
world.add(velocityArrow);
const trailCount = 96;
const trailMeanStep = Math.PI * 2 / (SECTOR_COUNT * 18);
const trailPositions = new Float32Array(trailCount * 3);
const trailGeometry = new THREE.BufferGeometry();
trailGeometry.setAttribute(
"position",
new THREE.BufferAttribute(trailPositions, 3)
);
const trail = new THREE.Points(
trailGeometry,
new THREE.PointsMaterial({
color: 0x67e8f9,
size: 0.075,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
world.add(trail);
// ------------------------------------------------------------
// DOM readouts and arc-length bars
// ------------------------------------------------------------
const maxArcLength = Math.max(...sectorArcLengths);
const sectorArea = Math.PI * A * B / SECTOR_COUNT;
document.getElementById("sector-time").textContent =
`${(PERIOD / SECTOR_COUNT).toFixed(2)} s`;
document.getElementById("sector-area").textContent =
`${sectorArea.toFixed(2)} u²`;
document.getElementById("focus-offset").textContent =
`${(A * ECCENTRICITY).toFixed(2)} u`;
for (let k = 0; k < SECTOR_COUNT; k++) {
const color = `#${colors[k].toString(16).padStart(6, "0")}`;
const row = document.createElement("div");
row.className = "sector-row";
const dot = document.createElement("span");
dot.className = "sector-dot";
dot.style.background = color;
dot.style.color = color;
const track = document.createElement("div");
track.className = "bar-track";
const bar = document.createElement("div");
bar.className = "bar";
bar.style.width = `${sectorArcLengths[k] / maxArcLength * 100}%`;
bar.style.background = color;
track.appendChild(bar);
const length = document.createElement("span");
length.className = "arc-length";
length.textContent = `ℓ ${sectorArcLengths[k].toFixed(2)}`;
row.append(dot, track, length);
barContainer.appendChild(row);
sectorRows.push(row);
}
const speedReadout = document.getElementById("speed");
const radiusReadout = document.getElementById("radius");
const currentSectorReadout = document.getElementById("current-sector");
// ------------------------------------------------------------
// Direct camera controls: no addon imports
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(CENTER_X - 0.05, 0, 0);
const spherical = new THREE.Spherical(14.2, 1.98, 0.78);
function resetCamera() {
spherical.set(14.2, 1.98, 0.78);
}
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.28,
Math.PI - 0.25
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
7.5,
25
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
let paused = false;
let simulationTime = 0;
let previousTime = performance.now();
let previousSector = -1;
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
});
function updateOrbitalBody(meanAnomaly) {
const E = solveKepler(meanAnomaly);
const position = ellipsePoint(E, 0.31);
const radius = Math.hypot(position.x, position.y);
body.position.copy(position);
bodyLight.position.copy(position);
bodyLight.position.z += 0.2;
const currentSector = Math.min(
SECTOR_COUNT - 1,
Math.floor(meanAnomaly / (Math.PI * 2) * SECTOR_COUNT)
);
if (currentSector !== previousSector) {
for (let k = 0; k < SECTOR_COUNT; k++) {
const active = k === currentSector;
sectorMeshes[k].material.opacity = active ? 0.57 : 0.27;
sectorMeshes[k].material.emissiveIntensity = active ? 0.2 : 0.035;
sectorEdges[k].material.opacity = active ? 1 : 0.48;
sectorRows[k].classList.toggle("current", active);
}
previousSector = currentSector;
}
// Differentiate the eccentric-anomaly parameterization.
const dEdt = MEAN_MOTION / (1 - ECCENTRICITY * Math.cos(E));
const velocity = new THREE.Vector3(
-A * Math.sin(E) * dEdt,
B * Math.cos(E) * dEdt,
0
);
const velocityDirection = velocity.clone().normalize();
const speedRatio = Math.sqrt(2 * A / radius - 1);
velocityArrow.position.copy(body.position);
velocityArrow.position.z += 0.025;
velocityArrow.setDirection(velocityDirection);
velocityArrow.setLength(
0.5 + speedRatio * 0.5,
0.2,
0.11
);
const speedColor = new THREE.Color().setHSL(
THREE.MathUtils.clamp(
(speedRatio - 0.45) / 1.7,
0,
1
) * 0.83,
0.9,
0.62
);
velocityArrow.setColor(speedColor);
speedReadout.textContent = `${speedRatio.toFixed(2)} v₍circ₎`;
radiusReadout.textContent = `${(radius / A).toFixed(2)} a`;
currentSectorReadout.textContent = `${currentSector + 1} / ${SECTOR_COUNT}`;
// The trail samples are separated by equal mean-anomaly intervals,
// so their unequal spatial spacing visualizes changing speed.
for (let i = 0; i < trailCount; i++) {
const trailM = meanAnomaly - i * trailMeanStep;
const trailE = solveKepler(trailM);
const trailPoint = ellipsePoint(trailE);
trailPositions[i * 3] = trailPoint.x;
trailPositions[i * 3 + 1] = trailPoint.y;
trailPositions[i * 3 + 2] = 0.19;
}
trailGeometry.attributes.position.needsUpdate = true;
}
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) simulationTime += delta;
const meanAnomaly = (
simulationTime / PERIOD * Math.PI * 2 + 0.16
) % (Math.PI * 2);
updateOrbitalBody(meanAnomaly);
updateCamera();
// Subtle background motion, independent of the paused simulation.
stars.rotation.y += delta * 0.003;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateCamera();
requestAnimationFrame(animate);
document.getElementById("loading").remove();
</script>
</body>
</html>
```