Prompt specification
Build or customize the Three.js 3D scene "Inheritance-model comparison board" 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: Inheritance-model comparison board
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inheritance-model-comparison-board-x0884
Scene Description Prompt:
Allow switching between complete dominance and an illustrative intermediate phenotype rule; keep parental token pairs fixed and show how the genotype-to-appearance mapping changes. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (inheritance-model-comparison-board-x0884):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dominance Explorer — Three.js</title>
<style>
:root {
--bg: #091410;
--panel: #10211b;
--panel-2: #142a22;
--border: #29453a;
--text: #edf6ef;
--muted: #9fb4a8;
--accent: #b9e986;
--dominant: #f47c48;
--recessive: #4287d5;
--blend: #9b728e;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
color: var(--text);
background:
radial-gradient(circle at 12% 0%, rgba(81, 135, 91, 0.18), transparent 34rem),
radial-gradient(circle at 88% 8%, rgba(66, 135, 213, 0.11), transparent 28rem),
var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
width: min(1480px, calc(100% - 32px));
margin: 0 auto;
padding: 34px 0 42px;
}
.hero {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 30px;
align-items: end;
margin-bottom: 24px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--accent);
font-size: 0.75rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 2px;
content: "";
background: var(--accent);
}
h1 {
max-width: 820px;
margin: 0;
font-size: clamp(2.1rem, 5vw, 4.65rem);
line-height: 0.98;
letter-spacing: -0.055em;
}
.hero-copy {
max-width: 670px;
margin: 18px 0 0;
color: var(--muted);
font-size: 1rem;
line-height: 1.65;
}
.hero-note {
max-width: 250px;
padding: 16px 18px;
border: 1px solid var(--border);
border-radius: 16px;
color: var(--muted);
background: rgba(16, 33, 27, 0.72);
font-size: 0.82rem;
line-height: 1.5;
}
.hero-note strong {
display: block;
margin-bottom: 5px;
color: var(--text);
}
.workspace {
display: grid;
grid-template-columns: 330px minmax(0, 1fr);
gap: 18px;
align-items: stretch;
}
.panel,
.stage {
overflow: hidden;
border: 1px solid var(--border);
border-radius: 20px;
background: rgba(16, 33, 27, 0.86);
box-shadow: 0 22px 65px rgba(0, 0, 0, 0.22);
}
.sidebar {
padding: 20px;
}
.section {
padding-bottom: 20px;
border-bottom: 1px solid var(--border);
}
.section + .section {
padding-top: 20px;
}
.section:last-child {
padding-bottom: 0;
border-bottom: 0;
}
.section-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 12px;
}
h2,
h3,
p {
margin-top: 0;
}
h2 {
margin-bottom: 0;
font-size: 0.82rem;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.locked {
padding: 4px 8px;
border: 1px solid #45634f;
border-radius: 999px;
color: #c9e3b6;
background: rgba(185, 233, 134, 0.07);
font-size: 0.66rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mode-switch {
display: grid;
gap: 9px;
}
.mode-button {
width: 100%;
padding: 12px 13px;
border: 1px solid var(--border);
border-radius: 13px;
color: var(--muted);
background: #0c1915;
text-align: left;
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}
.mode-button:hover {
border-color: #4c6b5a;
color: var(--text);
}
.mode-button.active {
border-color: var(--accent);
color: var(--text);
background: rgba(185, 233, 134, 0.08);
}
.mode-button strong {
display: block;
margin-bottom: 4px;
font-size: 0.9rem;
}
.mode-button span {
display: block;
font-size: 0.75rem;
line-height: 1.4;
}
.rule-box {
margin-top: 12px;
padding: 13px;
border-left: 3px solid var(--accent);
border-radius: 0 10px 10px 0;
color: var(--muted);
background: rgba(185, 233, 134, 0.055);
font-size: 0.78rem;
line-height: 1.5;
}
.rule-box code {
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.parent-pair {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 8px;
align-items: center;
}
.parent-token {
padding: 12px 8px;
border: 1px solid var(--border);
border-radius: 13px;
background: #0c1915;
text-align: center;
}
.parent-token small {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 0.67rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.allele-pair {
display: flex;
justify-content: center;
gap: 6px;
}
.allele {
display: grid;
width: 29px;
height: 29px;
place-items: center;
border-radius: 8px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.88rem;
font-weight: 900;
}
.allele.upper {
color: #ffd0b9;
background: rgba(244, 124, 72, 0.22);
}
.allele.lower {
color: #c8ddff;
background: rgba(66, 135, 213, 0.22);
}
.cross-symbol {
color: var(--muted);
font-size: 1.2rem;
}
.fixed-note {
margin: 10px 0 0;
color: var(--muted);
font-size: 0.74rem;
line-height: 1.5;
}
.punnett {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
.punnett-cell {
position: relative;
min-height: 48px;
padding: 9px 2px 16px;
border: 1px solid var(--border);
border-radius: 9px;
color: var(--text);
background: #0b1814;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.72rem;
font-weight: 800;
text-align: center;
transition: background 180ms ease, border-color 180ms ease;
}
.punnett-cell.dominant {
border-color: rgba(244, 124, 72, 0.48);
background: rgba(244, 124, 72, 0.1);
}
.punnett-cell.recessive {
border-color: rgba(66, 135, 213, 0.48);
background: rgba(66, 135, 213, 0.1);
}
.punnett-cell.blend {
border-color: rgba(155, 114, 142, 0.65);
background: rgba(155, 114, 142, 0.13);
}
.phen-dot {
position: absolute;
right: 7px;
bottom: 6px;
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--dot, #f47c48);
}
.detail-card {
padding: 14px;
border: 1px solid var(--border);
border-radius: 13px;
background: #0b1814;
}
.detail-top {
display: flex;
justify-content: space-between;
gap: 12px;
align-items: center;
}
.genotype-badge {
padding: 5px 9px;
border-radius: 8px;
color: #07120e;
background: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 900;
}
.detail-label {
color: var(--muted);
font-size: 0.68rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.detail-card h3 {
margin: 13px 0 6px;
font-size: 1.05rem;
}
.detail-card p {
margin: 0;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.5;
}
.stage {
position: relative;
min-height: 690px;
}
.canvas-wrap {
position: absolute;
inset: 0;
}
.canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.stage-top {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
z-index: 2;
display: flex;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.stage-card {
padding: 12px 14px;
border: 1px solid rgba(74, 104, 89, 0.72);
border-radius: 13px;
background: rgba(7, 18, 14, 0.76);
backdrop-filter: blur(10px);
}
.stage-card small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 0.65rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stage-card strong {
font-size: 0.88rem;
}
.split-stat {
text-align: right;
}
.split-stat strong {
color: #dce9df;
font-size: 0.8rem;
}
.stage-bottom {
position: absolute;
right: 16px;
bottom: 16px;
left: 16px;
z-index: 3;
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
pointer-events: none;
}
.stage-hint {
padding: 9px 12px;
border: 1px solid rgba(74, 104, 89, 0.58);
border-radius: 999px;
color: var(--muted);
background: rgba(7, 18, 14, 0.75);
font-size: 0.7rem;
backdrop-filter: blur(10px);
}
.reset-button {
padding: 9px 12px;
border: 1px solid rgba(74, 104, 89, 0.8);
border-radius: 999px;
color: var(--text);
background: rgba(7, 18, 14, 0.82);
cursor: pointer;
pointer-events: auto;
}
.reset-button:hover {
border-color: var(--accent);
}
.mapping-section {
margin-top: 18px;
padding: 20px;
}
.mapping-header {
display: flex;
justify-content: space-between;
gap: 20px;
align-items: end;
margin-bottom: 16px;
}
.mapping-header p {
max-width: 700px;
margin: 0;
color: var(--muted);
font-size: 0.8rem;
line-height: 1.5;
}
.mapping-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.map-card {
display: grid;
grid-template-columns: 52px 1fr;
gap: 13px;
align-items: center;
min-height: 92px;
padding: 13px;
border: 1px solid var(--border);
border-radius: 14px;
background: #0b1814;
transition: border-color 180ms ease, background 180ms ease;
}
.map-card.dominant {
border-color: rgba(244, 124, 72, 0.42);
background: rgba(244, 124, 72, 0.065);
}
.map-card.recessive {
border-color: rgba(66, 135, 213, 0.42);
background: rgba(66, 135, 213, 0.065);
}
.map-card.blend {
border-color: rgba(155, 114, 142, 0.58);
background: rgba(155, 114, 142, 0.08);
}
.specimen {
position: relative;
width: 48px;
height: 48px;
}
.specimen::before {
position: absolute;
inset: 10px 5px 4px;
content: "";
border-radius: 48% 48% 42% 42%;
background: var(--swatch);
clip-path: polygon(18% 0, 82% 0, 100% 58%, 73% 100%, 27% 100%, 0 58%);
box-shadow: 0 7px 15px rgba(0, 0, 0, 0.24);
}
.specimen::after {
position: absolute;
top: 0;
left: 22px;
width: 5px;
height: var(--crest, 12px);
content: "";
border-radius: 3px 3px 0 0;
background: var(--swatch);
}
.map-card strong,
.map-card span {
display: block;
}
.map-card strong {
margin-bottom: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 1rem;
}
.map-card span {
color: var(--muted);
font-size: 0.73rem;
line-height: 1.4;
}
.footnote {
margin: 16px 2px 0;
color: #839a8d;
font-size: 0.72rem;
line-height: 1.55;
}
@media (max-width: 980px) {
.hero {
grid-template-columns: 1fr;
}
.hero-note {
max-width: none;
}
.workspace {
grid-template-columns: 1fr;
}
.sidebar {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
.section + .section {
padding-top: 0;
}
.section {
border-bottom: 0;
}
.stage {
min-height: 650px;
}
}
@media (max-width: 680px) {
.app {
width: min(100% - 18px, 1480px);
padding-top: 24px;
}
.sidebar {
display: block;
}
.section + .section {
padding-top: 20px;
border-top: 1px solid var(--border);
}
.section {
border-bottom: 1px solid var(--border);
}
.section:last-child {
border-bottom: 0;
}
.stage {
min-height: 590px;
}
.stage-top {
align-items: flex-start;
}
.stage-card {
padding: 9px 10px;
}
.split-stat {
max-width: 160px;
}
.mapping-header {
display: block;
}
.mapping-header p {
margin-top: 8px;
}
.mapping-grid {
grid-template-columns: 1fr;
}
.stage-hint {
max-width: 190px;
border-radius: 12px;
line-height: 1.4;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<main class="app">
<header class="hero">
<div>
<div class="eyebrow">Interactive inheritance model</div>
<h1>One cross.<br />Two phenotype maps.</h1>
<p class="hero-copy">
The parental allele pairs and all offspring genotypes stay fixed.
Switch the inheritance rule to reveal how the same
<strong>Aa × Aa</strong> cross can produce a different visible result.
</p>
</div>
<aside class="hero-note">
<strong>What changes?</strong>
Only the lookup from genotype to appearance. The alleles, genotype
grid, and specimen positions never move.
</aside>
</header>
<div class="workspace">
<aside class="panel sidebar">
<section class="section">
<div class="section-heading">
<h2>Phenotype rule</h2>
</div>
<div class="mode-switch" role="group" aria-label="Phenotype rule">
<button
class="mode-button active"
type="button"
data-mode="complete"
aria-pressed="true"
>
<strong>Complete dominance</strong>
<span>A completely masks a, so Aa looks like AA.</span>
</button>
<button
class="mode-button"
type="button"
data-mode="intermediate"
aria-pressed="false"
>
<strong>Illustrative intermediate rule</strong>
<span>Aa receives a midpoint color and a shorter crest.</span>
</button>
</div>
<div class="rule-box" id="ruleBox"></div>
</section>
<section class="section">
<div class="section-heading">
<h2>Fixed parental pairs</h2>
<span class="locked">Locked</span>
</div>
<div class="parent-pair">
<div class="parent-token">
<small>Parent 1</small>
<div class="allele-pair">
<span class="allele upper">A</span>
<span class="allele lower">a</span>
</div>
</div>
<span class="cross-symbol">×</span>
<div class="parent-token">
<small>Parent 2</small>
<div class="allele-pair">
<span class="allele upper">A</span>
<span class="allele lower">a</span>
</div>
</div>
</div>
<p class="fixed-note">
Each parent can pass on A or a. The resulting 4 × 4 genotype
grid stays identical in both modes.
</p>
</section>
<section class="section">
<div class="section-heading">
<h2>Fixed genotype grid</h2>
</div>
<div class="punnett" id="punnettGrid" aria-label="Fixed four by four genotype grid"></div>
<p class="fixed-note">
Each colored dot shows the appearance assigned to that genotype
under the selected rule.
</p>
</section>
<section class="section">
<div class="section-heading">
<h2>Selected specimen</h2>
</div>
<div class="detail-card" id="detailCard" aria-live="polite">
<div class="detail-top">
<span class="genotype-badge" id="selectedGenotype">Aa</span>
<span class="detail-label">Genotype</span>
</div>
<h3 id="selectedPhenotype">Dominant appearance</h3>
<p id="selectedExplanation"></p>
</div>
<p class="fixed-note">Click any low-poly specimen in the scene.</p>
</section>
</aside>
<section class="stage" aria-label="Interactive three-dimensional inheritance scene">
<div class="canvas-wrap" id="canvasWrap"></div>
<div class="stage-top">
<div class="stage-card">
<small>Active mapping</small>
<strong id="stageMode">Complete dominance</strong>
</div>
<div class="stage-card split-stat">
<small>Visible offspring</small>
<strong id="stageSplit">12 dominant · 4 recessive</strong>
</div>
</div>
<div class="stage-bottom">
<div class="stage-hint">Drag to orbit · Scroll to zoom · Click to inspect</div>
<button class="reset-button" id="resetView" type="button">Reset view</button>
</div>
</section>
</div>
<section class="panel mapping-section">
<div class="mapping-header">
<h2>Genotype → appearance lookup</h2>
<p>
The same three genotype classes are shown below. Only the Aa
assignment changes, demonstrating how a different phenotype rule
changes visible inheritance patterns.
</p>
</div>
<div class="mapping-grid">
<article class="map-card dominant" id="mapAA">
<div class="specimen"></div>
<div>
<strong>AA</strong>
<span id="mapAAText">Dominant appearance</span>
</div>
</article>
<article class="map-card dominant" id="mapAa">
<div class="specimen"></div>
<div>
<strong>Aa</strong>
<span id="mapAaText">Same dominant appearance as AA</span>
</div>
</article>
<article class="map-card recessive" id="mapaa">
<div class="specimen"></div>
<div>
<strong>aa</strong>
<span id="mapaaText">Recessive appearance</span>
</div>
</article>
</div>
</section>
<p class="footnote">
This intermediate rule is an illustrative model, not a claim about how
all biological traits inherit. Real systems may involve incomplete
dominance, codominance, multiple genes, or environmental effects.
</p>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const modeButtons = [...document.querySelectorAll(".mode-button")];
const ruleBox = document.getElementById("ruleBox");
const stageMode = document.getElementById("stageMode");
const stageSplit = document.getElementById("stageSplit");
const punnettGrid = document.getElementById("punnettGrid");
const detailCard = document.getElementById("detailCard");
const selectedGenotype = document.getElementById("selectedGenotype");
const selectedPhenotype = document.getElementById("selectedPhenotype");
const selectedExplanation = document.getElementById("selectedExplanation");
const COLORS = {
dominant: 0xf47c48,
recessive: 0x4287d5,
blend: 0x9b728e
};
const CSS_COLORS = {
dominant: "#f47c48",
recessive: "#4287d5",
blend: "#9b728e"
};
const PHENOTYPE_NAMES = {
dominant: "Dominant appearance",
recessive: "Recessive appearance",
blend: "Intermediate blend"
};
// The genotype order is the fixed 4 × 4 Punnett-grid order.
const genotypes = [
"AA", "Aa", "AA", "Aa",
"Aa", "aa", "Aa", "aa",
"AA", "Aa", "AA", "Aa",
"Aa", "aa", "Aa", "aa"
];
let mode = "complete";
let selectedRecord = null;
let hoveredRecord = null;
function phenotypeFor(genotype) {
if (genotype === "AA") return "dominant";
if (genotype === "aa") return "recessive";
return mode === "complete" ? "dominant" : "blend";
}
// -------------------------------------------------------------------------
// Build the fixed genotype matrix.
// -------------------------------------------------------------------------
const punnettCells = genotypes.map((genotype) => {
const cell = document.createElement("div");
cell.className = "punnett-cell";
cell.innerHTML = `
<span>${genotype}</span>
<span class="phen-dot"></span>
`;
punnettGrid.appendChild(cell);
return cell;
});
// -------------------------------------------------------------------------
// Three.js scene.
// -------------------------------------------------------------------------
const canvasWrap = document.getElementById("canvasWrap");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091510);
scene.fog = new THREE.Fog(0x091510, 15, 28);
const camera = new THREE.PerspectiveCamera(
45,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional scene showing two fixed parents and sixteen offspring"
);
renderer.domElement.setAttribute("tabindex", "0");
canvasWrap.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xd9f3e3, 0x17261f, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.2);
keyLight.position.set(4, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7da7ff, 1.3);
rimLight.position.set(-5, 4, -5);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x10251e,
roughness: 0.92,
metalness: 0,
flatShading: true
});
const floor = new THREE.Mesh(
new THREE.CircleGeometry(7.8, 32),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(0, -0.08, 0.9);
floor.receiveShadow = true;
scene.add(floor);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x345448,
transparent: true,
opacity: 0.34
});
[2.6, 5.3].forEach((radius) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.012, 4, 48),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.055;
ring.position.z = 0.9;
scene.add(ring);
});
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0x284238,
roughness: 0.8,
metalness: 0.06,
flatShading: true
});
const eyeMaterial = new THREE.MeshBasicMaterial({ color: 0x07100d });
const beakMaterial = new THREE.MeshStandardMaterial({
color: 0xffe4a8,
roughness: 0.8,
flatShading: true
});
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.39, 0.022, 6, 36),
new THREE.MeshBasicMaterial({
color: 0xdaf5a7,
transparent: true,
opacity: 0.95
})
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.position.y = 0.025;
scene.add(selectionRing);
const records = [];
const pickables = [];
function makeTextSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 384;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 18, 14, 0.88)";
context.strokeStyle = "rgba(142, 181, 155, 0.62)";
context.lineWidth = 4;
context.beginPath();
context.moveTo(28, 8);
context.lineTo(356, 8);
context.quadraticCurveTo(376, 8, 376, 28);
context.lineTo(376, 84);
context.quadraticCurveTo(376, 104, 356, 104);
context.lineTo(28, 104);
context.quadraticCurveTo(8, 104, 8, 84);
context.lineTo(8, 28);
context.quadraticCurveTo(8, 8, 28, 8);
context.closePath();
context.fill();
context.stroke();
context.fillStyle = "#edf6ef";
context.font = "700 48px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 192, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.58, 0.17, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeWingGeometry(side) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
side * 0.54, 0.13, -0.04,
side * 0.20, 0.39, -0.16
], 3)
);
geometry.setIndex([0, 1, 2]);
geometry.computeVertexNormals();
return geometry;
}
function createCreature(genotype, options = {}) {
const root = new THREE.Group();
const creature = new THREE.Group();
root.add(creature);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(
options.parent ? 0.44 : 0.34,
options.parent ? 0.49 : 0.38,
0.09,
8
),
pedestalMaterial
);
pedestal.position.y = 0.015;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
root.add(pedestal);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: COLORS.dominant,
roughness: 0.58,
metalness: 0.02,
flatShading: true
});
const wingMaterial = new THREE.MeshStandardMaterial({
color: COLORS.dominant,
roughness: 0.7,
side: THREE.DoubleSide,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.27, 0),
bodyMaterial
);
body.position.y = 0.43;
body.castShadow = true;
creature.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
new THREE.MeshStandardMaterial({
color: 0xf3e8cf,
roughness: 0.8,
flatShading: true
})
);
head.position.set(0, 0.70, 0.025);
head.castShadow = true;
creature.add(head);
const eyeGeometry = new THREE.SphereGeometry(0.025, 8, 6);
[-1, 1].forEach((side) => {
const eye = new THREE.Mesh(eyeGeometry, eyeMaterial);
eye.position.set(side * 0.065, 0.73, 0.175);
creature.add(eye);
});
const beak = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.13, 4),
beakMaterial
);
beak.rotation.x = Math.PI / 2;
beak.position.set(0, 0.68, 0.235);
creature.add(beak);
const leftWing = new THREE.Mesh(
makeWingGeometry(-1),
wingMaterial
);
leftWing.position.set(-0.08, 0.45, 0);
leftWing.castShadow = true;
creature.add(leftWing);
const rightWing = new THREE.Mesh(
makeWingGeometry(1),
wingMaterial
);
rightWing.position.set(0.08, 0.45, 0);
rightWing.castShadow = true;
creature.add(rightWing);
const crest = new THREE.Mesh(
new THREE.ConeGeometry(0.09, 0.28, 4),
new THREE.MeshStandardMaterial({
color: 0xf6d681,
roughness: 0.72,
flatShading: true
})
);
crest.position.set(0, 0.94, 0.015);
crest.castShadow = true;
creature.add(crest);
const label = makeTextSprite(
options.parent ? `${options.label} · ${genotype}` : genotype
);
label.position.set(0, options.parent ? 1.38 : 1.12, 0);
root.add(label);
const record = {
genotype,
root,
creature,
body,
bodyMaterial,
wingMaterial,
crest,
leftWing,
rightWing,
parent: Boolean(options.parent),
baseScale: options.parent ? 1.18 : 1
};
root.scale.setScalar(record.baseScale);
body.userData.record = record;
head.userData.record = record;
leftWing.userData.record = record;
rightWing.userData.record = record;
crest.userData.record = record;
pickables.push(body, head, leftWing, rightWing, crest);
records.push(record);
return record;
}
// Two locked heterozygote parents.
const parent1 = createCreature("Aa", {
parent: true,
label: "P1"
});
parent1.root.position.set(-3.15, 0, -1.35);
const parent2 = createCreature("Aa", {
parent: true,
label: "P2"
});
parent2.root.position.set(3.15, 0, -1.35);
// Sixteen offspring in the same fixed order as the genotype matrix.
const xPositions = [-2.25, -0.75, 0.75, 2.25];
const zPositions = [0.2, 1.18, 2.16, 3.14];
const offspringRecords = [];
genotypes.forEach((genotype, index) => {
const row = Math.floor(index / 4);
const column = index % 4;
const record = createCreature(genotype);
record.root.position.set(
xPositions[column],
0,
zPositions[row]
);
scene.add(record.root);
offspringRecords.push(record);
});
scene.add(parent1.root);
scene.add(parent2.root);
// -------------------------------------------------------------------------
// Apply the selected phenotype rule to all models and interface elements.
// -------------------------------------------------------------------------
function updateModel(record) {
const phenotype = phenotypeFor(record.genotype);
const mainColor = new THREE.Color(COLORS[phenotype]);
const wingColor = mainColor.clone().multiplyScalar(0.82);
record.bodyMaterial.color.copy(mainColor);
record.wingMaterial.color.copy(wingColor);
// Silhouette also follows the illustrative rule.
if (phenotype === "dominant") {
record.crest.visible = true;
record.crest.scale.set(1, 1, 1);
record.body.scale.set(1, 1.08, 1);
} else if (phenotype === "blend") {
record.crest.visible = true;
record.crest.scale.set(0.8, 0.56, 0.8);
record.body.scale.set(1, 1.035, 1);
} else {
record.crest.visible = false;
record.body.scale.set(1, 1, 1);
}
}
function updatePunnett() {
punnettCells.forEach((cell, index) => {
const phenotype = phenotypeFor(genotypes[index]);
cell.className = `punnett-cell ${phenotype}`;
cell.style.setProperty("--dot", CSS_COLORS[phenotype]);
});
}
function updateMappingCards() {
const aa = phenotypeFor("AA");
const aA = phenotypeFor("Aa");
const aaLower = phenotypeFor("aa");
const mapAA = document.getElementById("mapAA");
const mapAa = document.getElementById("mapAa");
const mapaa = document.getElementById("mapaa");
mapAA.className = `map-card ${aa}`;
mapAa.className = `map-card ${aA}`;
mapaa.className = `map-card ${aaLower}`;
mapAA.style.setProperty("--swatch", CSS_COLORS[aa]);
mapAa.style.setProperty("--swatch", CSS_COLORS[aA]);
mapaa.style.setProperty("--swatch", CSS_COLORS[aaLower]);
mapAA.style.setProperty("--crest", aa === "dominant" ? "13px" : "9px");
mapAa.style.setProperty(
"--crest",
aA === "dominant" ? "13px" : aA === "blend" ? "8px" : "3px"
);
mapaa.style.setProperty("--crest", aaLower === "dominant" ? "13px" : "3px");
document.getElementById("mapAAText").textContent =
"Dominant reference appearance";
document.getElementById("mapAaText").textContent =
mode === "complete"
? "Same dominant appearance as AA"
: "Midpoint color and intermediate crest";
document.getElementById("mapaaText").textContent =
"Recessive reference appearance";
}
function updateSelectedDetail() {
if (!selectedRecord) return;
const phenotype = phenotypeFor(selectedRecord.genotype);
selectedGenotype.textContent = selectedRecord.genotype;
selectedPhenotype.textContent = PHENOTYPE_NAMES[phenotype];
selectedPhenotype.style.color = CSS_COLORS[phenotype];
if (selectedRecord.genotype === "AA") {
selectedExplanation.textContent =
"AA always keeps the dominant reference appearance in both rules.";
} else if (selectedRecord.genotype === "aa") {
selectedExplanation.textContent =
"aa always keeps the recessive reference appearance in both rules.";
} else if (mode === "complete") {
selectedExplanation.textContent =
"Under complete dominance, A masks a. This heterozygote is visually identical to AA.";
} else {
selectedExplanation.textContent =
"Under the illustrative intermediate rule, Aa receives a midpoint color and a partially intermediate crest.";
}
}
function updateMode(nextMode) {
mode = nextMode;
modeButtons.forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
if (mode === "complete") {
ruleBox.innerHTML =
"<strong>Complete dominance</strong><br>" +
"<code>Aa → AA appearance</code><br>" +
"The heterozygous offspring are indistinguishable from AA, producing a 3 dominant : 1 recessive phenotype ratio in this grid.";
stageMode.textContent = "Complete dominance";
stageSplit.textContent = "12 dominant · 4 recessive";
} else {
ruleBox.innerHTML =
"<strong>Illustrative intermediate rule</strong><br>" +
"<code>Aa → midpoint appearance</code><br>" +
"AA, Aa, and aa remain visually distinct, giving a 1 : 2 : 1 phenotype-class ratio in this grid.";
stageMode.textContent = "Illustrative intermediate";
stageSplit.textContent = "4 dominant · 8 blend · 4 recessive";
}
records.forEach(updateModel);
updatePunnett();
updateMappingCards();
updateSelectedDetail();
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
updateMode(button.dataset.mode);
});
});
// -------------------------------------------------------------------------
// Selection and raycasting.
// -------------------------------------------------------------------------
function selectRecord(record) {
if (!record) return;
selectedRecord = record;
selectionRing.position.set(
record.root.position.x,
0.025,
record.root.position.z
);
selectionRing.scale.setScalar(record.baseScale);
updateSelectedDetail();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickRecord(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickables, false)[0];
return hit ? hit.object.userData.record : null;
}
// -------------------------------------------------------------------------
// Camera controls implemented directly, without camera-control addons.
// -------------------------------------------------------------------------
const orbit = {
yaw: 0,
pitch: 0.52,
distance: 15.2,
target: new THREE.Vector3(0, 0.34, 1.0)
};
function updateCamera() {
const horizontal = Math.cos(orbit.pitch) * orbit.distance;
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.distance,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.yaw = 0;
orbit.pitch = 0.52;
orbit.distance = 15.2;
orbit.target.set(0, 0.34, 1.0);
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetCamera);
let dragging = false;
let pointerStart = null;
let lastPointer = null;
let dragDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
pointerStart = {
x: event.clientX,
y: event.clientY
};
lastPointer = {
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
dragDistance += Math.abs(dx) + Math.abs(dy);
orbit.yaw = THREE.MathUtils.clamp(
orbit.yaw - dx * 0.006,
-1.0,
1.0
);
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.0045,
0.22,
1.02
);
lastPointer = {
x: event.clientX,
y: event.clientY
};
updateCamera();
} else {
const record = pickRecord(event);
hoveredRecord = record;
renderer.domElement.style.cursor = record ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (dragging && dragDistance < 7) {
const record = pickRecord(event);
if (record) selectRecord(record);
}
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
hoveredRecord = null;
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance + event.deltaY * 0.012,
9.5,
20
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
// -------------------------------------------------------------------------
// Responsive rendering and animation.
// -------------------------------------------------------------------------
function resizeRenderer() {
const width = Math.max(1, canvasWrap.clientWidth);
const height = Math.max(1, canvasWrap.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(canvasWrap);
resizeRenderer();
updateCamera();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate(time) {
requestAnimationFrame(animate);
records.forEach((record, index) => {
const isHighlighted =
record === selectedRecord || record === hoveredRecord;
const targetScale = isHighlighted ? 1.065 : 1;
const nextScale = THREE.MathUtils.lerp(
record.creature.scale.x,
targetScale,
0.12
);
record.creature.scale.setScalar(nextScale);
if (!reducedMotion) {
record.creature.position.y =
Math.sin(time * 0.0017 + index * 0.72) * 0.025;
const flap = Math.sin(time * 0.0022 + index * 0.54) * 0.075;
record.leftWing.rotation.x = flap;
record.rightWing.rotation.x = -flap;
}
});
renderer.render(scene, camera);
}
updateMode("complete");
selectRecord(offspringRecords[1]);
requestAnimationFrame(animate);
</script>
</body>
</html>
```