Prompt specification
Build or customize the Three.js 3D scene "Separated habitat population model" 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: Separated habitat population model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/separated-habitat-population-model-x0957
Scene Description Prompt:
Build one fictional habitat split by a rising barrier, preserving marked individuals on both sides; distinguish geographical separation from the later development of reproductive isolation. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (separated-habitat-population-model-x0957):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Divided Grove</title>
<style>
:root {
color-scheme: dark;
--ink: #ecf8f1;
--muted: #9db7ae;
--panel: rgba(10, 27, 28, 0.88);
--line: rgba(210, 244, 226, 0.14);
--cyan: #67d5ff;
--orange: #ff9f68;
--green: #85e6a6;
--gold: #ffd166;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0a1b1e;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
border: 1px solid var(--line);
color: var(--ink);
background: rgba(255,255,255,0.06);
border-radius: 9px;
padding: 8px 12px;
cursor: pointer;
transition: background .15s ease, border-color .15s ease;
}
button:hover {
background: rgba(255,255,255,0.11);
border-color: rgba(255,255,255,0.28);
}
button:focus-visible, input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
#app, #scene-wrap {
position: fixed;
inset: 0;
}
#scene-wrap canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.brand {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
max-width: 410px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0,0,0,.65);
}
.eyebrow {
color: var(--gold);
font-size: 11px;
font-weight: 800;
letter-spacing: .2em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 4px;
font-size: clamp(26px, 4vw, 46px);
line-height: 1;
letter-spacing: -.035em;
}
.subtitle {
margin: 0;
color: #bdd1c8;
font-size: 13px;
line-height: 1.5;
}
.panel {
position: fixed;
z-index: 6;
top: 22px;
right: 22px;
width: 345px;
max-height: calc(100vh - 150px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0,0,0,.34);
backdrop-filter: blur(14px);
}
.phase-heading {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
}
#phaseNumber {
display: grid;
place-items: center;
width: 28px;
height: 28px;
flex: 0 0 auto;
border-radius: 50%;
color: #071719;
background: var(--green);
font-weight: 900;
}
#phaseName {
font-size: 17px;
font-weight: 800;
letter-spacing: -.01em;
}
#narrative {
min-height: 76px;
margin: 0 0 16px;
color: #bed0c9;
font-size: 13px;
line-height: 1.55;
}
.section-title {
margin: 16px 0 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.metric {
margin: 11px 0;
}
.metric-row {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 5px;
font-size: 12px;
}
.metric-row strong {
font-variant-numeric: tabular-nums;
}
.track {
height: 7px;
overflow: hidden;
border-radius: 20px;
background: rgba(255,255,255,.08);
}
.fill {
height: 100%;
width: 0;
border-radius: inherit;
transition: width .08s linear;
}
#geoFill { background: var(--cyan); }
#riFill { background: var(--orange); }
#compatFill { background: var(--green); }
#geneFill { background: var(--gold); }
.population {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.population > div {
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,.035);
}
.population span {
display: block;
color: var(--muted);
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.population strong {
display: block;
margin-top: 3px;
font-size: 23px;
font-variant-numeric: tabular-nums;
}
.survivors {
margin-top: 9px;
padding: 10px 11px;
border: 1px solid rgba(255,209,102,.28);
border-radius: 11px;
color: #ffe4a7;
background: rgba(255,209,102,.07);
font-size: 12px;
}
.key {
margin-top: 15px;
padding: 12px;
border-left: 3px solid var(--cyan);
border-radius: 0 10px 10px 0;
background: rgba(103,213,255,.07);
color: #c7dcd5;
font-size: 11px;
line-height: 1.5;
}
.key b {
display: block;
margin-bottom: 3px;
color: var(--ink);
}
.transport {
position: fixed;
z-index: 7;
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 30px));
transform: translateX(-50%);
padding: 13px 15px 12px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(8, 23, 25, .9);
box-shadow: 0 18px 55px rgba(0,0,0,.38);
backdrop-filter: blur(14px);
}
.transport-top {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
}
#play {
min-width: 84px;
border-color: rgba(133,230,166,.35);
background: rgba(133,230,166,.12);
font-weight: 800;
}
.spacer { flex: 1; }
.minor {
padding: 7px 10px;
color: #c6d8d0;
font-size: 11px;
}
#timeline {
width: 100%;
accent-color: var(--gold);
cursor: pointer;
}
.phase-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 7px;
}
.phase-buttons button {
padding: 7px 5px;
color: var(--muted);
font-size: 10px;
text-align: center;
}
.phase-buttons button.active {
color: var(--ink);
border-color: rgba(255,209,102,.55);
background: rgba(255,209,102,.1);
}
.view-hint {
position: fixed;
z-index: 4;
left: 24px;
bottom: 24px;
color: rgba(224,241,233,.68);
font-size: 11px;
line-height: 1.5;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 4px;
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #0a1b1e;
color: var(--muted);
font-size: 13px;
letter-spacing: .12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
}
.brand .subtitle { display: none; }
.panel {
top: auto;
right: 10px;
bottom: 132px;
width: min(345px, calc(100vw - 20px));
max-height: 43vh;
padding: 13px;
}
#narrative { min-height: auto; }
.view-hint { display: none; }
.transport {
bottom: 8px;
width: calc(100vw - 16px);
padding: 10px;
}
.phase-buttons button {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene-wrap"></div>
<header class="brand">
<div class="eyebrow">Fictional speciation field study</div>
<h1>The Divided Grove</h1>
<p class="subtitle">
One habitat, two marked lineages, and a barrier that changes the rules of reproduction.
</p>
</header>
<aside class="panel" aria-label="Simulation measurements">
<div class="phase-heading">
<div id="phaseNumber">1</div>
<div id="phaseName">Shared habitat</div>
</div>
<p id="narrative" aria-live="polite"></p>
<div class="section-title">Population monitoring</div>
<div class="population">
<div>
<span>West grove</span>
<strong id="leftPop">13</strong>
</div>
<div>
<span>East grove</span>
<strong id="rightPop">11</strong>
</div>
</div>
<div class="survivors">◆ Tracked marked individuals alive: <b>6 / 6</b></div>
<div class="section-title">Isolation diagnostics</div>
<div class="metric">
<div class="metric-row">
<span>Geographic separation</span>
<strong id="geoValue">0%</strong>
</div>
<div class="track"><div class="fill" id="geoFill"></div></div>
</div>
<div class="metric">
<div class="metric-row">
<span>Reproductive isolation</span>
<strong id="riValue">0%</strong>
</div>
<div class="track"><div class="fill" id="riFill"></div></div>
</div>
<div class="metric">
<div class="metric-row">
<span>Common-garden compatibility</span>
<strong id="compatValue">100%</strong>
</div>
<div class="track"><div class="fill" id="compatFill"></div></div>
</div>
<div class="metric">
<div class="metric-row">
<span>Gene flow through habitat</span>
<strong id="geneValue">100%</strong>
</div>
<div class="track"><div class="fill" id="geneFill"></div></div>
</div>
<div class="key">
<b>Key distinction</b>
A barrier creates geographic separation. Reproductive isolation is demonstrated separately
when lineages fail to mate even after both receive equal access to the same test space.
</div>
<div class="section-title">Scene legend</div>
<div class="legend">
<span><i class="dot" style="background:#ffd166"></i>Tracked individual</span>
<span><i class="dot" style="background:#47d7c2"></i>Cool trait</span>
<span><i class="dot" style="background:#ff8f62"></i>Warm trait</span>
</div>
</aside>
<section class="transport" aria-label="Timeline controls">
<div class="transport-top">
<button id="play" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<div class="spacer"></div>
<button id="labels" class="minor" type="button">Hide labels</button>
<button id="resetView" class="minor" type="button">Reset view</button>
</div>
<input
id="timeline"
type="range"
min="0"
max="100"
step="0.1"
value="0"
aria-label="Simulation timeline"
>
<div class="phase-buttons">
<button type="button" data-time="8" class="active">1 · Shared</button>
<button type="button" data-time="32">2 · Barrier rises</button>
<button type="button" data-time="55">3 · Geography only</button>
<button type="button" data-time="88">4 · Reproductive</button>
</div>
</section>
<div class="view-hint">
Drag to orbit · Scroll to zoom · Arrow keys to move view<br>
The marked individuals remain present in both groves.
</div>
<div id="loading">Loading the divided grove…</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 sceneWrap = document.querySelector("#scene-wrap");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D habitat. Drag to orbit and scroll to zoom."
);
sceneWrap.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a1b1e);
scene.fog = new THREE.Fog(0x0a1b1e, 28, 58);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.1, 0.5);
let cameraTheta = 0.66;
let cameraPhi = 0.91;
let cameraRadius = 28;
function updateCamera() {
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xbcefe1, 0x23352d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6bd, 3.1);
sun.position.set(-9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x5ec9ff, 1.15);
rim.position.set(12, 7, -12);
scene.add(rim);
const coolColor = new THREE.Color(0x47d7c2);
const warmColor = new THREE.Color(0xff8f62);
const goldColor = new THREE.Color(0xffd166);
const labelSprites = [];
const tracked = [];
const population = [];
function clamp01(v) {
return Math.max(0, Math.min(1, v));
}
function smoothstep(a, b, x) {
const t = clamp01((x - a) / (b - a));
return t * t * (3 - 2 * t);
}
function seededRandom(seed) {
const x = Math.sin(seed * 127.1 + 311.7) * 43758.5453123;
return x - Math.floor(x);
}
function groundHeight(x, z) {
const broad = Math.sin(x * 0.52 + z * 0.19) * 0.15;
const fine = Math.cos(z * 0.91 - x * 0.23) * 0.11;
const centerLift = Math.min(Math.abs(x) / 13, 1) * 0.18;
return 0.12 + broad + fine + centerLift;
}
function makeLabel(text, color = "#ffd166", width = 2.0) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 72;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(7, 18, 19, 0.86)";
ctx.fillRect(0, 8, 320, 54);
ctx.strokeStyle = color;
ctx.lineWidth = 3;
ctx.strokeRect(2, 10, 316, 50);
ctx.fillStyle = color;
ctx.font = "700 30px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 160, 35);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.225, 1);
sprite.renderOrder = 10;
labelSprites.push(sprite);
return sprite;
}
function createTerrain(side) {
const x0 = side < 0 ? -13 : -0.9;
const x1 = side < 0 ? -0.9 : 13;
const z0 = -9;
const z1 = 9;
const nx = 8;
const nz = 6;
const positions = [];
const colors = [];
const base = new THREE.Color(side < 0 ? 0x668e67 : 0x72936b);
function pushTriangle(a, b, c, shade) {
const color = base.clone().multiplyScalar(shade);
for (const p of [a, b, c]) {
positions.push(p[0], p[1], p[2]);
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const xa = THREE.MathUtils.lerp(x0, x1, ix / nx);
const xb = THREE.MathUtils.lerp(x0, x1, (ix + 1) / nx);
const za = THREE.MathUtils.lerp(z0, z1, iz / nz);
const zb = THREE.MathUtils.lerp(z0, z1, (iz + 1) / nz);
const p00 = [xa, groundHeight(xa, za), za];
const p10 = [xb, groundHeight(xb, za), za];
const p11 = [xb, groundHeight(xb, zb), zb];
const p01 = [xa, groundHeight(xa, zb), zb];
const variation = 0.83 + seededRandom(ix * 19 + iz * 43 + side * 9) * 0.3;
pushTriangle(p00, p11, p10, variation);
pushTriangle(p00, p01, p11, variation * 0.96);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.95,
metalness: 0,
flatShading: true
});
const terrain = new THREE.Mesh(geometry, material);
terrain.receiveShadow = true;
scene.add(terrain);
const baseGeometry = new THREE.BoxGeometry(12.1, 1.5, 18);
const baseMaterial = new THREE.MeshStandardMaterial({
color: side < 0 ? 0x30493b : 0x354c3c,
roughness: 1,
flatShading: true
});
const baseMesh = new THREE.Mesh(baseGeometry, baseMaterial);
baseMesh.position.set(side < 0 ? -6.95 : 6.95, -0.75, 0);
baseMesh.receiveShadow = true;
scene.add(baseMesh);
}
createTerrain(-1);
createTerrain(1);
const trench = new THREE.Mesh(
new THREE.PlaneGeometry(1.7, 18),
new THREE.MeshStandardMaterial({
color: 0x246c72,
emissive: 0x0c292d,
emissiveIntensity: 0.65,
roughness: 0.28,
metalness: 0.15,
transparent: true,
opacity: 0.9
})
);
trench.rotation.x = -Math.PI / 2;
trench.position.y = -0.32;
trench.receiveShadow = true;
scene.add(trench);
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, groundHeight(x, z), z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.25, 1.7, 5),
new THREE.MeshStandardMaterial({
color: 0x6e5139,
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.85;
trunk.castShadow = true;
group.add(trunk);
const foliageMaterial = new THREE.MeshStandardMaterial({
color: 0x3f7255,
roughness: 0.95,
flatShading: true
});
const lower = new THREE.Mesh(
new THREE.ConeGeometry(1.05, 2.2, 6),
foliageMaterial
);
lower.position.y = 2.0;
lower.castShadow = true;
group.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.73, 1.75, 6),
foliageMaterial.clone()
);
upper.material.color.offsetHSL(0.015, 0.02, 0.07);
upper.position.y = 2.9;
upper.castShadow = true;
group.add(upper);
scene.add(group);
}
const treeLocations = [
[-11.3,-7.2], [-10.6,1.0], [-8.1,-6.8], [-6.4,6.4],
[-11.6,5.7], [-3.3,-6.6], [-3.5,7.0], [-12.0,-1.7],
[11.2,-7.1], [10.5,1.2], [8.2,-6.5], [6.4,6.3],
[11.5,5.8], [3.3,-6.7], [3.5,6.9], [12.0,-1.6]
];
treeLocations.forEach(([x, z], i) => {
createTree(x, z, 0.75 + seededRandom(i + 50) * 0.38);
});
function createRock(x, z, scale) {
const rock = new THREE.Mesh(
new THREE.IcosahedronGeometry(scale, 0),
new THREE.MeshStandardMaterial({
color: 0x78847a,
roughness: 1,
flatShading: true
})
);
rock.position.set(x, groundHeight(x, z) + scale * 0.35, z);
rock.scale.set(1.4, 0.7, 1);
rock.rotation.set(0.2, seededRandom(x * 9) * Math.PI, 0.1);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
[
[-9.2,-4.9,0.5], [-5.6,-1.5,0.32], [-2.6,3.3,0.42],
[-10.2,3.0,0.36], [-7.4,6.2,0.28],
[9.2,-4.8,0.48], [5.6,-1.4,0.34], [2.6,3.4,0.4],
[10.1,3.1,0.37], [7.4,6.3,0.3]
].forEach((r) => createRock(...r));
const westLabel = makeLabel("WEST GROVE", "#a8ddc5", 2.5);
westLabel.position.set(-7.8, 3.8, -8.0);
scene.add(westLabel);
const eastLabel = makeLabel("EAST GROVE", "#a8ddc5", 2.5);
eastLabel.position.set(7.8, 3.8, -8.0);
scene.add(eastLabel);
const barrierPanels = [];
function createBarrier() {
for (let i = 0; i < 10; i++) {
const z = -6.8 + i * 1.49;
const group = new THREE.Group();
const panelMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(
0.52,
0.13,
0.27 + (i % 3) * 0.035
),
roughness: 0.63,
metalness: 0.42,
flatShading: true
});
const panel = new THREE.Mesh(
new THREE.BoxGeometry(1.58, 1, 1.28),
panelMaterial
);
panel.castShadow = true;
panel.receiveShadow = true;
group.add(panel);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.78, 1.3),
new THREE.MeshStandardMaterial({
color: 0x67d5ff,
emissive: 0x2c9db8,
emissiveIntensity: 1.2,
roughness: 0.4
})
);
stripe.position.z = 0.03;
group.add(stripe);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(1.74, 0.1, 1.42),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x6c4c0c,
emissiveIntensity: 0.55,
roughness: 0.55
})
);
cap.position.y = 0.5;
group.add(cap);
group.position.z = z;
group.scale.y = 0.02;
scene.add(group);
barrierPanels.push({ group, factor: 0.92 + seededRandom(i * 7) * 0.16 });
}
}
createBarrier();
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x101a19,
roughness: 0.5
});
function createCreature(side, marked, id, home, scale = 1) {
const root = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x8dc9a5,
roughness: 0.82,
metalness: 0.02,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.55, 0),
bodyMaterial
);
body.scale.set(1.12, 0.82, 0.92);
body.position.y = 0.72;
body.castShadow = true;
root.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.34, 0),
bodyMaterial
);
head.position.set(0, 1.03, 0.31);
head.castShadow = true;
root.add(head);
const snout = new THREE.Mesh(
new THREE.ConeGeometry(0.17, 0.38, 5),
bodyMaterial
);
snout.rotation.x = Math.PI / 2;
snout.position.set(0, 0.96, 0.61);
root.add(snout);
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.17, 0.72, 5),
bodyMaterial
);
tail.rotation.x = -Math.PI / 2;
tail.position.set(0, 0.78, -0.67);
root.add(tail);
const legs = [];
for (const [lx, lz] of [
[-0.3,0.25], [0.3,0.25], [-0.3,-0.3], [0.3,-0.3]
]) {
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.1, 0.5, 4),
bodyMaterial
);
leg.position.set(lx, 0.27, lz);
leg.castShadow = true;
root.add(leg);
legs.push(leg);
}
for (const ex of [-0.14, 0.14]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 5, 4),
eyeMaterial
);
eye.position.set(ex, 1.11, 0.57);
root.add(eye);
}
let label = null;
if (marked) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.035, 4, 20),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x8a5a0b,
emissiveIntensity: 1.1,
roughness: 0.4
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.07;
root.add(ring);
label = makeLabel(id, "#ffd166", 1.85);
label.position.set(0, 1.95, 0);
root.add(label);
}
root.scale.setScalar(scale);
root.position.set(home[0], groundHeight(home[0], home[1]), home[1]);
scene.add(root);
return {
root,
bodyMaterial,
legs,
side,
marked,
id,
home,
label,
seed: seededRandom((side + 2) * 100 + id.length * 13 + home[0]),
baseScale: scale
};
}
const markedHomes = {
left: [
[-6.9,-4.3],
[-4.8,1.1],
[-8.4,5.1]
],
right: [
[6.8,-3.8],
[4.8,1.4],
[8.4,5.0]
]
};
["L-01", "L-02", "L-03"].forEach((id, i) => {
tracked.push(createCreature(-1, true, id, markedHomes.left[i], 1));
});
["R-01", "R-02", "R-03"].forEach((id, i) => {
tracked.push(createCreature(1, true, id, markedHomes.right[i], 1));
});
function randomHome(side, index) {
const seed = side * 77 + index * 19;
let x = side * (2.0 + seededRandom(seed) * 9.4);
let z = -7.4 + seededRandom(seed + 8) * 14.8;
return [x, z];
}
for (let i = 0; i < 10; i++) {
population.push(createCreature(-1, false, `W${i}`, randomHome(-1, i), 0.78));
}
for (let i = 0; i < 8; i++) {
population.push(createCreature(1, false, `E${i}`, randomHome(1, i), 0.78));
}
const allCreatures = [...tracked, ...population];
// Common-garden test platform lies beyond the barrier. The specimens are
// transported there, so mating failure cannot be blamed on the wall.
const testPlatform = new THREE.Mesh(
new THREE.CylinderGeometry(1.4, 1.6, 0.34, 8),
new THREE.MeshStandardMaterial({
color: 0x243d3c,
roughness: 0.64,
metalness: 0.25,
flatShading: true
})
);
testPlatform.position.set(0, 0.15, 8.25);
testPlatform.receiveShadow = true;
scene.add(testPlatform);
const testRing = new THREE.Mesh(
new THREE.TorusGeometry(1.52, 0.04, 4, 32),
new THREE.MeshStandardMaterial({
color: 0x85e6a6,
emissive: 0x2a7b48,
emissiveIntensity: 0.85
})
);
testRing.rotation.x = Math.PI / 2;
testRing.position.set(0, 0.34, 8.25);
scene.add(testRing);
const testWest = createCreature(-1, false, "TEST-W", [-0.42, 8.25], 0.58);
const testEast = createCreature(1, false, "TEST-E", [0.42, 8.25], 0.58);
const testLabel = makeLabel("COMMON-GARDEN TEST", "#a8ddc5", 3.25);
testLabel.position.set(0, 2.8, 8.25);
scene.add(testLabel);
const linkGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.42, 1.15, 8.25),
new THREE.Vector3(0.42, 1.15, 8.25)
]);
const linkMaterial = new THREE.LineDashedMaterial({
color: 0x85e6a6,
dashSize: 0.25,
gapSize: 0.12,
linewidth: 2
});
const link = new THREE.Line(linkGeometry, linkMaterial);
link.computeLineDistances();
scene.add(link);
// Moving gene-flow particles show the early open habitat. Once the wall
// reaches their height, they reverse direction rather than crossing it.
const flowParticles = [];
const flowGeometry = new THREE.SphereGeometry(0.075, 5, 4);
for (let i = 0; i < 34; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0xffe59b,
emissive: 0xb58b24,
emissiveIntensity: 1.2,
transparent: true,
opacity: 0.9,
roughness: 0.5
});
const particle = new THREE.Mesh(flowGeometry, material);
particle.position.set(
-12 + seededRandom(i * 3) * 24,
0.35 + seededRandom(i * 5) * 5.4,
-6.8 + seededRandom(i * 7) * 13.6
);
particle.userData.direction = i % 2 === 0 ? 1 : -1;
particle.userData.speed = 2.2 + seededRandom(i * 11) * 2.4;
scene.add(particle);
flowParticles.push(particle);
}
const pollenGeometry = new THREE.BufferGeometry();
const pollenPositions = [];
for (let i = 0; i < 150; i++) {
pollenPositions.push(
(seededRandom(i * 2) - 0.5) * 27,
1 + seededRandom(i * 3) * 9,
(seededRandom(i * 5) - 0.5) * 19
);
}
pollenGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(pollenPositions, 3)
);
const pollen = new THREE.Points(
pollenGeometry,
new THREE.PointsMaterial({
color: 0xe9f7c6,
size: 0.055,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(pollen);
let timeline = 0;
let playing = true;
let labelsVisible = true;
const timelineInput = document.querySelector("#timeline");
const playButton = document.querySelector("#play");
const labelsButton = document.querySelector("#labels");
const phaseButtons = [...document.querySelectorAll(".phase-buttons button")];
const phaseNumber = document.querySelector("#phaseNumber");
const phaseName = document.querySelector("#phaseName");
const narrative = document.querySelector("#narrative");
const phases = [
{
end: 20,
name: "Shared habitat",
text: "One continuous grove supports both marked groups. Gene flow is high, and the lineages readily interbreed."
},
{
end: 45,
name: "The barrier rises",
text: "A physical wall is rising. Movement and gene flow are being reduced, but biological compatibility has not yet changed."
},
{
end: 65,
name: "Geographic isolation only",
text: "The barrier is complete, yet a common-garden test still succeeds. The lineages are separated geographically, not reproductively."
},
{
end: 101,
name: "Reproductive isolation develops",
text: "Divergent traits and genetic drift now reduce mating success even when both lineages are given equal access to the same test space."
}
];
function getPhase(t) {
if (t < 20) return phases[0];
if (t < 45) return phases[1];
if (t < 65) return phases[2];
return phases[3];
}
function setText(id, value) {
document.querySelector(id).textContent = value;
}
function updateUI() {
const phase = getPhase(timeline);
const phaseIndex = phases.indexOf(phase) + 1;
const geographic = smoothstep(15, 45, timeline) * 100;
const reproductive = smoothstep(65, 100, timeline) * 88;
const compatibility = 100 - reproductive;
const geneFlow = (1 - smoothstep(18, 45, timeline)) * 100;
phaseNumber.textContent = phaseIndex;
phaseName.textContent = phase.name;
narrative.textContent = phase.text;
setText("#geoValue", `${Math.round(geographic)}%`);
setText("#riValue", `${Math.round(reproductive)}%`);
setText("#compatValue", `${Math.round(compatibility)}%`);
setText("#geneValue", `${Math.round(geneFlow)}%`);
document.querySelector("#geoFill").style.width = `${geographic}%`;
document.querySelector("#riFill").style.width = `${reproductive}%`;
document.querySelector("#compatFill").style.width = `${compatibility}%`;
document.querySelector("#geneFill").style.width = `${geneFlow}%`;
timelineInput.value = timeline.toFixed(1);
phaseButtons.forEach((button, i) => {
button.classList.toggle("active", i === phaseIndex - 1);
});
}
function traitForSide(side, reproductiveProgress) {
if (side < 0) {
return 0.43 + reproductiveProgress * 0.45;
}
return 0.43 - reproductiveProgress * 0.34;
}
function updateCreature(creature, time, reproductiveProgress) {
const trait = traitForSide(creature.side, reproductiveProgress);
const color = coolColor.clone().lerp(warmColor, trait);
creature.bodyMaterial.color.copy(color);
const speed = creature.marked ? 0.32 : 0.65;
const phase = time * speed + creature.seed * 30;
const wanderX = Math.sin(phase) * (creature.marked ? 0.16 : 0.48);
const wanderZ = Math.cos(phase * 0.73) * (creature.marked ? 0.12 : 0.42);
const x = creature.home[0] + wanderX;
const z = creature.home[1] + wanderZ;
creature.root.position.x = x;
creature.root.position.z = z;
creature.root.position.y =
groundHeight(x, z) + Math.sin(time * 2.2 + creature.seed * 20) * 0.035;
creature.root.rotation.y =
Math.sin(phase * 0.52) * 0.8 + (creature.side < 0 ? -0.2 : 0.2);
creature.legs.forEach((leg, i) => {
leg.rotation.x = Math.sin(time * 3.2 + i * Math.PI + creature.seed * 10) * 0.11;
});
}
function updateScene(time, elapsed) {
const reproductiveProgress = smoothstep(65, 100, timeline);
const barrierProgress = smoothstep(18, 45, timeline);
const barrierHeight = barrierProgress * 6.15;
barrierPanels.forEach(({ group, factor }) => {
const height = Math.max(0.025, barrierHeight * factor);
group.scale.y = height;
group.position.y = -1 + height * 0.5;
});
allCreatures.forEach((creature) => {
updateCreature(creature, elapsed, reproductiveProgress);
});
const separation = smoothstep(65, 100, timeline);
const compatibility = 100 - reproductiveProgress * 88;
testWest.root.position.x = -0.43 - separation * 0.67;
testEast.root.position.x = 0.43 + separation * 0.67;
testWest.root.rotation.y = Math.PI / 2 + separation * 0.65;
testEast.root.rotation.y = -Math.PI / 2 - separation * 0.65;
const westTrait = traitForSide(-1, reproductiveProgress);
const eastTrait = traitForSide(1, reproductiveProgress);
testWest.bodyMaterial.color.copy(coolColor.clone().lerp(warmColor, westTrait));
testEast.bodyMaterial.color.copy(coolColor.clone().lerp(warmColor, eastTrait));
const linkPositions = linkGeometry.attributes.position;
linkPositions.setXYZ(
0,
testWest.root.position.x,
1.16,
testWest.root.position.z
);
linkPositions.setXYZ(
1,
testEast.root.position.x,
1.16,
testEast.root.position.z
);
linkPositions.needsUpdate = true;
link.computeLineDistances();
if (compatibility > 70) {
linkMaterial.color.set(0x85e6a6);
linkMaterial.dashSize = 0.4;
linkMaterial.gapSize = 0.02;
testRing.material.color.set(0x85e6a6);
} else if (compatibility > 40) {
linkMaterial.color.set(0xffd166);
linkMaterial.dashSize = 0.25;
linkMaterial.gapSize = 0.12;
testRing.material.color.set(0xffd166);
} else {
linkMaterial.color.set(0xff765f);
linkMaterial.dashSize = 0.18;
linkMaterial.gapSize = 0.16;
testRing.material.color.set(0xff765f);
}
flowParticles.forEach((particle, i) => {
const previousX = particle.position.x;
particle.position.x +=
particle.userData.direction * particle.userData.speed * 0.016;
const crossedCenter =
previousX * particle.position.x <= 0 &&
Math.abs(previousX) > 0.001;
if (crossedCenter && particle.position.y < barrierHeight + 0.08) {
particle.position.x = previousX;
particle.userData.direction *= -1;
}
if (particle.position.x > 13.2) particle.position.x = -13.2;
if (particle.position.x < -13.2) particle.position.x = 13.2;
particle.material.opacity =
0.12 + 0.88 * (1 - barrierProgress);
particle.position.y +=
Math.sin(elapsed * 1.4 + i) * 0.0008;
});
pollen.rotation.y = elapsed * 0.012;
pollen.position.y = Math.sin(elapsed * 0.35) * 0.15;
updateUI();
}
playButton.addEventListener("click", () => {
if (timeline >= 100) timeline = 0;
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
document.querySelector("#restart").addEventListener("click", () => {
timeline = 0;
playing = true;
playButton.textContent = "Pause";
});
timelineInput.addEventListener("input", (event) => {
timeline = Number(event.target.value);
playing = false;
playButton.textContent = "Play";
});
phaseButtons.forEach((button) => {
button.addEventListener("click", () => {
timeline = Number(button.dataset.time);
playing = false;
playButton.textContent = "Play";
});
});
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelSprites.forEach((sprite) => {
sprite.visible = labelsVisible;
});
labelsButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
document.querySelector("#resetView").addEventListener("click", resetView);
function resetView() {
cameraTheta = 0.66;
cameraPhi = 0.91;
cameraRadius = 28;
cameraTarget.set(0, 1.1, 0.5);
updateCamera();
}
// Camera controls are implemented directly here; no addons are used.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraTheta -= dx * 0.005;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.004, 0.34, 1.36);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
15,
45
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") cameraTheta += 0.08;
else if (event.key === "ArrowRight") cameraTheta -= 0.08;
else if (event.key === "ArrowUp") cameraPhi -= 0.06;
else if (event.key === "ArrowDown") cameraPhi += 0.06;
else if (event.key === "+" || event.key === "=") cameraRadius -= 1;
else if (event.key === "-") cameraRadius += 1;
else return;
cameraPhi = THREE.MathUtils.clamp(cameraPhi, 0.34, 1.36);
cameraRadius = THREE.MathUtils.clamp(cameraRadius, 15, 45);
updateCamera();
event.preventDefault();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
if (playing) {
timeline = Math.min(100, timeline + dt * 1.75);
if (timeline >= 100) {
playing = false;
playButton.textContent = "Replay";
}
}
updateScene(timeline, elapsed);
renderer.render(scene, camera);
}
updateScene(timeline, elapsed);
loading.style.display = "none";
animate();
</script>
</body>
</html>
```