Prompt specification
Build or customize the Three.js 3D scene "Parental chromosome combination cabinet" 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: Parental chromosome combination cabinet
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/parental-chromosome-combination-cabinet-x0953
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring sexual reproduction and genetic variation. Model two fictional parents with differently marked chromosome pairs and several empty offspring slots; distinguish inherited segments from newly created mutations using a separate symbol. Low-poly.
Working Three.js Starter (parental-chromosome-combination-cabinet-x0953):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Genetic Variation Lab</title>
<style>
:root {
color-scheme: dark;
--ink: #edf5ff;
--muted: #9aacc4;
--panel: rgba(12, 21, 38, 0.82);
--border: rgba(160, 195, 230, 0.18);
--parent-a: #43e0c0;
--parent-b: #ff746f;
--mutation: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 15%, #182844 0%, #0a1222 48%, #060b14 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 28px;
left: 30px;
width: min(440px, calc(100vw - 60px));
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
margin: 0 0 8px;
color: var(--parent-a);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(30px, 4vw, 54px);
line-height: 0.98;
letter-spacing: -0.045em;
}
header p {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.stats {
display: inline-flex;
gap: 16px;
margin-top: 15px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(8, 15, 28, 0.62);
color: #c9d8ea;
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.stats strong {
color: white;
}
.legend,
.controls {
position: absolute;
bottom: 26px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.legend {
left: 28px;
width: 310px;
padding: 16px 18px;
}
.legend-title {
margin-bottom: 11px;
color: #e7f0fb;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 9px;
color: #b8c8dc;
font-size: 12px;
}
.swatch {
position: relative;
flex: 0 0 auto;
width: 26px;
height: 13px;
border-radius: 4px;
background: #485569;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.swatch.a {
background: var(--parent-a);
box-shadow: 0 0 14px rgba(67, 224, 192, 0.35);
}
.swatch.b {
background: var(--parent-b);
box-shadow: 0 0 14px rgba(255, 116, 111, 0.35);
}
.swatch.mutation {
display: grid;
width: 20px;
height: 20px;
margin: 0 3px;
place-items: center;
background: transparent;
color: var(--mutation);
font-size: 20px;
line-height: 1;
text-shadow: 0 0 10px rgba(255, 209, 102, 0.6);
}
.legend-note {
margin: 13px 0 0;
padding-top: 11px;
border-top: 1px solid var(--border);
color: #8297b0;
font-size: 11px;
line-height: 1.45;
}
.controls {
right: 28px;
width: 290px;
padding: 16px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: #b8c8dc;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control-label output {
color: var(--mutation);
font-weight: 800;
}
input[type="range"] {
width: 100%;
margin: 0 0 14px;
accent-color: var(--mutation);
cursor: pointer;
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
button {
min-height: 42px;
border: 0;
border-radius: 11px;
font: inherit;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.04em;
cursor: pointer;
transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
filter: brightness(1.08);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: wait;
opacity: 0.55;
}
#generate {
padding: 0 16px;
color: #071622;
background: linear-gradient(135deg, #53e7c8, #8ce7ff);
box-shadow: 0 8px 24px rgba(67, 224, 192, 0.2);
}
#clear {
padding: 0 13px;
color: #d6e1ef;
background: rgba(126, 153, 185, 0.14);
box-shadow: inset 0 0 0 1px var(--border);
}
.camera-hint {
margin: 11px 2px 0;
color: #71869f;
font-size: 10px;
line-height: 1.4;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
header {
top: 17px;
left: 18px;
width: calc(100vw - 36px);
}
header p {
max-width: 310px;
font-size: 12px;
}
.stats {
margin-top: 10px;
}
.legend {
left: 14px;
bottom: 124px;
width: 245px;
padding: 12px 14px;
}
.legend-note {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 12px;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive low-poly genetics scene. Two fictional parents pass recombined chromosome segments to four offspring slots. Use the buttons to create offspring."
></canvas>
<div class="ui">
<header>
<p class="eyebrow">Genetic Variation Lab</p>
<h1>Inheritance,<br>remixed.</h1>
<p>
Sexual reproduction combines inherited chromosome segments from two parents.
New mutations can appear as distinct symbols.
</p>
<div class="stats" aria-live="polite">
<span>Slots <strong id="slot-count">0 / 4</strong></span>
<span>Mutations <strong id="mutation-count">0</strong></span>
</div>
</header>
<section class="legend" aria-label="Scene legend">
<div class="legend-title">Reading the chromosomes</div>
<div class="legend-row">
<span class="swatch a" aria-hidden="true"></span>
<span>Inherited segment from Mira</span>
</div>
<div class="legend-row">
<span class="swatch b" aria-hidden="true"></span>
<span>Inherited segment from Orin</span>
</div>
<div class="legend-row">
<span class="swatch mutation" aria-hidden="true">✦</span>
<span>New mutation symbol</span>
</div>
<div class="legend-row">
<span class="swatch" aria-hidden="true"></span>
<span>Unmarked chromosomal locus</span>
</div>
<p class="legend-note">
Each child receives one recombined chromosome from each parent.
Purple bands with a gold starburst indicate newly mutated loci.
</p>
</section>
<section class="controls" aria-label="Simulation controls">
<div class="control-label">
<span>Mutation chance</span>
<output id="rate-output" for="mutation-rate">35%</output>
</div>
<input
id="mutation-rate"
type="range"
min="0"
max="80"
value="35"
step="5"
aria-label="Mutation chance"
>
<div class="button-row">
<button id="generate" type="button">Generate offspring</button>
<button id="clear" type="button">Clear</button>
</div>
<p class="camera-hint">
Drag to orbit · Wheel or pinch to zoom · Arrow keys to rotate
</p>
</section>
<div id="announcement" class="sr-only" aria-live="polite"></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 canvas = document.querySelector("#scene");
const generateButton = document.querySelector("#generate");
const clearButton = document.querySelector("#clear");
const mutationRate = document.querySelector("#mutation-rate");
const rateOutput = document.querySelector("#rate-output");
const slotCount = document.querySelector("#slot-count");
const mutationCount = document.querySelector("#mutation-count");
const announcement = document.querySelector("#announcement");
const COLORS = {
background: 0x08111f,
ground: 0x0d1728,
panel: 0x111d30,
edge: 0x7695b7,
neutral: 0x526276,
neutralDark: 0x28374b,
parentA: 0x43e0c0,
parentB: 0xff746f,
mutation: 0xffd166,
mutatedBand: 0xb56cff,
white: 0xeaf3ff
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
scene.fog = new THREE.Fog(0x08111f, 22, 48);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.45, 0);
const cameraState = {
theta: 0,
phi: 0.43,
radius: 20,
desiredTheta: 0,
desiredPhi: 0.43,
desiredRadius: 20,
userAdjusted: false
};
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(0xbad9ff, 0x172033, 1.7);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.4);
keyLight.position.set(-5, 13, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
scene.add(keyLight);
const rimA = new THREE.PointLight(COLORS.parentA, 18, 12, 2);
rimA.position.set(-7, 4, 1);
scene.add(rimA);
const rimB = new THREE.PointLight(COLORS.parentB, 18, 12, 2);
rimB.position.set(7, 4, 1);
scene.add(rimB);
const fusionLight = new THREE.PointLight(0xffe3a4, 12, 10, 2);
fusionLight.position.set(0, 2.5, 0);
scene.add(fusionLight);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.06,
flatShading: true,
...options
});
}
function addEdges(mesh, color = COLORS.edge, opacity = 0.55) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeTextSprite(
text,
{
color = "#eaf3ff",
background = "rgba(8,16,29,0.84)",
border = "rgba(160,195,230,0.22)",
worldScale = 0.006,
fontWeight = 700
} = {}
) {
const textCanvas = document.createElement("canvas");
const context = textCanvas.getContext("2d");
context.font = `${fontWeight} 30px system-ui, sans-serif`;
const measured = context.measureText(text);
textCanvas.width = Math.max(48, Math.ceil(measured.width + 40));
textCanvas.height = 64;
context.font = `${fontWeight} 30px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
roundedRect(context, 2, 2, textCanvas.width - 4, textCanvas.height - 4, 15);
context.fillStyle = background;
context.fill();
context.strokeStyle = border;
context.lineWidth = 2;
context.stroke();
context.fillStyle = color;
context.fillText(text, textCanvas.width / 2, textCanvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(textCanvas.width * worldScale, textCanvas.height * worldScale, 1);
sprite.renderOrder = 20;
return sprite;
}
function createMutationSymbol() {
const shape = new THREE.Shape();
const points = 16;
for (let i = 0; i < points; i++) {
const radius = i % 2 === 0 ? 0.15 : 0.065;
const angle = (i / points) * Math.PI * 2 + Math.PI / 2;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.065,
bevelEnabled: false,
curveSegments: 1
});
geometry.center();
const group = new THREE.Group();
const outline = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({ color: 0x111827 })
);
outline.scale.setScalar(1.18);
outline.position.z = -0.018;
const star = new THREE.Mesh(
geometry,
standardMaterial(COLORS.mutation, {
emissive: COLORS.mutation,
emissiveIntensity: 0.9,
roughness: 0.45
})
);
star.position.z = 0.025;
group.add(outline, star);
return group;
}
function createChromosome(pattern, sourceColor, mutationBand = null) {
const group = new THREE.Group();
const bodyMaterial = standardMaterial(COLORS.neutralDark);
const bodyGeometry = new THREE.BoxGeometry(0.34, 0.27, 0.18);
for (let i = 0; i < 8; i++) {
const segment = new THREE.Mesh(bodyGeometry, bodyMaterial);
segment.position.set(Math.sin(i * 1.45) * 0.035, (i - 3.5) * 0.32, 0);
segment.castShadow = true;
group.add(segment);
if (pattern.includes(i)) {
const isMutated = mutationBand === i;
const bandMaterial = standardMaterial(
isMutated ? COLORS.mutatedBand : sourceColor,
{
emissive: isMutated ? COLORS.mutatedBand : sourceColor,
emissiveIntensity: isMutated ? 0.52 : 0.22,
roughness: 0.5
}
);
const band = new THREE.Mesh(
new THREE.BoxGeometry(0.39, 0.12, 0.205),
bandMaterial
);
band.position.set(segment.position.x, segment.position.y, 0.012);
group.add(band);
}
}
if (mutationBand !== null) {
const marker = createMutationSymbol();
marker.position.set(
0.3,
(mutationBand - 3.5) * 0.32,
0.2
);
marker.scale.setScalar(0.82);
group.add(marker);
}
return group;
}
const ground = new THREE.Mesh(
new THREE.CircleGeometry(15, 48),
standardMaterial(COLORS.ground, { roughness: 0.95 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.045;
ground.receiveShadow = true;
scene.add(ground);
const groundRing = new THREE.Mesh(
new THREE.TorusGeometry(9.2, 0.025, 4, 96),
new THREE.MeshBasicMaterial({
color: 0x557696,
transparent: true,
opacity: 0.26
})
);
groundRing.rotation.x = Math.PI / 2;
groundRing.position.y = 0.005;
scene.add(groundRing);
const random = (min, max) => min + Math.random() * (max - min);
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = [];
for (let i = 0; i < 150; i++) {
dustPositions.push(
random(-13, 13),
random(0.4, 10),
random(-9, 7)
);
}
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x9bc3e8,
size: 0.035,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(dust);
function createParent({
x,
z,
name,
clothColor,
skinColor,
hairColor,
sourceColor,
patterns
}) {
const parent = new THREE.Group();
parent.position.set(x, 0, z);
const cloth = standardMaterial(clothColor, {
emissive: clothColor,
emissiveIntensity: 0.035
});
const skin = standardMaterial(skinColor);
const hair = standardMaterial(hairColor);
const dark = standardMaterial(0x172131);
const legGeometry = new THREE.CylinderGeometry(0.18, 0.23, 1.2, 6);
const armGeometry = new THREE.CylinderGeometry(0.15, 0.19, 1.2, 6);
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(legGeometry, cloth);
leg.position.set(side * 0.28, 0.63, 0);
leg.rotation.z = side * 0.06;
leg.castShadow = true;
parent.add(leg);
const boot = new THREE.Mesh(
new THREE.BoxGeometry(0.39, 0.24, 0.55),
dark
);
boot.position.set(side * 0.28, 0.13, 0.11);
boot.castShadow = true;
parent.add(boot);
}
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.72, 1.45, 6),
cloth
);
torso.position.y = 1.85;
torso.castShadow = true;
parent.add(torso);
const belt = new THREE.Mesh(
new THREE.CylinderGeometry(0.69, 0.69, 0.13, 6),
standardMaterial(0x26384c)
);
belt.position.y = 1.24;
parent.add(belt);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.22, 0.35, 6),
skin
);
neck.position.y = 2.69;
parent.add(neck);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.49, 1),
skin
);
head.position.y = 3.13;
head.scale.set(0.92, 1.08, 0.92);
head.castShadow = true;
parent.add(head);
const hairMesh = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.49, 0),
hair
);
hairMesh.position.set(0, 3.37, -0.06);
hairMesh.scale.set(1.04, 0.68, 1.02);
hairMesh.rotation.z = 0.08;
hairMesh.castShadow = true;
parent.add(hairMesh);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 6),
dark
);
eye.position.set(side * 0.16, 3.18, 0.425);
parent.add(eye);
}
const mouth = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.025, 0.025),
dark
);
mouth.position.set(0, 2.98, 0.435);
parent.add(mouth);
for (const side of [-1, 1]) {
const arm = new THREE.Mesh(armGeometry, cloth);
arm.position.set(side * 0.73, 1.95, 0);
arm.rotation.z = side * 0.23;
arm.castShadow = true;
parent.add(arm);
const hand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.19, 0),
skin
);
hand.position.set(side * 0.86, 1.38, 0.03);
hand.castShadow = true;
parent.add(hand);
}
const chestGem = new THREE.Mesh(
new THREE.OctahedronGeometry(0.18, 0),
standardMaterial(sourceColor, {
emissive: sourceColor,
emissiveIntensity: 0.4
})
);
chestGem.position.set(0, 2.04, 0.58);
parent.add(chestGem);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(1.05, 0.035, 4, 36),
new THREE.MeshBasicMaterial({
color: sourceColor,
transparent: true,
opacity: 0.55
})
);
halo.rotation.x = Math.PI / 2;
halo.position.y = 0.025;
parent.add(halo);
scene.add(parent);
const genomePanel = new THREE.Group();
genomePanel.position.set(x, 4.55, z + 0.55);
const backing = new THREE.Mesh(
new THREE.BoxGeometry(2.65, 2.75, 0.08),
standardMaterial(0x101d30, {
transparent: true,
opacity: 0.91
})
);
addEdges(backing, sourceColor, 0.52);
genomePanel.add(backing);
const pair = new THREE.Group();
patterns.forEach((pattern, index) => {
const chromosome = createChromosome(pattern, sourceColor);
chromosome.scale.setScalar(0.63);
chromosome.position.set(index === 0 ? -0.43 : 0.43, 0.02, 0.11);
pair.add(chromosome);
const homologLabel = makeTextSprite(`H${index + 1}`, {
color: index === 0 ? "#eaf3ff" : "#b8c8dc",
worldScale: 0.004,
fontWeight: 800
});
homologLabel.position.set(index === 0 ? -0.43 : 0.43, -1.02, 0.17);
pair.add(homologLabel);
});
genomePanel.add(pair);
const nameLabel = makeTextSprite(`${name.toUpperCase()} · PARENT`, {
color: sourceColor === COLORS.parentA ? "#8ffff0" : "#ffaaa6",
worldScale: 0.007,
fontWeight: 800
});
nameLabel.position.set(0, 1.63, 0.14);
genomePanel.add(nameLabel);
scene.add(genomePanel);
return {
group: parent,
genomePanel,
pair,
sourceColor,
sourcePosition: new THREE.Vector3(x, 2.8, z + 0.25)
};
}
const parentAPatterns = [
[0, 2, 5, 7],
[1, 3, 4, 7]
];
const parentBPatterns = [
[0, 3, 5, 7],
[1, 2, 4, 6]
];
const mira = createParent({
x: -5.25,
z: -3.45,
name: "Mira",
clothColor: 0x147d78,
skinColor: 0x8f5d46,
hairColor: 0x171820,
sourceColor: COLORS.parentA,
patterns: parentAPatterns
});
const orin = createParent({
x: 5.25,
z: -3.45,
name: "Orin",
clothColor: 0x8f3e4b,
skinColor: 0xd59a75,
hairColor: 0x593322,
sourceColor: COLORS.parentB,
patterns: parentBPatterns
});
const fusionGroup = new THREE.Group();
fusionGroup.position.set(0, 1.38, 0.05);
const dais = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.55, 0.25, 8),
standardMaterial(0x18263a)
);
dais.position.set(0, 0.02, 0);
dais.receiveShadow = true;
fusionGroup.add(dais);
const fusionRingA = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.065, 6, 28),
standardMaterial(COLORS.parentA, {
emissive: COLORS.parentA,
emissiveIntensity: 0.42
})
);
fusionRingA.rotation.z = 0.55;
fusionGroup.add(fusionRingA);
const fusionRingB = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.065, 6, 28),
standardMaterial(COLORS.parentB, {
emissive: COLORS.parentB,
emissiveIntensity: 0.42
})
);
fusionRingB.rotation.z = -0.55;
fusionGroup.add(fusionRingB);
const fusionCore = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.2, 0),
standardMaterial(0xffe6ac, {
emissive: 0xffe6ac,
emissiveIntensity: 0.8
})
);
fusionGroup.add(fusionCore);
scene.add(fusionGroup);
const fusionLabel = makeTextSprite("GAMETE FUSION", {
color: "#e9f3ff",
worldScale: 0.006,
fontWeight: 800
});
fusionLabel.position.set(0, 2.75, 0.15);
scene.add(fusionLabel);
function createDashedLine(points, color, opacity = 0.18) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.18,
gapSize: 0.14,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
return line;
}
function createSlot(x, z, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.28, 1.42, 0.25, 6),
standardMaterial(0x16253a)
);
base.position.y = 0.13;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const baseRing = new THREE.Mesh(
new THREE.TorusGeometry(1.17, 0.028, 4, 36),
new THREE.MeshBasicMaterial({
color: 0x7998ba,
transparent: true,
opacity: 0.42
})
);
baseRing.rotation.x = Math.PI / 2;
baseRing.position.y = 0.28;
group.add(baseRing);
const board = new THREE.Mesh(
new THREE.BoxGeometry(2.3, 2.85, 0.13),
standardMaterial(COLORS.panel, {
transparent: true,
opacity: 0.95
})
);
board.position.y = 1.87;
board.castShadow = true;
addEdges(board, 0x7794b2, 0.42);
group.add(board);
const title = makeTextSprite(`OFFSPRING ${String(index + 1).padStart(2, "0")}`, {
color: "#eaf3ff",
worldScale: 0.007,
fontWeight: 800
});
title.position.set(0, 3.58, 0.18);
group.add(title);
const status = makeTextSprite("AWAITING FERTILIZATION", {
color: "#8299b3",
worldScale: 0.0046,
fontWeight: 700
});
status.position.set(0, 0.66, 0.19);
group.add(status);
const emptyGroup = new THREE.Group();
const ghostLeft = createDashedLine([
new THREE.Vector3(-0.39, 0.94, 0.18),
new THREE.Vector3(-0.39, 2.78, 0.18)
], COLORS.parentA, 0.24);
const ghostRight = createDashedLine([
new THREE.Vector3(0.39, 0.94, 0.18),
new THREE.Vector3(0.39, 2.78, 0.18)
], COLORS.parentB, 0.24);
const emptyLabel = makeTextSprite("EMPTY", {
color: "#b3c4d9",
background: "rgba(12,21,38,0.68)",
worldScale: 0.006,
fontWeight: 800
});
emptyLabel.position.set(0, 1.75, 0.2);
emptyGroup.add(ghostLeft, ghostRight, emptyLabel);
group.add(emptyGroup);
const childGroup = new THREE.Group();
group.add(childGroup);
const sourceA = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.06, 0.06),
standardMaterial(COLORS.parentA, {
emissive: COLORS.parentA,
emissiveIntensity: 0.4
})
);
sourceA.position.set(-0.42, 3.18, 0.18);
const sourceB = sourceA.clone();
sourceB.material = standardMaterial(COLORS.parentB, {
emissive: COLORS.parentB,
emissiveIntensity: 0.4
});
sourceB.position.x = 0.42;
group.add(sourceA, sourceB);
scene.add(group);
return {
index,
group,
board,
title,
status,
emptyGroup,
childGroup,
sourceA,
sourceB,
occupied: false,
mutations: 0
};
}
const slotPositions = [
[-4.8, 3.25],
[-1.6, 3.7],
[1.6, 3.7],
[4.8, 3.25]
];
const slots = slotPositions.map(([x, z], index) => createSlot(x, z, index));
function createParentPath(parent, slot, xOffset) {
const start = parent.sourcePosition.clone();
const end = new THREE.Vector3(
slot.group.position.x + xOffset,
1.86,
slot.group.position.z + 0.24
);
const curve = new THREE.CatmullRomCurve3([
start,
new THREE.Vector3(parent.sourcePosition.x * 0.72, 5.2, -1.2),
new THREE.Vector3(slot.group.position.x * 0.55, 4.55, 1.55),
end
]);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(48)),
new THREE.LineDashedMaterial({
color: parent.sourceColor,
transparent: true,
opacity: 0.16,
dashSize: 0.16,
gapSize: 0.13,
depthWrite: false
})
);
line.computeLineDistances();
scene.add(line);
return curve;
}
slots.forEach((slot) => {
createParentPath(mira, slot, -0.42);
createParentPath(orin, slot, 0.42);
});
function crossoverPattern(patterns) {
const first = Math.random() < 0.5 ? patterns[0] : patterns[1];
const second = first === patterns[0] ? patterns[1] : patterns[0];
const cut = Math.random() < 0.5 ? 3 : 4;
const combined = first.slice(0, cut).concat(second.slice(cut));
return [...new Set(combined)].sort((a, b) => a - b);
}
function clearSlot(slot) {
slot.group.remove(slot.childGroup);
slot.childGroup = new THREE.Group();
slot.group.add(slot.childGroup);
slot.emptyGroup.visible = true;
slot.status.material.opacity = 1;
slot.occupied = false;
slot.mutations = 0;
// Replacing the sprite ensures the status label returns to its empty state.
const oldStatus = slot.status;
slot.group.remove(oldStatus);
oldStatus.material.map.dispose();
oldStatus.material.dispose();
slot.status = makeTextSprite("AWAITING FERTILIZATION", {
color: "#8299b3",
worldScale: 0.0046,
fontWeight: 700
});
slot.status.position.set(0, 0.66, 0.19);
slot.group.add(slot.status);
}
function populateSlot(slot, parentPattern, parentPatternB, mutationSide, mutationBand) {
const chromosomeA = createChromosome(
parentPattern,
COLORS.parentA,
mutationSide === 0 ? mutationBand : null
);
chromosomeA.position.set(-0.43, 1.84, 0.22);
chromosomeA.rotation.z = -0.035;
chromosomeA.scale.setScalar(0.77);
const chromosomeB = createChromosome(
parentPatternB,
COLORS.parentB,
mutationSide === 1 ? mutationBand : null
);
chromosomeB.position.set(0.43, 1.84, 0.22);
chromosomeB.rotation.z = 0.035;
chromosomeB.scale.setScalar(0.77);
slot.childGroup.add(chromosomeA, chromosomeB);
slot.emptyGroup.visible = false;
slot.occupied = true;
slot.mutations = mutationSide === null ? 0 : 1;
slot.group.remove(slot.status);
slot.status.material.map.dispose();
slot.status.material.dispose();
slot.status = makeTextSprite(
slot.mutations ? "RECOMBINED · 1 MUTATION" : "RECOMBINED",
{
color: slot.mutations ? "#ffd166" : "#91e8d7",
worldScale: 0.0046,
fontWeight: 800
}
);
slot.status.position.set(0, 0.66, 0.19);
slot.group.add(slot.status);
}
function updateHud() {
const occupied = slots.filter((slot) => slot.occupied).length;
const mutations = slots.reduce(
(total, slot) => total + slot.mutations,
0
);
slotCount.textContent = `${occupied} / ${slots.length}`;
mutationCount.textContent = String(mutations);
}
let activeAnimation = null;
function removeAnimationParticles() {
if (!activeAnimation) return;
activeAnimation.jobs.forEach((job) => {
scene.remove(job.sphereA, job.sphereB);
job.sphereA.geometry.dispose();
job.sphereA.material.dispose();
job.sphereB.geometry.dispose();
job.sphereB.material.dispose();
});
activeAnimation = null;
}
function clearAll() {
removeAnimationParticles();
slots.forEach(clearSlot);
updateHud();
}
function startGeneration() {
clearAll();
const rate = Number(mutationRate.value) / 100;
const specifications = [];
for (const slot of slots) {
const patternA = crossoverPattern(parentAPatterns);
const patternB = crossoverPattern(parentBPatterns);
let mutationSide = null;
let mutationBand = null;
if (Math.random() < rate) {
mutationSide = Math.random() < 0.5 ? 0 : 1;
const selectedPattern = mutationSide === 0 ? patternA : patternB;
mutationBand = selectedPattern[
Math.floor(Math.random() * selectedPattern.length)
];
}
specifications.push({
patternA,
patternB,
mutationSide,
mutationBand
});
}
// Ensure the litter demonstrates mutation whenever the selected rate allows it.
if (rate > 0 && specifications.every((spec) => spec.mutationSide === null)) {
const slotIndex = Math.floor(Math.random() * specifications.length);
const spec = specifications[slotIndex];
spec.mutationSide = Math.random() < 0.5 ? 0 : 1;
const selectedPattern =
spec.mutationSide === 0 ? spec.patternA : spec.patternB;
spec.mutationBand = selectedPattern[
Math.floor(Math.random() * selectedPattern.length)
];
}
generateButton.disabled = true;
clearButton.disabled = true;
generateButton.textContent = "Combining…";
const jobs = specifications.map((spec, index) => {
const slot = slots[index];
const curveA = createParentPath(mira, slot, -0.42);
const curveB = createParentPath(orin, slot, 0.42);
const sphereGeometry = new THREE.SphereGeometry(0.13, 8, 6);
const sphereA = new THREE.Mesh(
sphereGeometry,
standardMaterial(COLORS.parentA, {
emissive: COLORS.parentA,
emissiveIntensity: 1.1
})
);
const sphereB = new THREE.Mesh(
sphereGeometry.clone(),
standardMaterial(COLORS.parentB, {
emissive: COLORS.parentB,
emissiveIntensity: 1.1
})
);
sphereA.position.copy(mira.sourcePosition);
sphereB.position.copy(orin.sourcePosition);
scene.add(sphereA, sphereB);
return {
slot,
spec,
curveA,
curveB,
sphereA,
sphereB,
delay: index * 0.16,
populated: false
};
});
activeAnimation = {
elapsed: 0,
jobs
};
announcement.textContent =
"Generating offspring by combining one recombined chromosome from each parent.";
}
function updateGeneration(delta) {
if (!activeAnimation) return;
activeAnimation.elapsed += delta;
let allPopulated = true;
for (const job of activeAnimation.jobs) {
const progress = THREE.MathUtils.clamp(
(activeAnimation.elapsed - job.delay) / 1.45,
0,
1
);
job.sphereA.position.copy(job.curveA.getPoint(progress));
job.sphereB.position.copy(job.curveB.getPoint(progress));
const pulse = 1 + Math.sin(progress * Math.PI * 8) * 0.16;
job.sphereA.scale.setScalar(pulse);
job.sphereB.scale.setScalar(pulse);
if (progress > 0.82 && !job.populated) {
populateSlot(
job.slot,
job.spec.patternA,
job.spec.patternB,
job.spec.mutationSide,
job.spec.mutationBand
);
job.populated = true;
updateHud();
}
if (!job.populated) allPopulated = false;
}
if (allPopulated && activeAnimation.elapsed > 2.45) {
removeAnimationParticles();
generateButton.disabled = false;
clearButton.disabled = false;
generateButton.textContent = "Generate new litter";
announcement.textContent =
"Four offspring slots filled. Colored segments are inherited; gold starbursts mark new mutations.";
}
}
mutationRate.addEventListener("input", () => {
rateOutput.value = `${mutationRate.value}%`;
rateOutput.textContent = `${mutationRate.value}%`;
});
generateButton.addEventListener("click", startGeneration);
clearButton.addEventListener("click", () => {
clearAll();
generateButton.textContent = "Generate offspring";
announcement.textContent = "All offspring slots cleared.";
});
function updateCamera() {
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.desiredTheta,
0.09
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.desiredPhi,
0.09
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.desiredRadius,
0.09
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi + dy * 0.004,
0.22,
0.9
);
cameraState.userAdjusted = true;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * (pinchDistance / distance),
11,
31
);
cameraState.userAdjusted = true;
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius + event.deltaY * 0.012,
11,
31
);
cameraState.userAdjusted = true;
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.desiredTheta = 0;
cameraState.desiredPhi = 0.43;
cameraState.desiredRadius = window.innerWidth < 760 ? 25 : 20;
});
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.desiredTheta += 0.12;
break;
case "ArrowRight":
cameraState.desiredTheta -= 0.12;
break;
case "ArrowUp":
cameraState.desiredPhi = Math.max(0.22, cameraState.desiredPhi - 0.08);
break;
case "ArrowDown":
cameraState.desiredPhi = Math.min(0.9, cameraState.desiredPhi + 0.08);
break;
case "+":
case "=":
cameraState.desiredRadius = Math.max(11, cameraState.desiredRadius - 1);
break;
case "-":
case "_":
cameraState.desiredRadius = Math.min(31, cameraState.desiredRadius + 1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
cameraState.userAdjusted = true;
}
});
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = aspect;
if (width < 760) {
camera.fov = 58;
if (!cameraState.userAdjusted) {
cameraState.desiredRadius = 25;
cameraState.desiredPhi = 0.47;
}
} else {
camera.fov = 46;
if (!cameraState.userAdjusted) {
cameraState.desiredRadius = 20;
cameraState.desiredPhi = 0.43;
}
}
camera.updateProjectionMatrix();
}
window.addEventListener("resize", onResize);
onResize();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera();
updateGeneration(delta);
mira.genomePanel.position.y = 4.55 + Math.sin(elapsed * 0.85) * 0.07;
orin.genomePanel.position.y = 4.55 + Math.sin(elapsed * 0.85 + 1.2) * 0.07;
mira.pair.rotation.y = Math.sin(elapsed * 0.55) * 0.045;
orin.pair.rotation.y = Math.sin(elapsed * 0.55 + 1) * 0.045;
fusionRingA.rotation.z = 0.55 + elapsed * 0.24;
fusionRingB.rotation.z = -0.55 - elapsed * 0.24;
fusionCore.rotation.x = elapsed * 0.7;
fusionCore.rotation.y = elapsed * 0.9;
fusionCore.scale.setScalar(
1 + Math.sin(elapsed * 3.2) * 0.08
);
fusionLight.intensity = 10 + Math.sin(elapsed * 3.2) * 3;
dust.rotation.y = elapsed * 0.008;
renderer.render(scene, camera);
}
updateHud();
animate();
</script>
</body>
</html>
```