Prompt specification
Build or customize the Three.js 3D scene "Random parental contribution machine" 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: Random parental contribution machine
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/random-parental-contribution-machine-x0922
Scene Description Prompt:
Make a stylized inheritance machine copying one random token from each parent pair into an offspring compartment. One HTML file using Three.js from cdnjs.
Working Three.js Starter (random-parental-contribution-machine-x0922):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Allele Foundry — Inheritance Machine</title>
<style>
:root {
color-scheme: dark;
--bg: #080b12;
--panel: rgba(13, 19, 30, 0.82);
--line: rgba(141, 206, 255, 0.18);
--text: #e8f6ff;
--muted: #8295a9;
--cyan: #36dcff;
--blue: #6478ff;
--pink: #ff5c9b;
--amber: #ffb84d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 28%, rgba(3, 5, 10, 0.23) 68%, rgba(3, 5, 10, 0.75) 100%),
linear-gradient(180deg, rgba(7, 10, 17, 0.22), transparent 25%, transparent 75%, rgba(7, 10, 17, 0.45));
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title {
position: absolute;
top: 28px;
left: 32px;
max-width: 420px;
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3.3vw, 49px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.045em;
text-shadow: 0 3px 24px rgba(0, 0, 0, 0.4);
}
.subtitle {
margin: 13px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
}
.status-panel {
position: absolute;
top: 28px;
right: 28px;
width: 270px;
padding: 16px;
border-radius: 14px;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
color: #b7c7d8;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 13px var(--cyan);
}
#statusTitle {
margin-top: 9px;
font-size: 14px;
font-weight: 700;
line-height: 1.3;
}
#statusDetail {
min-height: 34px;
margin-top: 5px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.readout > div {
min-width: 0;
padding: 9px 10px;
border: 1px solid rgba(135, 192, 232, 0.12);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
}
.readout span {
display: block;
color: #65788c;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
}
.readout strong {
display: block;
overflow: hidden;
margin-top: 7px;
color: #dcefff;
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-overflow: ellipsis;
white-space: nowrap;
}
.legend {
position: absolute;
bottom: 29px;
left: 30px;
padding: 14px 16px;
border-radius: 13px;
}
.legend-title {
margin-bottom: 10px;
color: #71869b;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: #a9bbcd;
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.token-chip {
display: inline-grid;
width: 23px;
height: 23px;
place-items: center;
border: 1px solid currentColor;
border-radius: 7px;
background: rgba(255, 255, 255, 0.04);
box-shadow: inset 0 0 10px currentColor;
font-size: 11px;
}
.cyan { color: var(--cyan); }
.blue { color: var(--blue); }
.amber { color: var(--amber); }
.pink { color: var(--pink); }
.command {
position: absolute;
bottom: 29px;
left: 50%;
display: flex;
align-items: center;
gap: 9px;
padding: 8px;
border-radius: 15px;
transform: translateX(-50%);
pointer-events: auto;
}
.run-button {
position: relative;
min-width: 192px;
padding: 14px 21px;
overflow: hidden;
border: 1px solid rgba(54, 220, 255, 0.5);
border-radius: 10px;
background: linear-gradient(135deg, #1dc9ed, #496fff);
box-shadow:
0 0 24px rgba(54, 220, 255, 0.16),
inset 0 1px 0 rgba(255, 255, 255, 0.25);
color: white;
cursor: pointer;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
transition: transform 160ms ease, filter 160ms ease, opacity 160ms ease;
}
.run-button::after {
position: absolute;
inset: 0;
background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.2) 45%, transparent 70%);
content: "";
transform: translateX(-120%);
transition: transform 500ms ease;
}
.run-button:hover:not(:disabled) {
filter: brightness(1.12);
transform: translateY(-2px);
}
.run-button:hover:not(:disabled)::after {
transform: translateX(120%);
}
.run-button:disabled {
cursor: wait;
opacity: 0.48;
}
.ghost-button {
padding: 13px 15px;
border: 1px solid rgba(151, 199, 232, 0.18);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
color: #9eb1c4;
cursor: pointer;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: background 160ms ease, color 160ms ease;
}
.ghost-button:hover,
.ghost-button.active {
background: rgba(54, 220, 255, 0.1);
color: var(--cyan);
}
.help {
position: absolute;
right: 30px;
bottom: 31px;
color: #667b8f;
font: 600 9px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-align: right;
text-transform: uppercase;
}
.progress {
display: flex;
gap: 5px;
margin-top: 13px;
}
.step {
height: 3px;
flex: 1;
overflow: hidden;
border-radius: 10px;
background: rgba(139, 186, 221, 0.12);
}
.step::after {
display: block;
width: 100%;
height: 100%;
border-radius: inherit;
background: var(--cyan);
box-shadow: 0 0 8px var(--cyan);
content: "";
transform: scaleX(0);
transform-origin: left;
transition: transform 250ms ease;
}
.step.active::after {
transform: scaleX(0.55);
animation: pulse 850ms ease-in-out infinite alternate;
}
.step.done::after {
transform: scaleX(1);
}
@keyframes pulse {
to { opacity: 0.42; }
}
@media (max-width: 800px) {
.title {
top: 20px;
left: 20px;
}
.subtitle,
.legend,
.help {
display: none;
}
.status-panel {
top: 105px;
right: 16px;
width: 220px;
}
.command {
bottom: 18px;
width: calc(100% - 32px);
justify-content: center;
}
.run-button {
flex: 1;
}
}
</style>
</head>
<body>
<div id="stage" role="img" aria-label="Interactive three-dimensional inheritance machine"></div>
<div class="vignette"></div>
<main class="hud">
<section class="title">
<div class="eyebrow">Stochastic Genetics Unit / 07</div>
<h1>ALLELE<br />FOUNDRY</h1>
<p class="subtitle">
One random token is sampled from each parental pair, copied through the machine,
and assembled inside the offspring compartment.
</p>
</section>
<aside class="status-panel panel">
<div class="status-row">
<span class="status-dot" id="statusDot"></span>
<span>Machine telemetry</span>
</div>
<div id="statusTitle">Ready for a new generation</div>
<div id="statusDetail">Press run to scan both parental pairs.</div>
<div class="progress">
<div class="step" id="stepA"></div>
<div class="step" id="stepB"></div>
<div class="step" id="stepC"></div>
</div>
<div class="readout">
<div>
<span>PAIR A</span>
<strong id="outA">PENDING</strong>
</div>
<div>
<span>PAIR B</span>
<strong id="outB">PENDING</strong>
</div>
</div>
</aside>
<section class="legend panel">
<div class="legend-title">Available tokens</div>
<div class="legend-row">
<span class="token-chip cyan">D</span>
<span class="token-chip blue">d</span>
<span>Pair A / maternal alleles</span>
</div>
<div class="legend-row">
<span class="token-chip amber">T</span>
<span class="token-chip pink">t</span>
<span>Pair B / paternal alleles</span>
</div>
</section>
<nav class="command panel" aria-label="Machine controls">
<button class="run-button" id="runButton">Run inheritance</button>
<button class="ghost-button" id="autoButton" aria-pressed="false">Auto</button>
<button class="ghost-button" id="clearButton">Clear</button>
</nav>
<div class="help">
Drag to orbit · Wheel/pinch to zoom<br />
Space: run · A: auto · R: reset view
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080b12);
scene.fog = new THREE.FogExp2(0x080b12, 0.032);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const hemi = new THREE.HemisphereLight(0xa9ddff, 0x15101c, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xe8f6ff, 3.3);
key.position.set(4.5, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 1;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x596aff, 2.2);
rim.position.set(-7, 5, -5);
scene.add(rim);
const warmFill = new THREE.PointLight(0xff8c61, 16, 11, 2);
warmFill.position.set(-1, 3.2, 4);
scene.add(warmFill);
// -------------------------------------------------------------------------
// Geometry and texture helpers
// -------------------------------------------------------------------------
function roundedPanel(width, height, depth, radius, material) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
curveSegments: 8,
steps: 1
});
geometry.translate(0, 0, -depth / 2);
return new THREE.Mesh(geometry, material);
}
function cylinderBetween(a, b, radius, material, segments = 12) {
const direction = new THREE.Vector3().subVectors(b, a);
const geometry = new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
segments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function drawRoundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeTextSprite(
text,
{
color = "#dff7ff",
background = "rgba(8,15,25,0.78)",
border = "rgba(113,205,255,0.28)",
fontSize = 43,
width = 1.7
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
drawRoundedRect(ctx, 5, 5, 502, 118, 18);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 2;
ctx.stroke();
ctx.font = `800 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeLetterSprite(letter, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.font = "900 78px Georgia, serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.shadowColor = color;
ctx.shadowBlur = 17;
ctx.fillStyle = "#f3fdff";
ctx.fillText(letter, 64, 67);
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.43, 0.43, 1);
sprite.position.z = 0.18;
sprite.renderOrder = 21;
return sprite;
}
function createToken(letter, color, scale = 1) {
const group = new THREE.Group();
const colorObject = new THREE.Color(color);
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.25, 2),
new THREE.MeshStandardMaterial({
color: colorObject,
emissive: colorObject,
emissiveIntensity: 0.36,
metalness: 0.48,
roughness: 0.23
})
);
core.castShadow = true;
group.add(core);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.32, 0.022, 10, 64),
new THREE.MeshBasicMaterial({ color: colorObject })
);
group.add(ring);
const equator = new THREE.Mesh(
new THREE.TorusGeometry(0.255, 0.012, 8, 48),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.38
})
);
equator.rotation.x = Math.PI / 2;
group.add(equator);
const letterSprite = makeLetterSprite(letter, color);
group.add(letterSprite);
group.scale.setScalar(scale);
group.userData = {
letter,
color,
core,
ring,
equator,
baseScale: scale,
birth: 1
};
return group;
}
// -------------------------------------------------------------------------
// Environment
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x0a1019,
roughness: 0.76,
metalness: 0.22
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 56, 0x24445d, 0x142536);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(260 * 3);
for (let i = 0; i < 260; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 21;
dustPositions[i * 3 + 1] = 0.5 + Math.random() * 7;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 15;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x9ddfff,
size: 0.025,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
scene.add(dust);
const machine = new THREE.Group();
scene.add(machine);
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x111a27,
roughness: 0.38,
metalness: 0.78
});
const edgeMetal = new THREE.MeshStandardMaterial({
color: 0x26374a,
roughness: 0.3,
metalness: 0.84
});
const cyanMetal = new THREE.MeshStandardMaterial({
color: 0x1b8098,
emissive: 0x0c5264,
emissiveIntensity: 0.55,
roughness: 0.3,
metalness: 0.7
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x7ecfff,
transparent: true,
opacity: 0.095,
roughness: 0.12,
metalness: 0.05,
transmission: 0.25,
side: THREE.DoubleSide,
depthWrite: false
});
const base = roundedPanel(9.7, 0.46, 2.9, 0.17, darkMetal);
base.position.set(0.1, 0.34, 0);
base.castShadow = true;
base.receiveShadow = true;
machine.add(base);
const baseInset = roundedPanel(9.35, 0.055, 2.55, 0.1, edgeMetal);
baseInset.position.set(0.1, 0.585, 0);
machine.add(baseInset);
// Front hazard marks.
for (let i = 0; i < 17; i++) {
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.085, 0.025),
new THREE.MeshStandardMaterial({
color: i % 2 ? 0x283343 : 0xd49738,
emissive: i % 2 ? 0x000000 : 0x6d3510,
emissiveIntensity: 0.25,
roughness: 0.6
})
);
stripe.position.set(-4.05 + i * 0.48, 0.31, 1.462);
stripe.rotation.z = -0.48;
machine.add(stripe);
}
// Structural gantry.
const leftColumn = roundedPanel(0.28, 3.8, 0.4, 0.08, edgeMetal);
leftColumn.position.set(-4.58, 2.17, -1.02);
leftColumn.castShadow = true;
machine.add(leftColumn);
const rightColumn = leftColumn.clone();
rightColumn.position.x = 4.73;
machine.add(rightColumn);
const topBeam = roundedPanel(9.58, 0.28, 0.43, 0.08, edgeMetal);
topBeam.position.set(0.08, 4.02, -1.02);
topBeam.castShadow = true;
machine.add(topBeam);
const topGlow = new THREE.Mesh(
new THREE.BoxGeometry(8.8, 0.035, 0.08),
new THREE.MeshBasicMaterial({ color: 0x287f9c })
);
topGlow.position.set(0.08, 3.86, -0.79);
machine.add(topGlow);
const rail = cylinderBetween(
new THREE.Vector3(-4.0, 3.52, -0.19),
new THREE.Vector3(4.1, 3.52, -0.19),
0.045,
cyanMetal,
18
);
machine.add(rail);
for (const x of [-3.9, 3.95]) {
machine.add(
cylinderBetween(
new THREE.Vector3(x, 3.53, -0.19),
new THREE.Vector3(x, 4.0, -0.72),
0.04,
edgeMetal
)
);
}
const carriage = new THREE.Group();
carriage.position.set(-3.35, 3.49, -0.19);
carriage.visible = false;
const carriageBody = roundedPanel(0.58, 0.22, 0.38, 0.07, edgeMetal);
carriage.add(carriageBody);
const carriageGlow = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.035, 0.4),
new THREE.MeshBasicMaterial({ color: 0x55e5ff })
);
carriageGlow.position.y = -0.13;
carriage.add(carriageGlow);
const emitter = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.32, 24),
new THREE.MeshStandardMaterial({
color: 0x6ee8ff,
emissive: 0x25a9c8,
emissiveIntensity: 1.25,
roughness: 0.25,
metalness: 0.55
})
);
emitter.position.y = -0.35;
emitter.rotation.z = Math.PI;
carriage.add(emitter);
machine.add(carriage);
// -------------------------------------------------------------------------
// Parental pair compartments
// -------------------------------------------------------------------------
const pairs = [];
function createParentPair(index, x, definitions, accent) {
const group = new THREE.Group();
machine.add(group);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.91, 1.02, 0.26, 48),
darkMetal
);
pedestal.position.set(x, 0.73, 0);
pedestal.castShadow = true;
group.add(pedestal);
const pedestalGlow = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.035, 10, 64),
new THREE.MeshBasicMaterial({ color: accent })
);
pedestalGlow.rotation.x = Math.PI / 2;
pedestalGlow.position.set(x, 0.88, 0);
group.add(pedestalGlow);
const glass = new THREE.Mesh(
new THREE.CylinderGeometry(0.82, 0.82, 1.65, 48, 1, true),
glassMaterial.clone()
);
glass.position.set(x, 1.67, 0);
group.add(glass);
for (const y of [0.85, 2.49]) {
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.055, 12, 64),
edgeMetal
);
rim.rotation.x = Math.PI / 2;
rim.position.set(x, y, 0);
group.add(rim);
const glow = new THREE.Mesh(
new THREE.TorusGeometry(0.78, 0.014, 8, 64),
new THREE.MeshBasicMaterial({ color: accent })
);
glow.rotation.x = Math.PI / 2;
glow.position.set(x, y + (y < 1 ? -0.025 : 0.025), 0);
group.add(glow);
}
const tokens = [];
definitions.forEach((definition, tokenIndex) => {
const token = createToken(definition.letter, definition.color);
token.position.set(
x + (tokenIndex === 0 ? -0.32 : 0.32),
1.67,
0.12
);
token.userData.home = token.position.clone();
token.userData.phase = index * 1.8 + tokenIndex * 2.3;
token.userData.colorName = definition.name;
group.add(token);
tokens.push(token);
});
const selection = new THREE.Mesh(
new THREE.TorusGeometry(0.405, 0.027, 12, 64),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.95
})
);
selection.position.z = 0.16;
selection.visible = false;
group.add(selection);
const scanner = new THREE.Group();
scanner.position.set(x - 0.55, 1.67, 0.22);
scanner.visible = false;
const scanBeam = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 1.48, 0.055),
new THREE.MeshBasicMaterial({ color: 0xff67a7 })
);
scanner.add(scanBeam);
const scanSweep = new THREE.Mesh(
new THREE.BoxGeometry(0.88, 0.025, 0.76),
new THREE.MeshBasicMaterial({
color: 0xff67a7,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
scanner.add(scanSweep);
const scanLight = new THREE.PointLight(0xff4c9c, 4, 2.6, 2);
scanner.add(scanLight);
scanner.userData.light = scanLight;
group.add(scanner);
const label = makeTextSprite(`PARENT PAIR ${index === 0 ? "A" : "B"}`, {
color: index === 0 ? "#b8f7ff" : "#ffe3bb",
border: index === 0
? "rgba(54,220,255,0.38)"
: "rgba(255,184,77,0.38)",
width: 1.8
});
label.position.set(x, 2.86, 0);
group.add(label);
const subtitle = makeTextSprite(
index === 0 ? "01 / MATERNAL" : "02 / PATERNAL",
{
color: "#6f879c",
background: "rgba(7,12,20,0.54)",
border: "rgba(120,170,205,0.12)",
fontSize: 34,
width: 1.42
}
);
subtitle.position.set(x, 2.58, 0);
group.add(subtitle);
const localLight = new THREE.PointLight(accent, 6, 4.4, 2);
localLight.position.set(x, 2.25, 1.1);
group.add(localLight);
return {
index,
x,
group,
tokens,
selection,
scanner,
selectedIndex: -1,
accent
};
}
pairs.push(
createParentPair(
0,
-3.35,
[
{ letter: "D", color: 0x36dcff, name: "CYAN" },
{ letter: "d", color: 0x6478ff, name: "BLUE" }
],
0x36dcff
)
);
pairs.push(
createParentPair(
1,
-0.65,
[
{ letter: "T", color: 0xffb84d, name: "AMBER" },
{ letter: "t", color: 0xff5c9b, name: "CORAL" }
],
0xffa557
)
);
// -------------------------------------------------------------------------
// Offspring compartment
// -------------------------------------------------------------------------
const offspring = new THREE.Group();
machine.add(offspring);
const childBase = roundedPanel(2.25, 0.28, 1.7, 0.13, darkMetal);
childBase.position.set(3.25, 0.69, 0);
childBase.castShadow = true;
offspring.add(childBase);
const childGlass = new THREE.Mesh(
new THREE.BoxGeometry(1.78, 2.17, 1.22),
glassMaterial.clone()
);
childGlass.position.set(3.25, 1.72, 0);
offspring.add(childGlass);
const childEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(1.78, 2.17, 1.22)),
new THREE.LineBasicMaterial({
color: 0x8ceaff,
transparent: true,
opacity: 0.65
})
);
childEdges.position.copy(childGlass.position);
offspring.add(childEdges);
const childLabel = makeTextSprite("OFFSPRING", {
color: "#d8d0ff",
border: "rgba(166,143,255,0.4)",
width: 1.78
});
childLabel.position.set(3.25, 3.03, 0);
offspring.add(childLabel);
const childSubtitle = makeTextSprite("03 / ASSEMBLY", {
color: "#74859c",
background: "rgba(7,12,20,0.54)",
border: "rgba(120,170,205,0.12)",
fontSize: 34,
width: 1.42
});
childSubtitle.position.set(3.25, 2.75, 0);
offspring.add(childSubtitle);
const childLight = new THREE.PointLight(0x8b6cff, 7, 4.8, 2);
childLight.position.set(3.25, 2.35, 1.1);
offspring.add(childLight);
const childSlots = [];
for (let i = 0; i < 2; i++) {
const slotPosition = new THREE.Vector3(
3.25 + (i === 0 ? -0.34 : 0.34),
1.66,
0.13
);
const socket = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.025, 10, 64),
new THREE.MeshBasicMaterial({
color: 0x42556d,
transparent: true,
opacity: 0.8
})
);
socket.position.copy(slotPosition);
offspring.add(socket);
const socketGlow = new THREE.Mesh(
new THREE.CircleGeometry(0.27, 48),
new THREE.MeshBasicMaterial({
color: 0x6d8cff,
transparent: true,
opacity: 0.035,
depthWrite: false
})
);
socketGlow.position.copy(slotPosition);
socketGlow.position.z -= 0.01;
offspring.add(socketGlow);
childSlots.push({
position: slotPosition,
socket,
socketGlow
});
}
// A small DNA helix behind the inherited tokens.
const helix = new THREE.Group();
helix.position.set(3.25, 1.7, -0.37);
offspring.add(helix);
function makeHelixLine(offset, color) {
const points = [];
for (let i = 0; i <= 110; i++) {
const u = i / 110;
const angle = u * Math.PI * 8 + offset;
points.push(
new THREE.Vector3(
Math.sin(angle) * 0.17,
(u - 0.5) * 1.65,
Math.cos(angle) * 0.095
)
);
}
return new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.36
})
);
}
helix.add(makeHelixLine(0, 0x58e6ff));
helix.add(makeHelixLine(Math.PI, 0xd87aff));
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.65, 0),
theta: 0.48,
phi: 1.08,
radius: 13.3,
targetTheta: 0.48,
targetPhi: 1.08,
targetRadius: 13.3
};
function resetCamera() {
cameraState.targetTheta = 0.48;
cameraState.targetPhi = 1.08;
cameraState.targetRadius = 13.3;
cameraState.target.set(0, 1.65, 0);
}
function updateCamera(dt) {
const damping = 1 - Math.exp(-dt * 8);
cameraState.theta +=
(cameraState.targetTheta - cameraState.theta) * damping;
cameraState.phi +=
(cameraState.targetPhi - cameraState.phi) * damping;
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * damping;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const pointers = new Map();
let lastPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const values = [...pointers.values()];
lastPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.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.targetTheta -= dx * 0.0055;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - dy * 0.0048,
0.35,
1.42
);
} else if (pointers.size >= 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius * (lastPinchDistance / distance),
7.5,
20
);
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius * Math.exp(event.deltaY * 0.001),
7.5,
20
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (e) => e.preventDefault());
// -------------------------------------------------------------------------
// Inheritance state machine
// -------------------------------------------------------------------------
const runButton = document.querySelector("#runButton");
const autoButton = document.querySelector("#autoButton");
const clearButton = document.querySelector("#clearButton");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const statusDot = document.querySelector("#statusDot");
const outA = document.querySelector("#outA");
const outB = document.querySelector("#outB");
const stepA = document.querySelector("#stepA");
const stepB = document.querySelector("#stepB");
const stepC = document.querySelector("#stepC");
let simulation = {
phase: "idle",
time: 0,
pairIndex: 0
};
let autoMode = false;
let transferObjects = null;
function randomIndex(length) {
if (window.crypto?.getRandomValues) {
const values = new Uint32Array(1);
const limit = Math.floor(0x100000000 / length);
do {
window.crypto.getRandomValues(values);
} while (values[0] >= limit);
return values[0] % length;
}
return Math.floor(Math.random() * length);
}
function setStatus(title, detail, color = "#36dcff") {
statusTitle.textContent = title;
statusDetail.textContent = detail;
statusDot.style.background = color;
statusDot.style.boxShadow = `0 0 13px ${color}`;
}
function setStep(element, state) {
element.classList.remove("active", "done");
if (state) element.classList.add(state);
}
function resetSteps() {
setStep(stepA, "");
setStep(stepB, "");
setStep(stepC, "");
}
function clearChildTokens() {
for (const token of offspring.userData.tokens || []) {
offspring.remove(token);
}
offspring.userData.tokens = [];
for (const slot of childSlots) {
slot.socket.material.color.set(0x42556d);
slot.socket.material.opacity = 0.8;
slot.socketGlow.material.opacity = 0.035;
}
}
function clearTransfer() {
if (!transferObjects) return;
offspring.remove(transferObjects.token);
offspring.remove(transferObjects.line);
transferObjects.token.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (object.material.map) object.material.map.dispose();
object.material.dispose();
}
});
transferObjects.line.geometry.dispose();
transferObjects.line.material.dispose();
transferObjects = null;
}
function clearMachine() {
clearTransfer();
clearChildTokens();
for (const pair of pairs) {
pair.selectedIndex = -1;
pair.selection.visible = false;
pair.scanner.visible = false;
}
simulation = { phase: "idle", time: 0, pairIndex: 0 };
carriage.visible = false;
runButton.disabled = false;
outA.textContent = "PENDING";
outB.textContent = "PENDING";
resetSteps();
setStatus(
"Ready for a new generation",
"Press run to scan both parental pairs."
);
}
function startRun() {
if (simulation.phase !== "idle" && simulation.phase !== "complete") return;
clearTransfer();
clearChildTokens();
resetSteps();
for (const pair of pairs) {
pair.selectedIndex = -1;
pair.selection.visible = false;
pair.scanner.visible = false;
}
simulation = {
phase: "scan",
time: 0,
pairIndex: 0
};
runButton.disabled = true;
outA.textContent = "PENDING";
outB.textContent = "PENDING";
setStatus(
"Scanning parental pair A",
"The scanner is sampling one random maternal token.",
"#36dcff"
);
setStep(stepA, "active");
}
function launchTransfer(pair, sourceIndex) {
const sourceToken = pair.tokens[sourceIndex];
const destinationSlot = childSlots[simulation.pairIndex];
const start = sourceToken.position.clone();
const end = destinationSlot.position.clone();
const control = start.clone().lerp(end, 0.5);
control.y = 3.08;
control.z = 0.38;
const curve = new THREE.QuadraticBezierCurve3(start, control, end);
const copiedToken = createToken(
sourceToken.userData.letter,
sourceToken.userData.color,
0.78
);
copiedToken.position.copy(start);
offspring.add(copiedToken);
const lineGeometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(64)
);
const line = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: sourceToken.userData.color,
transparent: true,
opacity: 0.76,
depthWrite: false
})
);
offspring.add(line);
transferObjects = {
token: copiedToken,
line,
curve,
sourceToken,
destinationSlot,
sourceX: sourceToken.position.x,
destinationX: destinationSlot.position.x
};
carriage.visible = true;
carriage.position.x = sourceToken.position.x;
}
function completeTransfer() {
if (!transferObjects) return;
const source = transferObjects.sourceToken;
const destination = transferObjects.destinationSlot;
const token = createToken(
source.userData.letter,
source.userData.color,
0.78
);
token.position.copy(destination.position);
token.userData.birth = 0;
token.userData.phase = Math.random() * Math.PI * 2;
offspring.add(token);
offspring.userData.tokens.push(token);
destination.socket.material.color.set(source.userData.color);
destination.socket.material.opacity = 1;
destination.socketGlow.material.color.set(source.userData.color);
destination.socketGlow.material.opacity = 0.1;
const result = `${source.userData.letter} / ${source.userData.colorName}`;
if (simulation.pairIndex === 0) {
outA.textContent = result;
setStep(stepA, "done");
setStep(stepB, "active");
setStatus(
"Sampling parental pair B",
"The first token was copied. One paternal token remains.",
"#ffb84d"
);
} else {
outB.textContent = result;
setStep(stepB, "done");
setStep(stepC, "active");
setStatus(
"Offspring assembled",
"Two independently sampled tokens are ready in the child chamber.",
"#b58cff"
);
}
clearTransfer();
carriage.visible = false;
}
function updateSimulation(dt) {
if (simulation.phase === "idle") return;
simulation.time += dt;
if (simulation.phase === "scan") {
const pair = pairs[simulation.pairIndex];
const progress = Math.min(simulation.time / 1.3, 1);
const eased = progress * progress * (3 - 2 * progress);
pair.scanner.visible = true;
pair.scanner.position.x = THREE.MathUtils.lerp(
pair.x - 0.55,
pair.x + 0.55,
eased
);
pair.scanner.userData.light.intensity = 3.2 + Math.sin(
simulation.time * 19
) * 1.2;
if (progress >= 1) {
pair.scanner.visible = false;
const selectedIndex = randomIndex(pair.tokens.length);
pair.selectedIndex = selectedIndex;
pair.selection.visible = true;
pair.selection.material.color.set(
pair.tokens[selectedIndex].userData.color
);
pair.selection.position.set(
pair.tokens[selectedIndex].position.x,
pair.tokens[selectedIndex].position.y,
0.17
);
simulation.phase = "transfer";
simulation.time = 0;
launchTransfer(pair, selectedIndex);
setStatus(
simulation.pairIndex === 0
? "Copying token from pair A"
: "Copying token from pair B",
"The selected token is traveling through the copy rail.",
simulation.pairIndex === 0 ? "#36dcff" : "#ffb84d"
);
}
} else if (simulation.phase === "transfer") {
if (!transferObjects) return;
const progress = Math.min(simulation.time / 1.45, 1);
const eased = progress * progress * (3 - 2 * progress);
const position = transferObjects.curve.getPoint(eased);
transferObjects.token.position.copy(position);
transferObjects.token.rotation.y += dt * 4.4;
transferObjects.token.rotation.x = Math.sin(
simulation.time * 8
) * 0.35;
transferObjects.line.material.opacity =
0.35 + Math.sin(simulation.time * 15) * 0.24;
carriage.position.x = THREE.MathUtils.lerp(
transferObjects.sourceX,
transferObjects.destinationX,
eased
);
if (progress >= 1) {
completeTransfer();
if (simulation.pairIndex === 0) {
simulation.phase = "gap";
simulation.time = 0;
} else {
simulation.phase = "complete";
simulation.time = 0;
runButton.disabled = false;
setStep(stepC, "done");
setStatus(
"Inheritance cycle complete",
"The offspring compartment now contains its sampled allele pair.",
"#b58cff"
);
}
}
} else if (simulation.phase === "gap") {
if (simulation.time > 0.35) {
simulation.pairIndex = 1;
simulation.phase = "scan";
simulation.time = 0;
}
} else if (
simulation.phase === "complete" &&
autoMode &&
simulation.time > 2.6
) {
startRun();
}
}
// -------------------------------------------------------------------------
// UI events
// -------------------------------------------------------------------------
runButton.addEventListener("click", startRun);
clearButton.addEventListener("click", clearMachine);
autoButton.addEventListener("click", () => {
autoMode = !autoMode;
autoButton.classList.toggle("active", autoMode);
autoButton.setAttribute("aria-pressed", String(autoMode));
autoButton.textContent = autoMode ? "Auto on" : "Auto";
if (autoMode && simulation.phase === "idle") {
startRun();
}
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
startRun();
} else if (event.key.toLowerCase() === "a") {
autoButton.click();
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const ambientTime = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = ambientTime.getElapsedTime();
updateSimulation(dt);
updateCamera(dt);
for (const pair of pairs) {
for (const token of pair.tokens) {
const home = token.userData.home;
const phase = token.userData.phase;
token.position.y = home.y + Math.sin(time * 1.85 + phase) * 0.055;
token.rotation.y += dt * 0.36;
token.rotation.x = Math.sin(time * 0.85 + phase) * 0.11;
const pulse =
1 +
Math.sin(time * 2.4 + phase) * 0.025 +
(pair.selectedIndex === pair.tokens.indexOf(token) ? 0.1 : 0);
token.scale.setScalar(token.userData.baseScale * pulse);
}
if (pair.selection.visible) {
const selected = pair.tokens[pair.selectedIndex];
pair.selection.position.x = selected.position.x;
pair.selection.position.y = selected.position.y;
pair.selection.rotation.z += dt * 0.85;
const selectionPulse = 1 + Math.sin(time * 5.5) * 0.075;
pair.selection.scale.setScalar(selectionPulse);
}
}
for (const token of offspring.userData.tokens || []) {
token.userData.birth = Math.min(1, token.userData.birth + dt * 2.7);
const birthScale =
1 - Math.pow(1 - token.userData.birth, 3);
const float = Math.sin(time * 2 + token.userData.phase) * 0.025;
token.position.y =
childSlots[offspring.userData.tokens.indexOf(token)].position.y +
float;
token.rotation.y += dt * 0.65;
token.scale.setScalar(
token.userData.baseScale *
birthScale *
(1 + Math.sin(time * 2.8) * 0.025)
);
}
for (const slot of childSlots) {
slot.socket.rotation.z += dt * 0.18;
slot.socketGlow.material.opacity +=
(0.075 - slot.socketGlow.material.opacity) * dt * 2.5;
}
helix.rotation.y += dt * 0.2;
topGlow.material.color.setHSL(
0.54,
0.7,
0.32 + Math.sin(time * 1.2) * 0.025
);
dust.rotation.y += dt * 0.008;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```