Prompt specification
Build or customize the Three.js 3D scene "Rapid frequency change versus slow morphology panels" 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: Rapid frequency change versus slow morphology panels
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rapid-frequency-change-versus-slow-morphology-panels-x0898
Scene Description Prompt:
Show stylized synthetic timelines comparing changing allele counts with slower schematic body-shape changes. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (rapid-frequency-change-versus-slow-morphology-panels-x0898):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Synthetic Evolutionary Timelines</title>
<style>
:root {
color-scheme: dark;
--bg: #061015;
--panel: #0a181e;
--panel-2: #0d2027;
--line: #213942;
--text: #e5f0f2;
--muted: #8da4aa;
--a: #ff6b6b;
--b: #4cc9f0;
--c: #f7d154;
--morph: #e9b95c;
--accent: #61dbc7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
select,
input {
font: inherit;
}
.app {
width: 100%;
height: 100dvh;
min-height: 690px;
display: grid;
grid-template-rows: auto minmax(430px, 1fr) auto;
}
.topbar {
position: relative;
z-index: 5;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 17px 22px;
border-bottom: 1px solid rgba(119, 161, 172, 0.16);
background: rgba(6, 16, 21, 0.88);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 4px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 25px);
font-weight: 650;
letter-spacing: -0.025em;
}
.subtitle {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.controls {
display: flex;
align-items: center;
gap: 9px;
flex-wrap: wrap;
justify-content: flex-end;
}
.control-button,
.speed-label {
min-height: 38px;
border: 1px solid #29434c;
border-radius: 9px;
background: #0b1c22;
color: var(--text);
}
.control-button {
padding: 0 13px;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.control-button:hover {
border-color: #4e7a86;
background: #10262e;
}
.control-button:active {
transform: translateY(1px);
}
#play {
min-width: 91px;
border-color: rgba(97, 219, 199, 0.44);
color: #bff8ef;
}
.speed-label {
display: flex;
align-items: center;
gap: 8px;
padding: 0 9px 0 12px;
color: var(--muted);
font-size: 11px;
}
.speed-label select {
border: 0;
outline: 0;
background: transparent;
color: var(--text);
cursor: pointer;
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 40%, rgba(26, 66, 74, 0.15), transparent 45%),
var(--bg);
}
#stage canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.camera-hint {
position: absolute;
z-index: 2;
right: 16px;
top: 14px;
padding: 7px 10px;
border: 1px solid rgba(110, 151, 161, 0.16);
border-radius: 999px;
background: rgba(5, 14, 18, 0.58);
color: #7f999f;
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
.loading {
position: absolute;
z-index: 3;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font-size: 13px;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.timeline-panel {
position: relative;
z-index: 5;
padding: 14px 22px 16px;
border-top: 1px solid rgba(119, 161, 172, 0.16);
background: rgba(7, 18, 23, 0.96);
}
.timeline-heading,
.readouts {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.timeline-heading {
margin-bottom: 8px;
}
.timeline-title {
font-size: 12px;
font-weight: 700;
letter-spacing: 0.03em;
}
.timeline-note {
color: var(--muted);
font-size: 10px;
}
.current-generation {
color: var(--accent);
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 700;
}
#timeline {
width: 100%;
height: 24px;
margin: 0;
appearance: none;
background: transparent;
cursor: ew-resize;
}
#timeline::-webkit-slider-runnable-track {
height: 4px;
border-radius: 4px;
background:
linear-gradient(
90deg,
var(--accent) 0%,
var(--accent) var(--progress, 0%),
#233a42 var(--progress, 0%),
#233a42 100%
);
}
#timeline::-moz-range-track {
height: 4px;
border-radius: 4px;
background: #233a42;
}
#timeline::-moz-range-progress {
height: 4px;
border-radius: 4px;
background: var(--accent);
}
#timeline::-webkit-slider-thumb {
width: 15px;
height: 15px;
margin-top: -5.5px;
appearance: none;
border: 2px solid #dffff8;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(97, 219, 199, 0.12);
}
#timeline::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #dffff8;
border-radius: 50%;
background: var(--accent);
}
.readouts {
align-items: stretch;
margin-top: 8px;
}
.metric {
display: flex;
align-items: baseline;
gap: 8px;
min-width: 150px;
}
.metric-label {
color: var(--muted);
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.09em;
}
.metric-value {
font-size: 15px;
font-weight: 720;
font-variant-numeric: tabular-nums;
}
.metric-value.a {
color: var(--a);
}
.metric-value.b {
color: var(--b);
}
.metric-value.c {
color: var(--c);
}
.metric-value.morph {
color: var(--morph);
}
.synthetic-note {
max-width: 430px;
margin-left: auto;
color: #6f888e;
font-size: 10px;
line-height: 1.45;
text-align: right;
}
@media (max-width: 800px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100dvh;
grid-template-rows: auto 560px auto;
}
.topbar {
align-items: flex-start;
flex-direction: column;
gap: 13px;
}
.controls {
justify-content: flex-start;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
}
.synthetic-note {
grid-column: 1 / -1;
max-width: none;
margin: 0;
text-align: left;
}
.timeline-note {
display: none;
}
}
@media (max-width: 480px) {
.topbar,
.timeline-panel {
padding-left: 14px;
padding-right: 14px;
}
.metric {
min-width: 0;
}
.metric-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<main class="app">
<header class="topbar">
<div>
<p class="eyebrow">Synthetic comparison / shared generation axis</p>
<h1>Allele variation vs. schematic body change</h1>
<p class="subtitle">
Rapid numerical fluctuations are paired with a deliberately slower,
low-frequency morphology trajectory.
</p>
</div>
<div class="controls">
<button class="control-button" id="play" type="button">❚❚ Pause</button>
<label class="speed-label">
Speed
<select id="speed" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="2">2×</option>
<option value="4">4×</option>
</select>
</label>
<button class="control-button" id="resetCamera" type="button">
Reset view
</button>
</div>
</header>
<section id="stage" aria-label="Interactive Three.js evolutionary timeline">
<div class="camera-hint">Drag to orbit · wheel to zoom · double-click to reset</div>
<div class="loading" id="loading">Preparing synthetic timeline…</div>
</section>
<footer class="timeline-panel">
<div class="timeline-heading">
<span class="timeline-title">Synchronized synthetic timeline</span>
<span class="timeline-note">
Allele A / B / C are colored consistently in the graph.
</span>
<span class="current-generation" id="currentGeneration">
Generation 000 / 100
</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="100"
step="0.1"
value="0"
aria-label="Synthetic generation"
>
<div class="readouts">
<div class="metric">
<span class="metric-label">Allele span</span>
<span class="metric-value" id="alleleSpan">—</span>
</div>
<div class="metric">
<span class="metric-label">Dominant copy</span>
<span class="metric-value" id="dominantAllele">—</span>
</div>
<div class="metric">
<span class="metric-label">Body shift</span>
<span class="metric-value morph" id="bodyShift">—</span>
</div>
<div class="synthetic-note">
Independent synthetic signals sharing one time axis; this is not a
causal population-genetic model.
</div>
</div>
</footer>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const playButton = document.getElementById("play");
const speedSelect = document.getElementById("speed");
const resetCameraButton = document.getElementById("resetCamera");
const timelineInput = document.getElementById("timeline");
const generationReadout = document.getElementById("currentGeneration");
const alleleSpanReadout = document.getElementById("alleleSpan");
const dominantAlleleReadout = document.getElementById("dominantAllele");
const bodyShiftReadout = document.getElementById("bodyShift");
const TAU = Math.PI * 2;
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const state = {
time: 0,
playing: !reducedMotion,
speed: 1
};
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional synthetic allele and morphology timeline"
);
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x061015);
scene.fog = new THREE.FogExp2(0x061015, 0.022);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 80);
const cameraTarget = new THREE.Vector3(0, 0.65, 0);
const cameraState = {
yaw: 0,
pitch: 0.19,
distance: 16.8
};
const hemisphere = new THREE.HemisphereLight(0xa9e8ef, 0x071015, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xe5ffff, 3.3);
keyLight.position.set(-3, 8, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x58d8d0, 30, 18, 2);
rimLight.position.set(7, 3, 4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xf3b568, 15, 15, 2);
warmLight.position.set(-7, 2, 5);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x071218,
roughness: 0.92,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.16;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x173039, 0x10252c);
grid.position.y = -2.145;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
function makeLabel(
text,
{
color = "#dce9ec",
fontSize = 34,
pixelScale = 0.010,
align = "center",
opacity = 1
} = {}
) {
const measuringCanvas = document.createElement("canvas");
const measuringContext = measuringCanvas.getContext("2d");
const font = `650 ${fontSize}px Inter, ui-sans-serif, system-ui, sans-serif`;
measuringContext.font = font;
const textWidth = Math.ceil(measuringContext.measureText(text).width);
const canvas = document.createElement("canvas");
canvas.width = Math.min(1400, textWidth + 36);
canvas.height = fontSize + 28;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.font = font;
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, 18, canvas.height * 0.53);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
opacity
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(
canvas.width * pixelScale,
canvas.height * pixelScale,
1
);
if (align === "left") sprite.center.set(0, 0.5);
if (align === "right") sprite.center.set(1, 0.5);
sprite.renderOrder = 20;
return sprite;
}
function makePanel(width, height, x, y, z, tint = 0x0b1b21) {
const group = new THREE.Group();
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshStandardMaterial({
color: tint,
roughness: 0.82,
metalness: 0.04,
transparent: true,
opacity: 0.94
})
);
panel.position.set(x, y, z);
panel.receiveShadow = true;
group.add(panel);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(panel.geometry),
new THREE.LineBasicMaterial({
color: 0x29444d,
transparent: true,
opacity: 0.8
})
);
outline.position.copy(panel.position);
outline.position.z += 0.012;
group.add(outline);
scene.add(group);
return group;
}
makePanel(6.5, 4.7, -4.15, 1.75, -1.08);
makePanel(7.5, 4.7, 3.8, 1.75, -1.08, 0x0a1c21);
makePanel(15.6, 1.0, 0, -1.65, -0.72, 0x08171d);
const graphTitle = makeLabel("ALLELE COPY COUNTS", {
color: "#e6f3f4",
fontSize: 37,
pixelScale: 0.0105,
align: "left"
});
graphTitle.position.set(-7.36, 4.43, -0.8);
scene.add(graphTitle);
const graphSubtitle = makeLabel(
"FAST SIGNAL · 1,000 synthetic gene copies",
{
color: "#78959b",
fontSize: 26,
pixelScale: 0.009,
align: "left"
}
);
graphSubtitle.position.set(-7.34, 4.08, -0.8);
scene.add(graphSubtitle);
const bodyTitle = makeLabel("SCHEMATIC BODY MORPH", {
color: "#e6f3f4",
fontSize: 37,
pixelScale: 0.0105,
align: "left"
});
bodyTitle.position.set(0.13, 4.43, -0.8);
scene.add(bodyTitle);
const bodySubtitle = makeLabel(
"SLOW SIGNAL · LOW-FREQUENCY TRAJECTORY",
{
color: "#78959b",
fontSize: 26,
pixelScale: 0.009,
align: "left"
}
);
bodySubtitle.position.set(0.14, 4.08, -0.8);
scene.add(bodySubtitle);
const timelineTitle = makeLabel("SHARED GENERATION AXIS", {
color: "#91a9ae",
fontSize: 25,
pixelScale: 0.009,
align: "left"
});
timelineTitle.position.set(-7.35, -0.97, -0.45);
scene.add(timelineTitle);
const plot = {
left: -6.9,
right: -1.45,
bottom: 0.08,
top: 3.72
};
const alleleColors = [0xff6b6b, 0x4cc9f0, 0xf7d154];
const alleleCSS = ["#ff6b6b", "#4cc9f0", "#f7d154"];
const alleleNames = ["A", "B", "C"];
function allelesAt(t) {
const a =
365 +
115 * Math.sin(TAU * 3.7 * t + 0.35) +
35 * Math.sin(TAU * 8.3 * t + 1.2);
const b =
330 +
95 * Math.sin(TAU * 2.9 * t + 2.1) +
45 * Math.sin(TAU * 6.1 * t + 0.1) +
20 * Math.sin(TAU * 12 * t);
const c = 1000 - a - b;
return [a, b, c];
}
function bodyParams(t) {
const smooth = t * t * (3 - 2 * t);
return {
height:
0.92 +
0.24 * smooth +
0.08 * Math.sin(TAU * t + 0.2),
girth:
0.88 +
0.14 * smooth +
0.10 * Math.sin(TAU * t + 1.0),
head:
0.98 -
0.16 * smooth +
0.07 * Math.sin(TAU * t + 2.3),
limb:
0.82 +
0.30 * smooth +
0.07 * Math.sin(TAU * t + 0.7),
tail:
0.76 +
0.38 * smooth +
0.10 * Math.sin(TAU * t + 1.7)
};
}
const graphX = (t) =>
THREE.MathUtils.lerp(plot.left, plot.right, t);
const graphY = (count) =>
THREE.MathUtils.lerp(
plot.bottom,
plot.top,
THREE.MathUtils.clamp(count / 1000, 0, 1)
);
const graphGridMaterial = new THREE.LineBasicMaterial({
color: 0x29434b,
transparent: true,
opacity: 0.55
});
for (let count = 0; count <= 1000; count += 250) {
const y = graphY(count);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(plot.left, y, -0.92),
new THREE.Vector3(plot.right, y, -0.92)
]),
graphGridMaterial
);
scene.add(line);
const label = makeLabel(String(count), {
color: "#688188",
fontSize: 24,
pixelScale: 0.008
});
label.position.set(plot.left - 0.16, y, -0.85);
scene.add(label);
}
for (let generation = 0; generation <= 100; generation += 25) {
const x = graphX(generation / 100);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, plot.bottom, -0.92),
new THREE.Vector3(x, plot.top, -0.92)
]),
graphGridMaterial
);
scene.add(line);
const label = makeLabel(String(generation), {
color: "#688188",
fontSize: 24,
pixelScale: 0.008
});
label.position.set(x, plot.bottom - 0.27, -0.85);
scene.add(label);
}
const axisMaterial = new THREE.LineBasicMaterial({
color: 0x6d8c93,
transparent: true,
opacity: 0.8
});
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(plot.left, plot.bottom, -0.88),
new THREE.Vector3(plot.right, plot.bottom, -0.88)
]),
axisMaterial
)
);
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(plot.left, plot.bottom, -0.88),
new THREE.Vector3(plot.left, plot.top, -0.88)
]),
axisMaterial
)
);
const sampleCount = 181;
const samples = Array.from(
{ length: sampleCount },
(_, index) => index / (sampleCount - 1)
);
const graphLines = [];
const endpointDots = [];
const endpointLabels = [];
alleleColors.forEach((color, alleleIndex) => {
const points = samples.map((t) => {
const count = allelesAt(t)[alleleIndex];
return new THREE.Vector3(graphX(t), graphY(count), -0.82);
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.96
})
);
scene.add(line);
graphLines.push(line);
const endCount = allelesAt(1)[alleleIndex];
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.072, 16, 12),
new THREE.MeshBasicMaterial({ color })
);
dot.position.set(plot.right, graphY(endCount), -0.75);
scene.add(dot);
endpointDots.push(dot);
const label = makeLabel(alleleNames[alleleIndex], {
color: alleleCSS[alleleIndex],
fontSize: 31,
pixelScale: 0.010
});
label.position.set(plot.right + 0.16, graphY(endCount), -0.7);
scene.add(label);
endpointLabels.push(label);
});
const graphCursor = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(plot.left, plot.bottom, -0.77),
new THREE.Vector3(plot.left, plot.top, -0.77)
]),
new THREE.LineDashedMaterial({
color: 0xd8ffff,
dashSize: 0.075,
gapSize: 0.055,
transparent: true,
opacity: 0.38
})
);
graphCursor.computeLineDistances();
scene.add(graphCursor);
const currentAlleleMarkers = alleleColors.map((color) => {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 18, 14),
new THREE.MeshBasicMaterial({ color })
);
marker.position.z = -0.66;
scene.add(marker);
return marker;
});
const timeline = {
left: -7.35,
right: 7.35,
alleleY: -1.32,
morphY: -1.83
};
const timelineX = (t) =>
THREE.MathUtils.lerp(timeline.left, timeline.right, t);
const timelineBase = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(timeline.left, timeline.alleleY, -0.42),
new THREE.Vector3(timeline.right, timeline.alleleY, -0.42)
]),
new THREE.LineBasicMaterial({
color: 0x36515a,
transparent: true,
opacity: 0.75
})
);
scene.add(timelineBase);
const microbarPositions = [];
const microbarColors = [];
for (let index = 0; index < 86; index += 1) {
const t = index / 85;
const values = allelesAt(t);
const dominantIndex = values.indexOf(Math.max(...values));
const mean = (values[0] + values[1] + values[2]) / 3;
const variation =
Math.min(1, Math.abs(values[dominantIndex] - mean) / 170);
const x = timelineX(t);
const height = 0.035 + variation * 0.13;
microbarPositions.push(
x,
timeline.alleleY,
-0.39,
x,
timeline.alleleY + height,
-0.39
);
const color = new THREE.Color(alleleColors[dominantIndex]);
microbarColors.push(color.r, color.g, color.b, color.r, color.g, color.b);
}
const microbarGeometry = new THREE.BufferGeometry();
microbarGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(microbarPositions, 3)
);
microbarGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(microbarColors, 3)
);
scene.add(
new THREE.LineSegments(
microbarGeometry,
new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.62
})
)
);
const morphTrackPoints = samples.map((t) => {
const params = bodyParams(t);
const normalized = THREE.MathUtils.clamp(
(params.girth - 0.75) / 0.55,
0,
1
);
return new THREE.Vector3(
timelineX(t),
timeline.morphY + normalized * 0.12,
-0.38
);
});
scene.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(morphTrackPoints),
new THREE.LineBasicMaterial({
color: 0xe9b95c,
transparent: true,
opacity: 0.9
})
)
);
for (let generation = 0; generation <= 100; generation += 20) {
const t = generation / 100;
const params = bodyParams(t);
const normalized = THREE.MathUtils.clamp(
(params.girth - 0.75) / 0.55,
0,
1
);
const node = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 14, 10),
new THREE.MeshBasicMaterial({ color: 0xe9b95c })
);
node.position.set(
timelineX(t),
timeline.morphY + normalized * 0.12,
-0.34
);
scene.add(node);
}
const timelineLegendA = makeLabel("FAST ALLELE ACTIVITY", {
color: "#799198",
fontSize: 19,
pixelScale: 0.0075,
align: "right"
});
timelineLegendA.position.set(7.25, -1.11, -0.28);
scene.add(timelineLegendA);
const timelineLegendB = makeLabel("SLOW BODY TRAIT", {
color: "#b59355",
fontSize: 19,
pixelScale: 0.0075,
align: "right"
});
timelineLegendB.position.set(7.25, -1.93, -0.28);
scene.add(timelineLegendB);
const timelineCursor = new THREE.Group();
const cursorLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -1.08, -0.25),
new THREE.Vector3(0, -2.0, -0.25)
]),
new THREE.LineBasicMaterial({
color: 0x9efff0,
transparent: true,
opacity: 0.82
})
);
timelineCursor.add(cursorLine);
const cursorTip = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 16, 12),
new THREE.MeshBasicMaterial({ color: 0x9efff0 })
);
cursorTip.position.y = -1.06;
timelineCursor.add(cursorTip);
scene.add(timelineCursor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.15, 2.3, 0.16, 72),
new THREE.MeshStandardMaterial({
color: 0x0e252b,
roughness: 0.48,
metalness: 0.38
})
);
platform.position.set(3.8, -1.9, 0.08);
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(1.82, 0.018, 8, 100),
new THREE.MeshBasicMaterial({
color: 0x61dbc7,
transparent: true,
opacity: 0.42
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.set(3.8, -1.805, 0.08);
scene.add(platformRing);
const organism = new THREE.Group();
organism.position.set(3.8, -1.8, 0.08);
organism.scale.setScalar(1.07);
scene.add(organism);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x56d2c0,
roughness: 0.34,
metalness: 0.09
});
const bodyLightMaterial = new THREE.MeshStandardMaterial({
color: 0x87e5d4,
roughness: 0.42,
metalness: 0.04
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x061014,
roughness: 0.25,
metalness: 0.12
});
const whiteMaterial = new THREE.MeshStandardMaterial({
color: 0xeafcf7,
roughness: 0.3
});
const wireMaterial = new THREE.MeshBasicMaterial({
color: 0xd4fff6,
wireframe: true,
transparent: true,
opacity: 0.085,
depthWrite: false
});
const torsoGeometry = new THREE.SphereGeometry(1, 48, 32);
const headGeometry = new THREE.SphereGeometry(1, 36, 24);
const torso = new THREE.Mesh(torsoGeometry, bodyMaterial);
torso.castShadow = true;
torso.receiveShadow = true;
organism.add(torso);
const torsoWire = new THREE.Mesh(torsoGeometry, wireMaterial);
organism.add(torsoWire);
const head = new THREE.Mesh(headGeometry, bodyLightMaterial);
head.castShadow = true;
organism.add(head);
const headWire = new THREE.Mesh(headGeometry, wireMaterial);
organism.add(headWire);
const snout = new THREE.Mesh(
new THREE.SphereGeometry(1, 28, 20),
bodyLightMaterial
);
snout.castShadow = true;
organism.add(snout);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.3, 1, 20),
bodyMaterial
);
neck.rotation.z = -Math.PI / 2;
neck.castShadow = true;
organism.add(neck);
const eyeMeshes = [];
const pupilMeshes = [];
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(1, 20, 14),
whiteMaterial
);
organism.add(eye);
eyeMeshes.push(eye);
const pupil = new THREE.Mesh(
new THREE.SphereGeometry(1, 18, 12),
darkMaterial
);
organism.add(pupil);
pupilMeshes.push(pupil);
}
const nostrilMeshes = [];
for (const side of [-1, 1]) {
const nostril = new THREE.Mesh(
new THREE.SphereGeometry(1, 14, 10),
darkMaterial
);
organism.add(nostril);
nostrilMeshes.push(nostril);
}
const legGroups = [];
for (const xDirection of [-1, 1]) {
for (const zDirection of [-1, 1]) {
const legGroup = new THREE.Group();
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.15, 1, 16),
bodyMaterial
);
shaft.castShadow = true;
const foot = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 20, 14),
bodyLightMaterial
);
foot.scale.set(1.35, 0.62, 1.05);
foot.position.y = 0.06;
foot.castShadow = true;
legGroup.add(shaft, foot);
organism.add(legGroup);
legGroups.push({ group: legGroup, shaft, xDirection, zDirection });
}
}
const tailSegments = [];
for (let index = 0; index < 7; index += 1) {
const segment = new THREE.Mesh(
new THREE.SphereGeometry(1, 20, 14),
bodyMaterial
);
segment.castShadow = true;
organism.add(segment);
tailSegments.push(segment);
}
const dorsalFins = [];
for (let index = 0; index < 3; index += 1) {
const fin = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.4, 4),
bodyLightMaterial
);
fin.castShadow = true;
organism.add(fin);
dorsalFins.push(fin);
}
const earMeshes = [];
for (const side of [-1, 1]) {
const ear = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.42, 4),
bodyLightMaterial
);
ear.castShadow = true;
organism.add(ear);
earMeshes.push(ear);
}
function updateOrganism(t) {
const p = bodyParams(t);
torso.scale.set(
1.18 * p.girth,
0.72 * p.height,
0.86 * p.girth
);
torso.position.set(0, 1.02 * p.height, 0);
torsoWire.scale.copy(torso.scale);
torsoWire.position.copy(torso.position);
head.scale.set(
0.43 * p.head,
0.45 * p.head,
0.43 * p.head
);
head.position.set(
1.12 * p.girth,
1.27 * p.height,
0
);
headWire.scale.copy(head.scale);
headWire.position.copy(head.position);
snout.scale.set(
0.34 * p.head,
0.21 * p.head,
0.23 * p.head
);
snout.position.set(
1.47 * p.girth,
1.19 * p.height,
0
);
neck.scale.set(
p.girth,
0.48 * p.height,
p.girth
);
neck.position.set(
0.83 * p.girth,
1.08 * p.height,
0
);
eyeMeshes.forEach((eye, index) => {
const side = index === 0 ? -1 : 1;
eye.scale.setScalar(0.105 * p.head);
eye.position.set(
1.36 * p.girth,
1.38 * p.height,
side * 0.245 * p.head
);
});
pupilMeshes.forEach((pupil, index) => {
const side = index === 0 ? -1 : 1;
pupil.scale.setScalar(0.047 * p.head);
pupil.position.set(
1.425 * p.girth,
1.385 * p.height,
side * 0.315 * p.head
);
});
nostrilMeshes.forEach((nostril, index) => {
const side = index === 0 ? -1 : 1;
nostril.scale.setScalar(0.032 * p.head);
nostril.position.set(
1.73 * p.girth,
1.21 * p.height,
side * 0.10 * p.head
);
});
legGroups.forEach(({ group, shaft, xDirection, zDirection }) => {
group.position.set(
xDirection * 0.55 * p.girth,
0,
zDirection * 0.47 * p.girth
);
shaft.scale.y = 0.78 * p.limb;
shaft.position.y = 0.39 * p.limb;
});
tailSegments.forEach((segment, index) => {
const q = index / (tailSegments.length - 1);
const radius =
0.24 * (1 - q * 0.78) * (0.75 + 0.25 * p.tail);
segment.scale.set(
radius,
radius,
radius
);
segment.position.set(
-1.0 * p.girth - q * 1.28 * p.tail,
1.08 * p.height +
q * 0.43 * p.tail -
q * q * 0.28 * p.tail,
Math.sin(q * Math.PI) * 0.08
);
});
dorsalFins.forEach((fin, index) => {
const x = (index - 1) * 0.62 * p.girth;
fin.scale.set(
0.8 * p.girth,
0.7 + 0.22 * p.height,
0.8 * p.girth
);
fin.position.set(
x,
1.67 * p.height + 0.09 * (2 - index),
0
);
});
earMeshes.forEach((ear, index) => {
const side = index === 0 ? -1 : 1;
ear.scale.setScalar(0.82 + 0.18 * p.head);
ear.position.set(
0.98 * p.girth,
1.7 * p.height,
side * 0.25 * p.head
);
});
}
const backgroundPositions = [];
for (let index = 0; index < 120; index += 1) {
backgroundPositions.push(
THREE.MathUtils.randFloatSpread(25),
THREE.MathUtils.randFloat(-1.5, 7),
THREE.MathUtils.randFloat(-8, -3.2)
);
}
const backgroundGeometry = new THREE.BufferGeometry();
backgroundGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(backgroundPositions, 3)
);
scene.add(
new THREE.Points(
backgroundGeometry,
new THREE.PointsMaterial({
color: 0x76a6ad,
size: 0.025,
transparent: true,
opacity: 0.26,
sizeAttenuation: true
})
)
);
const initialBody = bodyParams(0);
function bodyShiftPercent(t) {
const current = bodyParams(t);
const values = Object.keys(current);
let sum = 0;
for (const key of values) {
const difference = (current[key] - initialBody[key]) / 0.5;
sum += difference * difference;
}
return Math.round(
THREE.MathUtils.clamp(
(Math.sqrt(sum / values.length) * 100) / 0.62,
0,
99
)
);
}
function updateScene(t) {
const x = graphX(t);
const counts = allelesAt(t);
const graphPositions = graphCursor.geometry.attributes.position;
graphPositions.setX(0, x);
graphPositions.setX(1, x);
graphPositions.needsUpdate = true;
currentAlleleMarkers.forEach((marker, index) => {
marker.position.set(x, graphY(counts[index]), -0.66);
});
timelineCursor.position.x = timelineX(t);
updateOrganism(t);
const span = Math.max(...counts) - Math.min(...counts);
const dominantIndex = counts.indexOf(Math.max(...counts));
generationReadout.textContent =
`Generation ${String(Math.round(t * 100)).padStart(3, "0")} / 100`;
alleleSpanReadout.textContent =
`${Math.round(span).toLocaleString()} copies`;
dominantAlleleReadout.textContent =
`Allele ${alleleNames[dominantIndex]}`;
dominantAlleleReadout.className =
`metric-value ${alleleNames[dominantIndex].toLowerCase()}`;
bodyShiftReadout.textContent =
`${bodyShiftPercent(t)}% descriptor shift`;
timelineInput.value = String(t * 100);
timelineInput.style.setProperty("--progress", `${t * 100}%`);
timelineInput.setAttribute(
"aria-valuetext",
`Generation ${Math.round(t * 100)}`
);
}
function updatePlayButton() {
playButton.textContent = state.playing ? "❚❚ Pause" : "▶ Play";
playButton.setAttribute(
"aria-label",
state.playing ? "Pause animation" : "Play animation"
);
}
function togglePlayback() {
state.playing = !state.playing;
updatePlayButton();
}
playButton.addEventListener("click", togglePlayback);
speedSelect.addEventListener("change", () => {
state.speed = Number(speedSelect.value);
});
timelineInput.addEventListener("input", () => {
state.time = Number(timelineInput.value) / 100;
state.playing = false;
updatePlayButton();
updateScene(state.time);
});
timelineInput.addEventListener("pointerdown", () => {
state.playing = false;
updatePlayButton();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePlayback();
}
if (event.code === "ArrowLeft" || event.code === "ArrowRight") {
event.preventDefault();
state.playing = false;
updatePlayButton();
const direction = event.code === "ArrowRight" ? 1 : -1;
state.time = THREE.MathUtils.clamp(
state.time + direction * 0.01,
0,
1
);
updateScene(state.time);
}
});
function resetCamera() {
cameraState.yaw = 0;
cameraState.pitch = 0.19;
cameraState.distance = 16.8;
}
resetCameraButton.addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
const pointer = {
active: false,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const deltaX = event.clientX - pointer.x;
const deltaY = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
cameraState.yaw -= deltaX * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.003,
-0.05,
0.62
);
});
function endPointer(event) {
pointer.active = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.012,
11.5,
23
);
},
{ passive: false }
);
function updateCamera() {
const portraitFactor = Math.max(1, 1.28 / camera.aspect);
const distance = cameraState.distance * portraitFactor;
camera.position.set(
cameraTarget.x +
Math.sin(cameraState.yaw) *
Math.cos(cameraState.pitch) *
distance,
cameraTarget.y +
Math.sin(cameraState.pitch) *
distance,
cameraTarget.z +
Math.cos(cameraState.yaw) *
Math.cos(cameraState.pitch) *
distance
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
updatePlayButton();
updateScene(state.time);
let previousTime = performance.now();
renderer.setAnimationLoop(() => {
const now = performance.now();
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (state.playing) {
state.time += delta * 0.04 * state.speed;
if (state.time > 1) {
state.time = 0;
}
}
updateScene(state.time);
organism.position.y =
-1.8 + Math.sin(now * 0.0015) * 0.018;
platformRing.material.opacity =
0.37 + Math.sin(now * 0.0013) * 0.08;
updateCamera();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```