Prompt specification
Build or customize the Three.js 3D scene "Planet Disk Across a Stellar Disk" 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: Planet Disk Across a Stellar Disk
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/planet-disk-across-a-stellar-disk-x3777
Scene Description Prompt:
Animate a stylized planet transiting a star, showing projected overlap and distinguishing physical radius from screen size. Three.js from cdnjs, one HTML file.
Working Three.js Starter (planet-disk-across-a-stellar-disk-x3777):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Transit — Physical Scale vs. Screen Projection</title>
<style>
:root {
color-scheme: dark;
--bg: #050713;
--panel: rgba(10, 15, 32, 0.82);
--border: rgba(156, 184, 235, 0.18);
--text: #eef4ff;
--muted: #9aabc8;
--cyan: #68ddff;
--gold: #ffd36a;
--shadow: 0 20px 70px rgba(0, 0, 0, 0.42);
}
* {
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 {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 4;
top: 24px;
left: 28px;
max-width: 590px;
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.7);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.hero h1 {
margin: 0;
font-size: clamp(30px, 4vw, 58px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.045em;
}
.hero p {
max-width: 540px;
margin: 14px 0 0;
color: #b7c5dc;
font-size: 14px;
line-height: 1.55;
}
.hero strong {
color: #fff;
font-weight: 650;
}
.controls {
position: fixed;
z-index: 7;
top: 22px;
right: 22px;
display: flex;
gap: 8px;
}
.control-button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(12, 18, 37, 0.76);
color: #dce8ff;
cursor: pointer;
backdrop-filter: blur(14px);
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.control-button:hover {
border-color: rgba(104, 221, 255, 0.55);
background: rgba(20, 32, 58, 0.9);
transform: translateY(-1px);
}
.panel {
position: fixed;
z-index: 6;
top: 86px;
right: 22px;
width: 340px;
padding: 18px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(20px) saturate(130%);
}
.panel-kicker {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel h2 {
margin: 6px 0 7px;
font-size: 20px;
letter-spacing: -0.025em;
}
.panel-intro {
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.diagram-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 12px 0 7px;
color: #d8e5fa;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.diagram-title span:last-child {
color: #7588a9;
font-weight: 600;
letter-spacing: 0.04em;
text-transform: none;
}
.diagram {
display: block;
width: 100%;
height: auto;
overflow: hidden;
border: 1px solid rgba(155, 181, 226, 0.12);
border-radius: 11px;
background: rgba(2, 5, 15, 0.7);
}
#physicalCanvas {
aspect-ratio: 300 / 112;
}
#projectionCanvas {
aspect-ratio: 300 / 160;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
.metric {
min-width: 0;
padding: 10px 11px;
border: 1px solid rgba(155, 181, 226, 0.11);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
overflow: hidden;
margin-bottom: 4px;
color: #8294b4;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric strong {
color: #f3f7ff;
font-size: 14px;
font-variant-numeric: tabular-nums;
}
.status {
margin-top: 12px;
padding: 10px 11px;
border: 1px solid rgba(104, 221, 255, 0.2);
border-radius: 10px;
background: rgba(104, 221, 255, 0.06);
color: #aeeeff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
line-height: 1.4;
text-align: center;
text-transform: uppercase;
}
.status.overlap {
border-color: rgba(255, 202, 93, 0.35);
background: rgba(255, 202, 93, 0.09);
color: #ffe2a0;
}
.panel-note {
margin: 12px 1px 0;
color: #8294b4;
font-size: 10px;
line-height: 1.5;
}
.panel-note b {
color: #b9c9e3;
font-weight: 650;
}
.world-label {
position: fixed;
z-index: 5;
top: 0;
left: 0;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 999px;
background: rgba(3, 7, 18, 0.72);
box-shadow: 0 6px 30px rgba(0, 0, 0, 0.3);
color: #eff5ff;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.025em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(10px);
}
#starLabel {
border-color: rgba(255, 211, 106, 0.35);
color: #ffe5a5;
}
#planetLabel {
border-color: rgba(104, 221, 255, 0.4);
color: #bcefff;
}
.measure-outline {
position: fixed;
z-index: 3;
top: 0;
left: 0;
border-radius: 50%;
pointer-events: none;
transform: translate(0, 0);
}
#starOutline {
border: 1px dashed rgba(255, 255, 255, 0.24);
}
#planetOutline {
border: 1px solid rgba(104, 221, 255, 0.72);
box-shadow: 0 0 15px rgba(104, 221, 255, 0.12);
}
.hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 22px;
color: #7f91b1;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.055em;
pointer-events: none;
text-transform: uppercase;
}
@media (max-width: 800px) {
.hero {
top: 17px;
left: 18px;
max-width: calc(100vw - 36px);
}
.hero h1 {
max-width: 380px;
font-size: 34px;
}
.hero p {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
}
.panel {
top: auto;
right: 12px;
bottom: 64px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 13px;
overflow: auto;
}
.panel-intro,
.panel-note {
display: none;
}
.diagrams {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.diagram-title {
display: block;
}
.diagram-title span:last-child {
display: none;
}
.metric-grid {
grid-template-columns: repeat(4, 1fr);
}
.metric {
padding: 8px;
}
.metric strong {
font-size: 12px;
}
.hint {
display: none;
}
.world-label {
font-size: 9px;
}
}
@media (max-width: 520px) {
.diagrams {
grid-template-columns: 1fr;
}
#physicalCanvas {
display: none;
}
.metric-grid {
grid-template-columns: 1fr 1fr;
}
.panel {
max-height: 38vh;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Animated planet transit in front of a stylized star"></canvas>
<header class="hero">
<div class="eyebrow">Orbital geometry / live projection</div>
<h1>When a world crosses a sun.</h1>
<p>
The planet is <strong>physically small</strong>, but its foreground
position makes its projected silhouette look larger. The dashed circle
marks the star’s apparent radius; the cyan circle marks the planet’s.
</p>
</header>
<div class="controls">
<button class="control-button" id="pauseButton" type="button">Pause</button>
<button class="control-button" id="resetButton" type="button">Reset view</button>
</div>
<aside class="panel">
<div class="panel-kicker">Scale laboratory</div>
<h2>Two kinds of size</h2>
<p class="panel-intro">
Physical radius belongs to the meshes. Screen size is produced by the
camera and changes with distance and perspective.
</p>
<div class="diagrams">
<div>
<div class="diagram-title">
<span>Physical scale</span>
<span>1 world unit = 1 R★</span>
</div>
<canvas
id="physicalCanvas"
class="diagram"
width="600"
height="224"
aria-label="True relative radii of the star and planet"
></canvas>
</div>
<div>
<div class="diagram-title">
<span>Projected overlap</span>
<span>live camera</span>
</div>
<canvas
id="projectionCanvas"
class="diagram"
width="600"
height="320"
aria-label="Live screen-space projection of the star and planet"
></canvas>
</div>
</div>
<div class="metric-grid">
<div class="metric">
<span>Star screen diameter</span>
<strong id="starPixels">—</strong>
</div>
<div class="metric">
<span>Planet screen diameter</span>
<strong id="planetPixels">—</strong>
</div>
<div class="metric">
<span>Apparent radius ratio</span>
<strong id="apparentRatio">—</strong>
</div>
<div class="metric">
<span>Physical radius ratio</span>
<strong>16.0%</strong>
</div>
</div>
<div class="status" id="transitStatus">Calculating projection…</div>
<p class="panel-note">
<b>Reading the view:</b> the planet’s physical radius is 0.16 R★.
Its apparent radius is usually larger because the camera sees it from
in front of the stellar surface, not at the star’s center.
</p>
</aside>
<div id="starOutline" class="measure-outline"></div>
<div id="planetOutline" class="measure-outline"></div>
<div id="starLabel" class="world-label">STAR · physical R = 1.00 R★</div>
<div id="planetLabel" class="world-label">PLANET · physical R = 0.16 R★</div>
<div class="hint">Drag to orbit · wheel to zoom · space to pause</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneCanvas = document.querySelector("#scene");
const pauseButton = document.querySelector("#pauseButton");
const resetButton = document.querySelector("#resetButton");
const ui = {
starPixels: document.querySelector("#starPixels"),
planetPixels: document.querySelector("#planetPixels"),
apparentRatio: document.querySelector("#apparentRatio"),
status: document.querySelector("#transitStatus"),
starLabel: document.querySelector("#starLabel"),
planetLabel: document.querySelector("#planetLabel"),
starOutline: document.querySelector("#starOutline"),
planetOutline: document.querySelector("#planetOutline"),
physicalCanvas: document.querySelector("#physicalCanvas"),
projectionCanvas: document.querySelector("#projectionCanvas")
};
const STAR_RADIUS = 1.0;
const PLANET_RADIUS = 0.16;
const ORBIT_RADIUS = 1.55;
const TRANSIT_ARC = 1.25;
const renderer = new THREE.WebGLRenderer({
canvas: sceneCanvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x050713, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x050713, 0.022);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
radius: 5.4,
theta: 0,
phi: 1.53,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
// -------------------------------------------------------------------------
// Background stars
// -------------------------------------------------------------------------
const starPositions = [];
let seed = 81273;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
for (let i = 0; i < 650; i += 1) {
const radius = 13 + random() * 24;
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
starPositions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.sin(phi) * Math.sin(theta),
radius * Math.cos(phi)
);
}
const backgroundGeometry = new THREE.BufferGeometry();
backgroundGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const background = new THREE.Points(
backgroundGeometry,
new THREE.PointsMaterial({
color: 0xb9d4ff,
size: 0.035,
transparent: true,
opacity: 0.72,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(background);
// -------------------------------------------------------------------------
// Procedural star surface
// -------------------------------------------------------------------------
const starVertexShader = `
varying vec3 vLocal;
varying vec3 vWorld;
varying vec3 vWorldNormal;
void main() {
vLocal = position;
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorld = worldPosition.xyz;
vWorldNormal = normalize(mat3(modelMatrix) * normal);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`;
const starFragmentShader = `
uniform float uTime;
varying vec3 vLocal;
varying vec3 vWorld;
varying vec3 vWorldNormal;
float hash(vec3 p) {
p = fract(p * 0.3183099 + 0.1);
p *= 17.0;
return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
}
float noise(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(hash(i), hash(i + vec3(1,0,0)), f.x),
mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x),
f.y
),
mix(
mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x),
mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x),
f.y
),
f.z
);
}
float fbm(vec3 p) {
float value = 0.0;
float amplitude = 0.5;
for (int i = 0; i < 4; i++) {
value += amplitude * noise(p);
p = p * 2.03 + vec3(7.1, 3.7, 5.2);
amplitude *= 0.5;
}
return value;
}
void main() {
vec3 flow = vLocal * 3.7 + vec3(
uTime * 0.055,
-uTime * 0.035,
uTime * 0.025
);
float granulation = fbm(flow);
float broadFlow = fbm(vLocal * 1.35 + uTime * 0.018);
float hotBand = smoothstep(0.38, 0.82, broadFlow);
vec3 deepOrange = vec3(0.72, 0.105, 0.008);
vec3 orange = vec3(1.0, 0.34, 0.025);
vec3 gold = vec3(1.0, 0.73, 0.18);
vec3 pale = vec3(1.0, 0.94, 0.62);
vec3 color = mix(deepOrange, orange, granulation);
color = mix(color, gold, hotBand * 0.55);
color = mix(color, pale, smoothstep(0.77, 0.97, granulation) * 0.7);
vec3 viewDirection = normalize(cameraPosition - vWorld);
float facing = max(dot(normalize(vWorldNormal), viewDirection), 0.0);
float limb = pow(facing, 0.48);
color *= 0.67 + 0.48 * limb;
color += vec3(1.0, 0.26, 0.015) *
(1.0 - limb) * 0.22;
gl_FragColor = vec4(color, 1.0);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`;
const starMaterial = new THREE.ShaderMaterial({
vertexShader: starVertexShader,
fragmentShader: starFragmentShader,
uniforms: {
uTime: { value: 0 }
}
});
const starMesh = new THREE.Mesh(
new THREE.SphereGeometry(STAR_RADIUS, 72, 40),
starMaterial
);
scene.add(starMesh);
// Radial corona sprite. Its depth test keeps it behind the planet.
function createGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128, 128, 30,
128, 128, 128
);
gradient.addColorStop(0.0, "rgba(255, 205, 90, 0.48)");
gradient.addColorStop(0.32, "rgba(255, 155, 36, 0.22)");
gradient.addColorStop(0.62, "rgba(255, 105, 20, 0.075)");
gradient.addColorStop(1.0, "rgba(255, 80, 10, 0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const corona = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0xffffff,
transparent: true,
opacity: 0.85,
depthWrite: false,
depthTest: true,
blending: THREE.AdditiveBlending
})
);
corona.scale.set(3.15, 3.15, 1);
corona.renderOrder = -1;
scene.add(corona);
// -------------------------------------------------------------------------
// Stylized planet
// -------------------------------------------------------------------------
const planetVertexShader = `
varying vec3 vLocal;
varying vec3 vWorld;
varying vec3 vWorldNormal;
void main() {
vLocal = position;
vec4 worldPosition = modelMatrix * vec4(position, 1.0);
vWorld = worldPosition.xyz;
vWorldNormal = normalize(mat3(modelMatrix) * normal);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
}
`;
const planetFragmentShader = `
uniform float uTime;
varying vec3 vLocal;
varying vec3 vWorld;
varying vec3 vWorldNormal;
float hash(vec3 p) {
p = fract(p * 0.3183099 + 0.1);
p *= 17.0;
return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
}
float noise(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(
mix(
mix(hash(i), hash(i + vec3(1,0,0)), f.x),
mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x),
f.y
),
mix(
mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x),
mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x),
f.y
),
f.z
);
}
float fbm(vec3 p) {
float value = 0.0;
float amplitude = 0.5;
for (int i = 0; i < 4; i++) {
value += amplitude * noise(p);
p = p * 2.04 + vec3(4.7, 8.3, 2.9);
amplitude *= 0.5;
}
return value;
}
void main() {
vec3 p = vLocal * 8.0;
float terrain = fbm(p + vec3(0.0, uTime * 0.015, 0.0));
float land = smoothstep(0.51, 0.61, terrain);
float clouds = smoothstep(0.62, 0.79, fbm(p * 1.8 - uTime * 0.025));
vec3 ocean = vec3(0.018, 0.12, 0.23);
vec3 ground = vec3(0.08, 0.46, 0.47);
vec3 highland = vec3(0.42, 0.77, 0.62);
vec3 cloudColor = vec3(0.82, 0.94, 1.0);
vec3 color = mix(ocean, ground, land);
color = mix(color, highland, land * smoothstep(0.58, 0.72, terrain));
color = mix(color, cloudColor, clouds * 0.52);
vec3 normal = normalize(vWorldNormal);
vec3 viewDirection = normalize(cameraPosition - vWorld);
vec3 lightDirection = normalize(vec3(-0.45, 0.55, 1.0));
float diffuse = max(dot(normal, lightDirection), 0.0);
float facing = max(dot(normal, viewDirection), 0.0);
float rim = pow(1.0 - facing, 3.1);
color *= 0.34 + 0.78 * diffuse;
color += vec3(0.1, 0.55, 0.95) * rim * 0.9;
gl_FragColor = vec4(color, 1.0);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`;
const planetGroup = new THREE.Group();
const planetMaterial = new THREE.ShaderMaterial({
vertexShader: planetVertexShader,
fragmentShader: planetFragmentShader,
uniforms: {
uTime: { value: 0 }
}
});
const planetMesh = new THREE.Mesh(
new THREE.SphereGeometry(PLANET_RADIUS, 48, 32),
planetMaterial
);
planetGroup.add(planetMesh);
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(PLANET_RADIUS * 1.085, 48, 32),
new THREE.MeshBasicMaterial({
color: 0x59d8ff,
transparent: true,
opacity: 0.2,
side: THREE.BackSide,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
planetGroup.add(atmosphere);
scene.add(planetGroup);
// -------------------------------------------------------------------------
// Orbit guide
// -------------------------------------------------------------------------
const orbitPoints = [];
for (let i = 0; i <= 240; i += 1) {
const theta = (i / 240) * Math.PI * 2;
orbitPoints.push(
new THREE.Vector3(
Math.sin(theta) * ORBIT_RADIUS,
0,
Math.cos(theta) * ORBIT_RADIUS
)
);
}
const orbit = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(orbitPoints),
new THREE.LineDashedMaterial({
color: 0x6079a8,
dashSize: 0.07,
gapSize: 0.055,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
orbit.computeLineDistances();
scene.add(orbit);
// -------------------------------------------------------------------------
// Canvas diagrams
// -------------------------------------------------------------------------
const physicalContext = ui.physicalCanvas.getContext("2d");
const projectionContext = ui.projectionCanvas.getContext("2d");
function drawPhysicalDiagram() {
const context = physicalContext;
context.setTransform(2, 0, 0, 2, 0, 0);
context.clearRect(0, 0, 300, 112);
const starX = 53;
const starY = 48;
const starR = 38;
const planetX = 158;
const planetY = 48;
const planetR = starR * (PLANET_RADIUS / STAR_RADIUS);
const glow = context.createRadialGradient(
starX, starY, 5,
starX, starY, starR + 8
);
glow.addColorStop(0, "rgba(255, 221, 117, 0.26)");
glow.addColorStop(1, "rgba(255, 130, 20, 0)");
context.fillStyle = glow;
context.beginPath();
context.arc(starX, starY, starR + 8, 0, Math.PI * 2);
context.fill();
const starGradient = context.createRadialGradient(
starX - 10, starY - 12, 2,
starX, starY, starR
);
starGradient.addColorStop(0, "#fff3ad");
starGradient.addColorStop(0.45, "#ffc247");
starGradient.addColorStop(1, "#ee6415");
context.fillStyle = starGradient;
context.beginPath();
context.arc(starX, starY, starR, 0, Math.PI * 2);
context.fill();
context.strokeStyle = "#72dfff";
context.lineWidth = 1.4;
context.fillStyle = "#173d5b";
context.beginPath();
context.arc(planetX, planetY, planetR, 0, Math.PI * 2);
context.fill();
context.stroke();
context.setLineDash([3, 4]);
context.strokeStyle = "rgba(126, 152, 194, 0.42)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(starX + starR + 7, starY);
context.lineTo(planetX - planetR - 8, planetY);
context.stroke();
context.setLineDash([]);
context.font = "700 9px system-ui";
context.fillStyle = "#ffe2a0";
context.fillText("1.00 R★", 20, 101);
context.fillStyle = "#9eeeff";
context.fillText("0.16 R★", 134, 101);
context.font = "600 8px system-ui";
context.fillStyle = "#6f83a4";
context.fillText("TRUE RELATIVE RADII", 10, 15);
}
drawPhysicalDiagram();
function drawProjectionDiagram(dx, dy, starRadius, planetRadius) {
const context = projectionContext;
const width = 300;
const height = 160;
const centerX = width / 2;
const centerY = height / 2 + 3;
context.setTransform(2, 0, 0, 2, 0, 0);
context.clearRect(0, 0, width, height);
const requiredX = Math.max(starRadius, Math.abs(dx) + planetRadius);
const requiredY = Math.max(starRadius, Math.abs(dy) + planetRadius);
const scale = Math.min(
(width - 24) / (2 * requiredX),
(height - 38) / (2 * requiredY)
);
const drawnStarRadius = starRadius * scale;
const drawnPlanetRadius = planetRadius * scale;
const planetX = centerX + dx * scale;
const planetY = centerY + dy * scale;
context.font = "600 8px system-ui";
context.fillStyle = "#7085a7";
context.fillText("APPARENT DISKS · LIVE CAMERA", 10, 16);
context.setLineDash([3, 4]);
context.strokeStyle = "rgba(112, 133, 167, 0.35)";
context.lineWidth = 1;
context.beginPath();
context.moveTo(centerX, centerY);
context.lineTo(planetX, planetY);
context.stroke();
context.setLineDash([]);
const starGradient = context.createRadialGradient(
centerX - drawnStarRadius * 0.25,
centerY - drawnStarRadius * 0.3,
1,
centerX,
centerY,
drawnStarRadius
);
starGradient.addColorStop(0, "#fff0a0");
starGradient.addColorStop(0.55, "#ffc148");
starGradient.addColorStop(1, "#e65d13");
context.fillStyle = starGradient;
context.beginPath();
context.arc(centerX, centerY, drawnStarRadius, 0, Math.PI * 2);
context.fill();
context.fillStyle = "#071426";
context.strokeStyle = "#6ee2ff";
context.lineWidth = 1.4;
context.beginPath();
context.arc(planetX, planetY, drawnPlanetRadius, 0, Math.PI * 2);
context.fill();
context.stroke();
}
// -------------------------------------------------------------------------
// Projection calculations
// -------------------------------------------------------------------------
function projectToScreen(worldPosition) {
const projected = worldPosition.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight
};
}
function projectedSphereRadius(worldPosition, physicalRadius) {
const distance = camera.position.distanceTo(worldPosition);
const angularRadius = Math.asin(
Math.min(physicalRadius / Math.max(distance, 0.001), 0.999)
);
const focalPixels =
window.innerHeight /
(2 * Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)));
return focalPixels * Math.tan(angularRadius);
}
function circleOverlapArea(radiusA, radiusB, distance) {
if (distance >= radiusA + radiusB) return 0;
if (distance <= Math.abs(radiusA - radiusB)) {
const smaller = Math.min(radiusA, radiusB);
return Math.PI * smaller * smaller;
}
const radiusASquared = radiusA * radiusA;
const radiusBSquared = radiusB * radiusB;
const distanceSquared = distance * distance;
const angleA = Math.acos(
Math.max(
-1,
Math.min(
1,
(distanceSquared + radiusASquared - radiusBSquared) /
(2 * distance * radiusA)
)
)
);
const angleB = Math.acos(
Math.max(
-1,
Math.min(
1,
(distanceSquared + radiusBSquared - radiusASquared) /
(2 * distance * radiusB)
)
)
);
return (
radiusASquared * Math.acos(
Math.max(
-1,
Math.min(
1,
(distanceSquared + radiusASquared - radiusBSquared) /
(2 * distance * radiusA)
)
)
) +
radiusBSquared * Math.acos(
Math.max(
-1,
Math.min(
1,
(distanceSquared + radiusBSquared - radiusASquared) /
(2 * distance * radiusB)
)
)
) -
0.5 *
Math.sqrt(
Math.max(
0,
(-distance + radiusA + radiusB) *
(distance + radiusA - radiusB) *
(distance - radiusA + radiusB) *
(distance + radiusA + radiusB)
)
)
);
}
function positionElement(element, x, y) {
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function positionOutline(element, x, y, radius) {
element.style.left = `${x - radius}px`;
element.style.top = `${y - radius}px`;
element.style.width = `${radius * 2}px`;
element.style.height = `${radius * 2}px`;
}
const starWorldPosition = new THREE.Vector3();
const planetWorldPosition = new THREE.Vector3();
const starLabelPosition = new THREE.Vector3();
const planetLabelPosition = new THREE.Vector3();
function updateProjectionUI() {
starMesh.getWorldPosition(starWorldPosition);
planetGroup.getWorldPosition(planetWorldPosition);
const starScreen = projectToScreen(starWorldPosition);
const planetScreen = projectToScreen(planetWorldPosition);
const starRadius = projectedSphereRadius(
starWorldPosition,
STAR_RADIUS
);
const planetRadius = projectedSphereRadius(
planetWorldPosition,
PLANET_RADIUS
);
const dx = planetScreen.x - starScreen.x;
const dy = planetScreen.y - starScreen.y;
const centerDistance = Math.hypot(dx, dy);
const overlapArea = circleOverlapArea(
starRadius,
planetRadius,
centerDistance
);
const overlapPercent =
(overlapArea / (Math.PI * starRadius * starRadius)) * 100;
const apparentRadiusRatio = (planetRadius / starRadius) * 100;
ui.starPixels.textContent = `${(starRadius * 2).toFixed(0)} px`;
ui.planetPixels.textContent = `${(planetRadius * 2).toFixed(0)} px`;
ui.apparentRatio.textContent = `${apparentRadiusRatio.toFixed(1)}%`;
if (overlapPercent > 0.015) {
const proximity =
centerDistance < Math.max(2, starRadius * 0.08)
? " · near mid-transit"
: "";
ui.status.textContent =
`Projected overlap · ${overlapPercent.toFixed(1)}% of stellar disk${proximity}`;
ui.status.classList.add("overlap");
} else {
const gap = Math.max(
0,
centerDistance - starRadius - planetRadius
);
ui.status.textContent =
`Clear of the disk · ${gap.toFixed(0)} px projected gap`;
ui.status.classList.remove("overlap");
}
positionOutline(
ui.starOutline,
starScreen.x,
starScreen.y,
starRadius
);
positionOutline(
ui.planetOutline,
planetScreen.x,
planetScreen.y,
planetRadius
);
starLabelPosition.set(0, 1.25, 0);
const projectedStarLabel = projectToScreen(starLabelPosition);
positionElement(
ui.starLabel,
projectedStarLabel.x,
projectedStarLabel.y
);
planetLabelPosition.copy(planetWorldPosition);
planetLabelPosition.y += PLANET_RADIUS * 1.85;
const projectedPlanetLabel = projectToScreen(planetLabelPosition);
positionElement(
ui.planetLabel,
projectedPlanetLabel.x,
projectedPlanetLabel.y
);
drawProjectionDiagram(
dx,
dy,
starRadius,
planetRadius
);
}
// -------------------------------------------------------------------------
// Direct camera controls, implemented without Three.js addons
// -------------------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
sceneCanvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
sceneCanvas.classList.add("dragging");
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;
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.38,
Math.PI - 0.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
sceneCanvas.classList.remove("dragging");
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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
3.4,
11.5
);
updateCamera();
},
{ passive: false }
);
pauseButton.addEventListener("click", () => {
state.paused = !state.paused;
pauseButton.textContent = state.paused ? "Resume" : "Pause";
});
resetButton.addEventListener("click", () => {
cameraState.radius = 5.4;
cameraState.theta = 0;
cameraState.phi = 1.53;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
pauseButton.click();
}
if (
event.key.toLowerCase() === "r" &&
event.target === document.body
) {
resetButton.click();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const state = {
elapsed: 0,
paused: false
};
const clock = new THREE.Clock();
const replayDuration = 20;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!state.paused) {
state.elapsed += delta;
}
// Smooth back-and-forth transit replay. The planet always remains on
// the near side of the orbit, so it visibly occludes the stellar disk.
const normalizedTime =
(state.elapsed % replayDuration) / replayDuration;
const transitProgress =
(1 - Math.cos(normalizedTime * Math.PI * 2)) * 0.5;
const orbitAngle =
-TRANSIT_ARC + TRANSIT_ARC * 2 * transitProgress;
planetGroup.position.set(
Math.sin(orbitAngle) * ORBIT_RADIUS,
0,
Math.cos(orbitAngle) * ORBIT_RADIUS
);
planetMesh.rotation.y += delta * 0.32;
planetMesh.rotation.x += delta * 0.08;
starMaterial.uniforms.uTime.value = state.elapsed;
planetMaterial.uniforms.uTime.value = state.elapsed;
starMesh.rotation.y = state.elapsed * 0.025;
updateProjectionUI();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```