Prompt specification
Build or customize the Three.js 3D scene "Exoplanet Discovery Museum Station" 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: Exoplanet Discovery Museum Station
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/exoplanet-discovery-museum-station-x3779
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Build an educational exhibit linking orbital alignment, transit duration, and a synthetic brightness plot. Use source-checked explanations and avoid claiming the toy signal is real telescope data.
Working Three.js Starter (exoplanet-discovery-museum-station-x3779):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<title>Voxel Transit Lab — Alignment, Duration & Synthetic Light Curves</title>
<style>
:root {
--bg: #050914;
--panel: #0b1222;
--panel-2: #101b30;
--line: #24324b;
--text: #e8eef9;
--muted: #9aabc4;
--cyan: #64e6dc;
--blue: #72a8ff;
--gold: #ffd36b;
--orange: #ff9f6e;
--green: #8df0b5;
--radius: 14px;
}
* {
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;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 440px;
width: 100%;
height: 100%;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 46%, #122544 0%, #081222 42%, #030711 100%);
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.stage-header {
position: absolute;
z-index: 3;
top: 0;
left: 0;
right: 0;
padding: 22px 24px;
pointer-events: none;
background: linear-gradient(to bottom, rgba(3, 7, 17, 0.9), transparent);
}
.stage-kicker,
.eyebrow {
color: var(--cyan);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stage-header h2 {
margin: 6px 0 0;
font-size: clamp(1.35rem, 2.5vw, 2.2rem);
line-height: 1.05;
letter-spacing: -0.04em;
}
.synthetic-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding: 7px 10px;
border: 1px solid rgba(255, 211, 107, 0.35);
border-radius: 999px;
color: #ffe3a2;
background: rgba(44, 32, 10, 0.72);
font-size: 0.75rem;
font-weight: 750;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
.synthetic-badge::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 12px rgba(255, 211, 107, 0.8);
content: "";
}
.stage-footer {
position: absolute;
z-index: 3;
left: 20px;
right: 20px;
bottom: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.hint,
.legend {
padding: 10px 12px;
border: 1px solid rgba(112, 168, 255, 0.17);
border-radius: 10px;
color: var(--muted);
background: rgba(5, 10, 21, 0.66);
font-size: 0.76rem;
line-height: 1.45;
backdrop-filter: blur(10px);
}
.legend {
display: flex;
gap: 13px;
flex-wrap: wrap;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.dot.star { color: var(--gold); }
.dot.planet { color: var(--blue); }
.dot.orbit { color: var(--cyan); }
#panel {
min-width: 0;
height: 100%;
overflow-y: auto;
padding: 24px;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(16, 27, 48, 0.98), rgba(7, 13, 26, 0.99));
scrollbar-color: #334764 #0b1222;
}
h1 {
margin: 7px 0 10px;
font-size: 1.75rem;
line-height: 1.08;
letter-spacing: -0.045em;
}
.intro {
margin: 0 0 16px;
color: var(--muted);
font-size: 0.91rem;
line-height: 1.55;
}
.status {
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--panel-2);
font-size: 0.82rem;
font-weight: 750;
line-height: 1.4;
}
.status.transit {
border-color: rgba(141, 240, 181, 0.4);
color: var(--green);
background: rgba(25, 76, 56, 0.2);
}
.status.graze {
border-color: rgba(255, 211, 107, 0.4);
color: var(--gold);
background: rgba(83, 64, 20, 0.2);
}
.status.miss {
border-color: rgba(255, 159, 110, 0.4);
color: var(--orange);
background: rgba(89, 42, 29, 0.2);
}
.metrics {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
margin: 12px 0 20px;
}
.metric {
min-height: 68px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(16, 27, 48, 0.72);
}
.metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 0.68rem;
letter-spacing: 0.035em;
text-transform: uppercase;
}
.metric strong {
font-size: 1.04rem;
letter-spacing: -0.02em;
}
.section-title {
margin: 20px 0 11px;
color: #cbd8eb;
font-size: 0.75rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control {
margin: 13px 0;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.control label {
font-size: 0.83rem;
font-weight: 700;
}
.control output {
color: var(--cyan);
font-size: 0.8rem;
font-variant-numeric: tabular-nums;
font-weight: 800;
}
.control small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 0.7rem;
line-height: 1.4;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 4px 0;
border-radius: 999px;
appearance: none;
background: #263752;
accent-color: var(--cyan);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #dffefa;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 12px rgba(100, 230, 220, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #dffefa;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px rgba(100, 230, 220, 0.45);
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin: 10px 0;
}
button {
min-height: 36px;
padding: 8px 7px;
border: 1px solid #31425e;
border-radius: 9px;
background: #142039;
font-size: 0.72rem;
font-weight: 750;
cursor: pointer;
transition:
border-color 120ms ease,
background 120ms ease,
transform 120ms ease;
}
button:hover {
border-color: var(--cyan);
background: #1a2c48;
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: rgba(100, 230, 220, 0.45);
color: #dffffb;
background: rgba(37, 111, 112, 0.32);
}
.chart-card {
margin-top: 18px;
padding: 12px;
border: 1px solid var(--line);
border-radius: var(--radius);
background: rgba(7, 14, 27, 0.8);
}
.chart-card h3 {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin: 0 0 8px;
font-size: 0.86rem;
}
.chart-card h3 span {
color: var(--muted);
font-size: 0.65rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.chart-card canvas {
display: block;
width: 100%;
border-radius: 9px;
background: #050a14;
}
#skyCanvas {
height: 176px;
}
#lightCanvas {
height: 190px;
}
.chart-note {
margin: 8px 2px 0;
color: var(--muted);
font-size: 0.67rem;
line-height: 1.45;
}
details {
margin-top: 13px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(12, 22, 40, 0.65);
}
summary {
cursor: pointer;
color: #dce7f8;
font-size: 0.82rem;
font-weight: 800;
}
details p,
details li {
color: var(--muted);
font-size: 0.76rem;
line-height: 1.55;
}
details ul {
padding-left: 18px;
}
details li + li {
margin-top: 7px;
}
details b {
color: #dce7f8;
}
details a {
color: #9bc5ff;
text-underline-offset: 2px;
}
.equation {
margin: 8px 0;
padding: 9px 10px;
border-left: 2px solid var(--cyan);
color: #d9fbf7;
background: rgba(44, 99, 105, 0.12);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.68rem;
line-height: 1.55;
overflow-wrap: anywhere;
}
.source-label {
display: inline-block;
margin-bottom: 7px;
color: var(--gold);
font-size: 0.67rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.provenance {
margin-top: 14px;
padding: 12px;
border: 1px solid rgba(255, 211, 107, 0.25);
border-radius: 11px;
color: #d9c89e;
background: rgba(55, 43, 16, 0.16);
font-size: 0.73rem;
line-height: 1.5;
}
@media (max-width: 940px) {
html,
body {
overflow: auto;
}
#app {
display: block;
height: auto;
}
#stage {
height: 58vh;
min-height: 440px;
}
#panel {
height: auto;
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
}
@media (max-width: 560px) {
.stage-header {
padding: 17px;
}
.stage-footer {
left: 12px;
right: 12px;
bottom: 12px;
}
.legend {
display: none;
}
#panel {
padding: 20px 16px 30px;
}
.buttons {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<main id="app">
<section id="stage" aria-label="Interactive three-dimensional voxel transit scene">
<div id="scene"></div>
<header class="stage-header">
<div class="stage-kicker">Voxel Transit Lab</div>
<h2>Alignment → duration → brightness</h2>
<div class="synthetic-badge">Synthetic classroom model — not telescope data</div>
</header>
<footer class="stage-footer">
<div class="hint">
Drag to orbit the camera · Wheel to zoom · Double-click to reset<br>
Arrow keys rotate · + / − zoom
</div>
<div class="legend" aria-hidden="true">
<span class="dot star">Star</span>
<span class="dot planet">Planet</span>
<span class="dot orbit">Orbit / sight line</span>
</div>
</footer>
</section>
<aside id="panel">
<div class="eyebrow">Interactive educational exhibit</div>
<h1>When does a planet cross its star?</h1>
<p class="intro">
A transit needs three things: a planet in front of the star, an observer
on the correct line of sight, and enough orbital alignment for the
planet’s path to meet the stellar disk. Change the alignment and the
toy transit duration and synthetic light curve respond together.
</p>
<div id="status" class="status" aria-live="polite"></div>
<div class="metrics">
<div class="metric">
<span>Impact parameter b</span>
<strong id="bReadout">—</strong>
</div>
<div class="metric">
<span>First-to-fourth contact</span>
<strong id="durationReadout">—</strong>
</div>
<div class="metric">
<span>Mid-transit depth</span>
<strong id="depthReadout">—</strong>
</div>
<div class="metric">
<span>Toy orbital period</span>
<strong id="periodReadout">—</strong>
</div>
</div>
<div class="section-title">Geometry controls</div>
<div class="control">
<div class="control-head">
<label for="angle">Alignment tilt α</label>
<output id="angleOut" for="angle">3.0°</output>
</div>
<input id="angle" type="range" min="0" max="15" step="0.1" value="3">
<small>
0° is exactly edge-on. Increasing α moves the projected track away
from the stellar center; conventional inclination is 90° at edge-on.
</small>
</div>
<div class="control">
<div class="control-head">
<label for="planetRadius">Toy planet radius</label>
<output id="planetOut" for="planetRadius">0.120 R★</output>
</div>
<input id="planetRadius" type="range" min="0.04" max="0.20" step="0.005" value="0.12">
<small>Larger planets make deeper dips and, at fixed alignment, longer contacts.</small>
</div>
<div class="control">
<div class="control-head">
<label for="orbitRadius">Orbit radius a</label>
<output id="orbitOut" for="orbitRadius">12.0 R★</output>
</div>
<input id="orbitRadius" type="range" min="6" max="18" step="0.5" value="12">
<small>
Physical calculations use solar-radius units. The 3D orbit path is
compressed for viewing, while the observer-view inset preserves the
projected geometry.
</small>
</div>
<div class="control">
<div class="control-head">
<label for="speed">Playback speed</label>
<output id="speedOut" for="speed">1.00×</output>
</div>
<input id="speed" type="range" min="0.25" max="3" step="0.25" value="1">
</div>
<div class="buttons">
<button id="centerButton" class="primary" type="button">Center transit</button>
<button id="edgeButton" type="button">Edge-on</button>
<button id="grazingButton" type="button">Grazing</button>
<button id="missButton" type="button">Miss</button>
</div>
<div class="chart-card">
<h3>
Observer’s sky view
<span>Synthetic geometry</span>
</h3>
<canvas
id="skyCanvas"
role="img"
aria-label="Synthetic observer view showing the stellar disk and projected planet path">
</canvas>
<p class="chart-note">
The dashed horizontal line is the planet’s projected path. The
vertical separation b is measured in stellar radii.
</p>
</div>
<div class="chart-card">
<h3>
Relative brightness
<span>Synthetic — no noise or observations</span>
</h3>
<canvas
id="lightCanvas"
role="img"
aria-label="Synthetic stellar brightness curve with a transit dip">
</canvas>
<p class="chart-note">
A uniform-disk toy model is used: baseline brightness is 1, and the
dip comes only from the planet blocking a calculated area of the star.
</p>
</div>
<details open>
<summary>How the three displays are linked</summary>
<ul>
<li>
<b>Alignment:</b> the projected center-to-center separation at
mid-transit is b = (a/R★) sin α. The transit occurs only when
b ≤ 1 + Rp/R★.
</li>
<li>
<b>Duration:</b> the planet travels across a chord of the stellar
disk. A longer chord means a longer first-to-fourth-contact time.
</li>
<li>
<b>Brightness:</b> the curve is calculated from the overlap area of
two circles: the stellar disk and the planet’s projected disk.
</li>
</ul>
<div class="equation">
P = 365.256 (a/AU)^(3/2)<br>
T14 ≈ 2√[(1 + Rp/R★)² − b²] / v<br>
F = 1 − Aoverlap / (πR★²)
</div>
<p>
These equations define this classroom model. They are not a fit to a
named planet and do not include limb darkening, spots, clouds,
reflected light, instrumental noise, or uncertainty.
</p>
</details>
<details>
<summary>Source-checked concept references</summary>
<div class="source-label">Concept sources, not curve data</div>
<ul>
<li>
<a href="https://science.nasa.gov/exoplanets/transit/" target="_blank" rel="noopener">
NASA Science — Exoplanets: Transit
</a>
: the transit method and the relationship between a planet’s
transit and a temporary stellar-brightness dip.
</li>
<li>
<a href="https://science.nasa.gov/mission/kepler/" target="_blank" rel="noopener">
NASA — Kepler Mission
</a>
: transit light curves and the use of repeated transits to study
planets around other stars.
</li>
<li>
<a href="https://science.nasa.gov/solar-system/orbits-and-keplers-laws/" target="_blank" rel="noopener">
NASA — Orbits and Kepler’s Laws
</a>
: the period–orbit-size relation used here for the toy circular orbit.
</li>
<li>
<a href="https://exoplanets.nasa.gov/faq/" target="_blank" rel="noopener">
NASA Exoplanet Exploration — FAQ
</a>
: background on how exoplanet size and orbital properties are
inferred from transit observations.
</li>
</ul>
<p>
The external sources support the science concepts. The curve and
numbers in this page were generated by the code in this file; they
are not reproduced from any telescope or published light curve.
</p>
</details>
<div class="provenance">
<b>Data provenance:</b> every value, orbit, and brightness point in
this exhibit is synthetic. It is designed to demonstrate how alignment
affects transit duration and apparent stellar brightness.
</div>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and state
// -------------------------------------------------------------------------
const $ = (id) => document.getElementById(id);
const stage = $("stage");
const sceneContainer = $("scene");
const state = {
angleDeg: 3,
planetRadiusRs: 0.12,
orbitRadiusRs: 12,
speed: 1,
phase: -0.8,
direction: 1,
playing: true
};
const RSUN_AU = 0.00465047;
const SCENE_PER_RSUN = 4;
let currentModel = null;
let currentTimeHours = 0;
let currentFlux = 1;
// -------------------------------------------------------------------------
// Renderer, camera and direct camera controls (no Three.js addons)
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050914);
scene.fog = new THREE.FogExp2(0x050914, 0.0032);
const camera = new THREE.PerspectiveCamera(
46,
1,
0.1,
500
);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
sceneContainer.innerHTML =
'<div style="padding:2rem;color:#e8eef9">' +
"WebGL could not be initialized. Please try a browser with WebGL enabled." +
"</div>";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Voxel star, planet, orbit and observer. Drag to rotate the camera."
);
renderer.domElement.tabIndex = 0;
sceneContainer.appendChild(renderer.domElement);
const controls = {
target: new THREE.Vector3(0, 0, 3),
distance: 66,
theta: 0.66,
phi: 1.02
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.distance * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.distance * Math.cos(controls.phi),
controls.target.z + controls.distance * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.set(0, 0, 3);
controls.distance = 66;
controls.theta = 0.66;
controls.phi = 1.02;
updateCamera();
}
resetCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.006,
0.22,
2.65
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
22,
150
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta += 0.08;
break;
case "ArrowRight":
controls.theta -= 0.08;
break;
case "ArrowUp":
controls.phi = Math.max(0.22, controls.phi - 0.06);
break;
case "ArrowDown":
controls.phi = Math.min(2.65, controls.phi + 0.06);
break;
case "+":
case "=":
controls.distance = Math.max(22, controls.distance * 0.92);
break;
case "-":
case "_":
controls.distance = Math.min(150, controls.distance * 1.08);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
const resizeObserver = new ResizeObserver(() => {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(stage);
// -------------------------------------------------------------------------
// Lighting and background
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9ec7ff, 0x120c18, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.2);
keyLight.position.set(8, 14, 18);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4e8cff, 1.4);
rimLight.position.set(-14, 7, -12);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb550, 30, 24, 1.8);
warmLight.position.set(0, 0, 0);
scene.add(warmLight);
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (1664525 * value + 1013904223) >>> 0;
return value / 4294967296;
};
}
const starRandom = seededRandom(20250308);
const starPositions = [];
for (let i = 0; i < 420; i++) {
const radius = 95 + starRandom() * 110;
const theta = starRandom() * Math.PI * 2;
const phi = Math.acos(2 * starRandom() - 1);
starPositions.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(starPositions, 3)
);
const starField = new THREE.Points(
starFieldGeometry,
new THREE.PointsMaterial({
color: 0x9ebcff,
size: 0.16,
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
scene.add(starField);
// -------------------------------------------------------------------------
// Voxel helpers and labels
// -------------------------------------------------------------------------
function createVoxelBall(radius, cellSize, palette, seed) {
const random = seededRandom(seed);
const extent = Math.ceil(radius / cellSize);
const positions = [];
for (let x = -extent; x <= extent; x++) {
for (let y = -extent; y <= extent; y++) {
for (let z = -extent; z <= extent; z++) {
const px = x * cellSize;
const py = y * cellSize;
const pz = z * cellSize;
const distance = Math.sqrt(px * px + py * py + pz * pz);
if (distance <= radius * 0.96) {
positions.push([px, py, pz]);
}
}
}
}
const geometry = new THREE.BoxGeometry(
cellSize * 0.84,
cellSize * 0.84,
cellSize * 0.84
);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.72,
metalness: 0.02
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
positions.forEach((position, index) => {
dummy.position.set(...position);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const base = new THREE.Color(
palette[Math.floor(random() * palette.length)]
);
base.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.08,
(random() - 0.5) * 0.08
);
mesh.setColorAt(index, base);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
return mesh;
}
function createLabel(text, color = "#b8d4ff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(5, 10, 22, 0.76)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(110, 168, 255, 0.34)";
context.lineWidth = 4;
context.strokeRect(2, 2, canvas.width - 4, canvas.height - 4);
context.fillStyle = color;
context.font = "700 32px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(6.4, 1.2, 1);
return sprite;
}
const star = createVoxelBall(
SCENE_PER_RSUN,
0.66,
[0xffb62e, 0xffce55, 0xff8d25, 0xffe18a, 0xf59b24],
1207
);
scene.add(star);
const starLabel = createLabel("STAR", "#ffe3a1");
starLabel.position.set(0, 5.2, 0);
scene.add(starLabel);
const planetGroup = new THREE.Group();
scene.add(planetGroup);
let planetMesh = null;
function rebuildPlanet() {
if (planetMesh) {
planetGroup.remove(planetMesh);
planetMesh.geometry.dispose();
planetMesh.material.dispose();
}
const radius = state.planetRadiusRs * SCENE_PER_RSUN;
const cell = Math.max(0.065, radius / 4.7);
planetMesh = createVoxelBall(
radius,
cell,
[0x356dce, 0x5e91ef, 0x274f9c, 0x8bb8ff, 0x19418f],
8831
);
planetGroup.add(planetMesh);
}
rebuildPlanet();
const planetLabel = createLabel("PLANET", "#9fc5ff");
scene.add(planetLabel);
// -------------------------------------------------------------------------
// Orbit, observer and sight lines
// -------------------------------------------------------------------------
const ORBIT_COUNT = 190;
const orbitMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.25, 0.25, 0.25),
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
transparent: true,
opacity: 0.72,
roughness: 0.8
}),
ORBIT_COUNT
);
orbitMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(orbitMesh);
const referencePositions = [];
for (let i = 0; i < 160; i++) {
const theta = (i / 160) * Math.PI * 2;
referencePositions.push(
Math.cos(theta) * 24,
0,
Math.sin(theta) * 24
);
}
const referenceGeometry = new THREE.BufferGeometry();
referenceGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(referencePositions, 3)
);
const referenceOrbit = new THREE.LineLoop(
referenceGeometry,
new THREE.LineBasicMaterial({
color: 0x536987,
transparent: true,
opacity: 0.25
})
);
scene.add(referenceOrbit);
const observer = new THREE.Group();
const observerMaterial = new THREE.MeshStandardMaterial({
color: 0x9aabc3,
roughness: 0.55,
metalness: 0.35
});
const observerDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x111a2d,
roughness: 0.38,
metalness: 0.55
});
const observerBody = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.9, 0.9),
observerMaterial
);
observer.add(observerBody);
const observerLens = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.58, 0.32),
observerDarkMaterial
);
observerLens.position.z = -0.58;
observer.add(observerLens);
const observerSideA = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 1.25, 0.28),
observerMaterial
);
observerSideA.position.x = -0.95;
observer.add(observerSideA);
const observerSideB = observerSideA.clone();
observerSideB.position.x = 0.95;
observer.add(observerSideB);
scene.add(observer);
const observerLabel = createLabel("OBSERVER", "#79eee4");
scene.add(observerLabel);
const sightGeometry = new THREE.BufferGeometry();
sightGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const sightLine = new THREE.Line(
sightGeometry,
new THREE.LineBasicMaterial({
color: 0x6adfd9,
transparent: true,
opacity: 0.18
})
);
scene.add(sightLine);
const planetRayGeometry = new THREE.BufferGeometry();
planetRayGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const planetRay = new THREE.Line(
planetRayGeometry,
new THREE.LineBasicMaterial({
color: 0x72a8ff,
transparent: true,
opacity: 0.48
})
);
scene.add(planetRay);
let visualOrbitRadius = 24;
let visualOrbitTilt = 0;
let observerZ = 34;
const orbitDummy = new THREE.Object3D();
const orbitColor = new THREE.Color();
function updateOrbitGeometry() {
visualOrbitRadius = 23 + 0.2 * (state.orbitRadiusRs - 12);
const projectedBY = currentModel.b * SCENE_PER_RSUN;
visualOrbitTilt = Math.asin(
Math.min(0.96, projectedBY / visualOrbitRadius)
);
for (let i = 0; i < ORBIT_COUNT; i++) {
const theta = (i / ORBIT_COUNT) * Math.PI * 2;
orbitDummy.position.set(
visualOrbitRadius * Math.cos(theta),
visualOrbitRadius * Math.sin(theta) * Math.sin(visualOrbitTilt),
visualOrbitRadius * Math.sin(theta) * Math.cos(visualOrbitTilt)
);
orbitDummy.rotation.set(0, theta, 0);
orbitDummy.updateMatrix();
orbitMesh.setMatrixAt(i, orbitDummy.matrix);
const shade = 0.42 + 0.28 * (0.5 + 0.5 * Math.sin(theta));
orbitColor.setRGB(shade * 0.35, shade, shade);
orbitMesh.setColorAt(i, orbitColor);
}
orbitMesh.instanceMatrix.needsUpdate = true;
orbitMesh.instanceColor.needsUpdate = true;
observerZ = visualOrbitRadius + 9;
observer.position.set(0, 0, observerZ);
observerLabel.position.set(0, 2.2, observerZ);
const sight = sightGeometry.attributes.position;
sight.setXYZ(0, 0, 0, 0);
sight.setXYZ(1, 0, 0, observerZ);
sight.needsUpdate = true;
sightGeometry.computeBoundingSphere();
}
// -------------------------------------------------------------------------
// Physical toy model
// -------------------------------------------------------------------------
function overlapArea(radiusA, radiusB, separation) {
if (separation >= radiusA + radiusB) {
return 0;
}
if (separation <= Math.abs(radiusA - radiusB)) {
const smaller = Math.min(radiusA, radiusB);
return Math.PI * smaller * smaller;
}
const a2 = radiusA * radiusA;
const b2 = radiusB * radiusB;
const d2 = separation * separation;
const alpha = Math.acos(
THREE.MathUtils.clamp(
(d2 + a2 - b2) / (2 * separation * radiusA),
-1,
1
)
);
const beta = Math.acos(
THREE.MathUtils.clamp(
(d2 + b2 - a2) / (2 * separation * radiusB),
-1,
1
)
);
return (
a2 * alpha +
b2 * beta -
0.5 *
Math.sqrt(
Math.max(
0,
(-separation + radiusA + radiusB) *
(separation + radiusA - radiusB) *
(separation - radiusA + radiusB) *
(separation + radiusA + radiusB)
)
)
);
}
function computeModel() {
const alpha = THREE.MathUtils.degToRad(state.angleDeg);
const a = state.orbitRadiusRs;
const rp = state.planetRadiusRs;
const rs = 1;
const b = a * Math.sin(alpha);
const contact = b <= rs + rp;
const chordHalf = contact
? Math.sqrt(
Math.max(0, (rs + rp) * (rs + rp) - b * b)
)
: 0;
const orbitAU = a * RSUN_AU;
const periodDays = 365.256 * Math.pow(orbitAU, 1.5);
const orbitalSpeedRsPerHour =
(2 * Math.PI * a) / (periodDays * 24);
const durationHours = contact
? (2 * chordHalf) / orbitalSpeedRsPerHour
: 0;
const centerFlux =
1 - overlapArea(rs, rp, b) / (Math.PI * rs * rs);
const fullTransit = b <= rs - rp;
return {
alpha,
a,
rp,
b,
contact,
chordHalf,
periodDays,
orbitalSpeedRsPerHour,
durationHours,
centerFlux,
depth: 1 - centerFlux,
fullTransit,
windowHours: Math.max(durationHours * 0.75, 0.8)
};
}
function projectedPosition(timeHours) {
const omega =
(2 * Math.PI) / (currentModel.periodDays * 24);
const theta = Math.PI / 2 + omega * timeHours;
return {
x: -currentModel.a * Math.sin(omega * timeHours),
y:
currentModel.a *
Math.cos(omega * timeHours) *
Math.sin(currentModel.alpha),
z:
currentModel.a *
Math.cos(omega * timeHours) *
Math.cos(currentModel.alpha),
theta
};
}
function fluxAtTime(timeHours) {
const position = projectedPosition(timeHours);
const separation = Math.hypot(position.x, position.y);
return (
1 -
overlapArea(1, currentModel.rp, separation) / Math.PI
);
}
function updateReadouts() {
currentModel = computeModel();
$("angleOut").textContent = `${state.angleDeg.toFixed(1)}°`;
$("planetOut").textContent =
`${state.planetRadiusRs.toFixed(3)} R★`;
$("orbitOut").textContent =
`${state.orbitRadiusRs.toFixed(1)} R★`;
$("speedOut").textContent = `${state.speed.toFixed(2)}×`;
$("bReadout").textContent = `${currentModel.b.toFixed(3)} R★`;
if (currentModel.contact) {
if (currentModel.durationHours < 0.02) {
$("durationReadout").textContent = "Grazing contact";
} else {
$("durationReadout").textContent =
`${currentModel.durationHours.toFixed(2)} hr`;
}
} else {
$("durationReadout").textContent = "No contact";
}
$("depthReadout").textContent =
`${(currentModel.depth * 100).toFixed(3)}%`;
$("periodReadout").textContent =
`${currentModel.periodDays.toFixed(2)} days`;
const status = $("status");
if (!currentModel.contact) {
status.className = "status miss";
status.textContent =
"No transit — the projected planet path misses the stellar disk.";
} else if (currentModel.fullTransit) {
status.className = "status transit";
status.textContent =
"Full transit — at mid-transit the planet can lie entirely on the stellar disk.";
} else {
status.className = "status graze";
status.textContent =
"Partial transit — the planet overlaps part of the stellar disk near mid-transit.";
}
updateOrbitGeometry();
}
// -------------------------------------------------------------------------
// Canvas charts
// -------------------------------------------------------------------------
function prepareCanvas(canvas) {
const width = Math.max(1, canvas.clientWidth);
const height = Math.max(1, canvas.clientHeight);
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const pixelWidth = Math.round(width * dpr);
const pixelHeight = Math.round(height * dpr);
if (canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
canvas.width = pixelWidth;
canvas.height = pixelHeight;
}
const context = canvas.getContext("2d");
context.setTransform(dpr, 0, 0, dpr, 0, 0);
context.clearRect(0, 0, width, height);
return { context, width, height };
}
function drawSkyView() {
const { context, width, height } = prepareCanvas($("skyCanvas"));
const background = context.createLinearGradient(
0,
0,
0,
height
);
background.addColorStop(0, "#0a1427");
background.addColorStop(1, "#040812");
context.fillStyle = background;
context.fillRect(0, 0, width, height);
const centerX = width / 2;
const centerY = height / 2;
const scale = Math.min(
43,
(height * 0.37) /
Math.max(0.35, currentModel.b + currentModel.rp + 0.12)
);
const pathY = centerY + currentModel.b * scale;
context.save();
context.setLineDash([5, 5]);
context.strokeStyle = "rgba(100, 230, 220, 0.55)";
context.lineWidth = 1.4;
context.beginPath();
context.moveTo(10, pathY);
context.lineTo(width - 10, pathY);
context.stroke();
context.restore();
const starGradient = context.createRadialGradient(
centerX - 6,
centerY - 7,
1,
centerX,
centerY,
Math.max(2, scale)
);
starGradient.addColorStop(0, "#fff4b8");
starGradient.addColorStop(0.55, "#ffbd45");
starGradient.addColorStop(1, "#e77724");
context.fillStyle = starGradient;
context.beginPath();
context.arc(centerX, centerY, scale, 0, Math.PI * 2);
context.fill();
context.strokeStyle = "rgba(255, 231, 164, 0.7)";
context.lineWidth = 1;
context.stroke();
const projected = projectedPosition(currentTimeHours);
const planetX = centerX + projected.x * scale;
const planetY = centerY + projected.y * scale;
const planetRadius = Math.max(2, currentModel.rp * scale);
context.fillStyle = "#72a8ff";
context.beginPath();
context.arc(
planetX,
planetY,
planetRadius,
0,
Math.PI * 2
);
context.fill();
context.strokeStyle = "rgba(211, 230, 255, 0.9)";
context.stroke();
if (currentModel.contact && currentModel.b > 0.01) {
context.save();
context.strokeStyle = "rgba(255, 211, 107, 0.7)";
context.lineWidth = 1;
context.setLineDash([3, 4]);
context.beginPath();
context.moveTo(centerX, centerY);
context.lineTo(centerX, pathY);
context.stroke();
context.restore();
context.fillStyle = "#ffe19a";
context.font = "700 10px system-ui, sans-serif";
context.textAlign = "right";
context.fillText(
`b = ${currentModel.b.toFixed(2)} R★`,
width - 8,
centerY - 7
);
}
context.fillStyle = "#91a7c4";
context.font = "600 10px system-ui, sans-serif";
context.textAlign = "left";
context.fillText("PROJECTED TRACK", 9, 16);
}
function drawLightCurve() {
const { context, width, height } = prepareCanvas($("lightCanvas"));
const padding = {
left: 45,
right: 14,
top: 18,
bottom: 31
};
const plotWidth = width - padding.left - padding.right;
const plotHeight = height - padding.top - padding.bottom;
const yMin = currentModel.contact
? Math.max(
0,
1 - Math.max(currentModel.depth * 1.35, 0.012)
)
: 0.985;
const yMax = 1.005;
const xMap = (time) =>
padding.left +
((time + currentModel.windowHours) /
(2 * currentModel.windowHours)) *
plotWidth;
const yMap = (flux) =>
padding.top +
((yMax - flux) / (yMax - yMin)) * plotHeight;
context.fillStyle = "#050a14";
context.fillRect(0, 0, width, height);
const gridLevels = [yMin, yMin + (1 - yMin) * 0.5, 1];
context.font = "10px system-ui, sans-serif";
context.textAlign = "right";
context.textBaseline = "middle";
gridLevels.forEach((level) => {
const y = yMap(level);
context.strokeStyle =
level === 1
? "rgba(154, 171, 196, 0.32)"
: "rgba(154, 171, 196, 0.12)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(padding.left, y);
context.lineTo(width - padding.right, y);
context.stroke();
context.fillStyle = "#8295b1";
context.fillText(level.toFixed(3), padding.left - 7, y);
});
context.textAlign = "center";
context.textBaseline = "top";
const timeTicks = [-currentModel.windowHours, 0, currentModel.windowHours];
timeTicks.forEach((tick) => {
const x = xMap(tick);
context.strokeStyle = "rgba(154, 171, 196, 0.12)";
context.beginPath();
context.moveTo(x, padding.top);
context.lineTo(x, padding.top + plotHeight);
context.stroke();
context.fillStyle = "#8295b1";
context.fillText(
`${tick > 0 ? "+" : ""}${tick.toFixed(1)} h`,
x,
padding.top + plotHeight + 8
);
});
const points = [];
for (let i = 0; i <= 260; i++) {
const normalized = -1 + (2 * i) / 260;
const time = normalized * currentModel.windowHours;
const flux = fluxAtTime(time);
points.push({
x: xMap(time),
y: yMap(flux),
flux,
time
});
}
context.beginPath();
context.moveTo(points[0].x, padding.top + plotHeight);
points.forEach((point) => {
context.lineTo(point.x, point.y);
});
context.lineTo(points[points.length - 1].x, padding.top + plotHeight);
context.closePath();
const fill = context.createLinearGradient(
0,
padding.top,
0,
padding.top + plotHeight
);
fill.addColorStop(0, "rgba(100, 230, 220, 0.04)");
fill.addColorStop(1, "rgba(100, 230, 220, 0.20)");
context.fillStyle = fill;
context.fill();
context.beginPath();
points.forEach((point, index) => {
if (index === 0) {
context.moveTo(point.x, point.y);
} else {
context.lineTo(point.x, point.y);
}
});
context.strokeStyle = "#64e6dc";
context.lineWidth = 2;
context.stroke();
const currentX = xMap(currentTimeHours);
const currentY = yMap(currentFlux);
context.fillStyle = "#ffffff";
context.beginPath();
context.arc(currentX, currentY, 3.8, 0, Math.PI * 2);
context.fill();
context.strokeStyle = "rgba(255, 255, 255, 0.3)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(currentX, padding.top);
context.lineTo(currentX, padding.top + plotHeight);
context.stroke();
context.fillStyle = "#9aabc4";
context.font = "10px system-ui, sans-serif";
context.textAlign = "left";
context.textBaseline = "bottom";
context.fillText(
"Relative brightness F",
padding.left,
padding.top - 5
);
context.textAlign = "right";
context.fillText(
"Time from mid-transit",
width - padding.right,
height - 2
);
}
// -------------------------------------------------------------------------
// UI input
// -------------------------------------------------------------------------
$("angle").addEventListener("input", (event) => {
state.angleDeg = Number(event.target.value);
updateReadouts();
});
$("planetRadius").addEventListener("input", (event) => {
state.planetRadiusRs = Number(event.target.value);
rebuildPlanet();
updateReadouts();
});
$("orbitRadius").addEventListener("input", (event) => {
state.orbitRadiusRs = Number(event.target.value);
updateReadouts();
});
$("speed").addEventListener("input", (event) => {
state.speed = Number(event.target.value);
updateReadouts();
});
function setAngle(angle) {
state.angleDeg = THREE.MathUtils.clamp(angle, 0, 15);
$("angle").value = state.angleDeg;
updateReadouts();
}
$("centerButton").addEventListener("click", () => {
state.phase = 0;
state.direction = 1;
state.playing = true;
});
$("edgeButton").addEventListener("click", () => {
setAngle(0);
});
$("grazingButton").addEventListener("click", () => {
const ratio =
(1 + state.planetRadiusRs) / state.orbitRadiusRs;
setAngle(
THREE.MathUtils.radToDeg(
Math.asin(THREE.MathUtils.clamp(ratio, 0, 0.999))
)
);
});
$("missButton").addEventListener("click", () => {
const ratio =
(1 + state.planetRadiusRs + 0.25) /
state.orbitRadiusRs;
setAngle(
THREE.MathUtils.radToDeg(
Math.asin(THREE.MathUtils.clamp(ratio, 0, 0.999))
)
);
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
state.phase +=
state.direction * delta * state.speed * 0.46;
if (state.phase > 1) {
state.phase = 1;
state.direction = -1;
} else if (state.phase < -1) {
state.phase = -1;
state.direction = 1;
}
}
currentTimeHours = state.phase * currentModel.windowHours;
currentFlux = fluxAtTime(currentTimeHours);
const omega =
(2 * Math.PI) / (currentModel.periodDays * 24);
const theta = Math.PI / 2 + omega * currentTimeHours;
const planetPosition = new THREE.Vector3(
visualOrbitRadius * Math.cos(theta),
visualOrbitRadius *
Math.sin(theta) *
Math.sin(visualOrbitTilt),
visualOrbitRadius *
Math.sin(theta) *
Math.cos(visualOrbitTilt)
);
planetGroup.position.copy(planetPosition);
planetGroup.rotation.y += delta * 0.35;
planetLabel.position.copy(planetPosition);
planetLabel.position.y += 1.4;
const ray = planetRayGeometry.attributes.position;
ray.setXYZ(0, planetPosition.x, planetPosition.y, planetPosition.z);
ray.setXYZ(1, 0, 0, observerZ);
ray.needsUpdate = true;
planetRayGeometry.computeBoundingSphere();
star.rotation.y += delta * 0.035;
starField.rotation.y += delta * 0.002;
drawSkyView();
drawLightCurve();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateReadouts();
animate();
</script>
</body>
</html>
```