Prompt specification
Build or customize the Three.js 3D scene "One Sourced Stellar Life-Cycle Sequence" 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: One Sourced Stellar Life-Cycle Sequence
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/one-sourced-stellar-life-cycle-sequence-x3830
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Animate a schematic sequence for one clearly specified stellar class. State the compressed timescale and show changes in size and color as educational approximations.
Working Three.js Starter (one-sourced-stellar-life-cycle-sequence-x3830):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>G2V Stellar Evolution — Educational Schematic</title>
<style>
:root {
color-scheme: dark;
--bg: #030611;
--panel: rgba(8, 14, 31, 0.78);
--panel-strong: rgba(8, 14, 31, 0.94);
--border: rgba(170, 204, 255, 0.17);
--text: #eef5ff;
--muted: #91a4c4;
--accent: #8acbff;
--star-color: #fff0a3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 35% 45%, #101a38 0%, #060a18 42%, #02040b 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--text);
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 40% 45%, transparent 35%, rgba(0, 0, 0, 0.22) 75%),
linear-gradient(180deg, rgba(0, 0, 0, 0.2), transparent 25%, transparent 75%, rgba(0, 0, 0, 0.3));
}
.topbar {
position: fixed;
z-index: 5;
top: 22px;
left: 26px;
right: 26px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 224, 129, 0.38);
border-radius: 50%;
background: radial-gradient(circle, #fff4b0 0 12%, #ffb23f 28%, rgba(255, 99, 25, 0.1) 65%);
box-shadow: 0 0 25px rgba(255, 174, 58, 0.28);
}
.brand-mark::after {
content: "";
position: absolute;
inset: -6px;
border: 1px solid rgba(255, 215, 117, 0.12);
border-radius: 50%;
}
.brand-kicker,
.eyebrow {
margin: 0 0 4px;
color: var(--accent);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand h2 {
margin: 0;
font-size: 17px;
font-weight: 650;
letter-spacing: 0.02em;
}
.header-badges {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.badge {
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(7, 12, 28, 0.66);
color: #c7d7ef;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.04em;
backdrop-filter: blur(14px);
}
.badge.primary {
border-color: rgba(255, 205, 95, 0.28);
color: #ffe4a1;
}
.info-panel {
position: fixed;
z-index: 4;
top: 98px;
right: 24px;
width: 346px;
max-height: calc(100vh - 260px);
overflow: auto;
padding: 22px;
border: 1px solid var(--border);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(22px);
}
.info-panel::-webkit-scrollbar {
width: 5px;
}
.info-panel::-webkit-scrollbar-thumb {
border-radius: 10px;
background: rgba(160, 195, 255, 0.2);
}
.class-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.class-heading h1 {
margin: 0;
font-size: 48px;
line-height: 0.95;
letter-spacing: -0.06em;
}
.mass {
padding-bottom: 4px;
color: var(--muted);
font-size: 12px;
text-align: right;
line-height: 1.55;
}
.mass strong {
display: block;
color: var(--text);
font-size: 13px;
}
.intro {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.timescale {
margin-bottom: 18px;
padding: 13px 14px;
border: 1px solid rgba(120, 185, 255, 0.15);
border-radius: 13px;
background: rgba(58, 111, 183, 0.09);
}
.timescale strong {
display: block;
margin-bottom: 4px;
color: #cce8ff;
font-size: 13px;
}
.timescale span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.stage-block {
padding-top: 17px;
border-top: 1px solid var(--border);
}
.stage-heading {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
}
.color-chip {
width: 17px;
height: 17px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--star-color);
box-shadow:
0 0 0 3px rgba(255, 255, 255, 0.06),
0 0 20px var(--star-color);
}
.stage-heading h3 {
margin: 0;
font-size: 21px;
font-weight: 650;
letter-spacing: -0.025em;
}
.stage-description {
min-height: 56px;
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-width: 0;
padding: 12px;
border: 1px solid rgba(167, 198, 245, 0.11);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: #f4f8ff;
font-size: 15px;
font-weight: 650;
text-overflow: ellipsis;
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.radius-visual {
margin-top: 15px;
}
.radius-labels {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
}
.radius-track {
height: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.radius-fill {
width: 50%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #6caeff, #b5e2ff);
box-shadow: 0 0 12px rgba(120, 199, 255, 0.5);
transition: width 80ms linear;
}
.scale-note {
margin: 12px 0 0;
color: #7388a8;
font-size: 9px;
line-height: 1.55;
}
.timeline-panel {
position: fixed;
z-index: 5;
left: 26px;
bottom: 24px;
width: min(720px, calc(100vw - 430px));
min-width: 430px;
padding: 16px 18px 14px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel-strong);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(20px);
}
.timeline-top {
display: flex;
align-items: center;
gap: 12px;
}
.icon-button {
width: 36px;
height: 36px;
flex: 0 0 auto;
display: grid;
place-items: center;
border: 1px solid rgba(170, 205, 255, 0.18);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #e6f0ff;
cursor: pointer;
transition: 160ms ease;
}
.icon-button:hover {
border-color: rgba(140, 202, 255, 0.46);
background: rgba(110, 178, 255, 0.12);
}
.progress-wrap {
position: relative;
flex: 1;
height: 36px;
cursor: pointer;
}
.progress-track {
position: absolute;
top: 17px;
left: 0;
right: 0;
height: 3px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.09);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #ff8a3d, #ffd978 48%, #8bdcff 78%, #d8f3ff);
box-shadow: 0 0 12px rgba(135, 205, 255, 0.4);
}
.playhead {
position: absolute;
top: 11px;
left: 0;
width: 14px;
height: 14px;
margin-left: -7px;
border: 2px solid #d9efff;
border-radius: 50%;
background: #0b1427;
box-shadow: 0 0 14px rgba(154, 214, 255, 0.8);
}
.time-readout {
min-width: 82px;
color: #c7d6ec;
font-size: 11px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.phase-legend {
display: flex;
gap: 6px;
margin-top: 11px;
}
.phase-chip {
flex: 1;
min-width: 0;
padding: 8px 7px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
color: #7185a4;
cursor: pointer;
text-align: left;
transition: 150ms ease;
}
.phase-chip:hover {
color: #dbeaff;
background: rgba(255, 255, 255, 0.06);
}
.phase-chip.active {
border-color: rgba(125, 196, 255, 0.28);
background: rgba(78, 148, 221, 0.12);
color: #e9f4ff;
}
.phase-chip strong,
.phase-chip span {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.phase-chip strong {
font-size: 10px;
font-weight: 650;
}
.phase-chip span {
margin-top: 3px;
color: #657b9d;
font-size: 8px;
}
.orbit-hint {
position: fixed;
z-index: 3;
left: 30px;
bottom: 168px;
color: rgba(157, 180, 211, 0.58);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
.error {
position: fixed;
z-index: 20;
inset: 0;
display: none;
place-items: center;
padding: 30px;
background: #050916;
color: #e8f0ff;
text-align: center;
}
@media (max-width: 900px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand h2 {
font-size: 14px;
}
.header-badges .badge:not(.primary) {
display: none;
}
.info-panel {
top: auto;
right: 10px;
bottom: 138px;
left: 10px;
width: auto;
max-height: 42vh;
padding: 16px;
border-radius: 16px;
}
.class-heading {
margin-bottom: 8px;
}
.class-heading h1 {
font-size: 34px;
}
.intro {
margin-bottom: 10px;
}
.timescale {
margin-bottom: 11px;
padding: 10px 12px;
}
.stage-description {
min-height: 0;
}
.timeline-panel {
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
min-width: 0;
padding: 12px;
}
.phase-chip span {
display: none;
}
.orbit-hint {
display: none;
}
}
@media (max-width: 520px) {
.brand-kicker {
display: none;
}
.brand-mark {
width: 30px;
height: 30px;
}
.badge {
padding: 7px 9px;
font-size: 9px;
}
.metrics {
grid-template-columns: 1fr 1fr;
}
.metric {
padding: 9px;
}
.metric-value {
font-size: 12px;
}
.phase-chip {
padding: 7px 4px;
}
.phase-chip strong {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive three-dimensional schematic of the evolution of a G2V Sun-like star"
></canvas>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="brand-kicker">Stellar Evolution Laboratory</p>
<h2>One Sun-like star, from dust to remnant</h2>
</div>
</div>
<div class="header-badges">
<span class="badge">Drag to orbit · Scroll to zoom</span>
<span class="badge primary">G2V · 1.0 M☉</span>
</div>
</header>
<aside class="info-panel" aria-live="polite">
<p class="eyebrow">Specified stellar class</p>
<div class="class-heading">
<h1>G2V</h1>
<div class="mass">
<strong>1.0 M☉</strong>
Solar-type star<br />
Yellow-white main sequence
</div>
</div>
<p class="intro">
A schematic lifetime of a single Sun-like star. Colors and relative sizes
are educational approximations rather than resolved astronomical images.
</p>
<div class="timescale">
<strong>≈10.1 billion years → 60 seconds</strong>
<span>
Average compression: 1 second ≈ 168 million years. Individual phases
are expanded for visibility, so boundaries are not linearly proportional.
</span>
</div>
<section class="stage-block">
<div class="stage-heading">
<span class="color-chip" aria-hidden="true"></span>
<h3 id="stage-name">Protostar</h3>
</div>
<p class="stage-description" id="stage-description">
A dusty, contracting core is heating up but has not yet reached stable
core hydrogen fusion.
</p>
<div class="metrics">
<div class="metric">
<span class="metric-label">Radius</span>
<span class="metric-value" id="radius-value">≈1.5 R☉</span>
</div>
<div class="metric">
<span class="metric-label">Temperature</span>
<span class="metric-value" id="temperature-value">≈3,500 K</span>
</div>
<div class="metric">
<span class="metric-label">Physical duration</span>
<span class="metric-value" id="duration-value">≈10⁵ yr</span>
</div>
<div class="metric">
<span class="metric-label">Animation interval</span>
<span class="metric-value" id="screen-value">0–8 s</span>
</div>
</div>
<div class="radius-visual">
<div class="radius-labels">
<span>0.01 R☉</span>
<span>Actual-radius scale</span>
<span>100 R☉</span>
</div>
<div class="radius-track">
<div class="radius-fill" id="radius-fill"></div>
</div>
</div>
<p class="scale-note">
The 3D star radius is logarithmically compressed so that the white dwarf
remains visible beside the 100-R☉ giant. Concentric rings mark 1, 10,
and 100 solar radii.
</p>
</section>
</aside>
<div class="orbit-hint">Mouse / touch: drag to orbit · wheel or pinch: zoom</div>
<section class="timeline-panel" aria-label="Animation timeline">
<div class="timeline-top">
<button class="icon-button" id="play-button" aria-label="Pause animation">
❚❚
</button>
<div
class="progress-wrap"
id="progress-wrap"
role="slider"
tabindex="0"
aria-label="Animation time"
aria-valuemin="0"
aria-valuemax="60"
aria-valuenow="0"
>
<div class="progress-track">
<div class="progress-fill" id="progress-fill"></div>
</div>
<div class="playhead" id="playhead"></div>
</div>
<div class="time-readout" id="time-readout">00.0 / 60 s</div>
<button class="icon-button" id="restart-button" aria-label="Restart animation">
↺
</button>
</div>
<div class="phase-legend">
<button class="phase-chip active" data-time="0">
<strong>Protostar</strong><span>0–8 s</span>
</button>
<button class="phase-chip" data-time="8">
<strong>Main sequence</strong><span>8–32 s</span>
</button>
<button class="phase-chip" data-time="32">
<strong>Red giant</strong><span>32–45 s</span>
</button>
<button class="phase-chip" data-time="45">
<strong>Nebula</strong><span>45–52 s</span>
</button>
<button class="phase-chip" data-time="52">
<strong>White dwarf</strong><span>52–60 s</span>
</button>
</div>
</section>
<div class="error" id="error-message">
<div>
<h2>WebGL could not be initialized</h2>
<p>Please open this file in a modern browser with WebGL enabled.</p>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const errorMessage = document.getElementById("error-message");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
console.error(error);
errorMessage.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x030611, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x030611, 0.018);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
150
);
const world = new THREE.Group();
scene.add(world);
const controls = {
target: new THREE.Vector3(),
distance: 15,
theta: 0.16,
phi: 1.16,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const spherical = new THREE.Spherical(
controls.distance,
controls.phi,
controls.theta
);
camera.position.setFromSpherical(spherical).add(controls.target);
camera.lookAt(controls.target);
}
// ---------------------------------------------------------------------
// Background star field
// ---------------------------------------------------------------------
function createBackgroundStars(count, radiusMin, radiusMax, size, opacity) {
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const color = new THREE.Color();
for (let i = 0; i < count; i++) {
const radius = THREE.MathUtils.lerp(radiusMin, radiusMax, Math.random());
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] = radius * Math.cos(phi);
positions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
color.setHSL(
0.52 + (Math.random() - 0.5) * 0.16,
0.18 + Math.random() * 0.35,
0.68 + Math.random() * 0.3
);
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.BufferAttribute(colors, 3)
);
const material = new THREE.PointsMaterial({
size,
vertexColors: true,
transparent: true,
opacity,
sizeAttenuation: true,
depthWrite: false,
fog: false
});
const points = new THREE.Points(geometry, material);
scene.add(points);
return points;
}
const distantStars = createBackgroundStars(1600, 32, 80, 0.065, 0.85);
const brightStars = createBackgroundStars(120, 24, 55, 0.15, 0.95);
// ---------------------------------------------------------------------
// Radius guide rings and labels
// ---------------------------------------------------------------------
function visualRadius(radiusInSolarRadii) {
// Logarithmic visual mapping:
// 1 R☉ -> 1.45 units, 100 R☉ -> 5.78 units.
return 1.45 * Math.pow(Math.max(radiusInSolarRadii, 0.001), 0.3);
}
function createLabel(text, color = "#9eb4d2") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 64;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 256, 64);
context.font = "600 25px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.shadowColor = "rgba(0, 0, 0, 0.9)";
context.shadowBlur = 8;
context.fillStyle = color;
context.fillText(text, 128, 32);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false,
opacity: 0.8
})
);
sprite.scale.set(1.25, 0.31, 1);
sprite.renderOrder = 20;
return sprite;
}
function createRadiusRing(solarRadius, label) {
const points = [];
const radius = visualRadius(solarRadius);
for (let i = 0; i < 160; i++) {
const angle = (i / 160) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0,
Math.sin(angle) * radius
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color: 0x84a8d8,
transparent: true,
opacity: 0.24,
dashSize: 0.14,
gapSize: 0.11,
depthWrite: false
});
const line = new THREE.LineLoop(geometry, material);
line.computeLineDistances();
world.add(line);
const labelSprite = createLabel(label);
labelSprite.position.set(0, 0.08, -radius);
world.add(labelSprite);
return { line, labelSprite };
}
createRadiusRing(1, "1 R☉");
createRadiusRing(10, "10 R☉");
createRadiusRing(100, "100 R☉");
// ---------------------------------------------------------------------
// Protostar dust cloud
// ---------------------------------------------------------------------
function createDustCloud() {
const count = 900;
const positions = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const radius = 2.8 + Math.pow(Math.random(), 0.55) * 7.2;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] = radius * Math.cos(phi) * 0.46;
positions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
const material = new THREE.PointsMaterial({
color: 0xa75f3b,
size: 0.065,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending,
sizeAttenuation: true
});
const points = new THREE.Points(geometry, material);
world.add(points);
return points;
}
const dustCloud = createDustCloud();
// ---------------------------------------------------------------------
// Planetary-nebula particles
// ---------------------------------------------------------------------
function createPlanetaryNebula() {
const count = 1500;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const color = new THREE.Color();
for (let i = 0; i < count; i++) {
const radius = 3.0 + Math.pow(Math.random(), 0.5) * 4.4;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] = radius * Math.cos(phi) * 0.68;
positions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
const cyan = new THREE.Color(0x75cfff);
const pink = new THREE.Color(0xe6a8ff);
const white = new THREE.Color(0xf4f7ff);
color.copy(cyan).lerp(pink, Math.random());
if (Math.random() > 0.78) color.lerp(white, 0.65);
colors[i * 3] = color.r;
colors[i * 3 + 1] = color.g;
colors[i * 3 + 2] = color.b;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.BufferAttribute(colors, 3)
);
const material = new THREE.PointsMaterial({
size: 0.1,
vertexColors: true,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending,
sizeAttenuation: true
});
const points = new THREE.Points(geometry, material);
world.add(points);
return points;
}
const planetaryNebula = createPlanetaryNebula();
// ---------------------------------------------------------------------
// Star surface shader
// ---------------------------------------------------------------------
const starUniforms = {
uTime: { value: 0 },
uColorA: { value: new THREE.Color(0xff6b24) },
uColorB: { value: new THREE.Color(0xffc45a) },
uActivity: { value: 0.3 }
};
const starMaterial = new THREE.ShaderMaterial({
uniforms: starUniforms,
vertexShader: `
varying vec3 vLocalPosition;
varying vec3 vViewNormal;
varying vec3 vViewDirection;
void main() {
vLocalPosition = position;
vec4 viewPosition = modelViewMatrix * vec4(position, 1.0);
vViewNormal = normalize(normalMatrix * normal);
vViewDirection = normalize(-viewPosition.xyz);
gl_Position = projectionMatrix * viewPosition;
}
`,
fragmentShader: `
uniform float uTime;
uniform vec3 uColorA;
uniform vec3 uColorB;
uniform float uActivity;
varying vec3 vLocalPosition;
varying vec3 vViewNormal;
varying vec3 vViewDirection;
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 + vec3(0, 0, 0)), 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(11.7, 4.3, 8.9);
amplitude *= 0.5;
}
return value;
}
void main() {
vec3 p = normalize(vLocalPosition);
float broad = fbm(
p * 2.1 + vec3(
uTime * 0.045,
-uTime * 0.025,
uTime * 0.032
)
);
float fine = fbm(
p * 5.0 - vec3(
uTime * 0.07,
uTime * 0.04,
-uTime * 0.05
)
);
float pattern = clamp(broad * 0.72 + fine * 0.38, 0.0, 1.0);
float blend = smoothstep(0.22, 0.78, pattern);
vec3 surfaceColor = mix(uColorA, uColorB, blend);
float facing = max(
dot(normalize(vViewNormal), normalize(vViewDirection)),
0.0
);
float limb = 0.68 + 0.32 * pow(facing, 0.42);
float brightness =
1.03 + uActivity * (0.12 + 0.24 * fine);
gl_FragColor = vec4(
surfaceColor * limb * brightness,
1.0
);
}
`,
depthWrite: true,
depthTest: true
});
const starMesh = new THREE.Mesh(
new THREE.SphereGeometry(1, 64, 64),
starMaterial
);
world.add(starMesh);
// ---------------------------------------------------------------------
// Procedural corona sprite
// ---------------------------------------------------------------------
function createGlowTexture() {
const glowCanvas = document.createElement("canvas");
glowCanvas.width = 256;
glowCanvas.height = 256;
const context = glowCanvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
128,
0,
128,
128,
128
);
gradient.addColorStop(0, "rgba(255,255,255,1)");
gradient.addColorStop(0.12, "rgba(255,255,255,0.85)");
gradient.addColorStop(0.32, "rgba(255,255,255,0.28)");
gradient.addColorStop(0.62, "rgba(255,255,255,0.08)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(glowCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const coronaMaterial = new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0xffb34f,
transparent: true,
opacity: 0.6,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const corona = new THREE.Sprite(coronaMaterial);
corona.renderOrder = 2;
world.add(corona);
// ---------------------------------------------------------------------
// Animation keyframes
// ---------------------------------------------------------------------
const keyframes = [
{
t: 0,
radius: 1.5,
temperature: 3500,
activity: 0.34,
dust: 1.0,
nebula: 0.0,
colorA: 0xff4d1c,
colorB: 0xffb54e
},
{
t: 5,
radius: 1.5,
temperature: 3500,
activity: 0.34,
dust: 0.82,
nebula: 0.0,
colorA: 0xff4d1c,
colorB: 0xffb54e
},
{
t: 9,
radius: 1.0,
temperature: 5778,
activity: 0.17,
dust: 0.0,
nebula: 0.0,
colorA: 0xffbd3f,
colorB: 0xfff1a6
},
{
t: 29,
radius: 1.0,
temperature: 5778,
activity: 0.17,
dust: 0.0,
nebula: 0.0,
colorA: 0xffbd3f,
colorB: 0xfff1a6
},
{
t: 35,
radius: 100,
temperature: 3500,
activity: 0.48,
dust: 0.0,
nebula: 0.0,
colorA: 0xff3215,
colorB: 0xff8f35
},
{
t: 42,
radius: 100,
temperature: 3500,
activity: 0.48,
dust: 0.0,
nebula: 0.0,
colorA: 0xff3215,
colorB: 0xff8f35
},
{
t: 47,
radius: 0.1,
temperature: 100000,
activity: 0.34,
dust: 0.0,
nebula: 1.0,
colorA: 0x8fd9ff,
colorB: 0xffffff
},
{
t: 52,
radius: 0.013,
temperature: 30000,
activity: 0.15,
dust: 0.0,
nebula: 0.48,
colorA: 0x79bfff,
colorB: 0xe9fbff
},
{
t: 60,
radius: 0.013,
temperature: 18000,
activity: 0.1,
dust: 0.0,
nebula: 0.0,
colorA: 0x87bfff,
colorB: 0xdcefff
}
].map((keyframe) => ({
...keyframe,
colorA: new THREE.Color(keyframe.colorA),
colorB: new THREE.Color(keyframe.colorB)
}));
const stages = [
{
name: "Protostar",
description:
"A dusty, contracting core is heating up but has not yet reached stable core hydrogen fusion.",
radius: "≈1.5 R☉",
temperature: "≈3,500 K",
duration: "≈10⁵ yr",
screen: "0–8 s",
start: 0
},
{
name: "Main sequence",
description:
"Stable core hydrogen fusion establishes a Sun-like G2V star. This is the longest physical stage.",
radius: "≈1.0 R☉",
temperature: "≈5,800 K",
duration: "≈10¹⁰ yr",
screen: "8–32 s",
start: 8
},
{
name: "Red giant",
description:
"After core hydrogen is depleted, shell fusion expands the cool envelope to roughly 100 solar radii.",
radius: "≈100 R☉",
temperature: "≈3,500 K",
duration: "≈10⁸ yr",
screen: "32–45 s",
start: 32
},
{
name: "Planetary nebula",
description:
"The outer envelope is ejected. The exposed, very hot core illuminates the expanding nebula.",
radius: "≈0.1 R☉ core",
temperature: "≈100,000 K",
duration: "≈10⁴ yr",
screen: "45–52 s",
start: 45
},
{
name: "White dwarf",
description:
"A dense electron-degenerate core remains after nuclear fusion ends. It gradually cools and fades.",
radius: "≈0.013 R☉",
temperature: "30,000→18,000 K",
duration: "Cooling; no fixed end",
screen: "52–60 s",
start: 52
}
];
const scratchColorA = new THREE.Color();
const scratchColorB = new THREE.Color();
function sampleState(time) {
let index = 0;
while (
index < keyframes.length - 2 &&
time > keyframes[index + 1].t
) {
index++;
}
const first = keyframes[index];
const second = keyframes[index + 1];
const local = THREE.MathUtils.clamp(
(time - first.t) / (second.t - first.t),
0,
1
);
const eased = local * local * (3 - 2 * local);
const lerp = THREE.MathUtils.lerp;
scratchColorA.copy(first.colorA).lerp(second.colorA, eased);
scratchColorB.copy(first.colorB).lerp(second.colorB, eased);
return {
radius: lerp(first.radius, second.radius, eased),
temperature: lerp(first.temperature, second.temperature, eased),
activity: lerp(first.activity, second.activity, eased),
dust: lerp(first.dust, second.dust, eased),
nebula: lerp(first.nebula, second.nebula, eased),
colorA: scratchColorA,
colorB: scratchColorB
};
}
function stageIndexForTime(time) {
if (time < 8) return 0;
if (time < 32) return 1;
if (time < 45) return 2;
if (time < 52) return 3;
return 4;
}
// ---------------------------------------------------------------------
// UI
// ---------------------------------------------------------------------
const playButton = document.getElementById("play-button");
const restartButton = document.getElementById("restart-button");
const progressWrap = document.getElementById("progress-wrap");
const progressFill = document.getElementById("progress-fill");
const playhead = document.getElementById("playhead");
const timeReadout = document.getElementById("time-readout");
const stageName = document.getElementById("stage-name");
const stageDescription = document.getElementById("stage-description");
const radiusValue = document.getElementById("radius-value");
const temperatureValue = document.getElementById("temperature-value");
const durationValue = document.getElementById("duration-value");
const screenValue = document.getElementById("screen-value");
const radiusFill = document.getElementById("radius-fill");
const colorChip = document.querySelector(".color-chip");
const phaseChips = [...document.querySelectorAll(".phase-chip")];
const duration = 60;
let elapsed = 0;
let playing = true;
let lastStage = -1;
function updateStageUI(stageIndex) {
if (stageIndex === lastStage) return;
lastStage = stageIndex;
const stage = stages[stageIndex];
stageName.textContent = stage.name;
stageDescription.textContent = stage.description;
radiusValue.textContent = stage.radius;
temperatureValue.textContent = stage.temperature;
durationValue.textContent = stage.duration;
screenValue.textContent = stage.screen;
phaseChips.forEach((chip, index) => {
chip.classList.toggle("active", index === stageIndex);
});
}
function seek(time) {
elapsed = THREE.MathUtils.clamp(time, 0, duration);
lastStage = -1;
}
function togglePlayback() {
playing = !playing;
playButton.textContent = playing ? "❚❚" : "▶";
playButton.setAttribute(
"aria-label",
playing ? "Pause animation" : "Play animation"
);
}
playButton.addEventListener("click", togglePlayback);
restartButton.addEventListener("click", () => {
elapsed = 0;
lastStage = -1;
});
phaseChips.forEach((chip) => {
chip.addEventListener("click", () => {
seek(Number(chip.dataset.time));
});
});
function seekFromPointer(event) {
const bounds = progressWrap.getBoundingClientRect();
const fraction = (event.clientX - bounds.left) / bounds.width;
seek(fraction * duration);
}
progressWrap.addEventListener("pointerdown", (event) => {
progressWrap.setPointerCapture(event.pointerId);
seekFromPointer(event);
});
progressWrap.addEventListener("pointermove", (event) => {
if (progressWrap.hasPointerCapture(event.pointerId)) {
seekFromPointer(event);
}
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePlayback();
}
if (event.key.toLowerCase() === "r") {
elapsed = 0;
lastStage = -1;
}
});
// ---------------------------------------------------------------------
// Direct camera controls: no addon imports
// ---------------------------------------------------------------------
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const deltaX = event.clientX - controls.pointerX;
const deltaY = event.clientY - controls.pointerY;
controls.theta -= deltaX * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + deltaY * 0.0045,
0.45,
1.48
);
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
8.5,
23
);
updateCamera();
},
{ passive: false }
);
// Basic pinch-to-zoom support.
const activePointers = new Map();
let previousPinchDistance = null;
canvas.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance !== null) {
const scale = previousPinchDistance / distance;
controls.distance = THREE.MathUtils.clamp(
controls.distance * scale,
8.5,
23
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function clearPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) previousPinchDistance = null;
}
canvas.addEventListener("pointerup", clearPointer);
canvas.addEventListener("pointercancel", clearPointer);
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
world.position.set(
width > 900 ? -1.45 : 0,
width <= 700 ? 0.8 : 0,
0
);
controls.target.copy(world.position);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
elapsed += delta;
if (elapsed >= duration) elapsed %= duration;
}
const state = sampleState(elapsed);
const stageIndex = stageIndexForTime(elapsed);
updateStageUI(stageIndex);
const pulse =
1 +
Math.sin(elapsed * (1.7 + state.activity * 2.0)) *
0.012 *
state.activity;
const displayedRadius = visualRadius(state.radius) * pulse;
starMesh.scale.setScalar(displayedRadius);
corona.scale.setScalar(displayedRadius * (2.55 + state.activity * 0.22));
starUniforms.uTime.value = elapsed;
starUniforms.uColorA.value.copy(state.colorA);
starUniforms.uColorB.value.copy(state.colorB);
starUniforms.uActivity.value = state.activity;
coronaMaterial.color.copy(state.colorB);
coronaMaterial.opacity =
0.38 + state.activity * 0.28 + Math.sin(elapsed * 2.1) * 0.025;
dustCloud.material.opacity = state.dust * 0.48;
dustCloud.rotation.y = elapsed * 0.026;
dustCloud.rotation.z = Math.sin(elapsed * 0.08) * 0.08;
dustCloud.visible = state.dust > 0.005;
planetaryNebula.material.opacity = state.nebula * 0.82;
planetaryNebula.rotation.y = -elapsed * 0.035;
planetaryNebula.rotation.x = Math.sin(elapsed * 0.09) * 0.08;
planetaryNebula.visible = state.nebula > 0.005;
distantStars.rotation.y = elapsed * 0.0015;
brightStars.rotation.y = -elapsed * 0.0022;
const progress = elapsed / duration;
progressFill.style.width = `${progress * 100}%`;
playhead.style.left = `${progress * 100}%`;
timeReadout.textContent = `${elapsed.toFixed(1).padStart(4, "0")} / 60 s`;
progressWrap.setAttribute("aria-valuenow", elapsed.toFixed(1));
const radiusPercent =
((Math.log10(Math.max(state.radius, 0.01)) + 2) / 4) * 100;
radiusFill.style.width = `${THREE.MathUtils.clamp(radiusPercent, 2, 100)}%`;
const uiColor = state.colorB.getStyle();
document.documentElement.style.setProperty("--star-color", uiColor);
colorChip.style.background = uiColor;
colorChip.style.boxShadow = `
0 0 0 3px rgba(255,255,255,0.06),
0 0 20px ${uiColor}
`;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```