Prompt specification
Build or customize the Three.js 3D scene "Generation beads along a branching path" 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: Generation beads along a branching path
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/generation-beads-along-a-branching-path-x0897
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows evolutionary timescales. Create a short sequence of fictional populations with changing variant frequencies and one branch; label generations explicitly and avoid arranging forms from primitive to advanced. Low-poly.
Working Three.js Starter (generation-beads-along-a-branching-path-x0897):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Variant Frequencies Across Evolutionary Timescales</title>
<style>
:root {
color-scheme: dark;
--bg: #08111b;
--panel: rgba(12, 23, 36, 0.82);
--border: rgba(150, 191, 216, 0.18);
--text: #edf5f7;
--muted: #91a6b5;
--rose: #ff7a90;
--teal: #55d6c2;
--amber: #f4c95d;
--accent: #7be7d6;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.hero {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
max-width: 500px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3.3vw, 45px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.hero p {
max-width: 470px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
width: 250px;
padding: 15px 16px;
border-radius: 14px;
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
margin: 8px 0;
color: #d9e5e9;
font-size: 12px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
transform: rotate(45deg);
}
.legend-note {
margin: 12px 0 0;
padding-top: 10px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.readout {
position: fixed;
top: 181px;
right: 24px;
z-index: 5;
width: 278px;
padding: 17px;
border-radius: 15px;
}
.readout h2 {
margin: 0 0 5px;
font-size: 18px;
letter-spacing: -0.02em;
}
.readout-copy {
margin: 0 0 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.population-block + .population-block {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--border);
}
.population-name {
margin-bottom: 8px;
font-size: 11px;
font-weight: 750;
}
.freq-row {
display: grid;
grid-template-columns: 52px 1fr 36px;
align-items: center;
gap: 7px;
margin: 7px 0;
font-size: 10px;
color: #c9d7dd;
}
.freq-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.freq-fill {
height: 100%;
border-radius: inherit;
}
.freq-value {
text-align: right;
font-variant-numeric: tabular-nums;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
width: 166px;
padding: 9px 10px;
border: 1px solid rgba(152, 185, 204, 0.17);
border-radius: 10px;
background: rgba(8, 17, 27, 0.74);
box-shadow: 0 9px 24px rgba(0, 0, 0, 0.2);
color: var(--text);
text-align: left;
transform: translate(-50%, -50%);
opacity: 0.68;
pointer-events: auto;
cursor: pointer;
transition:
opacity 180ms ease,
border-color 180ms ease,
box-shadow 180ms ease,
background 180ms ease;
}
.scene-label:hover,
.scene-label.active {
opacity: 1;
border-color: rgba(123, 231, 214, 0.65);
background: rgba(12, 29, 40, 0.92);
box-shadow:
0 9px 28px rgba(0, 0, 0, 0.28),
0 0 0 1px rgba(123, 231, 214, 0.08);
}
.scene-label .generation {
display: block;
margin-bottom: 3px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-label .population {
display: block;
margin-bottom: 6px;
font-size: 12px;
font-weight: 750;
}
.mini-freq {
display: flex;
flex-wrap: wrap;
gap: 4px 8px;
color: #afc1ca;
font-size: 9px;
}
.mini-freq i {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 3px;
border-radius: 1px;
transform: rotate(45deg);
}
.timeline {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 6;
width: min(820px, calc(100% - 48px));
padding: 13px 16px 12px;
border-radius: 16px;
transform: translateX(-50%);
}
.timeline-top {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 14px;
}
#play {
width: 38px;
height: 38px;
padding: 0;
border: 1px solid rgba(123, 231, 214, 0.35);
border-radius: 50%;
background: rgba(123, 231, 214, 0.1);
color: var(--accent);
font-size: 14px;
cursor: pointer;
}
#play:hover {
background: rgba(123, 231, 214, 0.18);
}
#timeline {
width: 100%;
accent-color: var(--accent);
cursor: pointer;
}
#generation-readout {
min-width: 105px;
color: #dce8ec;
font-size: 11px;
font-weight: 750;
text-align: right;
font-variant-numeric: tabular-nums;
}
.stops {
display: grid;
grid-template-columns: repeat(6, 1fr);
margin-top: 7px;
padding: 0 2px;
}
.stop {
padding: 4px 2px;
border: 0;
background: transparent;
color: #6f8493;
font-size: 9px;
cursor: pointer;
}
.stop.active {
color: var(--accent);
font-weight: 800;
}
.timeline-note {
margin-top: 5px;
color: #738896;
font-size: 9px;
line-height: 1.35;
text-align: center;
}
.help {
position: fixed;
bottom: 119px;
left: 25px;
z-index: 5;
color: rgba(193, 210, 218, 0.62);
font-size: 10px;
line-height: 1.6;
pointer-events: none;
}
.help strong {
color: rgba(222, 236, 241, 0.82);
font-weight: 650;
}
@media (max-width: 860px) {
.hero {
top: 17px;
left: 18px;
max-width: 62vw;
}
.hero p {
display: none;
}
.legend {
top: 16px;
right: 16px;
width: 210px;
padding: 12px;
}
.readout {
display: none;
}
.help {
display: none;
}
.timeline {
bottom: 12px;
width: calc(100% - 24px);
}
}
@media (max-width: 560px) {
.hero {
max-width: calc(100% - 32px);
}
h1 {
max-width: 280px;
font-size: 25px;
}
.legend {
top: 88px;
left: 16px;
right: auto;
width: 235px;
}
.legend-row {
display: inline-grid;
width: 31%;
margin: 4px 1%;
}
.legend-note {
display: none;
}
.scene-label {
width: 137px;
padding: 7px 8px;
}
.mini-freq {
gap: 3px;
font-size: 8px;
}
.timeline {
padding: 10px 11px;
}
.timeline-top {
gap: 9px;
}
#generation-readout {
min-width: 78px;
font-size: 10px;
}
.stops {
display: none;
}
.timeline-note {
margin-top: 2px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive three-dimensional population timeline"></canvas>
<header class="hero">
<p class="eyebrow">A fictional evolutionary timeline</p>
<h1>Variant frequencies across generations</h1>
<p>
Six snapshots follow three fictional haplotypes through time and one split.
Every population has the same body plan; color and bars represent variant
frequency, not biological advancement.
</p>
</header>
<section class="legend glass" aria-label="Variant legend">
<div class="legend-title">Variant / haplotype frequency</div>
<div class="legend-row">
<span class="swatch" style="background: var(--rose)"></span>
<span>Rose</span>
<span>20–55%</span>
</div>
<div class="legend-row">
<span class="swatch" style="background: var(--teal)"></span>
<span>Teal</span>
<span>20–60%</span>
</div>
<div class="legend-row">
<span class="swatch" style="background: var(--amber)"></span>
<span>Amber</span>
<span>15–50%</span>
</div>
<p class="legend-note">
The bars beside each population show the exact frequency of each
haplotype at that generation.
</p>
</section>
<aside class="readout glass" aria-live="polite">
<div id="readout-content"></div>
</aside>
<div id="labels"></div>
<div class="help">
<strong>Drag</strong> to orbit · <strong>Shift-drag</strong> to pan ·
<strong>Scroll</strong> to zoom · <strong>Double-click</strong> to reset
</div>
<footer class="timeline glass">
<div class="timeline-top">
<button id="play" type="button" aria-label="Play timeline" aria-pressed="false">
▶
</button>
<input
id="timeline"
type="range"
min="0"
max="5"
step="1"
value="0"
aria-label="Select a population snapshot"
/>
<div id="generation-readout">Generation 0</div>
</div>
<div id="stops" class="stops"></div>
<div class="timeline-note">
Time runs left to right. The two generation-150 populations are equal
branches, not stages of progress.
</div>
</footer>
<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 labelLayer = document.querySelector("#labels");
const readout = document.querySelector("#readout-content");
const generationReadout = document.querySelector("#generation-readout");
const timeline = document.querySelector("#timeline");
const playButton = document.querySelector("#play");
const stopsElement = document.querySelector("#stops");
const variants = [
{ name: "Rose", color: 0xff7a90, css: "#ff7a90" },
{ name: "Teal", color: 0x55d6c2, css: "#55d6c2" },
{ name: "Amber", color: 0xf4c95d, css: "#f4c95d" }
];
const snapshots = [
{
generation: 0,
name: "Morrow",
frequencies: [0.20, 0.30, 0.50],
position: new THREE.Vector3(-8.1, 0, 0),
barsOffset: 1.05,
seed: 1103
},
{
generation: 30,
name: "Morrow",
frequencies: [0.35, 0.45, 0.20],
position: new THREE.Vector3(-5.0, 0, 0),
barsOffset: 1.05,
seed: 2207
},
{
generation: 60,
name: "Morrow",
frequencies: [0.55, 0.25, 0.20],
position: new THREE.Vector3(-2.0, 0, 0),
barsOffset: 1.05,
seed: 3301
},
{
generation: 90,
name: "Morrow",
frequencies: [0.45, 0.35, 0.20],
position: new THREE.Vector3(1.0, 0, 0),
barsOffset: 1.05,
seed: 4409,
branchPoint: true
},
{
generation: 150,
name: "Aster",
frequencies: [0.25, 0.60, 0.15],
position: new THREE.Vector3(5.0, 0, -2.65),
barsOffset: 1.05,
seed: 5501
},
{
generation: 150,
name: "Reef",
frequencies: [0.15, 0.35, 0.50],
position: new THREE.Vector3(5.0, 0, 2.65),
barsOffset: -1.05,
seed: 6607
}
];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111b);
scene.fog = new THREE.Fog(0x08111b, 19, 39);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
class CameraControls {
constructor(cameraObject, domElement) {
this.camera = cameraObject;
this.dom = domElement;
this.target = new THREE.Vector3(-1.1, 0.25, 0);
this.theta = 0.56;
this.phi = 0.88;
this.radius = window.innerWidth < 700 ? 28 : 19.5;
this.minRadius = 9;
this.maxRadius = 40;
this.dragging = false;
this.panning = false;
this.pointerId = null;
this.lastX = 0;
this.lastY = 0;
this.direction = new THREE.Vector3();
this.right = new THREE.Vector3();
this.up = new THREE.Vector3();
this.worldUp = new THREE.Vector3(0, 1, 0);
this.bind();
this.update();
}
bind() {
this.dom.addEventListener("pointerdown", (event) => {
this.dragging = true;
this.panning = event.shiftKey || event.button === 2;
this.pointerId = event.pointerId;
this.lastX = event.clientX;
this.lastY = event.clientY;
this.dom.setPointerCapture(event.pointerId);
});
this.dom.addEventListener("pointermove", (event) => {
if (!this.dragging || event.pointerId !== this.pointerId) return;
const dx = event.clientX - this.lastX;
const dy = event.clientY - this.lastY;
this.lastX = event.clientX;
this.lastY = event.clientY;
if (this.panning) {
this.camera.getWorldDirection(this.direction);
this.right.crossVectors(this.direction, this.worldUp).normalize();
this.up.crossVectors(this.right, this.direction).normalize();
const panScale = this.radius * 0.0014;
this.target.addScaledVector(this.right, -dx * panScale);
this.target.addScaledVector(this.up, dy * panScale);
} else {
this.theta -= dx * 0.006;
this.phi = THREE.MathUtils.clamp(
this.phi + dy * 0.005,
0.34,
1.43
);
}
this.update();
});
const stopDragging = (event) => {
if (event.pointerId !== this.pointerId) return;
this.dragging = false;
this.panning = false;
this.pointerId = null;
};
this.dom.addEventListener("pointerup", stopDragging);
this.dom.addEventListener("pointercancel", stopDragging);
this.dom.addEventListener(
"wheel",
(event) => {
event.preventDefault();
this.radius = THREE.MathUtils.clamp(
this.radius * Math.exp(event.deltaY * 0.001),
this.minRadius,
this.maxRadius
);
this.update();
},
{ passive: false }
);
this.dom.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
this.dom.addEventListener("dblclick", () => this.reset());
}
reset() {
this.target.set(-1.1, 0.25, 0);
this.theta = 0.56;
this.phi = 0.88;
this.radius = window.innerWidth < 700 ? 28 : 19.5;
this.update();
}
update() {
const sinPhi = Math.sin(this.phi);
this.camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
}
const controls = new CameraControls(camera, canvas);
const hemisphere = new THREE.HemisphereLight(0xbfe8ff, 0x18202d, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.35);
keyLight.position.set(-4, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.001;
scene.add(keyLight);
const tealLight = new THREE.PointLight(0x55d6c2, 18, 18, 2);
tealLight.position.set(-5, 4, -5);
scene.add(tealLight);
const roseLight = new THREE.PointLight(0xff7a90, 15, 16, 2);
roseLight.position.set(7, 3.5, 5);
scene.add(roseLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 28),
new THREE.MeshStandardMaterial({
color: 0x0a1420,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x385269, 0x1c2d3d);
grid.position.y = -0.018;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const bodyGeometry = new THREE.OctahedronGeometry(0.17, 0);
const crownGeometry = new THREE.TetrahedronGeometry(0.095, 0);
const footGeometry = new THREE.BoxGeometry(0.25, 0.055, 0.105);
const crownMaterial = new THREE.MeshStandardMaterial({
color: 0xd6e0e3,
roughness: 0.75,
flatShading: true
});
const footMaterial = new THREE.MeshStandardMaterial({
color: 0x263643,
roughness: 0.9,
flatShading: true
});
const variantMaterials = variants.map(
(variant) =>
new THREE.MeshStandardMaterial({
color: variant.color,
emissive: variant.color,
emissiveIntensity: 0.055,
roughness: 0.72,
metalness: 0.02,
flatShading: true
})
);
function mulberry32(seed) {
return function random() {
let value = (seed += 0x6d2b79f5);
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
function shuffle(array, random) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function assignVariants(frequencies, seed) {
const random = mulberry32(seed);
const assignments = [];
frequencies.forEach((frequency, variantIndex) => {
const count = Math.round(frequency * 20);
for (let i = 0; i < count; i++) {
assignments.push(variantIndex);
}
});
while (assignments.length < 20) assignments.push(0);
return shuffle(assignments, random);
}
const animatedMembers = [];
const animatedBars = [];
const snapshotObjects = [];
snapshots.forEach((snapshot, snapshotIndex) => {
const population = new THREE.Group();
population.position.copy(snapshot.position);
scene.add(population);
const variantAssignments = assignVariants(
snapshot.frequencies,
snapshot.seed
);
const random = mulberry32(snapshot.seed + 91);
variantAssignments.forEach((variantIndex, memberIndex) => {
const member = new THREE.Group();
const angle =
(memberIndex / variantAssignments.length) * Math.PI * 2 +
(random() - 0.5) * 0.45;
const radius = 0.28 + Math.sqrt(random()) * 0.83;
member.position.set(
Math.cos(angle) * radius * 1.16,
0,
Math.sin(angle) * radius * 0.72
);
member.rotation.y = random() * Math.PI * 2;
const body = new THREE.Mesh(
bodyGeometry,
variantMaterials[variantIndex]
);
body.position.y = 0.23;
body.scale.set(1, 0.7, 1.12);
body.castShadow = true;
body.receiveShadow = true;
member.add(body);
const crown = new THREE.Mesh(crownGeometry, crownMaterial);
crown.position.set(0, 0.385, 0.075);
crown.rotation.y = random() * Math.PI;
crown.castShadow = true;
member.add(crown);
const foot = new THREE.Mesh(footGeometry, footMaterial);
foot.position.y = 0.085;
foot.castShadow = true;
member.add(foot);
population.add(member);
animatedMembers.push({
group: member,
phase: random() * Math.PI * 2,
baseY: 0
});
});
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x486477,
transparent: true,
opacity: 0.34,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.RingGeometry(1.19, 1.235, 48),
ringMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.015;
population.add(ring);
const barBase = new THREE.Mesh(
new THREE.BoxGeometry(1.16, 0.035, 0.34),
new THREE.MeshStandardMaterial({
color: 0x182936,
roughness: 0.9
})
);
barBase.position.set(0, 0.035, snapshot.barsOffset);
barBase.receiveShadow = true;
population.add(barBase);
snapshot.frequencies.forEach((frequency, variantIndex) => {
const material = new THREE.MeshStandardMaterial({
color: variants[variantIndex].color,
emissive: variants[variantIndex].color,
emissiveIntensity: 0.1,
roughness: 0.72,
transparent: true,
opacity: 0.88
});
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 1, 0.22),
material
);
const x = (variantIndex - 1) * 0.34;
bar.position.set(x, 0.06, snapshot.barsOffset);
bar.scale.y = 0.001;
bar.castShadow = true;
population.add(bar);
animatedBars.push({
mesh: bar,
material,
targetHeight: frequency * 1.08,
currentHeight: 0.001,
snapshotIndex
});
});
const label = document.createElement("button");
label.type = "button";
label.className = "scene-label";
label.setAttribute(
"aria-label",
`Select generation ${snapshot.generation}, ${snapshot.name} population`
);
const miniFrequencies = snapshot.frequencies
.map(
(frequency, variantIndex) =>
`<span><i style="background:${variants[variantIndex].css}"></i>${Math.round(
frequency * 100
)}%</span>`
)
.join("");
label.innerHTML = `
<span class="generation">Generation ${snapshot.generation}</span>
<span class="population">${snapshot.name} population</span>
<span class="mini-freq">${miniFrequencies}</span>
`;
label.addEventListener("click", () => {
setActive(snapshotIndex);
});
labelLayer.appendChild(label);
snapshotObjects.push({
population,
ring,
ringMaterial,
label,
anchor: new THREE.Vector3(
snapshot.position.x,
1.48,
snapshot.position.z
)
});
});
const pathMaterial = new THREE.MeshStandardMaterial({
color: 0x60758a,
emissive: 0x263746,
emissiveIntensity: 0.18,
roughness: 0.8,
metalness: 0.08,
flatShading: true
});
const mainCurve = new THREE.CatmullRomCurve3(
snapshots.slice(0, 4).map((snapshot) =>
new THREE.Vector3(snapshot.position.x, 0.085, snapshot.position.z)
),
false,
"catmullrom",
0.12
);
const mainPath = new THREE.Mesh(
new THREE.TubeGeometry(mainCurve, 72, 0.032, 5, false),
pathMaterial
);
mainPath.receiveShadow = true;
scene.add(mainPath);
const branchA = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(1.0, 0.085, 0),
new THREE.Vector3(2.6, 0.085, -1.35),
new THREE.Vector3(5.0, 0.085, -2.65)
);
const branchB = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(1.0, 0.085, 0),
new THREE.Vector3(2.6, 0.085, 1.35),
new THREE.Vector3(5.0, 0.085, 2.65)
);
[
[branchA, 0x55d6c2],
[branchB, 0xff7a90]
].forEach(([curve, color]) => {
const branchMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.12,
roughness: 0.78,
metalness: 0.04,
flatShading: true
});
const branchMesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 40, 0.032, 5, false),
branchMaterial
);
branchMesh.receiveShadow = true;
scene.add(branchMesh);
});
const splitMarker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 0),
new THREE.MeshStandardMaterial({
color: 0xe6f4f2,
emissive: 0x7be7d6,
emissiveIntensity: 0.32,
roughness: 0.6,
flatShading: true
})
);
splitMarker.position.set(1.0, 0.16, 0);
splitMarker.castShadow = true;
scene.add(splitMarker);
const axis = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-9.2, 0.015, -4.35),
new THREE.Vector3(6.2, 0.015, -4.35)
]),
new THREE.LineBasicMaterial({
color: 0x51687b,
transparent: true,
opacity: 0.55
})
);
scene.add(axis);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.38, 5),
new THREE.MeshStandardMaterial({
color: 0x71899b,
roughness: 0.75,
flatShading: true
})
);
arrow.position.set(6.25, 0.06, -4.35);
arrow.rotation.z = -Math.PI / 2;
scene.add(arrow);
const timeLabel = document.createElement("div");
timeLabel.className = "scene-label";
timeLabel.style.width = "124px";
timeLabel.style.pointerEvents = "none";
timeLabel.innerHTML = `
<span class="generation">Direction of time</span>
<span class="population">Increasing generation →</span>
`;
labelLayer.appendChild(timeLabel);
const timeAnchor = new THREE.Vector3(6.1, 0.45, -4.35);
let activeIndex = 0;
let playing = false;
let lastAdvance = 0;
const stopButtons = snapshots.map((snapshot, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "stop";
button.dataset.index = index;
button.textContent =
index === 4 ? "G150 · A" : index === 5 ? "G150 · B" : `G${snapshot.generation}`;
button.addEventListener("click", () => setActive(index));
stopsElement.appendChild(button);
return button;
});
function frequencyRows(frequencies) {
return frequencies
.map(
(frequency, index) => `
<div class="freq-row">
<span>${variants[index].name}</span>
<span class="freq-track">
<span
class="freq-fill"
style="width:${frequency * 100}%;background:${variants[index].css}"
></span>
</span>
<span class="freq-value">${Math.round(frequency * 100)}%</span>
</div>
`
)
.join("");
}
function populationBlock(name, frequencies) {
return `
<div class="population-block">
<div class="population-name">${name}</div>
${frequencyRows(frequencies)}
</div>
`;
}
function updateReadout() {
const snapshot = snapshots[activeIndex];
if (activeIndex <= 3) {
readout.innerHTML = `
<p class="eyebrow">Generation ${snapshot.generation}</p>
<h2>${snapshot.name} population</h2>
<p class="readout-copy">
${
snapshot.branchPoint
? "The lineage reaches one split. The following generation contains two descendant populations."
: "A contemporaneous population snapshot. Its variant shares change without any change to the body plan."
}
</p>
${populationBlock("Variant frequencies", snapshot.frequencies)}
`;
} else {
readout.innerHTML = `
<p class="eyebrow">Generation 150</p>
<h2>Aster and Reef</h2>
<p class="readout-copy">
Two descendants coexist after the single split. Their frequencies
differ, but neither is presented as more advanced.
</p>
${populationBlock("Aster population", snapshots[4].frequencies)}
${populationBlock("Reef population", snapshots[5].frequencies)}
`;
}
}
function setActive(index) {
activeIndex = THREE.MathUtils.clamp(index, 0, snapshots.length - 1);
const snapshot = snapshots[activeIndex];
timeline.value = String(activeIndex);
generationReadout.textContent = `Generation ${snapshot.generation}`;
snapshotObjects.forEach((object, objectIndex) => {
object.label.classList.toggle("active", objectIndex === activeIndex);
});
stopButtons.forEach((button, index) => {
button.classList.toggle("active", index === activeIndex);
});
updateReadout();
}
timeline.addEventListener("input", () => {
setActive(Number(timeline.value));
});
playButton.addEventListener("click", () => {
playing = !playing;
lastAdvance = performance.now();
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute("aria-pressed", String(playing));
playButton.setAttribute(
"aria-label",
playing ? "Pause timeline" : "Play timeline"
);
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (event.code === "Space" && tag !== "INPUT" && tag !== "BUTTON") {
event.preventDefault();
playButton.click();
}
if (event.code === "ArrowRight") {
setActive(activeIndex + 1);
}
if (event.code === "ArrowLeft") {
setActive(activeIndex - 1);
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
setActive(0);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.display = "none";
return;
}
element.style.display = "";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const clock = new THREE.Clock();
function animate(now) {
const elapsed = clock.getElapsedTime();
if (playing && now - lastAdvance > 2200) {
setActive((activeIndex + 1) % snapshots.length);
lastAdvance = now;
}
animatedMembers.forEach((member) => {
member.group.position.y =
member.baseY + Math.sin(elapsed * 1.35 + member.phase) * 0.018;
});
animatedBars.forEach((bar) => {
bar.currentHeight +=
(bar.targetHeight - bar.currentHeight) * 0.075;
bar.mesh.scale.y = Math.max(0.001, bar.currentHeight);
bar.mesh.position.y = 0.06 + bar.currentHeight / 2;
const isActive = bar.snapshotIndex === activeIndex;
const desiredOpacity = isActive ? 0.96 : 0.43;
bar.material.opacity +=
(desiredOpacity - bar.material.opacity) * 0.1;
});
snapshotObjects.forEach((object, index) => {
const isActive = index === activeIndex;
const desiredOpacity = isActive ? 0.9 : 0.28;
object.ringMaterial.opacity +=
(desiredOpacity - object.ringMaterial.opacity) * 0.1;
object.ringMaterial.color.lerp(
new THREE.Color(isActive ? 0x7be7d6 : 0x486477),
0.08
);
const pulse = isActive ? 1 + Math.sin(elapsed * 2.2) * 0.018 : 1;
object.ring.scale.setScalar(pulse);
positionLabel(object.label, object.anchor);
});
const pulse = 1 + Math.sin(elapsed * 2.8) * 0.08;
splitMarker.scale.setScalar(pulse);
splitMarker.rotation.y = elapsed * 0.35;
positionLabel(timeLabel, timeAnchor);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```