Prompt specification
Build or customize the Three.js 3D scene "Plasticity versus inheritance teaching 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: Plasticity versus inheritance teaching model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plasticity-versus-inheritance-teaching-model-x0944
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows phenotypic plasticity. Toggle environment within one generation and hereditary variants across generations in separate panels; keep the two mechanisms visually distinct using matched fictional plants. Low-poly.
Working Three.js Starter (plasticity-versus-inheritance-teaching-model-x0944):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Phenotypic Plasticity vs. Heritable Variation</title>
<style>
:root {
--ink: #203a33;
--muted: #6d786f;
--paper: #f3f0e7;
--card: #fffdf7;
--line: #d9d6c9;
--plasticity: #197b6d;
--plasticity-soft: #dceee7;
--heredity: #b45b38;
--heredity-soft: #f3e2d6;
--shadow: 0 16px 40px rgba(50, 61, 49, 0.08);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
color: var(--ink);
background:
radial-gradient(circle at 10% 0%, rgba(255, 255, 255, 0.9), transparent 28rem),
var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
width: min(1480px, 100%);
margin: 0 auto;
padding: 28px 28px 22px;
}
.masthead {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 28px;
margin-bottom: 24px;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 220px;
}
.brand-mark {
width: 44px;
height: 44px;
display: grid;
place-items: center;
color: white;
background: var(--ink);
border-radius: 13px;
box-shadow: 0 8px 18px rgba(32, 58, 51, 0.16);
}
.brand-mark svg {
width: 27px;
height: 27px;
}
.brand strong {
display: block;
font-size: 15px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.brand span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 12px;
}
.intro {
text-align: center;
}
.eyebrow {
margin: 0 0 5px;
color: var(--plasticity);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 42px);
font-weight: 500;
letter-spacing: -0.035em;
}
.species {
min-width: 220px;
text-align: right;
}
.species span {
display: block;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.species strong {
display: block;
margin-top: 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-style: italic;
font-weight: 500;
}
.panels {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 22px;
}
.panel {
--accent: var(--plasticity);
--accent-soft: var(--plasticity-soft);
overflow: hidden;
background: var(--card);
border: 1px solid var(--line);
border-radius: 24px;
box-shadow: var(--shadow);
}
.panel.heredity {
--accent: var(--heredity);
--accent-soft: var(--heredity-soft);
}
.panel-header {
display: grid;
grid-template-columns: auto 1fr;
gap: 15px;
padding: 23px 24px 18px;
}
.panel-number {
width: 38px;
height: 38px;
display: grid;
place-items: center;
color: var(--accent);
background: var(--accent-soft);
border-radius: 12px;
font-size: 13px;
font-weight: 850;
}
.panel-header h2 {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
letter-spacing: -0.025em;
}
.panel-header p {
max-width: 590px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.mechanism {
display: flex;
align-items: center;
gap: 9px;
margin-top: 11px;
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.095em;
text-transform: uppercase;
}
.mechanism::before {
content: "";
width: 18px;
height: 3px;
background: currentColor;
border-radius: 999px;
}
.scene-shell {
position: relative;
height: 440px;
overflow: hidden;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
background: #e9eee2;
}
.viewport {
position: absolute;
inset: 0;
overflow: hidden;
}
.viewport canvas {
position: absolute;
inset: 0;
z-index: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
.viewport canvas:active {
cursor: grabbing;
}
.scene-overlay {
position: absolute;
z-index: 2;
pointer-events: none;
}
.scene-chip {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
color: #31443b;
background: rgba(255, 253, 247, 0.83);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
box-shadow: 0 5px 18px rgba(44, 60, 50, 0.08);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.scene-chip.top-left {
top: 15px;
left: 15px;
}
.scene-chip.bottom-left {
bottom: 15px;
left: 15px;
}
.chip-dot {
width: 7px;
height: 7px;
background: var(--accent);
border-radius: 50%;
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}
.reset-camera {
position: absolute;
right: 15px;
bottom: 15px;
z-index: 3;
width: 35px;
height: 35px;
display: grid;
place-items: center;
color: #53645b;
background: rgba(255, 253, 247, 0.84);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 50%;
box-shadow: 0 5px 18px rgba(44, 60, 50, 0.08);
cursor: pointer;
backdrop-filter: blur(8px);
}
.reset-camera:hover {
color: var(--accent);
background: white;
}
.reset-camera svg {
width: 17px;
height: 17px;
}
.controls {
padding: 20px 24px 22px;
}
.control-label {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
margin-bottom: 9px;
}
.control-label span {
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control-label small {
color: var(--muted);
font-size: 11px;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
padding: 4px;
background: #ece9df;
border-radius: 13px;
}
.segmented.two {
grid-template-columns: repeat(2, 1fr);
}
.segmented button {
min-height: 42px;
color: #647169;
background: transparent;
border: 0;
border-radius: 10px;
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.segmented button:hover {
color: var(--ink);
background: rgba(255, 255, 255, 0.52);
}
.segmented button.active {
color: var(--accent);
background: white;
box-shadow: 0 3px 10px rgba(47, 61, 51, 0.09);
}
.traits {
display: grid;
gap: 8px;
margin-top: 17px;
}
.trait {
display: grid;
grid-template-columns: 82px 1fr 40px;
align-items: center;
gap: 10px;
font-size: 11px;
}
.trait-name {
color: #4c5e54;
font-weight: 700;
}
.meter {
height: 6px;
overflow: hidden;
background: #e8e6dc;
border-radius: 99px;
}
.meter i {
display: block;
width: 50%;
height: 100%;
background: var(--accent);
border-radius: inherit;
transition: width 300ms ease, background 200ms ease;
}
.trait output {
color: var(--accent);
text-align: right;
font-size: 10px;
font-weight: 850;
}
.explanation {
display: flex;
align-items: flex-start;
gap: 11px;
margin-top: 17px;
padding: 13px 14px;
color: #53645b;
background: var(--accent-soft);
border-radius: 13px;
font-size: 12px;
line-height: 1.5;
}
.explanation svg {
flex: 0 0 auto;
width: 18px;
height: 18px;
margin-top: 1px;
color: var(--accent);
}
.lineage-section {
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.lineage-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-bottom: 13px;
}
.lineage-header strong {
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.lineage-header span {
color: var(--muted);
font-size: 11px;
}
.lineage {
display: flex;
align-items: center;
justify-content: space-between;
gap: 4px;
}
.generation {
position: relative;
width: 51px;
height: 51px;
display: grid;
place-items: center;
color: #89928b;
background: #eceae1;
border: 2px solid transparent;
border-radius: 50%;
font-size: 11px;
font-weight: 850;
}
.generation small {
position: absolute;
bottom: -16px;
left: 50%;
color: #89928b;
transform: translateX(-50%);
font-size: 8px;
letter-spacing: 0.03em;
}
.generation.reached {
color: var(--heredity);
background: var(--heredity-soft);
}
.generation.reached small {
color: var(--heredity);
}
.generation.active {
color: white;
background: var(--heredity);
border-color: var(--heredity);
box-shadow: 0 0 0 5px var(--heredity-soft);
}
.generation.active small {
color: var(--heredity);
}
.generation-line {
flex: 1;
height: 2px;
margin: 0 3px 16px;
background: #dfddd3;
}
.generation-line.reached {
background: var(--heredity);
}
.breed-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 31px;
}
.breed-button {
flex: 1;
min-height: 42px;
color: white;
background: var(--heredity);
border: 0;
border-radius: 11px;
cursor: pointer;
font-size: 12px;
font-weight: 800;
box-shadow: 0 7px 16px rgba(180, 91, 56, 0.16);
transition: transform 150ms ease, filter 150ms ease;
}
.breed-button:hover {
filter: brightness(1.06);
transform: translateY(-1px);
}
.breed-button:active {
transform: translateY(0);
}
.inheritance-note {
flex: 1.5;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.toast {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 20;
max-width: calc(100% - 30px);
padding: 11px 16px;
color: white;
background: #263c34;
border-radius: 999px;
box-shadow: 0 10px 30px rgba(22, 38, 31, 0.22);
font-size: 12px;
font-weight: 700;
opacity: 0;
transform: translate(-50%, 12px);
pointer-events: none;
transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.footer {
display: flex;
justify-content: space-between;
gap: 20px;
margin-top: 18px;
color: #778078;
font-size: 11px;
line-height: 1.5;
}
.footer strong {
color: #526158;
}
@media (max-width: 980px) {
.masthead {
grid-template-columns: auto 1fr;
}
.intro {
grid-column: 1 / -1;
grid-row: 2;
}
.species {
text-align: right;
}
.panels {
grid-template-columns: 1fr;
}
.scene-shell {
height: 480px;
}
}
@media (max-width: 620px) {
.app {
padding: 16px 12px;
}
.masthead {
gap: 12px;
margin-bottom: 17px;
}
.brand {
min-width: 0;
}
.brand span,
.species {
display: none;
}
.panel {
border-radius: 19px;
}
.panel-header {
padding: 19px 17px 16px;
}
.panel-header h2 {
font-size: 21px;
}
.scene-shell {
height: 390px;
}
.controls {
padding: 17px;
}
.trait {
grid-template-columns: 74px 1fr 38px;
}
.breed-row {
align-items: stretch;
flex-direction: column;
}
.inheritance-note {
min-height: 30px;
}
.footer {
flex-direction: column;
gap: 5px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="masthead">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M16 27V13" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/>
<path d="M16 17C10 17 6 13 6 7c6 0 10 3 10 10Z" fill="currentColor" opacity=".9"/>
<path d="M16 22c6 0 10-4 10-10-6 0-10 3-10 10Z" fill="currentColor" opacity=".55"/>
</svg>
</div>
<div>
<strong>Plant Lab</strong>
<span>Interactive adaptation study</span>
</div>
</div>
<div class="intro">
<p class="eyebrow">One species · two evolutionary mechanisms</p>
<h1>How does a plant change?</h1>
</div>
<div class="species">
<span>Matched fictional species</span>
<strong>Luma mirabilis</strong>
</div>
</header>
<main class="panels">
<!-- PHENOTYPIC PLASTICITY PANEL -->
<section class="panel plasticity" aria-labelledby="plasticity-title">
<div class="panel-header">
<div class="panel-number">01</div>
<div>
<h2 id="plasticity-title">Phenotypic plasticity</h2>
<p>
The genotype stays fixed while the environment changes during a single
generation. Watch the same plant reshape and recolor.
</p>
<div class="mechanism">Environment changes · DNA unchanged</div>
</div>
</div>
<div class="scene-shell">
<div id="plasticityViewport" class="viewport" aria-label="Interactive low-poly plant in changing environments">
<div class="scene-overlay top-left">
<div class="scene-chip">
<span class="chip-dot"></span>
<span>Genotype <b id="leftAllele">A / A</b> · fixed</span>
</div>
</div>
<div class="scene-overlay bottom-left">
<div class="scene-chip" id="environmentChip">Environment · moderate soil</div>
</div>
<button class="reset-camera" data-reset="plasticityViewport" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 8V4m0 0h4M4 4l4.3 4.3A7 7 0 1 1 6 15" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
<div class="controls">
<div class="control-label">
<span>Environment</span>
<small>Changes within one generation</small>
</div>
<div class="segmented" id="environmentControls" role="group" aria-label="Plant environment">
<button type="button" data-environment="dry" aria-pressed="false">☀ Dry soil</button>
<button type="button" data-environment="moderate" class="active" aria-pressed="true">◐ Moderate</button>
<button type="button" data-environment="wet" aria-pressed="false">💧 Wet soil</button>
</div>
<div class="traits" aria-label="Observed plant traits">
<div class="trait">
<span class="trait-name">Stem height</span>
<span class="meter"><i id="leftStemMeter"></i></span>
<output id="leftStemValue">100%</output>
</div>
<div class="trait">
<span class="trait-name">Leaf spread</span>
<span class="meter"><i id="leftLeafMeter"></i></span>
<output id="leftLeafValue">100%</output>
</div>
<div class="trait">
<span class="trait-name">Bloom size</span>
<span class="meter"><i id="leftBloomMeter"></i></span>
<output id="leftBloomValue">100%</output>
</div>
</div>
<div class="explanation">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M7 10V8a5 5 0 0 1 10 0v2M6 10h12v10H6V10Z" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
</svg>
<span>
These are reversible <strong>phenotypic responses</strong>, not mutations.
The plant adjusts its form to moisture conditions without changing its alleles.
</span>
</div>
</div>
</section>
<!-- HEREDITARY VARIATION PANEL -->
<section class="panel heredity" aria-labelledby="heredity-title">
<div class="panel-header">
<div class="panel-number">02</div>
<div>
<h2 id="heredity-title">Heritable variation</h2>
<p>
A different allele changes the plant’s form. Breed it forward and the
offspring inherit the trait across generations.
</p>
<div class="mechanism">Alleles change · traits are inherited</div>
</div>
</div>
<div class="scene-shell">
<div id="heredityViewport" class="viewport" aria-label="Interactive low-poly plant with inherited variants">
<div class="scene-overlay top-left">
<div class="scene-chip">
<span class="chip-dot"></span>
<span id="rightAllele">A / A · generation 1</span>
</div>
</div>
<div class="scene-overlay bottom-left">
<div class="scene-chip">Environment · constant</div>
</div>
<button class="reset-camera" data-reset="heredityViewport" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 8V4m0 0h4M4 4l4.3 4.3A7 7 0 1 1 6 15" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
<div class="controls">
<div class="control-label">
<span>Parent variant</span>
<small>Toggle a heritable allele</small>
</div>
<div class="segmented two" id="variantControls" role="group" aria-label="Heritable plant variant">
<button type="button" data-variant="wild" class="active" aria-pressed="true">A / A · Wild leaf</button>
<button type="button" data-variant="copper" aria-pressed="false">Aᶜ / A · Copper leaf</button>
</div>
<div class="traits" aria-label="Inherited plant traits">
<div class="trait">
<span class="trait-name">Stem height</span>
<span class="meter"><i id="rightStemMeter"></i></span>
<output id="rightStemValue">100%</output>
</div>
<div class="trait">
<span class="trait-name">Leaf spread</span>
<span class="meter"><i id="rightLeafMeter"></i></span>
<output id="rightLeafValue">100%</output>
</div>
<div class="trait">
<span class="trait-name">Bloom size</span>
<span class="meter"><i id="rightBloomMeter"></i></span>
<output id="rightBloomValue">100%</output>
</div>
</div>
<div class="lineage-section">
<div class="lineage-header">
<strong>Generation trail</strong>
<span id="lineageStatus">Founder generation</span>
</div>
<div class="lineage" id="lineage"></div>
</div>
<div class="breed-row">
<button type="button" class="breed-button" id="breedButton">Breed generation 2 →</button>
<div class="inheritance-note" id="inheritanceNote">
Toggle a parent variant, then breed the next generation.
</div>
</div>
<div class="explanation">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M8 3c8 1 9 8 8 15M16 3C8 4 7 11 8 18M5 8c4 0 7 2 9 5m5-5c-4 0-7 2-9 5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
<span>
The copper allele creates narrower leaves and a rust-colored bloom.
Once bred, the offspring receive that allele rather than a temporary
environmental response.
</span>
</div>
</div>
</section>
</main>
<footer class="footer">
<span><strong>Interaction:</strong> drag to orbit · scroll or pinch to zoom · use the reset button to recenter.</span>
<span><strong>Note:</strong> Luma mirabilis is fictional; allele notation and trait values are illustrative.</span>
</footer>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const COLOR = {
paper: 0xfffdf7,
ink: 0x203a33,
plasticity: 0x197b6d,
heredity: 0xb45b38
};
const ENVIRONMENT_PROFILES = {
dry: {
label: "dry soil",
height: 0.82,
spread: 0.62,
bloom: 0.72,
leaf: 0x7d8958,
flower: 0xd79a55,
stem: 0x5e7347,
ground: 0xb78e62,
background: 0xeadfc9,
moisture: 0.08
},
moderate: {
label: "moderate soil",
height: 1.0,
spread: 1.0,
bloom: 1.0,
leaf: 0x4f915f,
flower: 0xe6c761,
stem: 0x477a50,
ground: 0x789568,
background: 0xe9eee2,
moisture: 0.42
},
wet: {
label: "wet soil",
height: 1.12,
spread: 1.25,
bloom: 1.14,
leaf: 0x287a52,
flower: 0xf0838c,
stem: 0x246849,
ground: 0x4f8063,
background: 0xdcebe5,
moisture: 1.0
}
};
const VARIANT_PROFILES = {
wild: {
allele: "A / A",
compact: "AA",
height: 1.0,
spread: 1.0,
bloom: 1.0,
leaf: 0x4f915f,
flower: 0xe6c761,
stem: 0x477a50,
copper: 0
},
copper: {
allele: "Aᶜ / A",
compact: "AᶜA",
height: 1.06,
spread: 0.82,
bloom: 0.90,
leaf: 0x886b45,
flower: 0xc9693e,
stem: 0x785437,
copper: 1
}
};
function createLeafGeometry() {
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array([
0.00, 0.00, 0.72, // tip
0.00, 0.00, -0.55, // base
-0.32, 0.00, 0.02, // left
0.32, 0.00, 0.02, // right
0.00, 0.13, 0.05, // upper ridge
0.00, -0.07, 0.00 // lower ridge
]);
const indices = [
0, 2, 4,
0, 4, 3,
1, 3, 4,
1, 4, 2,
0, 5, 2,
0, 3, 5,
1, 2, 5,
1, 5, 3
];
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
class LowPolyPlant {
constructor(scene) {
this.group = new THREE.Group();
this.group.name = "Luma mirabilis";
this.stemMaterial = new THREE.MeshStandardMaterial({
color: 0x477a50,
roughness: 0.9,
metalness: 0,
flatShading: true
});
this.leafMaterial = new THREE.MeshStandardMaterial({
color: 0x4f915f,
roughness: 0.86,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
});
this.flowerMaterial = new THREE.MeshStandardMaterial({
color: 0xe6c761,
roughness: 0.78,
metalness: 0,
flatShading: true
});
this.centerMaterial = new THREE.MeshStandardMaterial({
color: 0x9c6c2f,
roughness: 0.88,
flatShading: true
});
this.copperMaterial = new THREE.MeshStandardMaterial({
color: 0xa95032,
roughness: 0.8,
flatShading: true
});
this.stemSegments = [];
const stemGeometry = new THREE.CylinderGeometry(0.055, 0.095, 1, 5, 1, false);
[
{ y: 0.38, h: 0.76 },
{ y: 0.96, h: 0.61 },
{ y: 1.40, h: 0.34 }
].forEach((segment) => {
const mesh = new THREE.Mesh(stemGeometry, this.stemMaterial);
mesh.position.y = segment.y;
mesh.scale.y = segment.h;
mesh.castShadow = true;
mesh.receiveShadow = true;
this.group.add(mesh);
this.stemSegments.push({ mesh, y: segment.y, h: segment.h });
});
this.leaves = [];
const leafGeometry = createLeafGeometry();
const leafData = [
{ y: 0.34, side: 1, angle: 1.06, pitch: -0.22, width: 1.00 },
{ y: 0.50, side: -1, angle: 1.13, pitch: 0.12, width: 0.95 },
{ y: 0.67, side: 1, angle: 1.04, pitch: -0.12, width: 0.86 },
{ y: 0.80, side: -1, angle: 0.98, pitch: 0.18, width: 0.75 },
{ y: 0.92, side: 1, angle: 0.88, pitch: -0.10, width: 0.62 },
{ y: 1.03, side: -1, angle: 0.80, pitch: 0.13, width: 0.52 }
];
leafData.forEach((data, index) => {
const pivot = new THREE.Group();
pivot.position.y = data.y;
pivot.rotation.x = data.pitch;
const leaf = new THREE.Mesh(leafGeometry, this.leafMaterial);
leaf.castShadow = true;
leaf.receiveShadow = true;
pivot.add(leaf);
this.group.add(pivot);
this.leaves.push({ pivot, leaf, data, phase: index * 0.73 });
});
this.flower = new THREE.Group();
this.flower.position.y = 1.54;
this.flower.rotation.x = -0.08;
const petalGeometry = new THREE.TetrahedronGeometry(0.23, 0);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = new THREE.Mesh(petalGeometry, this.flowerMaterial);
petal.position.set(
Math.sin(angle) * 0.19,
0,
Math.cos(angle) * 0.19
);
petal.rotation.y = angle;
petal.scale.set(0.78, 0.34, 1.45);
petal.castShadow = true;
this.flower.add(petal);
}
const center = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 0),
this.centerMaterial
);
center.position.y = 0.035;
center.castShadow = true;
this.flower.add(center);
this.group.add(this.flower);
this.copperMarks = new THREE.Group();
for (let i = 0; i < 3; i++) {
const angle = (i / 3) * Math.PI * 2;
const spike = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.29, 4),
this.copperMaterial
);
spike.position.set(
Math.sin(angle) * 0.14,
1.30 + i * 0.055,
Math.cos(angle) * 0.14
);
spike.rotation.z = Math.sin(angle) * 0.35;
spike.rotation.x = Math.cos(angle) * 0.35;
spike.castShadow = true;
this.copperMarks.add(spike);
}
this.copperMarks.scale.setScalar(0.001);
this.group.add(this.copperMarks);
this.current = {
height: 1,
spread: 1,
bloom: 1,
copper: 0,
leaf: new THREE.Color(ENVIRONMENT_PROFILES.moderate.leaf),
flower: new THREE.Color(ENVIRONMENT_PROFILES.moderate.flower),
stem: new THREE.Color(ENVIRONMENT_PROFILES.moderate.stem)
};
this.target = {
height: 1,
spread: 1,
bloom: 1,
copper: 0,
leaf: new THREE.Color(ENVIRONMENT_PROFILES.moderate.leaf),
flower: new THREE.Color(ENVIRONMENT_PROFILES.moderate.flower),
stem: new THREE.Color(ENVIRONMENT_PROFILES.moderate.stem)
};
scene.add(this.group);
}
setProfile(profile) {
this.target.height = profile.height;
this.target.spread = profile.spread;
this.target.bloom = profile.bloom;
this.target.copper = profile.copper ?? 0;
this.target.leaf.set(profile.leaf);
this.target.flower.set(profile.flower);
this.target.stem.set(profile.stem);
}
update(delta, elapsed) {
const smoothing = 1 - Math.exp(-delta * 5.0);
this.current.height = THREE.MathUtils.lerp(
this.current.height, this.target.height, smoothing
);
this.current.spread = THREE.MathUtils.lerp(
this.current.spread, this.target.spread, smoothing
);
this.current.bloom = THREE.MathUtils.lerp(
this.current.bloom, this.target.bloom, smoothing
);
this.current.copper = THREE.MathUtils.lerp(
this.current.copper, this.target.copper, smoothing
);
this.current.leaf.lerp(this.target.leaf, smoothing);
this.current.flower.lerp(this.target.flower, smoothing);
this.current.stem.lerp(this.target.stem, smoothing);
this.stemMaterial.color.copy(this.current.stem);
this.leafMaterial.color.copy(this.current.leaf);
this.flowerMaterial.color.copy(this.current.flower);
this.stemSegments.forEach((segment, index) => {
segment.mesh.position.y = segment.y * this.current.height;
segment.mesh.scale.y = segment.h * this.current.height;
const width = 0.92 + (this.current.height - 1) * 0.38;
segment.mesh.scale.x = width;
segment.mesh.scale.z = width;
segment.mesh.rotation.z = Math.sin(elapsed * 0.75 + index) * 0.012;
});
this.leaves.forEach(({ pivot, leaf, data, phase }) => {
pivot.position.y = data.y * this.current.height;
pivot.rotation.z =
data.side *
data.angle *
(0.58 + this.current.spread * 0.42);
pivot.rotation.z += Math.sin(elapsed * 1.15 + phase) * 0.022;
leaf.scale.set(
this.current.spread * data.width,
this.current.spread * (0.88 + this.current.height * 0.12),
this.current.spread * data.width
);
});
this.flower.position.y = 1.54 * this.current.height;
this.flower.scale.setScalar(this.current.bloom);
this.flower.rotation.y = elapsed * 0.12;
this.copperMarks.visible = this.current.copper > 0.01;
this.copperMarks.scale.setScalar(Math.max(0.001, this.current.copper));
this.group.rotation.z = Math.sin(elapsed * 0.75) * 0.012;
}
}
class CameraRig {
constructor(canvas) {
this.canvas = canvas;
this.target = new THREE.Vector3(0, 1.03, 0);
this.desired = {
radius: 5.25,
theta: 0.43,
phi: 1.13
};
this.current = { ...this.desired };
this.dragging = false;
this.pointerX = 0;
this.pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
this.dragging = true;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!this.dragging) return;
const dx = event.clientX - this.pointerX;
const dy = event.clientY - this.pointerY;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
this.desired.theta -= dx * 0.007;
this.desired.phi = THREE.MathUtils.clamp(
this.desired.phi - dy * 0.005,
0.55,
1.43
);
});
const stopDragging = (event) => {
this.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
};
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
this.desired.radius = THREE.MathUtils.clamp(
this.desired.radius + event.deltaY * 0.004,
3.7,
8.0
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => this.reset());
}
reset() {
this.desired.radius = 5.25;
this.desired.theta = 0.43;
this.desired.phi = 1.13;
}
update(delta) {
const smoothing = 1 - Math.exp(-delta * 8.0);
this.current.radius = THREE.MathUtils.lerp(
this.current.radius, this.desired.radius, smoothing
);
this.current.theta = THREE.MathUtils.lerp(
this.current.theta, this.desired.theta, smoothing
);
this.current.phi = THREE.MathUtils.lerp(
this.current.phi, this.desired.phi, smoothing
);
const { radius, theta, phi } = this.current;
const sinPhi = Math.sin(phi);
this.camera.position.set(
this.target.x + radius * sinPhi * Math.sin(theta),
this.target.y + radius * Math.cos(phi),
this.target.z + radius * sinPhi * Math.cos(theta)
);
this.camera.lookAt(this.target);
}
}
class LowPolyStage {
constructor(scene, isHeredity) {
this.isHeredity = isHeredity;
this.sideMaterial = new THREE.MeshStandardMaterial({
color: 0x765f43,
roughness: 1,
flatShading: true
});
this.topMaterial = new THREE.MeshStandardMaterial({
color: 0x789568,
roughness: 1,
flatShading: true
});
this.platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.35, 2.55, 0.28, 12, 1, false),
[this.sideMaterial, this.topMaterial, this.sideMaterial]
);
this.platform.position.y = -0.16;
this.platform.receiveShadow = true;
scene.add(this.platform);
const rockGeometry = new THREE.DodecahedronGeometry(0.18, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x9b9a83,
roughness: 1,
flatShading: true
});
[
[-1.55, 0.04, 0.72, 0.85],
[1.52, 0.02, 0.52, 1.12],
[-0.75, -0.01, -1.55, 0.72],
[1.05, -0.02, -1.32, 0.64],
[1.80, 0.00, -0.30, 0.52]
].forEach(([x, y, z, scale]) => {
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
rock.position.set(x, y + 0.06, z);
rock.scale.set(scale, scale * 0.68, scale);
rock.rotation.set(0.2, x * 0.8, 0.12);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
});
this.puddles = [];
const puddleMaterial = new THREE.MeshBasicMaterial({
color: 0x8dc8c4,
transparent: true,
opacity: 0.35,
depthWrite: false,
side: THREE.DoubleSide
});
[
[-0.73, 0.012, 0.54, 0.38],
[0.78, 0.014, -0.12, 0.29],
[-0.25, 0.013, -0.90, 0.24]
].forEach(([x, y, z, radius]) => {
const puddle = new THREE.Mesh(
new THREE.CircleGeometry(radius, 8),
puddleMaterial.clone()
);
puddle.rotation.x = -Math.PI / 2;
puddle.rotation.z = x * 0.7;
puddle.position.set(x, y, z);
scene.add(puddle);
this.puddles.push(puddle);
});
const crackPositions = new Float32Array([
-0.85, 0.022, 0.78, -0.57, 0.022, 0.61,
-0.57, 0.022, 0.61, -0.44, 0.022, 0.83,
-0.44, 0.022, 0.83, -0.23, 0.022, 0.75,
0.60, 0.023, 0.91, 0.82, 0.023, 0.65,
0.82, 0.023, 0.65, 0.72, 0.023, 0.43
]);
const crackGeometry = new THREE.BufferGeometry();
crackGeometry.setAttribute(
"position",
new THREE.BufferAttribute(crackPositions, 3)
);
this.cracks = new THREE.LineSegments(
crackGeometry,
new THREE.LineBasicMaterial({
color: 0x68533b,
transparent: true,
opacity: 0.65
})
);
scene.add(this.cracks);
this.tufts = [];
const tuftGeometry = new THREE.ConeGeometry(0.06, 0.24, 3);
for (let i = 0; i < 11; i++) {
const angle = (i / 11) * Math.PI * 2 + 0.35;
const radius = 1.55 + (i % 3) * 0.17;
const tuft = new THREE.Mesh(
tuftGeometry,
new THREE.MeshStandardMaterial({
color: 0x6d8e57,
roughness: 1,
flatShading: true
})
);
tuft.position.set(
Math.sin(angle) * radius,
0.10,
Math.cos(angle) * radius
);
tuft.rotation.z = Math.sin(angle * 4) * 0.22;
tuft.scale.y = 0.7;
scene.add(tuft);
this.tufts.push(tuft);
}
this.generationRings = [];
if (isHeredity) {
const ringMaterial = new THREE.MeshBasicMaterial({
color: COLOR.heredity,
transparent: true,
opacity: 0.65,
depthWrite: false
});
for (let i = 0; i < 4; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.74 + i * 0.12, 0.012, 4, 16),
ringMaterial.clone()
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.018 + i * 0.002;
ring.visible = false;
scene.add(ring);
this.generationRings.push(ring);
}
}
this.currentGround = new THREE.Color(0x789568);
this.targetGround = new THREE.Color(0x789568);
this.currentBackground = new THREE.Color(0xe9eee2);
this.targetBackground = new THREE.Color(0xe9eee2);
this.moisture = 0.42;
this.targetMoisture = 0.42;
}
setEnvironment(profile) {
this.targetGround.set(profile.ground);
this.targetBackground.set(profile.background);
this.targetMoisture = profile.moisture;
}
setGeneration(generation) {
this.generationRings.forEach((ring, index) => {
ring.visible = index < generation;
});
}
update(delta, scene) {
const smoothing = 1 - Math.exp(-delta * 4.0);
this.currentGround.lerp(this.targetGround, smoothing);
this.currentBackground.lerp(this.targetBackground, smoothing);
this.moisture = THREE.MathUtils.lerp(
this.moisture,
this.targetMoisture,
smoothing
);
this.topMaterial.color.copy(this.currentGround);
scene.background.copy(this.currentBackground);
if (scene.fog) scene.fog.color.copy(this.currentBackground);
this.puddles.forEach((puddle, index) => {
puddle.material.opacity = Math.max(
0,
this.moisture * (0.48 - index * 0.055)
);
puddle.visible = puddle.material.opacity > 0.01;
puddle.scale.setScalar(0.7 + this.moisture * 0.3);
});
this.cracks.material.opacity = Math.max(
0,
(1 - this.moisture * 1.9) * 0.72
);
this.tufts.forEach((tuft, index) => {
const localMoisture = THREE.MathUtils.clamp(
this.moisture * 1.25 - (index % 4) * 0.08,
0,
1
);
tuft.scale.y = 0.25 + localMoisture * 0.95;
tuft.material.color.set(this.moisture > 0.65 ? 0x4f8056 : 0x8b8a55);
});
}
}
function createWorld(viewportId, isHeredity) {
const viewport = document.getElementById(viewportId);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
isHeredity
? "Heritable variation plant. Drag to rotate and scroll to zoom."
: "Phenotypic plasticity plant. Drag to rotate and scroll to zoom."
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee2);
scene.fog = new THREE.Fog(0xe9eee2, 7, 13);
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 40);
const rig = new CameraRig(renderer.domElement);
rig.camera = camera;
const hemisphere = new THREE.HemisphereLight(
0xfff9e8,
0x526455,
2.0
);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff4dc, 3.0);
sunlight.position.set(4.5, 7.0, 3.5);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(1024, 1024);
sunlight.shadow.camera.left = -4;
sunlight.shadow.camera.right = 4;
sunlight.shadow.camera.top = 5;
sunlight.shadow.camera.bottom = -3;
sunlight.shadow.bias = -0.0008;
scene.add(sunlight);
const fill = new THREE.DirectionalLight(0xbcd9d2, 1.1);
fill.position.set(-4, 3, -4);
scene.add(fill);
const stage = new LowPolyStage(scene, isHeredity);
const plant = new LowPolyPlant(scene);
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
resize();
if ("ResizeObserver" in window) {
const observer = new ResizeObserver(resize);
observer.observe(viewport);
} else {
window.addEventListener("resize", resize);
}
return {
renderer,
scene,
camera,
rig,
stage,
plant
};
}
const plasticityWorld = createWorld("plasticityViewport", false);
const heredityWorld = createWorld("heredityViewport", true);
plasticityWorld.plant.setProfile(ENVIRONMENT_PROFILES.moderate);
plasticityWorld.stage.setEnvironment(ENVIRONMENT_PROFILES.moderate);
heredityWorld.plant.setProfile(VARIANT_PROFILES.wild);
document.querySelectorAll("[data-reset]").forEach((button) => {
button.addEventListener("click", () => {
const viewport = document.getElementById(button.dataset.reset);
const world = viewport.id === "plasticityViewport"
? plasticityWorld
: heredityWorld;
world.rig.reset();
});
});
function updateMeter(prefix, height, spread, bloom) {
const values = [height, spread, bloom];
["Stem", "Leaf", "Bloom"].forEach((name, index) => {
const value = Math.round(values[index]);
const meter = document.getElementById(`${prefix}${name}Meter`);
const output = document.getElementById(`${prefix}${name}Value`);
meter.style.width = `${Math.min(value, 130) / 1.3}%`;
output.textContent = `${value}%`;
});
}
document.querySelectorAll("[data-environment]").forEach((button) => {
button.addEventListener("click", () => {
const environment = button.dataset.environment;
const profile = ENVIRONMENT_PROFILES[environment];
document.querySelectorAll("[data-environment]").forEach((other) => {
const active = other === button;
other.classList.toggle("active", active);
other.setAttribute("aria-pressed", String(active));
});
plasticityWorld.plant.setProfile(profile);
plasticityWorld.stage.setEnvironment(profile);
document.getElementById("environmentChip").textContent =
`Environment · ${profile.label}`;
updateMeter("left", profile.height, profile.spread, profile.bloom);
});
});
let currentVariant = "wild";
let currentGeneration = 1;
let lineage = [{ generation: 1, variant: "wild" }];
function variantLabel(variant) {
return variant === "copper" ? "copper allele" : "wild-type alleles";
}
function updateLineage() {
const lineageElement = document.getElementById("lineage");
lineageElement.innerHTML = "";
for (let generation = 1; generation <= 4; generation++) {
if (generation > 1) {
const line = document.createElement("span");
line.className = "generation-line";
if (generation <= currentGeneration) line.classList.add("reached");
lineageElement.appendChild(line);
}
const node = document.createElement("div");
const entry = lineage.find(item => item.generation === generation);
node.className = "generation";
if (entry) node.classList.add("reached");
if (generation === currentGeneration) node.classList.add("active");
node.innerHTML = `
G${generation}
<small>${entry ? VARIANT_PROFILES[entry.variant].compact : "—"}</small>
`;
lineageElement.appendChild(node);
}
const profile = VARIANT_PROFILES[currentVariant];
document.getElementById("rightAllele").textContent =
`${profile.allele} · generation ${currentGeneration}`;
document.getElementById("lineageStatus").textContent =
currentGeneration === 1 ? "Founder generation" : `${currentGeneration} generations`;
const note = document.getElementById("inheritanceNote");
if (currentGeneration > 1) {
note.textContent =
`G${currentGeneration} inherited the ${variantLabel(currentVariant)} from G${currentGeneration - 1}.`;
} else {
note.textContent =
`G1 carries the ${variantLabel(currentVariant)}. Breeding passes it to G2.`;
}
document.getElementById("breedButton").textContent =
currentGeneration < 4
? `Breed generation ${currentGeneration + 1} →`
: "Start a new lineage";
heredityWorld.stage.setGeneration(currentGeneration);
}
function chooseVariant(variant) {
currentVariant = variant;
const profile = VARIANT_PROFILES[variant];
document.querySelectorAll("[data-variant]").forEach((button) => {
const active = button.dataset.variant === variant;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
heredityWorld.plant.setProfile(profile);
const currentEntry = lineage.find(
item => item.generation === currentGeneration
);
if (currentEntry) currentEntry.variant = variant;
updateMeter(
"right",
profile.height,
profile.spread,
profile.bloom
);
updateLineage();
}
document.querySelectorAll("[data-variant]").forEach((button) => {
button.addEventListener("click", () => {
chooseVariant(button.dataset.variant);
});
});
let toastTimer;
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
document.getElementById("breedButton").addEventListener("click", () => {
if (currentGeneration >= 4) {
currentGeneration = 1;
lineage = [{ generation: 1, variant: currentVariant }];
showToast("A new lineage begins with the selected parent allele.");
} else {
currentGeneration += 1;
lineage.push({
generation: currentGeneration,
variant: currentVariant
});
showToast(
`Generation ${currentGeneration} inherited the ${variantLabel(currentVariant)}.`
);
}
chooseVariant(currentVariant);
});
updateMeter("left", 1, 1, 1);
updateMeter("right", 1, 1, 1);
updateLineage();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
plasticityWorld.rig.update(delta);
heredityWorld.rig.update(delta);
plasticityWorld.plant.update(delta, elapsed);
heredityWorld.plant.update(delta, elapsed);
plasticityWorld.stage.update(delta, plasticityWorld.scene);
heredityWorld.stage.update(delta, heredityWorld.scene);
plasticityWorld.renderer.render(
plasticityWorld.scene,
plasticityWorld.camera
);
heredityWorld.renderer.render(
heredityWorld.scene,
heredityWorld.camera
);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```