Prompt specification
Build or customize the Three.js 3D scene "Budding lineage tabletop" 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: Budding lineage tabletop
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/budding-lineage-tabletop-x0878
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: budding lineage tabletop. Animate one labeled yeast cell growing a bud and separating into two cells; preserve lineage labels and distinguish individual growth from population-count increase. Return one self-contained HTML file.
Working Three.js Starter (budding-lineage-tabletop-x0878):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Budding Lineage — Tabletop Study</title>
<style>
:root {
--ink: #102522;
--panel: rgba(13, 31, 28, 0.88);
--panel-soft: rgba(22, 45, 40, 0.72);
--line: rgba(205, 238, 226, 0.16);
--paper: #f4f0e6;
--muted: #a6bbb4;
--mint: #91e4c2;
--mint-bright: #baf7dc;
--amber: #f1b36c;
--amber-bright: #ffd29c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9bba8;
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 1;
background:
linear-gradient(90deg, rgba(8, 24, 21, 0.24), transparent 28%, transparent 72%, rgba(8, 24, 21, 0.2)),
linear-gradient(0deg, rgba(8, 24, 21, 0.32), transparent 30%);
mix-blend-mode: multiply;
}
.topbar {
position: absolute;
z-index: 10;
top: 0;
left: 0;
right: 0;
height: 78px;
padding: 20px 28px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
color: var(--ink);
text-shadow: 0 1px 12px rgba(255, 255, 255, 0.2);
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(16, 37, 34, 0.35);
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 50%;
background: var(--ink);
}
.brand-mark::before {
width: 13px;
height: 13px;
left: 8px;
top: 11px;
}
.brand-mark::after {
width: 10px;
height: 10px;
right: 7px;
top: 8px;
border: 2px solid #c9bba8;
background: var(--mint);
}
.brand-title {
font-size: 15px;
font-weight: 780;
letter-spacing: 0.01em;
}
.brand-subtitle {
margin-top: 3px;
font-size: 9px;
font-weight: 760;
letter-spacing: 0.19em;
opacity: 0.62;
}
.top-actions {
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.mode-pill {
margin-right: 7px;
padding: 9px 12px;
border-radius: 999px;
border: 1px solid rgba(16, 37, 34, 0.18);
color: var(--ink);
background: rgba(244, 240, 230, 0.36);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
}
.mode-pill i {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: #4b9d78;
box-shadow: 0 0 0 4px rgba(75, 157, 120, 0.14);
vertical-align: 1px;
}
.icon-button {
min-width: 38px;
height: 38px;
padding: 0 12px;
border: 1px solid rgba(16, 37, 34, 0.2);
border-radius: 10px;
color: var(--ink);
background: rgba(244, 240, 230, 0.48);
backdrop-filter: blur(10px);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: background 160ms ease, transform 160ms ease;
}
.icon-button:hover {
background: rgba(244, 240, 230, 0.72);
transform: translateY(-1px);
}
.panel {
position: absolute;
z-index: 8;
border: 1px solid rgba(218, 241, 232, 0.13);
background: var(--panel);
box-shadow: 0 24px 70px rgba(17, 25, 22, 0.2);
backdrop-filter: blur(18px) saturate(1.15);
}
.info-panel {
top: 92px;
left: 28px;
width: 306px;
padding: 23px;
border-radius: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--mint);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 16px;
height: 1px;
background: currentColor;
}
h1 {
margin: 14px 0 11px;
color: var(--paper);
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 3vw, 47px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
h1 em {
color: var(--mint-bright);
font-weight: 500;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.lineage-card {
margin-top: 19px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.025);
}
.card-label {
display: flex;
justify-content: space-between;
align-items: center;
color: #b9cac4;
font-size: 8px;
font-weight: 820;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.preserved {
padding: 4px 6px;
border: 1px solid rgba(145, 228, 194, 0.22);
border-radius: 999px;
color: var(--mint);
background: rgba(145, 228, 194, 0.06);
font-size: 7px;
}
.tree {
position: relative;
margin-top: 14px;
}
.tree-node {
position: relative;
display: grid;
grid-template-columns: 37px 1fr auto;
gap: 10px;
align-items: center;
padding: 9px 0;
}
.tree-node + .tree-node {
padding-left: 20px;
}
.tree-node + .tree-node::before {
content: "";
position: absolute;
left: 7px;
top: -12px;
width: 13px;
height: 28px;
border-left: 1px solid rgba(145, 228, 194, 0.38);
border-bottom: 1px solid rgba(145, 228, 194, 0.38);
border-radius: 0 0 0 8px;
}
.node-dot {
width: 29px;
height: 29px;
display: grid;
place-items: center;
border: 1px solid rgba(145, 228, 194, 0.42);
border-radius: 50%;
color: var(--mint-bright);
background: rgba(145, 228, 194, 0.08);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.03em;
}
.tree-node.pending .node-dot {
border-color: rgba(241, 179, 108, 0.28);
color: rgba(255, 210, 156, 0.65);
background: rgba(241, 179, 108, 0.04);
}
.tree-node.active .node-dot {
box-shadow: 0 0 0 5px rgba(145, 228, 194, 0.06);
}
.node-name {
color: var(--paper);
font-size: 12px;
font-weight: 750;
}
.node-role {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.lineage-chip {
padding: 5px 7px;
border: 1px solid rgba(145, 228, 194, 0.2);
border-radius: 6px;
color: var(--mint);
background: rgba(145, 228, 194, 0.05);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
}
.rule {
display: flex;
gap: 10px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.rule-icon {
flex: 0 0 24px;
height: 24px;
display: grid;
place-items: center;
border: 1px solid rgba(241, 179, 108, 0.25);
border-radius: 50%;
color: var(--amber);
font-size: 11px;
}
.rule b {
display: block;
margin-bottom: 2px;
color: #d8e4df;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metrics-panel {
top: 92px;
right: 28px;
width: 286px;
padding: 18px;
border-radius: 20px;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.metric-card {
min-width: 0;
padding: 14px 12px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.025);
}
.metric-card.growth {
border-color: rgba(145, 228, 194, 0.2);
}
.metric-card.population {
border-color: rgba(241, 179, 108, 0.2);
}
.metric-title {
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.metric-value {
margin-top: 8px;
color: var(--paper);
font-family: Georgia, "Times New Roman", serif;
font-size: 32px;
line-height: 1;
white-space: nowrap;
}
.growth .metric-value {
color: var(--mint-bright);
}
.population .metric-value {
color: var(--amber-bright);
}
.metric-unit {
margin-left: 3px;
color: var(--muted);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 9px;
font-weight: 700;
}
.metric-sub {
margin-top: 8px;
color: #879d96;
font-size: 8px;
line-height: 1.35;
}
.metric-track {
height: 3px;
margin-top: 11px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.07);
}
.metric-fill {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 120ms linear;
}
.growth .metric-fill {
background: var(--mint);
box-shadow: 0 0 12px rgba(145, 228, 194, 0.5);
}
.population .metric-fill {
width: 50%;
background: var(--amber);
box-shadow: 0 0 12px rgba(241, 179, 108, 0.45);
}
.metric-card.bump {
animation: bump 420ms ease;
}
@keyframes bump {
0%, 100% { transform: scale(1); }
45% { transform: scale(1.055); }
}
.event-header {
margin: 17px 0 9px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.events {
display: grid;
gap: 5px;
}
.event {
display: grid;
grid-template-columns: 34px 1fr;
gap: 8px;
padding: 8px 7px;
border-radius: 9px;
opacity: 0.38;
transition: opacity 200ms ease, background 200ms ease;
}
.event.active {
opacity: 1;
background: rgba(145, 228, 194, 0.055);
}
.event.done {
opacity: 0.68;
}
.event-time {
padding-top: 1px;
color: #8ba49b;
font-size: 8px;
font-variant-numeric: tabular-nums;
}
.event b {
display: block;
color: #dbe7e2;
font-size: 9px;
letter-spacing: 0.025em;
}
.event small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
line-height: 1.35;
}
.cell-label {
position: absolute;
z-index: 6;
min-width: 112px;
padding: 7px 9px;
border: 1px solid rgba(207, 244, 229, 0.32);
border-radius: 10px;
color: var(--paper);
background: rgba(12, 34, 29, 0.82);
box-shadow: 0 10px 28px rgba(7, 21, 18, 0.22);
backdrop-filter: blur(9px);
pointer-events: none;
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 220ms ease;
}
.cell-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 16px;
background: linear-gradient(var(--mint), transparent);
opacity: 0.7;
}
.cell-label.visible {
opacity: 1;
}
.cell-label .cell-id {
color: var(--mint-bright);
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
line-height: 1;
}
.cell-label .cell-meta {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 5px;
color: var(--muted);
font-size: 7px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.cell-label .cell-meta b {
color: var(--mint);
font-weight: 850;
}
.observation-bar {
position: absolute;
z-index: 9;
left: 50%;
bottom: 24px;
width: min(700px, calc(100vw - 670px));
min-width: 480px;
transform: translateX(-50%);
overflow: hidden;
border: 1px solid rgba(220, 241, 233, 0.14);
border-radius: 18px;
background: rgba(11, 29, 26, 0.86);
box-shadow: 0 22px 64px rgba(11, 20, 17, 0.25);
backdrop-filter: blur(18px);
}
.observation-main {
display: grid;
grid-template-columns: 49px 1fr auto;
gap: 14px;
align-items: center;
padding: 14px 17px 13px;
}
.phase-index {
width: 43px;
height: 43px;
display: grid;
place-items: center;
border: 1px solid rgba(145, 228, 194, 0.24);
border-radius: 12px;
color: var(--mint-bright);
background: rgba(145, 228, 194, 0.06);
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
}
.phase-kicker {
color: var(--mint);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.phase-title {
margin: 3px 0 0;
color: var(--paper);
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 500;
}
.phase-desc {
margin: 4px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.elapsed {
align-self: start;
padding-top: 3px;
color: #9db2aa;
font-size: 9px;
font-variant-numeric: tabular-nums;
letter-spacing: 0.08em;
}
.timeline {
display: grid;
grid-template-columns: repeat(3, 1fr);
border-top: 1px solid rgba(220, 241, 233, 0.1);
}
.timeline-step {
position: relative;
padding: 10px 12px 11px;
color: #738b83;
font-size: 8px;
font-weight: 780;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-step + .timeline-step {
border-left: 1px solid rgba(220, 241, 233, 0.08);
}
.timeline-step::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: var(--step, 0%);
height: 2px;
background: var(--mint);
box-shadow: 0 0 10px rgba(145, 228, 194, 0.45);
}
.timeline-step.active {
color: var(--paper);
}
.timeline-step span {
margin-right: 5px;
color: var(--mint);
font-variant-numeric: tabular-nums;
}
.camera-hint {
position: absolute;
z-index: 7;
left: 50%;
bottom: 195px;
transform: translateX(-50%);
padding: 7px 10px;
border: 1px solid rgba(16, 37, 34, 0.15);
border-radius: 999px;
color: rgba(16, 37, 34, 0.65);
background: rgba(244, 240, 230, 0.28);
backdrop-filter: blur(8px);
font-size: 8px;
font-weight: 760;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.loading {
position: absolute;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #c9bba8;
transition: opacity 500ms ease, visibility 500ms ease;
}
.loading-card {
text-align: center;
}
.loading-orbit {
width: 42px;
height: 42px;
margin: 0 auto 12px;
border: 1px solid rgba(16, 37, 34, 0.25);
border-radius: 50%;
animation: orbit 1.4s linear infinite;
}
.loading-orbit::after {
content: "";
display: block;
width: 11px;
height: 11px;
margin: 4px 0 0 4px;
border-radius: 50%;
background: var(--ink);
}
.loading p {
margin: 0;
font-size: 9px;
font-weight: 820;
letter-spacing: 0.17em;
text-transform: uppercase;
}
@keyframes orbit {
to { transform: rotate(360deg); }
}
body.ready .loading {
opacity: 0;
visibility: hidden;
}
@media (max-width: 1180px) {
.info-panel {
left: 18px;
width: 278px;
}
.metrics-panel {
right: 18px;
width: 260px;
}
.observation-bar {
width: 460px;
min-width: 460px;
bottom: 18px;
}
.camera-hint {
bottom: 190px;
}
}
@media (max-width: 820px) {
.topbar {
height: 66px;
padding: 14px;
}
.brand-subtitle,
.mode-pill,
.camera-hint {
display: none;
}
.info-panel {
top: 72px;
left: 12px;
right: 12px;
width: auto;
padding: 14px;
border-radius: 16px;
}
.info-panel h1 {
margin: 8px 0 0;
font-size: 25px;
line-height: 1.05;
}
.info-panel .intro,
.rule,
.tree-node,
.card-label {
display: none;
}
.lineage-card {
margin-top: 10px;
padding: 9px 11px;
}
.lineage-card::after {
content: "MOTHER Y1 → DAUGHTER Y1a · LINEAGE L-07";
color: var(--muted);
font-size: 8px;
font-weight: 760;
letter-spacing: 0.08em;
}
.metrics-panel {
top: auto;
left: 12px;
right: 12px;
bottom: 145px;
width: auto;
padding: 10px;
border-radius: 15px;
}
.metric-card {
padding: 10px;
}
.metric-value {
font-size: 25px;
}
.event-header,
.events {
display: none;
}
.observation-bar {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
min-width: 0;
transform: none;
border-radius: 15px;
}
.observation-main {
grid-template-columns: 39px 1fr auto;
gap: 9px;
padding: 10px 12px;
}
.phase-index {
width: 36px;
height: 36px;
font-size: 15px;
}
.phase-title {
font-size: 15px;
}
.phase-desc {
display: none;
}
.timeline-step {
padding: 8px;
font-size: 7px;
}
.cell-label {
min-width: 94px;
padding: 6px 7px;
}
}
@media (prefers-reduced-motion: reduce) {
.loading-orbit {
animation: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive 3D yeast budding experiment"></canvas>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<span class="brand-mark" aria-hidden="true"></span>
<div>
<div class="brand-title">Budding Lineage</div>
<div class="brand-subtitle">Tabletop / Live Culture</div>
</div>
</div>
<div class="top-actions">
<div class="mode-pill"><i></i>Phase-locked observation</div>
<button class="icon-button" id="pauseButton" type="button" aria-label="Pause animation">Pause</button>
<button class="icon-button" id="replayButton" type="button" aria-label="Replay animation">↻ Replay</button>
</div>
</header>
<aside class="panel info-panel">
<div class="eyebrow">Focal lineage / L-07</div>
<h1>One cell.<br /><em>Two descendants.</em></h1>
<p class="intro">
Follow a labeled mother cell as its bud expands, closes its neck, and
separates into a new individual.
</p>
<div class="lineage-card">
<div class="card-label">
<span>Lineage identity</span>
<span class="preserved">Preserved</span>
</div>
<div class="tree">
<div class="tree-node">
<div class="node-dot">Y1</div>
<div>
<div class="node-name">Mother cell</div>
<div class="node-role">Origin · focal individual</div>
</div>
<div class="lineage-chip">L-07</div>
</div>
<div class="tree-node pending" id="daughterNode">
<div class="node-dot">Y1a</div>
<div>
<div class="node-name">Bud / daughter</div>
<div class="node-role" id="daughterRole">Not yet separated</div>
</div>
<div class="lineage-chip">L-07</div>
</div>
</div>
</div>
<div class="rule">
<span class="rule-icon">1</span>
<div>
<b>Counting rule</b>
One connected membrane equals one individual. The population changes
only when the bud becomes a separate cell.
</div>
</div>
</aside>
<aside class="panel metrics-panel">
<div class="metric-grid">
<div class="metric-card growth">
<div class="metric-title">Tracked volume</div>
<div class="metric-value"><span id="growthValue">+0</span><span class="metric-unit">%</span></div>
<div class="metric-sub" id="growthSub">Connected body of Y1</div>
<div class="metric-track"><div class="metric-fill" id="growthFill"></div></div>
</div>
<div class="metric-card population" id="populationCard">
<div class="metric-title">Population</div>
<div class="metric-value"><span id="populationValue">1</span><span class="metric-unit">cell</span></div>
<div class="metric-sub" id="populationSub">One connected individual</div>
<div class="metric-track"><div class="metric-fill" id="populationFill"></div></div>
</div>
</div>
<div class="card-label event-header">Observation log</div>
<div class="events">
<div class="event active" id="baselineEvent">
<div class="event-time">00.0</div>
<div><b>Baseline registered</b><small>Y1 · lineage L-07 · population 1</small></div>
</div>
<div class="event" id="growthEvent">
<div class="event-time">01.4</div>
<div><b>Individual growth</b><small>Connected volume rises · population remains 1</small></div>
</div>
<div class="event" id="divisionEvent">
<div class="event-time">05.6</div>
<div><b>Cytokinesis</b><small id="divisionDetail">Neck closing · population remains 1</small></div>
</div>
</div>
</aside>
<div class="cell-label" id="motherLabel">
<div class="cell-id">Y1</div>
<div class="cell-meta"><span>Mother</span><b>L-07</b></div>
</div>
<div class="cell-label" id="daughterLabel">
<div class="cell-id">Y1a</div>
<div class="cell-meta"><span id="daughterLabelRole">Attached bud</span><b>L-07</b></div>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom · double-click to reset</div>
<section class="observation-bar" aria-live="polite">
<div class="observation-main">
<div class="phase-index" id="phaseIndex">01</div>
<div>
<div class="phase-kicker" id="phaseKicker">Phase 01 / Baseline</div>
<h2 class="phase-title" id="phaseTitle">A single labeled mother</h2>
<p class="phase-desc" id="phaseDesc">
Y1 is registered as one connected individual in lineage L-07.
</p>
</div>
<div class="elapsed" id="elapsed">00.0 s</div>
</div>
<div class="timeline">
<div class="timeline-step active" id="stepBaseline"><span>01</span>Baseline</div>
<div class="timeline-step" id="stepGrowth"><span>02</span>Bud growth</div>
<div class="timeline-step" id="stepDivision"><span>03</span>Cytokinesis</div>
</div>
</section>
<div class="loading">
<div class="loading-card">
<div class="loading-orbit"></div>
<p>Preparing culture</p>
</div>
</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.querySelector("#scene");
const app = document.querySelector("#app");
const motherLabel = document.querySelector("#motherLabel");
const daughterLabel = document.querySelector("#daughterLabel");
const daughterLabelRole = document.querySelector("#daughterLabelRole");
const daughterNode = document.querySelector("#daughterNode");
const daughterRole = document.querySelector("#daughterRole");
const populationCard = document.querySelector("#populationCard");
const populationValue = document.querySelector("#populationValue");
const populationSub = document.querySelector("#populationSub");
const populationFill = document.querySelector("#populationFill");
const growthValue = document.querySelector("#growthValue");
const growthSub = document.querySelector("#growthSub");
const growthFill = document.querySelector("#growthFill");
const phaseIndex = document.querySelector("#phaseIndex");
const phaseKicker = document.querySelector("#phaseKicker");
const phaseTitle = document.querySelector("#phaseTitle");
const phaseDesc = document.querySelector("#phaseDesc");
const elapsedLabel = document.querySelector("#elapsed");
const pauseButton = document.querySelector("#pauseButton");
const replayButton = document.querySelector("#replayButton");
const baselineEvent = document.querySelector("#baselineEvent");
const growthEvent = document.querySelector("#growthEvent");
const divisionEvent = document.querySelector("#divisionEvent");
const divisionDetail = document.querySelector("#divisionDetail");
const stepBaseline = document.querySelector("#stepBaseline");
const stepGrowth = document.querySelector("#stepGrowth");
const stepDivision = document.querySelector("#stepDivision");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c9bba8");
scene.fog = new THREE.Fog("#c9bba8", 13, 24);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 60);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const target = new THREE.Vector3(0, 0.55, 0);
const initialCamera = new THREE.Vector3(6.4, 5.8, 7.9);
const spherical = new THREE.Spherical().setFromVector3(initialCamera.clone().sub(target));
const desired = {
theta: spherical.theta,
phi: spherical.phi,
radius: spherical.radius
};
const hemi = new THREE.HemisphereLight("#fff2d9", "#584236", 2.25);
scene.add(hemi);
const key = new THREE.DirectionalLight("#fff3dc", 3.1);
key.position.set(4.5, 8.5, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0004;
scene.add(key);
const mintLight = new THREE.PointLight("#7ce3bc", 18, 12, 2);
mintLight.position.set(-4.5, 3.2, 3.5);
scene.add(mintLight);
const amberLight = new THREE.PointLight("#ffb568", 14, 10, 2);
amberLight.position.set(4, 2.5, -2);
scene.add(amberLight);
function makeWoodTexture() {
const c = document.createElement("canvas");
c.width = c.height = 512;
const ctx = c.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 512, 0);
gradient.addColorStop(0, "#936747");
gradient.addColorStop(0.45, "#ad805b");
gradient.addColorStop(1, "#805a40");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 512, 512);
for (let i = 0; i < 150; i++) {
const y = (i * 37.7) % 512;
const wave = 2 + (i % 7);
ctx.beginPath();
for (let x = -20; x <= 532; x += 8) {
const yy = y + Math.sin(x * 0.022 + i) * wave;
if (x === -20) ctx.moveTo(x, yy);
else ctx.lineTo(x, yy);
}
ctx.strokeStyle = `rgba(52,28,17,${0.025 + (i % 5) * 0.009})`;
ctx.lineWidth = 1 + (i % 3) * 0.45;
ctx.stroke();
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3, 2);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(32, 17),
new THREE.MeshStandardMaterial({ color: "#c8beac", roughness: 1 })
);
wall.position.set(0, 4.8, -7.2);
wall.receiveShadow = true;
scene.add(wall);
const tableBase = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.6, 12),
new THREE.MeshStandardMaterial({ color: "#684b38", roughness: 0.88 })
);
tableBase.position.y = -0.32;
tableBase.receiveShadow = true;
scene.add(tableBase);
const tableTop = new THREE.Mesh(
new THREE.PlaneGeometry(18, 12),
new THREE.MeshStandardMaterial({
map: makeWoodTexture(),
roughness: 0.72,
metalness: 0.02
})
);
tableTop.rotation.x = -Math.PI / 2;
tableTop.position.y = 0.005;
tableTop.receiveShadow = true;
scene.add(tableTop);
const dishBase = new THREE.Mesh(
new THREE.CylinderGeometry(3.62, 3.62, 0.18, 96),
new THREE.MeshPhysicalMaterial({
color: "#d9eee7",
roughness: 0.1,
metalness: 0,
transparent: true,
opacity: 0.2,
transmission: 0.25,
thickness: 0.45,
clearcoat: 1,
clearcoatRoughness: 0.08,
depthWrite: false
})
);
dishBase.position.y = 0.12;
dishBase.receiveShadow = true;
scene.add(dishBase);
const agar = new THREE.Mesh(
new THREE.CylinderGeometry(3.42, 3.42, 0.085, 96),
new THREE.MeshPhysicalMaterial({
color: "#d8a868",
roughness: 0.48,
transparent: true,
opacity: 0.73,
transmission: 0.04,
clearcoat: 0.35,
depthWrite: false
})
);
agar.position.y = 0.255;
agar.receiveShadow = true;
scene.add(agar);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(3.54, 0.065, 16, 128),
new THREE.MeshPhysicalMaterial({
color: "#e7f8f1",
roughness: 0.08,
transmission: 0.35,
transparent: true,
opacity: 0.62,
clearcoat: 1,
depthWrite: false
})
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.315;
scene.add(rim);
const tickMaterial = new THREE.MeshStandardMaterial({
color: "#f1dfbb",
roughness: 0.65,
transparent: true,
opacity: 0.48
});
for (let i = 0; i < 40; i++) {
const angle = (i / 40) * Math.PI * 2;
const major = i % 5 === 0;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(major ? 0.035 : 0.022, 0.012, major ? 0.18 : 0.11),
tickMaterial
);
const radius = 3.39;
tick.position.set(Math.sin(angle) * radius, 0.315, Math.cos(angle) * radius);
tick.rotation.y = angle;
scene.add(tick);
}
function blobGeometry(seed) {
const geometry = new THREE.SphereGeometry(1, 64, 48);
const position = geometry.attributes.position;
const vector = new THREE.Vector3();
for (let i = 0; i < position.count; i++) {
vector.fromBufferAttribute(position, i);
const n = 1 +
Math.sin(vector.x * 7.3 + seed) * 0.025 +
Math.sin(vector.y * 9.1 - seed * 0.7) * 0.021 +
Math.sin((vector.x + vector.z) * 5.7 + seed * 1.8) * 0.018;
vector.normalize().multiplyScalar(n);
position.setXYZ(i, vector.x, vector.y, vector.z);
}
geometry.computeVertexNormals();
return geometry;
}
const membraneMaterial = new THREE.MeshPhysicalMaterial({
color: "#87d9b7",
roughness: 0.22,
metalness: 0,
transparent: true,
opacity: 0.88,
transmission: 0.1,
thickness: 0.8,
clearcoat: 0.8,
clearcoatRoughness: 0.2,
emissive: "#135c47",
emissiveIntensity: 0.16
});
const shellMaterial = new THREE.MeshBasicMaterial({
color: "#c5ffe7",
transparent: true,
opacity: 0.1,
side: THREE.BackSide,
depthWrite: false
});
const nucleusMaterial = new THREE.MeshPhysicalMaterial({
color: "#f2a459",
roughness: 0.4,
emissive: "#a43f12",
emissiveIntensity: 0.28,
clearcoat: 0.4
});
const organelleMaterial = new THREE.MeshPhysicalMaterial({
color: "#e8f0a6",
roughness: 0.5,
emissive: "#53641f",
emissiveIntensity: 0.16
});
function createCell(seed, bodyScale, isBud = false) {
const group = new THREE.Group();
const geometry = blobGeometry(seed);
const body = new THREE.Mesh(geometry, membraneMaterial);
body.scale.copy(bodyScale);
body.castShadow = true;
body.receiveShadow = true;
body.renderOrder = 2;
group.add(body);
const shell = new THREE.Mesh(geometry, shellMaterial);
shell.scale.set(bodyScale.x * 1.045, bodyScale.y * 1.045, bodyScale.z * 1.045);
shell.renderOrder = 3;
group.add(shell);
const nucleus = new THREE.Mesh(
new THREE.SphereGeometry(isBud ? 0.22 : 0.27, 32, 24),
nucleusMaterial
);
nucleus.position.set(isBud ? -0.08 : 0.04, 0.025, 0.02);
nucleus.scale.set(1, 0.82, 0.92);
nucleus.castShadow = true;
group.add(nucleus);
const organelles = [];
const positions = isBud
? [[0.21, 0.08, 0.12], [-0.2, -0.06, -0.08], [0.05, -0.18, 0.2]]
: [[0.29, 0.12, 0.15], [-0.3, 0.08, -0.13], [0.16, -0.2, 0.25], [-0.18, -0.18, 0.22], [0.34, -0.1, -0.25]];
for (const p of positions) {
const organelle = new THREE.Mesh(
new THREE.SphereGeometry(isBud ? 0.04 : 0.045, 14, 10),
organelleMaterial
);
organelle.position.set(...p);
organelles.push(organelle);
group.add(organelle);
}
return { group, body, shell, nucleus, organelles };
}
const mother = createCell(1.2, new THREE.Vector3(0.76, 0.65, 0.71), false);
mother.group.position.set(-0.82, 1.02, 0);
mother.group.rotation.y = -0.12;
scene.add(mother.group);
const daughter = createCell(3.7, new THREE.Vector3(0.56, 0.51, 0.54), true);
daughter.group.position.set(-0.04, 1.02, 0.02);
daughter.group.visible = false;
scene.add(daughter.group);
const neckMaterial = new THREE.MeshPhysicalMaterial({
color: "#8ddfbd",
roughness: 0.28,
transparent: true,
opacity: 0.55,
transmission: 0.08,
depthWrite: false
});
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(1, 1, 1, 36),
neckMaterial
);
neck.visible = false;
neck.renderOrder = 4;
scene.add(neck);
const growthRing = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.014, 8, 96),
new THREE.MeshBasicMaterial({
color: "#f4b76c",
transparent: true,
opacity: 0,
depthWrite: false
})
);
growthRing.rotation.x = Math.PI / 2;
growthRing.position.set(-0.82, 0.355, 0);
scene.add(growthRing);
const pathCurve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(-0.82, 0.345, 0),
new THREE.Vector3(0.02, 0.345, -0.18),
new THREE.Vector3(1.22, 0.345, 0.08)
);
const pathGeometry = new THREE.BufferGeometry().setFromPoints(pathCurve.getPoints(80));
const pathMaterial = new THREE.LineDashedMaterial({
color: "#e9ffdb",
dashSize: 0.13,
gapSize: 0.085,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const path = new THREE.Line(pathGeometry, pathMaterial);
path.computeLineDistances();
path.geometry.setDrawRange(0, 1);
scene.add(path);
const endpointMaterial = new THREE.MeshBasicMaterial({
color: "#dfffcb",
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const motherPoint = new THREE.Mesh(new THREE.CircleGeometry(0.07, 24), endpointMaterial);
motherPoint.rotation.x = -Math.PI / 2;
motherPoint.position.set(-0.82, 0.355, 0);
scene.add(motherPoint);
const daughterPoint = new THREE.Mesh(new THREE.CircleGeometry(0.07, 24), endpointMaterial);
daughterPoint.rotation.x = -Math.PI / 2;
daughterPoint.position.set(1.22, 0.355, 0.08);
scene.add(daughterPoint);
const BASELINE_END = 1.4;
const GROWTH_END = 5.6;
const DIVISION_END = 8.8;
const TOTAL = DIVISION_END;
let elapsed = 0;
let paused = false;
let previousCount = 1;
let pointerDown = false;
let pointerX = 0;
let pointerY = 0;
let lastTime = performance.now();
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(min, max, value) {
const x = clamp((value - min) / (max - min), 0, 1);
return x * x * (3 - 2 * x);
}
function easeOutCubic(x) {
return 1 - Math.pow(1 - x, 3);
}
function formatTime(time) {
return `${time.toFixed(1).padStart(4, "0")} s`;
}
function setEventState(element, state) {
element.classList.remove("active", "done");
if (state) element.classList.add(state);
}
function updateNeck(start, end, alpha) {
neck.visible = alpha > 0.01;
if (!neck.visible) return;
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5);
neck.position.copy(midpoint);
neck.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
neck.scale.set(0.17, length * 0.9, 0.17);
neckMaterial.opacity = 0.52 * alpha;
}
function updateScene(time) {
let phase = "baseline";
let phaseNumber = 1;
let phaseProgress = 0;
let growthProgress = 0;
let divisionProgress = 0;
let population = 1;
let growthPercent = 0;
let daughterVisible = false;
let daughterSeparated = false;
if (time < BASELINE_END) {
phaseProgress = time / BASELINE_END;
} else if (time < GROWTH_END) {
phase = "growth";
phaseNumber = 2;
growthProgress = (time - BASELINE_END) / (GROWTH_END - BASELINE_END);
phaseProgress = growthProgress;
growthPercent = Math.round(68 * easeOutCubic(growthProgress));
} else if (time < DIVISION_END) {
phase = "division";
phaseNumber = 3;
divisionProgress = (time - GROWTH_END) / (DIVISION_END - GROWTH_END);
phaseProgress = divisionProgress;
growthPercent = 68;
daughterSeparated = divisionProgress >= 0.68;
population = daughterSeparated ? 2 : 1;
daughterVisible = daughterSeparated;
} else {
phase = "complete";
phaseNumber = 3;
phaseProgress = 1;
growthPercent = 68;
population = 2;
daughterSeparated = true;
daughterVisible = true;
}
const motherScale = 1 + (phase === "baseline" ? 0 : 0.065 * easeOutCubic(growthProgress));
mother.group.scale.set(motherScale, motherScale * 0.99, motherScale);
if (phase === "baseline") {
daughter.group.visible = false;
neck.visible = false;
growthRing.material.opacity = 0;
path.geometry.setDrawRange(0, 1);
endpointMaterial.opacity = 0;
} else if (phase === "growth") {
const p = growthProgress;
const budScale = Math.max(0.025, easeOutCubic(p));
daughter.group.visible = true;
daughter.group.scale.setScalar(budScale);
daughter.group.position.set(
mother.group.position.x + lerp(0.76, 0.94, p),
1.02 + Math.sin(p * Math.PI) * 0.025,
0.02 + Math.sin(p * Math.PI) * 0.018
);
daughter.group.rotation.y = 0.18 + p * 0.12;
updateNeck(
mother.group.position,
daughter.group.position,
smoothstep(0.02, 0.14, p) * (1 - smoothstep(0.88, 1, p) * 0.35)
);
growthRing.material.opacity = 0.56 * Math.sin(Math.min(1, p * 1.15) * Math.PI * 0.78);
growthRing.scale.setScalar(lerp(0.85, 1.28, p));
path.geometry.setDrawRange(0, 1);
endpointMaterial.opacity = 0;
} else if (phase === "division") {
const p = divisionProgress;
const separation = smoothstep(0.12, 0.94, p);
daughter.group.visible = true;
daughter.group.scale.setScalar(lerp(1, 0.96, smoothstep(0.45, 1, p)));
daughter.group.position.set(
lerp(mother.group.position.x + 0.94, 1.22, separation),
1.02 + Math.sin(p * Math.PI) * 0.04,
0.02 + Math.sin(p * Math.PI) * 0.15 + p * 0.06
);
daughter.group.rotation.y = 0.3 + p * 0.32;
const neckAlpha = 1 - smoothstep(0.12, 0.68, p);
updateNeck(mother.group.position, daughter.group.position, neckAlpha);
growthRing.material.opacity = Math.max(0, 0.28 * (1 - p * 1.7));
growthRing.scale.setScalar(lerp(1.28, 1.43, p));
const pathProgress = smoothstep(0.42, 0.96, p);
path.geometry.setDrawRange(0, Math.max(1, Math.floor(pathProgress * 80) + 1));
endpointMaterial.opacity = 0.62 * smoothstep(0.6, 0.95, p);
} else {
daughter.group.visible = true;
daughter.group.scale.setScalar(0.96);
daughter.group.position.set(1.22, 1.025, 0.08);
neck.visible = false;
growthRing.material.opacity = 0;
path.geometry.setDrawRange(0, 81);
endpointMaterial.opacity = 0.62;
}
if (population !== previousCount) {
populationCard.classList.remove("bump");
void populationCard.offsetWidth;
populationCard.classList.add("bump");
previousCount = population;
}
growthValue.textContent = `+${growthPercent}`;
growthFill.style.width = `${growthPercent}%`;
growthSub.textContent = population === 1
? "Connected body of Y1"
: "Growth before division · no extra cell";
populationValue.textContent = population;
populationFill.style.width = population === 1 ? "50%" : "100%";
populationSub.textContent = population === 1
? "One connected individual"
: "Y1 + Y1a · same lineage";
daughterVisible = daughterVisible || (phase === "growth" && growthProgress > 0.11);
daughterLabel.classList.toggle("visible", daughterVisible);
motherLabel.classList.add("visible");
if (daughterSeparated) {
daughterLabelRole.textContent = "Daughter";
daughterRole.textContent = "Separated individual";
daughterNode.classList.remove("pending");
daughterNode.classList.add("active");
} else if (phase === "growth") {
daughterLabelRole.textContent = "Attached bud";
daughterRole.textContent = "Attached to Y1 · not counted";
daughterNode.classList.add("pending");
}
stepBaseline.style.setProperty("--step", `${(phase === "baseline" ? phaseProgress : 1) * 100}%`);
stepGrowth.style.setProperty("--step", `${(phase === "growth" ? phaseProgress : phase === "division" || phase === "complete" ? 1 : 0) * 100}%`);
stepDivision.style.setProperty("--step", `${(phase === "division" ? phaseProgress : phase === "complete" ? 1 : 0) * 100}%`);
stepBaseline.classList.toggle("active", phase === "baseline");
stepGrowth.classList.toggle("active", phase === "growth");
stepDivision.classList.toggle("active", phase === "division" || phase === "complete");
setEventState(baselineEvent, phase === "baseline" ? "active" : "done");
setEventState(growthEvent, phase === "growth" ? "active" : phase === "division" || phase === "complete" ? "done" : "");
setEventState(divisionEvent, phase === "division" ? "active" : phase === "complete" ? "done" : "");
if (phase === "division") {
divisionDetail.textContent = daughterSeparated
? "Y1a separated · population 1 → 2"
: "Neck closing · population remains 1";
} else if (phase === "complete") {
divisionDetail.textContent = "Y1a separated · population 1 → 2";
} else {
divisionDetail.textContent = "Neck closing · population remains 1";
}
if (phase === "baseline") {
phaseIndex.textContent = "01";
phaseKicker.textContent = "Phase 01 / Baseline";
phaseTitle.textContent = "A single labeled mother";
phaseDesc.textContent = "Y1 is registered as one connected individual in lineage L-07.";
} else if (phase === "growth") {
phaseIndex.textContent = "02";
phaseKicker.textContent = "Phase 02 / Bud growth";
phaseTitle.textContent = "The bud expands inside one body";
phaseDesc.textContent = "Tracked volume rises while the connected membrane still represents one individual.";
} else if (phase === "division") {
phaseIndex.textContent = "03";
phaseKicker.textContent = daughterSeparated
? "Phase 03 / Separation"
: "Phase 03 / Cytokinesis";
phaseTitle.textContent = daughterSeparated
? "Y1a becomes a separate individual"
: "The division neck is closing";
phaseDesc.textContent = daughterSeparated
? "The population increases from 1 to 2. Both cells retain lineage L-07."
: "The bud is still attached, so the population count remains unchanged.";
} else {
phaseIndex.textContent = "✓";
phaseKicker.textContent = "Observation complete / L-07";
phaseTitle.textContent = "One lineage, two labeled individuals";
phaseDesc.textContent = "Y1 and Y1a are separate cells. Their shared lineage identity remains L-07.";
}
elapsedLabel.textContent = formatTime(Math.min(time, TOTAL));
}
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
const motherWorld = new THREE.Vector3(
mother.group.position.x,
mother.group.position.y + 1.0 * mother.group.scale.y,
mother.group.position.z
);
const motherProjected = motherWorld.clone().project(camera);
motherLabel.style.left = `${(motherProjected.x * 0.5 + 0.5) * width}px`;
motherLabel.style.top = `${(-motherProjected.y * 0.5 + 0.5) * height}px`;
motherLabel.style.visibility = motherProjected.z < 1 ? "visible" : "hidden";
const daughterWorld = new THREE.Vector3(
daughter.group.position.x,
daughter.group.position.y + 0.92 * daughter.group.scale.y,
daughter.group.position.z
);
const daughterProjected = daughterWorld.clone().project(camera);
daughterLabel.style.left = `${(daughterProjected.x * 0.5 + 0.5) * width}px`;
daughterLabel.style.top = `${(-daughterProjected.y * 0.5 + 0.5) * height}px`;
daughterLabel.style.visibility = daughterProjected.z < 1 ? "visible" : "hidden";
}
function updateCamera(dt) {
const ease = 1 - Math.exp(-8 * dt);
spherical.theta += (desired.theta - spherical.theta) * ease;
spherical.phi += (desired.phi - spherical.phi) * ease;
spherical.radius += (desired.radius - spherical.radius) * ease;
spherical.phi = clamp(spherical.phi, 0.32, 1.3);
spherical.radius = clamp(spherical.radius, 7.2, 14.5);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = clamp(desired.phi - dy * 0.005, 0.32, 1.3);
});
function endPointer(event) {
pointerDown = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
desired.radius = clamp(desired.radius + event.deltaY * 0.008, 7.2, 14.5);
}, { passive: false });
canvas.addEventListener("dblclick", () => {
desired.theta = spherical.theta;
desired.phi = spherical.phi;
desired.radius = spherical.radius;
const initial = new THREE.Spherical().setFromVector3(initialCamera.clone().sub(target));
desired.theta = initial.theta;
desired.phi = initial.phi;
desired.radius = initial.radius;
});
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-label", paused ? "Resume animation" : "Pause animation");
}
function replay() {
elapsed = 0;
paused = false;
previousCount = 1;
pauseButton.textContent = "Pause";
pauseButton.setAttribute("aria-label", "Pause animation");
updateScene(0);
}
pauseButton.addEventListener("click", togglePause);
replayButton.addEventListener("click", replay);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
if (event.key.toLowerCase() === "r") replay();
});
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
function animate(now) {
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
elapsed = Math.min(TOTAL, elapsed + dt);
}
updateCamera(dt);
updateScene(elapsed);
updateLabels();
renderer.render(scene, camera);
}
updateCamera(1);
updateScene(0);
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => document.body.classList.add("ready"));
</script>
</body>
</html>
```