Prompt specification
Build or customize the Three.js 3D scene "Transit Geometry and Synthetic Light Curve" 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: Transit Geometry and Synthetic Light Curve
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/transit-geometry-and-synthetic-light-curve-x3778
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: transit geometry and synthetic light curve. Animate a simple uniform-brightness stellar transit and compute relative blocked area. Display the resulting synthetic light curve while explicitly omitting more detailed stellar effects.
Working Three.js Starter (transit-geometry-and-synthetic-light-curve-x3778):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Stellar Transit Laboratory</title>
<style>
:root {
color-scheme: dark;
--bg: #070a12;
--panel: #0d1220;
--panel-2: #121a2b;
--line: #243149;
--text: #e7edf8;
--muted: #92a1ba;
--cyan: #60dcff;
--yellow: #ffd166;
--green: #65e6a4;
--orange: #ff9f68;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
header {
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(8, 12, 22, 0.96);
}
header h1 {
margin: 0;
font-size: 18px;
letter-spacing: 0.02em;
}
header p {
margin: 3px 0 0;
color: var(--muted);
font-size: 12px;
}
.badge {
padding: 7px 10px;
border: 1px solid #34506d;
border-radius: 999px;
color: var(--cyan);
background: #102235;
font-size: 11px;
white-space: nowrap;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1.35fr) minmax(390px, 0.8fr);
height: calc(100vh - 68px);
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, #172239 0%, #090d17 48%, #05070d 100%);
}
#webgl {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#webgl:active {
cursor: grabbing;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
z-index: 3;
padding: 5px 8px;
border: 1px solid rgba(96, 220, 255, 0.25);
border-radius: 5px;
background: rgba(5, 10, 20, 0.78);
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.08em;
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
}
#planetLabel {
color: #b5c8e5;
border-color: rgba(181, 200, 229, 0.25);
}
.stage-info {
position: absolute;
left: 18px;
bottom: 18px;
z-index: 4;
max-width: 340px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(7, 11, 20, 0.78);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
pointer-events: none;
}
.stage-info strong {
color: var(--text);
}
.stage-help {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 4;
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
aside {
min-width: 0;
overflow-y: auto;
padding: 18px;
border-left: 1px solid var(--line);
background: var(--panel);
}
.panel-section {
margin-bottom: 20px;
}
.panel-section h2 {
margin: 0 0 4px;
font-size: 14px;
}
.panel-section > p {
margin: 0 0 11px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.formula {
padding: 10px 12px;
border: 1px solid #29425c;
border-radius: 7px;
background: #0a1625;
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13px;
text-align: center;
}
.chart-wrap {
position: relative;
width: 100%;
height: 265px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 8px;
background: #090e19;
}
#lightCurve {
display: block;
width: 100%;
height: 100%;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 70px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 7px;
background: var(--panel-2);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 17px;
}
#fluxValue {
color: var(--green);
}
#blockedValue {
color: var(--yellow);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 7px;
background: var(--panel-2);
font-size: 11px;
}
#transitStatus {
color: var(--cyan);
font-weight: 700;
letter-spacing: 0.05em;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 37px;
padding: 8px 12px;
border: 1px solid #31445f;
border-radius: 6px;
background: #162337;
color: var(--text);
font: inherit;
font-size: 12px;
cursor: pointer;
}
button:hover {
border-color: var(--cyan);
background: #1b3048;
}
button.primary {
border-color: #3e7992;
background: #14384b;
color: #bcefff;
}
.range-row {
margin-top: 12px;
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: var(--muted);
font-size: 11px;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.assumptions {
padding: 12px;
border: 1px solid #3e3540;
border-radius: 8px;
background: #19131b;
color: #c7bbc6;
font-size: 11px;
line-height: 1.55;
}
.assumptions strong {
color: var(--orange);
}
.assumptions ul {
margin: 7px 0 0;
padding-left: 18px;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
header {
height: auto;
min-height: 68px;
padding: 12px 16px;
}
header .badge {
display: none;
}
.layout {
display: block;
height: auto;
}
.stage {
height: 60vh;
min-height: 430px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
}
@media (max-width: 520px) {
.stage-info {
right: 12px;
left: 12px;
max-width: none;
}
.stage-help {
display: none;
}
.metrics {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<header>
<div>
<h1>Voxel Stellar Transit Laboratory</h1>
<p>Geometric occultation of a uniformly bright star</p>
</div>
<div class="badge">CORE THREE.JS · CDNJS</div>
</header>
<main class="layout">
<section class="stage" id="stage">
<canvas id="webgl" aria-label="Interactive voxel stellar transit scene"></canvas>
<div class="scene-label" id="starLabel">UNIFORM STAR</div>
<div class="scene-label" id="planetLabel">PLANET</div>
<div class="stage-info">
<strong>Idealized face-on observer model.</strong><br>
The voxel bodies are a visual approximation. The light curve uses
ideal circular projected disks.
</div>
<div class="stage-help">Drag to orbit · Wheel to zoom</div>
</section>
<aside>
<section class="panel-section">
<h2>Relative blocked area</h2>
<p>
For a uniformly bright stellar disk, the fractional flux loss is
exactly the projected overlap area divided by the stellar disk area.
</p>
<div class="formula">
F/F₀ = 1 − A<sub>blocked</sub> / (πR★²)
</div>
</section>
<section class="panel-section">
<h2>Synthetic light curve</h2>
<p>
Flux sampled over the transit. Dashed lines mark first, second,
third, and fourth contact.
</p>
<div class="chart-wrap">
<canvas id="lightCurve" aria-label="Synthetic transit light curve"></canvas>
</div>
</section>
<section class="panel-section">
<h2>Current geometry</h2>
<div class="metrics">
<div class="metric">
<span class="metric-label">Projected separation</span>
<span class="metric-value" id="separationValue">0.000 R★</span>
</div>
<div class="metric">
<span class="metric-label">Blocked disk area</span>
<span class="metric-value" id="blockedValue">0.000%</span>
</div>
<div class="metric">
<span class="metric-label">Relative flux</span>
<span class="metric-value" id="fluxValue">1.000000</span>
</div>
<div class="metric">
<span class="metric-label">Planet / star radius</span>
<span class="metric-value">0.120</span>
</div>
</div>
<div class="status-row">
<span id="transitStatus">OUT OF TRANSIT</span>
<span id="phaseValue">phase −1.000</span>
</div>
</section>
<section class="panel-section">
<h2>Animation</h2>
<div class="controls">
<button class="primary" id="playButton" type="button">Pause</button>
<button id="restartButton" type="button">Restart transit</button>
<button id="cameraButton" type="button">Reset camera</button>
<button id="speedButton" type="button">Speed: 1.0×</button>
</div>
<div class="range-row">
<div class="range-label">
<span>Transit phase</span>
<span>−1 to +1</span>
</div>
<input
id="phaseSlider"
type="range"
min="-1"
max="1"
step="0.001"
value="-1"
aria-label="Transit phase"
>
</div>
<div class="range-row">
<div class="range-label">
<span>Playback speed</span>
<span id="speedValue">1.0×</span>
</div>
<input
id="speedSlider"
type="range"
min="0.25"
max="2"
step="0.25"
value="1"
aria-label="Playback speed"
>
</div>
</section>
<section class="panel-section">
<div class="assumptions">
<strong>Deliberately omitted stellar effects:</strong>
<ul>
<li>Limb darkening or atmospheric limb structure</li>
<li>Starspots, faculae, or magnetic activity</li>
<li>Granulation, pulsation, or differential rotation</li>
<li>Stellar oblateness or gravitational lensing</li>
<li>Planetary atmosphere, rings, or reflected light</li>
<li>Finite exposure time and time averaging</li>
</ul>
The model assumes an opaque circular planet crossing a uniformly
bright circular star with no additional astrophysical variability.
</div>
</section>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model constants
// -------------------------------------------------------------------------
const STAR_RADIUS = 1.0;
const PLANET_RADIUS = 0.12;
const RADIUS_RATIO = PLANET_RADIUS / STAR_RADIUS;
const MAX_SEPARATION = 1.18;
const PLANET_Z = 1.16;
const stage = document.getElementById("stage");
const sceneCanvas = document.getElementById("webgl");
const chartCanvas = document.getElementById("lightCurve");
const chartContext = chartCanvas.getContext("2d");
const starLabel = document.getElementById("starLabel");
const planetLabel = document.getElementById("planetLabel");
const separationValue = document.getElementById("separationValue");
const blockedValue = document.getElementById("blockedValue");
const fluxValue = document.getElementById("fluxValue");
const transitStatus = document.getElementById("transitStatus");
const phaseValue = document.getElementById("phaseValue");
const playButton = document.getElementById("playButton");
const restartButton = document.getElementById("restartButton");
const cameraButton = document.getElementById("cameraButton");
const speedButton = document.getElementById("speedButton");
const phaseSlider = document.getElementById("phaseSlider");
const speedSlider = document.getElementById("speedSlider");
const speedValue = document.getElementById("speedValue");
// -------------------------------------------------------------------------
// Exact circle-circle overlap area
// -------------------------------------------------------------------------
function clamp(value, minimum, maximum) {
return Math.max(minimum, Math.min(maximum, value));
}
function overlapArea(distance, radiusRatio) {
const r1 = 1.0;
const r2 = radiusRatio;
// No overlap.
if (distance >= r1 + r2) {
return 0;
}
// The planet lies entirely within the stellar disk.
if (distance <= r1 - r2) {
return Math.PI * r2 * r2;
}
// Partial overlap of two circles.
const angle1 = Math.acos(
clamp(
(distance * distance + r1 * r1 - r2 * r2) /
(2 * distance * r1),
-1,
1
)
);
const angle2 = Math.acos(
clamp(
(distance * distance + r2 * r2 - r1 * r1) /
(2 * distance * r2),
-1,
1
)
);
const radical =
(-distance + r1 + r2) *
(distance + r1 - r2) *
(distance - r1 + r2) *
(distance + r1 + r2);
return (
r1 * r1 * angle1 +
r2 * r2 * angle2 -
0.5 * Math.sqrt(Math.max(0, radical))
);
}
function separationAtPhase(phase) {
return MAX_SEPARATION * Math.abs(Math.sin(Math.PI * phase));
}
function planetXAtPhase(phase) {
return MAX_SEPARATION * Math.sin(Math.PI * phase);
}
function blockedFractionAtPhase(phase) {
const separation = separationAtPhase(phase);
return overlapArea(separation, RADIUS_RATIO) / Math.PI;
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
canvas: sceneCanvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x070a12, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
const camera = new THREE.OrthographicCamera(-2, 2, 2, -2, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0);
let cameraTheta = 0;
let cameraPhi = Math.PI / 2;
let cameraZoom = 1;
function updateCamera() {
const radius = 8;
camera.position.set(
cameraTarget.x +
radius *
Math.sin(cameraPhi) *
Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z +
radius *
Math.sin(cameraPhi) *
Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resizeRenderer() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
const aspect = width / height;
const halfHeight = 1.65;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
function resetCamera() {
cameraTheta = 0;
cameraPhi = Math.PI / 2;
cameraZoom = 1;
updateCamera();
}
// Lighting is used for the planet only; the stellar disk is intentionally
// rendered with a uniform, non-lit material.
scene.add(new THREE.HemisphereLight(0xbcd8ff, 0x111827, 1.6));
const planetLight = new THREE.PointLight(0xffffff, 35, 20);
planetLight.position.set(3, 4, 6);
scene.add(planetLight);
// Deterministic background star field.
let randomSeed = 78123;
function seededRandom() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const starfieldPositions = [];
for (let i = 0; i < 700; i++) {
const theta = seededRandom() * Math.PI * 2;
const cosPhi = seededRandom() * 2 - 1;
const phi = Math.acos(cosPhi);
const radius = 11 + seededRandom() * 12;
starfieldPositions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
}
const starfieldGeometry = new THREE.BufferGeometry();
starfieldGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starfieldPositions, 3)
);
const starfield = new THREE.Points(
starfieldGeometry,
new THREE.PointsMaterial({
color: 0x9eb9db,
size: 0.035,
transparent: true,
opacity: 0.65,
depthWrite: false
})
);
scene.add(starfield);
// Create a filled 3D volume of cubes. The stepped silhouette provides the
// voxel appearance while the material remains uniformly bright.
function createVoxelBall(
radius,
gridSize,
solidMaterial,
wireOpacity = 0
) {
const step = (2 * radius) / gridSize;
const cells = [];
for (let ix = 0; ix < gridSize; ix++) {
const x = -radius + (ix + 0.5) * step;
for (let iy = 0; iy < gridSize; iy++) {
const y = -radius + (iy + 0.5) * step;
for (let iz = 0; iz < gridSize; iz++) {
const z = -radius + (iz + 0.5) * step;
if (x * x + y * y + z * z <= radius * radius) {
cells.push([x, y, z]);
}
}
}
}
const group = new THREE.Group();
const geometry = new THREE.BoxGeometry(1, 1, 1);
const solid = new THREE.InstancedMesh(
geometry,
solidMaterial,
cells.length
);
const dummy = new THREE.Object3D();
cells.forEach((position, index) => {
dummy.position.set(position[0], position[1], position[2]);
dummy.scale.setScalar(step);
dummy.updateMatrix();
solid.setMatrixAt(index, dummy.matrix);
});
solid.instanceMatrix.needsUpdate = true;
solid.frustumCulled = false;
group.add(solid);
if (wireOpacity > 0) {
const wire = new THREE.InstancedMesh(
geometry,
new THREE.MeshBasicMaterial({
color: 0xffffff,
wireframe: true,
transparent: true,
opacity: wireOpacity,
depthWrite: false,
toneMapped: false
}),
cells.length
);
cells.forEach((position, index) => {
dummy.position.set(position[0], position[1], position[2]);
dummy.scale.setScalar(step * 1.003);
dummy.updateMatrix();
wire.setMatrixAt(index, dummy.matrix);
});
wire.instanceMatrix.needsUpdate = true;
wire.frustumCulled = false;
wire.renderOrder = 2;
group.add(wire);
}
return group;
}
const star = createVoxelBall(
STAR_RADIUS,
20,
new THREE.MeshBasicMaterial({
color: 0xffcf5a,
toneMapped: false
}),
0.08
);
scene.add(star);
const planet = createVoxelBall(
PLANET_RADIUS,
5,
new THREE.MeshStandardMaterial({
color: 0x263a5c,
emissive: 0x07101f,
roughness: 0.9,
metalness: 0.08
})
);
planet.position.z = PLANET_Z;
scene.add(planet);
// Soft procedural halo. The image texture is generated locally.
const haloCanvas = document.createElement("canvas");
haloCanvas.width = 128;
haloCanvas.height = 128;
const haloContext = haloCanvas.getContext("2d");
const haloGradient = haloContext.createRadialGradient(
64, 64, 4,
64, 64, 64
);
haloGradient.addColorStop(0, "rgba(255, 207, 90, 0.28)");
haloGradient.addColorStop(0.35, "rgba(255, 190, 70, 0.10)");
haloGradient.addColorStop(1, "rgba(255, 170, 50, 0)");
haloContext.fillStyle = haloGradient;
haloContext.fillRect(0, 0, 128, 128);
const haloTexture = new THREE.CanvasTexture(haloCanvas);
haloTexture.colorSpace = THREE.SRGBColorSpace;
const halo = new THREE.Sprite(
new THREE.SpriteMaterial({
map: haloTexture,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false,
depthTest: true
})
);
halo.position.set(0, 0, -0.35);
halo.scale.set(3.5, 3.5, 1);
scene.add(halo);
// Dashed projected planet path.
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-MAX_SEPARATION, 0, PLANET_Z),
new THREE.Vector3(MAX_SEPARATION, 0, PLANET_Z)
]);
const path = new THREE.Line(
pathGeometry,
new THREE.LineDashedMaterial({
color: 0x60dcff,
dashSize: 0.08,
gapSize: 0.06,
transparent: true,
opacity: 0.38
})
);
path.computeLineDistances();
scene.add(path);
// -------------------------------------------------------------------------
// Direct camera interaction; no controls add-on is used.
// -------------------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
sceneCanvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
sceneCanvas.setPointerCapture(event.pointerId);
});
sceneCanvas.addEventListener("pointermove", (event) => {
if (!dragging) {
return;
}
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = clamp(
cameraPhi - deltaY * 0.006,
0.22,
Math.PI - 0.22
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
sceneCanvas.hasPointerCapture(event.pointerId)
) {
sceneCanvas.releasePointerCapture(event.pointerId);
}
}
sceneCanvas.addEventListener("pointerup", endDrag);
sceneCanvas.addEventListener("pointercancel", endDrag);
sceneCanvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.72,
2.4
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Synthetic light curve and chart
// -------------------------------------------------------------------------
const curveSamples = Array.from({ length: 601 }, (_, index) => {
const phase = -1 + (2 * index) / 600;
const blocked = blockedFractionAtPhase(phase);
return {
phase,
separation: separationAtPhase(phase),
blocked,
flux: 1 - blocked
};
});
const outerContactPhase =
Math.asin((1 + RADIUS_RATIO) / MAX_SEPARATION) / Math.PI;
const innerContactPhase =
Math.asin((1 - RADIUS_RATIO) / MAX_SEPARATION) / Math.PI;
const contactPhases = [
{ phase: -outerContactPhase, label: "I" },
{ phase: -innerContactPhase, label: "II" },
{ phase: innerContactPhase, label: "III" },
{ phase: outerContactPhase, label: "IV" }
];
function drawChart(currentPhase, currentFlux) {
const rect = chartCanvas.getBoundingClientRect();
if (rect.width < 2 || rect.height < 2) {
return;
}
const pixelRatio = Math.min(window.devicePixelRatio || 1, 2);
const pixelWidth = Math.round(rect.width * pixelRatio);
const pixelHeight = Math.round(rect.height * pixelRatio);
if (
chartCanvas.width !== pixelWidth ||
chartCanvas.height !== pixelHeight
) {
chartCanvas.width = pixelWidth;
chartCanvas.height = pixelHeight;
}
const context = chartContext;
context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
context.clearRect(0, 0, rect.width, rect.height);
const padding = {
left: 46,
right: 15,
top: 25,
bottom: 32
};
const width = rect.width;
const height = rect.height;
const plotWidth = width - padding.left - padding.right;
const plotHeight = height - padding.top - padding.bottom;
const minimumFlux = 1 - RADIUS_RATIO * RADIUS_RATIO * 1.3;
const maximumFlux = 1.0015;
const xAt = (phase) =>
padding.left + ((phase + 1) / 2) * plotWidth;
const yAt = (flux) =>
padding.top +
((maximumFlux - flux) / (maximumFlux - minimumFlux)) * plotHeight;
context.fillStyle = "#090e19";
context.fillRect(0, 0, width, height);
// Grid and vertical-axis labels.
context.font = "10px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "right";
context.textBaseline = "middle";
for (let index = 0; index <= 4; index++) {
const flux =
minimumFlux +
((maximumFlux - minimumFlux) * index) / 4;
const y = yAt(flux);
context.strokeStyle = "#202b3d";
context.lineWidth = 1;
context.beginPath();
context.moveTo(padding.left, y);
context.lineTo(width - padding.right, y);
context.stroke();
context.fillStyle = "#78889f";
context.fillText(flux.toFixed(3), padding.left - 7, y);
}
context.textAlign = "center";
context.textBaseline = "top";
for (const phase of [-1, -0.5, 0, 0.5, 1]) {
const x = xAt(phase);
context.strokeStyle = "#182235";
context.beginPath();
context.moveTo(x, padding.top);
context.lineTo(x, height - padding.bottom);
context.stroke();
context.fillStyle = "#78889f";
context.fillText(
phase.toFixed(phase === 0 ? 0 : 1),
x,
height - padding.bottom + 9
);
}
// Contact markers.
context.setLineDash([3, 4]);
for (const contact of contactPhases) {
const x = xAt(contact.phase);
context.strokeStyle = "#5b5365";
context.beginPath();
context.moveTo(x, padding.top + 12);
context.lineTo(x, height - padding.bottom);
context.stroke();
context.fillStyle = "#9b8da6";
context.textAlign = "center";
context.textBaseline = "bottom";
context.fillText(contact.label, x, padding.top + 10);
}
context.setLineDash([]);
// Baseline.
context.strokeStyle = "#718096";
context.lineWidth = 1;
context.beginPath();
context.moveTo(padding.left, yAt(1));
context.lineTo(width - padding.right, yAt(1));
context.stroke();
// Synthetic light curve.
context.strokeStyle = "#60dcff";
context.lineWidth = 2;
context.beginPath();
curveSamples.forEach((sample, index) => {
const x = xAt(sample.phase);
const y = yAt(sample.flux);
if (index === 0) {
context.moveTo(x, y);
} else {
context.lineTo(x, y);
}
});
context.stroke();
// Current animation marker.
const markerX = xAt(currentPhase);
const markerY = yAt(currentFlux);
context.strokeStyle = "rgba(255, 209, 102, 0.45)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(markerX, padding.top);
context.lineTo(markerX, height - padding.bottom);
context.stroke();
context.fillStyle = "#ffd166";
context.beginPath();
context.arc(markerX, markerY, 4, 0, Math.PI * 2);
context.fill();
context.strokeStyle = "#fff1c2";
context.lineWidth = 1.5;
context.stroke();
context.fillStyle = "#b9c7da";
context.textAlign = "left";
context.textBaseline = "top";
context.fillText("F/F₀", 7, 6);
context.textAlign = "right";
context.fillText("phase", width - 7, height - 14);
}
// -------------------------------------------------------------------------
// Animation state and UI
// -------------------------------------------------------------------------
let phase = -1;
let playing = true;
let speed = 1;
let previousTime = performance.now();
function updatePlayButton() {
playButton.textContent = playing ? "Pause" : "Play";
}
function updateSceneAndReadouts() {
const separation = separationAtPhase(phase);
const planetX = planetXAtPhase(phase);
const blocked = blockedFractionAtPhase(phase);
const flux = 1 - blocked;
planet.position.x = planetX;
separationValue.textContent = `${separation.toFixed(3)} R★`;
blockedValue.textContent = `${(blocked * 100).toFixed(3)}%`;
fluxValue.textContent = flux.toFixed(6);
phaseValue.textContent = `phase ${phase.toFixed(3)}`;
if (separation >= 1 + RADIUS_RATIO) {
transitStatus.textContent = "OUT OF TRANSIT";
} else if (separation > 1 - RADIUS_RATIO) {
transitStatus.textContent =
planetX < 0 ? "INGRESS" : "EGRESS";
} else {
transitStatus.textContent = "FULLY IN TRANSIT";
}
phaseSlider.value = phase.toFixed(3);
drawChart(phase, flux);
}
function positionSceneLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.visibility =
projected.z >= -1 && projected.z <= 1 ? "visible" : "hidden";
}
playButton.addEventListener("click", () => {
if (phase >= 1) {
phase = -1;
}
playing = !playing;
updatePlayButton();
});
restartButton.addEventListener("click", () => {
phase = -1;
playing = true;
updatePlayButton();
});
cameraButton.addEventListener("click", resetCamera);
speedButton.addEventListener("click", () => {
const values = [0.25, 0.5, 1, 1.5, 2];
const currentIndex = values.indexOf(speed);
const nextIndex = (currentIndex + 1) % values.length;
speed = values[nextIndex];
speedSlider.value = speed;
speedValue.textContent = `${speed.toFixed(2).replace(/0$/, "")}×`;
speedButton.textContent = `Speed: ${speed.toFixed(2).replace(/0$/, "")}×`;
});
phaseSlider.addEventListener("input", () => {
phase = Number(phaseSlider.value);
playing = false;
updatePlayButton();
});
speedSlider.addEventListener("input", () => {
speed = Number(speedSlider.value);
speedValue.textContent = `${speed.toFixed(2).replace(/0$/, "")}×`;
speedButton.textContent = `Speed: ${speed.toFixed(2).replace(/0$/, "")}×`;
});
const stageResizeObserver = new ResizeObserver(resizeRenderer);
stageResizeObserver.observe(stage);
const chartResizeObserver = new ResizeObserver(() => {
drawChart(phase, 1 - blockedFractionAtPhase(phase));
});
chartResizeObserver.observe(chartCanvas.parentElement);
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
function animate(now) {
const deltaSeconds = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
// One complete transit in twelve seconds at 1× speed.
phase += (deltaSeconds * speed) / 6;
if (phase > 1) {
phase = -1;
}
}
updateSceneAndReadouts();
positionSceneLabel(
starLabel,
new THREE.Vector3(0, 1.08, 0)
);
positionSceneLabel(
planetLabel,
new THREE.Vector3(planet.position.x, 0.29, PLANET_Z)
);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resizeRenderer();
resetCamera();
updatePlayButton();
updateSceneAndReadouts();
requestAnimationFrame(animate);
</script>
</body>
</html>
```