Prompt specification
Build or customize the Three.js 3D scene "Fictional garden inheritance exhibit" 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: Fictional garden inheritance exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fictional-garden-inheritance-exhibit-x0923
Scene Description Prompt:
Make an HTML voxel garden using Three.js from cdnjs, showing parent and offspring plants inheriting one simplified binary trait through token combinations.
Working Three.js Starter (fictional-garden-inheritance-exhibit-x0923):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Heredity Garden</title>
<style>
:root {
--ink: #19362d;
--muted: #6e7f74;
--paper: #fffdf5;
--panel: #f5f1e6;
--line: #d9ddce;
--lime: #d9ed88;
--amber: #f2b84b;
--coral: #ef705f;
--green: #4e8d61;
--shadow: 0 16px 44px rgba(31, 57, 43, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: #dfe9df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
width: 100vw;
height: 100dvh;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 18% 15%, rgba(255, 255, 255, 0.7), transparent 28%),
#dfe9df;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.hud {
position: absolute;
top: 26px;
left: 28px;
z-index: 5;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.pixel-mark {
display: grid;
grid-template-columns: repeat(2, 10px);
grid-template-rows: repeat(2, 10px);
gap: 3px;
transform: rotate(-4deg);
}
.pixel-mark span {
background: var(--ink);
}
.pixel-mark span:nth-child(2) {
background: var(--coral);
}
.pixel-mark span:nth-child(3) {
background: var(--lime);
}
.pixel-mark span:nth-child(4) {
background: var(--ink);
}
.hud-kicker {
margin: 0 0 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.hud h2 {
margin: 0;
font-size: 18px;
font-weight: 850;
letter-spacing: -0.03em;
}
.generation-badge {
position: absolute;
top: 28px;
right: 26px;
z-index: 5;
padding: 9px 12px;
border: 1px solid rgba(25, 54, 45, 0.12);
border-radius: 999px;
background: rgba(255, 253, 245, 0.72);
color: var(--ink);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.generation-badge::before {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(78, 141, 97, 0.13);
content: "";
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.plant-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 124px;
padding: 8px 10px;
border: 1px solid rgba(25, 54, 45, 0.13);
border-radius: 10px;
background: rgba(255, 253, 245, 0.9);
box-shadow: 0 8px 24px rgba(25, 54, 45, 0.1);
color: var(--ink);
text-align: left;
transform: translate(-50%, -100%);
backdrop-filter: blur(9px);
cursor: pointer;
pointer-events: auto;
transition:
border-color 160ms ease,
box-shadow 160ms ease,
transform 160ms ease;
}
.plant-label:hover,
.plant-label.selected {
border-color: rgba(25, 54, 45, 0.38);
box-shadow: 0 10px 28px rgba(25, 54, 45, 0.17);
transform: translate(-50%, -100%) translateY(-2px);
}
.plant-label strong {
display: block;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.1em;
}
.plant-label small {
display: flex;
align-items: center;
gap: 4px;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
white-space: nowrap;
}
.label-dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--coral);
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}
.label-dot.amber {
background: var(--amber);
}
.mini-token {
display: inline-grid;
width: 15px;
height: 15px;
place-items: center;
border-radius: 4px;
color: var(--ink);
font-size: 9px;
font-weight: 900;
}
.mini-token.t0 {
background: var(--amber);
}
.mini-token.t1 {
background: var(--coral);
}
.stage-footer {
position: absolute;
right: 24px;
bottom: 22px;
left: 24px;
z-index: 5;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.instructions {
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid rgba(25, 54, 45, 0.1);
border-radius: 10px;
background: rgba(255, 253, 245, 0.72);
color: var(--muted);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 700;
}
.instructions b {
color: var(--ink);
}
.view-button {
border: 1px solid rgba(25, 54, 45, 0.12);
border-radius: 10px;
padding: 9px 12px;
background: rgba(255, 253, 245, 0.82);
color: var(--ink);
box-shadow: 0 7px 20px rgba(25, 54, 45, 0.08);
cursor: pointer;
pointer-events: auto;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.view-button:hover {
background: var(--paper);
}
.panel {
position: relative;
z-index: 10;
min-height: 0;
overflow-y: auto;
padding: 30px 28px 26px;
border-left: 1px solid rgba(25, 54, 45, 0.09);
background:
linear-gradient(rgba(245, 241, 230, 0.94), rgba(245, 241, 230, 0.94)),
repeating-linear-gradient(
0deg,
transparent,
transparent 23px,
rgba(25, 54, 45, 0.04) 24px
);
box-shadow: -18px 0 50px rgba(25, 54, 45, 0.07);
}
.panel-kicker {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 11px;
color: var(--green);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-kicker::before {
width: 18px;
height: 2px;
background: currentColor;
content: "";
}
.panel h1 {
max-width: 300px;
margin: 0;
font-size: clamp(29px, 3vw, 39px);
font-weight: 900;
letter-spacing: -0.055em;
line-height: 0.98;
}
.intro {
margin: 15px 0 23px;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.trait-card {
padding: 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 253, 245, 0.76);
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-label span:last-child {
letter-spacing: 0;
text-transform: none;
}
.trait-options {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.trait-option {
display: flex;
align-items: center;
gap: 9px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: #fffaf0;
}
.trait-swatch {
width: 25px;
height: 25px;
flex: 0 0 auto;
border-radius: 7px;
box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.trait-option strong {
display: block;
font-size: 10px;
font-weight: 900;
}
.trait-option small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.rule {
margin-top: 12px;
padding: 10px 11px;
border-radius: 9px;
background: var(--ink);
color: #eaf0df;
font-size: 10px;
line-height: 1.5;
}
.rule b {
color: var(--lime);
}
.section-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 24px 0 10px;
}
.section-heading h2 {
margin: 0;
font-size: 13px;
font-weight: 900;
}
.section-heading span {
color: var(--muted);
font-size: 9px;
}
.parent-list {
display: grid;
gap: 8px;
}
.parent-card {
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 253, 245, 0.65);
cursor: pointer;
transition: 160ms ease;
}
.parent-card:hover,
.parent-card.selected {
border-color: rgba(25, 54, 45, 0.32);
background: var(--paper);
}
.plant-icon {
position: relative;
width: 31px;
height: 31px;
border-radius: 8px;
background: #dfe9d5;
}
.plant-icon::before {
position: absolute;
top: 6px;
left: 13px;
width: 4px;
height: 18px;
border-radius: 2px;
background: #397554;
content: "";
}
.plant-icon::after {
position: absolute;
top: 5px;
left: 9px;
width: 12px;
height: 12px;
border-radius: 3px;
background: var(--coral);
box-shadow:
8px 0 0 -3px var(--coral),
0 8px 0 -3px var(--coral);
content: "";
}
.parent-card strong {
display: block;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.04em;
}
.parent-card small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.allele-bank {
display: flex;
gap: 4px;
}
.allele {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 7px;
color: var(--ink);
font-size: 10px;
font-weight: 900;
}
.allele.zero {
background: var(--amber);
}
.allele.one {
background: var(--coral);
}
.child-list {
display: grid;
gap: 9px;
}
.child-card {
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 253, 245, 0.7);
transition: 160ms ease;
}
.child-card.selected {
border-color: rgba(25, 54, 45, 0.35);
background: var(--paper);
box-shadow: 0 7px 20px rgba(25, 54, 45, 0.06);
}
.child-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 11px;
}
.child-select {
display: flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
background: none;
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.06em;
}
.child-index {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border-radius: 7px;
background: var(--ink);
color: var(--lime);
font-size: 9px;
}
.phenotype {
padding: 5px 7px;
border-radius: 6px;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.phenotype.amber {
background: rgba(242, 184, 75, 0.25);
color: #91621c;
}
.phenotype.coral {
background: rgba(239, 112, 95, 0.18);
color: #a24c40;
}
.inherit-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
padding: 7px 0;
border-top: 1px dashed rgba(25, 54, 45, 0.12);
color: var(--muted);
font-size: 9px;
}
.token-buttons {
display: flex;
gap: 5px;
}
.token-choice {
width: 29px;
height: 27px;
border: 1px solid var(--line);
border-radius: 7px;
background: #fffdf8;
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 900;
transition: 140ms ease;
}
.token-choice:hover {
transform: translateY(-1px);
}
.token-choice[data-token="0"].active {
border-color: #d89e35;
background: var(--amber);
color: var(--ink);
box-shadow: 0 4px 10px rgba(242, 184, 75, 0.25);
}
.token-choice[data-token="1"].active {
border-color: #d85d50;
background: var(--coral);
color: white;
box-shadow: 0 4px 10px rgba(239, 112, 95, 0.22);
}
.selected-readout {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14px;
padding: 10px 11px;
border: 1px dashed rgba(25, 54, 45, 0.2);
border-radius: 9px;
color: var(--muted);
font-size: 9px;
}
.selected-readout strong {
color: var(--ink);
font-size: 9px;
letter-spacing: 0.06em;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 18px;
}
.action {
min-height: 42px;
padding: 10px 12px;
border-radius: 10px;
cursor: pointer;
font-size: 10px;
font-weight: 850;
transition: 160ms ease;
}
.action.primary {
border: 1px solid var(--ink);
background: var(--ink);
color: var(--paper);
}
.action.secondary {
border: 1px solid var(--line);
background: var(--paper);
color: var(--ink);
}
.action:hover {
transform: translateY(-1px);
box-shadow: 0 7px 18px rgba(25, 54, 45, 0.1);
}
.action.full {
grid-column: 1 / -1;
}
.panel-note {
margin: 13px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
text-align: center;
}
.toast {
position: absolute;
bottom: 75px;
left: 50%;
z-index: 12;
padding: 10px 14px;
border-radius: 999px;
background: var(--ink);
color: var(--paper);
box-shadow: var(--shadow);
font-size: 10px;
font-weight: 800;
opacity: 0;
transform: translate(-50%, 10px);
transition: 200ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 850px) {
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: 60dvh auto;
height: auto;
min-height: 100dvh;
}
.panel {
overflow: visible;
padding: 27px 22px 34px;
border-top: 1px solid rgba(25, 54, 45, 0.09);
border-left: 0;
}
.hud {
top: 18px;
left: 18px;
}
.hud h2 {
font-size: 15px;
}
.generation-badge {
top: 18px;
right: 16px;
}
.stage-footer {
right: 16px;
bottom: 16px;
left: 16px;
}
.instructions {
max-width: 230px;
line-height: 1.4;
}
.plant-label {
min-width: 102px;
padding: 6px 8px;
}
.plant-label small {
font-size: 8px;
}
}
@media (max-width: 480px) {
.hud-kicker,
.generation-badge {
display: none;
}
.instructions span {
display: none;
}
.trait-options {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<main class="app">
<section class="stage" id="stage" aria-label="Interactive voxel inheritance garden">
<canvas
id="scene"
tabindex="0"
aria-label="Voxel garden. Drag to orbit, scroll to zoom, and select plants."
></canvas>
<div id="labels"></div>
<header class="hud">
<div class="pixel-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<p class="hud-kicker">A pocket-sized genetics experiment</p>
<h2>VOXEL HEREDITY</h2>
</div>
</header>
<div class="generation-badge" id="generationBadge">Generation 01</div>
<footer class="stage-footer">
<div class="instructions">
<b>DRAG</b><span>to orbit</span>
<b>SCROLL</b><span>to zoom</span>
<b>CLICK</b><span>a flower to inspect</span>
</div>
<button class="view-button" id="resetView">Reset view</button>
</footer>
<div class="toast" id="toast">Offspring grown</div>
</section>
<aside class="panel">
<div class="panel-kicker">Field notes / 01</div>
<h1>The inheritance patch</h1>
<p class="intro">
Two parents pass binary bloom tokens to their offspring.
Choose each inherited token and watch the flower respond.
</p>
<section class="trait-card">
<div class="section-label">
<span>One binary trait</span>
<span>Bloom pigment</span>
</div>
<div class="trait-options">
<div class="trait-option">
<span class="trait-swatch" style="background: var(--amber)"></span>
<div>
<strong>TOKEN 0 · AMBER</strong>
<small>recessive bloom</small>
</div>
</div>
<div class="trait-option">
<span class="trait-swatch" style="background: var(--coral)"></span>
<div>
<strong>TOKEN 1 · CORAL</strong>
<small>dominant bloom</small>
</div>
</div>
</div>
<div class="rule">
Simplified rule: <b>token 1 is dominant</b>. Only <b>0 + 0</b>
produces an amber flower.
</div>
</section>
<div class="section-heading">
<h2>Parent token banks</h2>
<span>Each can pass 0 or 1</span>
</div>
<div class="parent-list">
<div class="parent-card" id="parent-a-card" data-select-plant="parent-a">
<div class="plant-icon" aria-hidden="true"></div>
<div>
<strong>ASTER</strong>
<small>Parent A · mixed token bank</small>
</div>
<div class="allele-bank" aria-label="Can pass token 0 or token 1">
<span class="allele zero">0</span>
<span class="allele one">1</span>
</div>
</div>
<div class="parent-card" id="parent-b-card" data-select-plant="parent-b">
<div class="plant-icon" aria-hidden="true"></div>
<div>
<strong>BRAMBLE</strong>
<small>Parent B · mixed token bank</small>
</div>
<div class="allele-bank" aria-label="Can pass token 0 or token 1">
<span class="allele zero">0</span>
<span class="allele one">1</span>
</div>
</div>
</div>
<div class="section-heading">
<h2>Offspring crosses</h2>
<span>Choose inherited tokens</span>
</div>
<div class="child-list">
<article class="child-card selected" id="child-card-0">
<div class="child-head">
<button class="child-select" data-select-child="0">
<span class="child-index">O1</span>
OFFSPRING ONE
</button>
<span class="phenotype amber" id="phenotype-0">Amber</span>
</div>
<div class="inherit-row">
<span>Token inherited from Aster</span>
<div class="token-buttons">
<button class="token-choice active" data-child="0" data-parent="0" data-token="0" aria-pressed="true">0</button>
<button class="token-choice" data-child="0" data-parent="0" data-token="1" aria-pressed="false">1</button>
</div>
</div>
<div class="inherit-row">
<span>Token inherited from Bramble</span>
<div class="token-buttons">
<button class="token-choice active" data-child="0" data-parent="1" data-token="0" aria-pressed="true">0</button>
<button class="token-choice" data-child="0" data-parent="1" data-token="1" aria-pressed="false">1</button>
</div>
</div>
</article>
<article class="child-card" id="child-card-1">
<div class="child-head">
<button class="child-select" data-select-child="1">
<span class="child-index">O2</span>
OFFSPRING TWO
</button>
<span class="phenotype coral" id="phenotype-1">Coral</span>
</div>
<div class="inherit-row">
<span>Token inherited from Aster</span>
<div class="token-buttons">
<button class="token-choice active" data-child="1" data-parent="0" data-token="0" aria-pressed="true">0</button>
<button class="token-choice" data-child="1" data-parent="0" data-token="1" aria-pressed="false">1</button>
</div>
</div>
<div class="inherit-row">
<span>Token inherited from Bramble</span>
<div class="token-buttons">
<button class="token-choice" data-child="1" data-parent="1" data-token="0" aria-pressed="false">0</button>
<button class="token-choice active" data-child="1" data-parent="1" data-token="1" aria-pressed="true">1</button>
</div>
</div>
</article>
</div>
<div class="selected-readout">
<span>Selected specimen</span>
<strong id="selectedName">OFFSPRING ONE</strong>
</div>
<div class="actions">
<button class="action primary" id="growButton">Grow offspring</button>
<button class="action secondary" id="shuffleButton">Shuffle tokens</button>
<button class="action secondary full" id="resetCross">Reset the cross</button>
</div>
<p class="panel-note">
A deliberately small inheritance model: one trait, two tokens,
and a simple dominant rule.
</p>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const canvas = document.querySelector("#scene");
const labelsRoot = document.querySelector("#labels");
const toast = document.querySelector("#toast");
const TOKEN_COLORS = {
0: 0xf2b84b,
1: 0xef705f
};
const TRAIT_NAMES = {
0: "AMBER",
1: "CORAL"
};
const combos = [
{ a: 0, b: 0 },
{ a: 0, b: 1 }
];
let generation = 1;
let activeChild = 0;
let selectedPlant = "child-0";
let toastTimer;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9df);
scene.fog = new THREE.Fog(0xdfe9df, 19, 34);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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.08;
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 80);
const cameraTarget = new THREE.Vector3(0, 0.6, 0);
const cameraState = {
yaw: 0.48,
pitch: 0.68,
radius: 18
};
const hemisphere = new THREE.HemisphereLight(0xf8ffe9, 0x55705b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d6, 3.1);
sun.position.set(-7, 12, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d8ee, 0.75);
fill.position.set(8, 5, -8);
scene.add(fill);
const materialCache = new Map();
function getMaterial(color, extra = {}) {
const key = `${color}-${JSON.stringify(extra)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
flatShading: true,
...extra
})
);
}
return materialCache.get(key);
}
function box(parent, width, height, depth, color, x = 0, y = 0, z = 0, extra = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
extra.material || getMaterial(color, extra.materialOptions || {})
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function buildGarden() {
const garden = new THREE.Group();
scene.add(garden);
// Floating voxel plot.
box(garden, 14.4, 0.56, 10.7, 0x78956c, 0, -0.42, 0);
box(garden, 14.05, 0.2, 10.35, 0xa9c887, 0, -0.05, 0);
// Soil beds.
makeBed(garden, -3.35, -2.15, 4.7, 2.55);
makeBed(garden, 3.35, -2.15, 4.7, 2.55);
makeBed(garden, -2.15, 2.1, 3.7, 2.65);
makeBed(garden, 2.15, 2.1, 3.7, 2.65);
// Central stepping stones.
for (let i = 0; i < 7; i++) {
const z = -4.1 + i * 1.35;
box(
garden,
0.9 + (i % 2) * 0.12,
0.12,
0.57,
i % 2 ? 0xd5c5a6 : 0xe4d6b9,
0,
0.16,
z
);
}
// Back fence.
for (let x = -6.4; x <= 6.5; x += 1.3) {
box(garden, 0.18, 1.25, 0.18, 0xd7b083, x, 0.65, -4.9);
box(garden, 0.23, 0.12, 0.23, 0xefcba0, x, 1.29, -4.9);
}
box(garden, 13.2, 0.16, 0.16, 0xc99b70, 0, 0.56, -4.9);
box(garden, 13.2, 0.16, 0.16, 0xc99b70, 0, 1.02, -4.9);
// Corner shrubs and tiny flowers.
makeShrub(garden, -6.15, -3.65, 0.9);
makeShrub(garden, 6.15, -3.65, 0.78);
makeShrub(garden, -6.2, 3.75, 0.68);
makeShrub(garden, 6.2, 3.75, 0.74);
makeTinyFlowers(garden, -5.95, -1.0);
makeTinyFlowers(garden, 5.95, 1.1);
makeTinyFlowers(garden, -5.95, 2.75);
makeTinyFlowers(garden, 5.95, -0.8);
// Voxel sun in the distant sky.
const skySun = new THREE.Group();
skySun.position.set(-7.1, 7.0, -8.5);
box(skySun, 1.1, 1.1, 0.35, 0xf6d978, 0, 0, 0);
box(skySun, 1.55, 0.18, 0.2, 0xf6d978, 0, 0.34, 0);
box(skySun, 1.55, 0.18, 0.2, 0xf6d978, 0, -0.34, 0);
box(skySun, 0.18, 1.55, 0.2, 0xf6d978, 0.34, 0, 0);
box(skySun, 0.18, 1.55, 0.2, 0xf6d978, -0.34, 0, 0);
scene.add(skySun);
// A few drifting pollen motes.
const pollenGeometry = new THREE.BufferGeometry();
const pollenPositions = new Float32Array(42 * 3);
for (let i = 0; i < 42; i++) {
pollenPositions[i * 3] = (Math.random() - 0.5) * 13;
pollenPositions[i * 3 + 1] = 0.7 + Math.random() * 4.7;
pollenPositions[i * 3 + 2] = (Math.random() - 0.5) * 9;
}
pollenGeometry.setAttribute(
"position",
new THREE.BufferAttribute(pollenPositions, 3)
);
const pollen = new THREE.Points(
pollenGeometry,
new THREE.PointsMaterial({
color: 0xfff3bd,
size: 0.075,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
pollen.name = "pollen";
scene.add(pollen);
}
function makeBed(parent, x, z, width, depth) {
const bed = new THREE.Group();
bed.position.set(x, 0, z);
parent.add(bed);
box(bed, width, 0.28, depth, 0x745547, 0, 0.16, 0);
const railColor = 0xbd835c;
const railHeight = 0.2;
box(bed, width + 0.16, railHeight, 0.15, railColor, 0, 0.27, -depth / 2);
box(bed, width + 0.16, railHeight, 0.15, railColor, 0, 0.27, depth / 2);
box(bed, 0.15, railHeight, depth, railColor, -width / 2, 0.27, 0);
box(bed, 0.15, railHeight, depth, railColor, width / 2, 0.27, 0);
// A few deterministic soil flecks.
for (let i = 0; i < 13; i++) {
const px = ((i * 7) % 10) / 10 - 0.5;
const pz = ((i * 3) % 7) / 7 - 0.5;
box(
bed,
0.12 + (i % 3) * 0.03,
0.04,
0.09,
i % 2 ? 0x5d443a : 0x8a6852,
px * (width - 0.5),
0.32,
pz * (depth - 0.4)
);
}
}
function makeShrub(parent, x, z, scale) {
const shrub = new THREE.Group();
shrub.position.set(x, 0.1, z);
shrub.scale.setScalar(scale);
parent.add(shrub);
box(shrub, 0.2, 0.8, 0.2, 0x745c3c, 0, 0.4, 0);
box(shrub, 0.8, 0.7, 0.7, 0x4f855a, 0, 1.05, 0);
box(shrub, 0.58, 0.65, 0.58, 0x69a565, -0.18, 1.42, 0.08);
box(shrub, 0.5, 0.5, 0.5, 0x78b76b, 0.35, 1.35, -0.08);
}
function makeTinyFlowers(parent, x, z) {
const colors = [0xf2b84b, 0xef705f, 0xf3d879];
for (let i = 0; i < 4; i++) {
const px = x + (i - 1.5) * 0.23;
const pz = z + Math.sin(i * 2.1) * 0.22;
box(parent, 0.055, 0.45, 0.055, 0x4b8358, px, 0.28, pz);
box(parent, 0.22, 0.16, 0.22, colors[i % colors.length], px, 0.55, pz);
}
}
const plantMeshes = [];
const plants = {};
const labels = [];
const tokenCubes = [[], []];
const parentTokenCubes = { "parent-a": [], "parent-b": [] };
function createPlant({
id,
name,
x,
z,
scale = 1,
trait = 1,
parentType = false
}) {
const root = new THREE.Group();
root.position.set(x, 0.33, z);
root.userData.plantId = id;
root.userData.phase = Math.random() * Math.PI * 2;
scene.add(root);
const visual = new THREE.Group();
visual.scale.setScalar(0.05);
root.add(visual);
const bloomMaterial = new THREE.MeshStandardMaterial({
color: TOKEN_COLORS[trait],
roughness: 0.78,
flatShading: true
});
// Stem.
const stem = box(visual, 0.2, 1.62, 0.2, 0x326c49, 0, 0.81, 0);
stem.userData.plantId = id;
const upperStem = box(visual, 0.16, 0.72, 0.16, 0x3c7951, 0.09, 1.6, 0);
upperStem.rotation.z = -0.12;
upperStem.userData.plantId = id;
// Blocky leaves.
const leaves = [
{ x: -0.34, y: 0.78, z: 0, sx: 0.68, sy: 0.13, sz: 0.3, rz: 0.18 },
{ x: 0.34, y: 1.08, z: 0.03, sx: 0.66, sy: 0.13, sz: 0.3, rz: -0.18 },
{ x: 0.02, y: 0.49, z: 0.3, sx: 0.3, sy: 0.12, sz: 0.65, rz: 0 },
{ x: -0.02, y: 1.36, z: -0.28, sx: 0.28, sy: 0.12, sz: 0.6, rz: 0 }
];
leaves.forEach((leaf, index) => {
const mesh = box(
visual,
leaf.sx,
leaf.sy,
leaf.sz,
index % 2 ? 0x57965c : 0x6aa762,
leaf.x,
leaf.y,
leaf.z
);
mesh.rotation.z = leaf.rz;
mesh.rotation.x = index === 2 ? -0.15 : index === 3 ? 0.12 : 0;
mesh.userData.plantId = id;
});
// Voxel flower head.
const petalPositions = [
[0, 0, 0.39, 0.48, 0.23, 0.4],
[0, 0, -0.39, 0.48, 0.23, 0.4],
[0.39, 0, 0, 0.4, 0.23, 0.48],
[-0.39, 0, 0, 0.4, 0.23, 0.48]
];
petalPositions.forEach(([px, py, pz, w, h, d]) => {
const petal = box(
visual,
w,
h,
d,
TOKEN_COLORS[trait],
px,
2.03 + py,
pz,
{ material: bloomMaterial }
);
petal.userData.plantId = id;
});
const center = box(
visual,
0.38,
0.3,
0.38,
trait ? 0xf6d36d : 0xffdd87,
0,
2.1,
0
);
center.userData.plantId = id;
if (!parentType) {
const frontZ = z + 0.88;
for (let i = 0; i < 2; i++) {
const cubeMaterial = new THREE.MeshStandardMaterial({
color: TOKEN_COLORS[i],
roughness: 0.72,
flatShading: true
});
const cube = box(
scene,
0.27,
0.27,
0.27,
TOKEN_COLORS[i],
x + (i === 0 ? -0.2 : 0.2),
0.52,
frontZ,
{ material: cubeMaterial }
);
tokenCubes[Number(id.slice(-1))][i] = cube;
}
} else {
const frontZ = z + 0.82;
for (let i = 0; i < 2; i++) {
const cubeMaterial = new THREE.MeshStandardMaterial({
color: TOKEN_COLORS[i],
roughness: 0.72,
flatShading: true
});
const cube = box(
scene,
0.25,
0.25,
0.25,
TOKEN_COLORS[i],
x + (i === 0 ? -0.18 : 0.18),
0.48,
frontZ,
{ material: cubeMaterial }
);
parentTokenCubes[id][i] = cube;
}
}
const label = createLabel(id, name, x, z + (parentType ? 2.85 : 2.85), parentType);
labels.push(label);
const plant = {
id,
name,
root,
visual,
bloomMaterial,
scale,
growth: 0.05,
phase: root.userData.phase,
parentType
};
plants[id] = plant;
visual.traverse((object) => {
if (object.isMesh) {
object.userData.plantId = id;
plantMeshes.push(object);
}
});
return plant;
}
function createLabel(id, name, x, y, parentType) {
const button = document.createElement("button");
button.className = "plant-label";
button.dataset.selectPlant = id;
button.type = "button";
labelsRoot.appendChild(button);
button.addEventListener("click", (event) => {
event.stopPropagation();
selectPlant(id);
});
return {
id,
element: button,
parentType,
anchor: new THREE.Vector3(x, y + 0.33, 0)
};
}
buildGarden();
createPlant({
id: "parent-a",
name: "ASTER",
x: -3.35,
z: -2.15,
scale: 1.08,
trait: 1,
parentType: true
});
createPlant({
id: "parent-b",
name: "BRAMBLE",
x: 3.35,
z: -2.15,
scale: 1.02,
trait: 1,
parentType: true
});
createPlant({
id: "child-0",
name: "OFFSPRING ONE",
x: -2.15,
z: 2.1,
scale: 0.9,
trait: 0
});
createPlant({
id: "child-1",
name: "OFFSPRING TWO",
x: 2.15,
z: 2.1,
scale: 0.94,
trait: 1
});
// Square selection frame.
const selectionFrame = new THREE.Group();
scene.add(selectionFrame);
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0xd9ed88,
transparent: true,
opacity: 0.9
});
const frameBars = [
box(selectionFrame, 1, 0.06, 0.08, 0xd9ed88, 0, 0, 0, {
material: selectionMaterial
}),
box(selectionFrame, 1, 0.06, 0.08, 0xd9ed88, 0, 0, 0, {
material: selectionMaterial
}),
box(selectionFrame, 0.08, 0.06, 1, 0xd9ed88, 0, 0, 0, {
material: selectionMaterial
}),
box(selectionFrame, 0.08, 0.06, 1, 0xd9ed88, 0, 0, 0, {
material: selectionMaterial
})
];
const plantPositions = {
"parent-a": { x: -3.35, z: -2.15, w: 4.8, d: 2.7 },
"parent-b": { x: 3.35, z: -2.15, w: 4.8, d: 2.7 },
"child-0": { x: -2.15, z: 2.1, w: 3.85, d: 2.8 },
"child-1": { x: 2.15, z: 2.1, w: 3.85, d: 2.8 }
};
function updateSelectionFrame() {
const position = plantPositions[selectedPlant];
const y = 0.43;
frameBars[0].position.set(position.x, y, position.z - position.d / 2);
frameBars[0].scale.x = position.w;
frameBars[1].position.set(position.x, y, position.z + position.d / 2);
frameBars[1].scale.x = position.w;
frameBars[2].position.set(position.x - position.w / 2, y, position.z);
frameBars[2].scale.z = position.d;
frameBars[3].position.set(position.x + position.w / 2, y, position.z);
frameBars[3].scale.z = position.d;
}
updateSelectionFrame();
function selectPlant(id) {
if (!plants[id]) return;
selectedPlant = id;
if (id.startsWith("child-")) {
activeChild = Number(id.split("-")[1]);
}
document.querySelectorAll(".plant-label").forEach((label) => {
label.classList.toggle("selected", label.dataset.selectPlant === id);
});
document.querySelectorAll(".parent-card").forEach((card) => {
card.classList.toggle("selected", card.dataset.selectPlant === id);
});
document.querySelectorAll(".child-card").forEach((card, index) => {
card.classList.toggle("selected", index === activeChild);
});
document.querySelector("#selectedName").textContent = plants[id].name;
updateSelectionFrame();
}
function traitFromCombo(combo) {
return combo.a || combo.b;
}
function updatePlantTrait(childIndex, animate = true) {
const combo = combos[childIndex];
const trait = traitFromCombo(combo);
const plant = plants[`child-${childIndex}`];
plant.bloomMaterial.color.setHex(TOKEN_COLORS[trait]);
tokenCubes[childIndex][0].material.color.setHex(TOKEN_COLORS[combo.a]);
tokenCubes[childIndex][1].material.color.setHex(TOKEN_COLORS[combo.b]);
if (animate) {
plant.growth = 0.28;
}
}
function updateInterface() {
combos.forEach((combo, index) => {
const trait = traitFromCombo(combo);
const phenotype = document.querySelector(`#phenotype-${index}`);
phenotype.textContent = TRAIT_NAMES[trait];
phenotype.className = `phenotype ${trait === 0 ? "amber" : "coral"}`;
document.querySelectorAll(`.token-choice[data-child="${index}"]`).forEach((button) => {
const parentIndex = Number(button.dataset.parent);
const token = Number(button.dataset.token);
const active = combo[parentIndex === 0 ? "a" : "b"] === token;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
});
labels.forEach((label) => {
if (label.parentType) {
const isAmber = false;
label.element.innerHTML = `
<span class="label-dot ${isAmber ? "amber" : ""}"></span>
<span>
<strong>${label.id === "parent-a" ? "ASTER" : "BRAMBLE"}</strong>
<small>PARENT · CAN PASS 0 / 1</small>
</span>
`;
return;
}
const index = Number(label.id.split("-")[1]);
const combo = combos[index];
const trait = traitFromCombo(combo);
label.element.innerHTML = `
<span class="label-dot ${trait === 0 ? "amber" : ""}"></span>
<span>
<strong>OFFSPRING ${index + 1}</strong>
<small>
<b class="mini-token t${combo.a}">${combo.a}</b>
+
<b class="mini-token t${combo.b}">${combo.b}</b>
· ${TRAIT_NAMES[trait]}
</small>
</span>
`;
});
document.querySelector("#generationBadge").textContent =
`Generation ${String(generation).padStart(2, "0")}`;
}
document.querySelectorAll(".token-choice").forEach((button) => {
button.addEventListener("click", () => {
const childIndex = Number(button.dataset.child);
const parentIndex = Number(button.dataset.parent);
const token = Number(button.dataset.token);
combos[childIndex][parentIndex === 0 ? "a" : "b"] = token;
updatePlantTrait(childIndex, true);
updateInterface();
selectPlant(`child-${childIndex}`);
});
});
document.querySelectorAll("[data-select-child]").forEach((button) => {
button.addEventListener("click", () => {
const index = Number(button.dataset.selectChild);
activeChild = index;
selectPlant(`child-${index}`);
});
});
document.querySelectorAll("[data-select-plant]").forEach((button) => {
button.addEventListener("click", () => {
selectPlant(button.dataset.selectPlant);
});
});
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 1700);
}
document.querySelector("#growButton").addEventListener("click", () => {
generation += 1;
combos.forEach((_, index) => updatePlantTrait(index, true));
updateInterface();
showToast(`Generation ${generation} grown`);
});
document.querySelector("#shuffleButton").addEventListener("click", () => {
const firstA = Math.random() < 0.5 ? 0 : 1;
const firstB = Math.random() < 0.5 ? 0 : 1;
combos[0].a = firstA;
combos[0].b = firstB;
combos[1].a = firstB;
combos[1].b = firstA;
// Keep at least one recessive cross visible in the garden.
if (traitFromCombo(combos[0]) === 1 && traitFromCombo(combos[1]) === 1) {
combos[0].a = 0;
combos[0].b = 0;
}
generation += 1;
combos.forEach((_, index) => updatePlantTrait(index, true));
updateInterface();
showToast("Tokens reshuffled");
});
document.querySelector("#resetCross").addEventListener("click", () => {
combos[0].a = 0;
combos[0].b = 0;
combos[1].a = 0;
combos[1].b = 1;
generation = 1;
combos.forEach((_, index) => updatePlantTrait(index, true));
updateInterface();
selectPlant("child-0");
showToast("The original cross is restored");
});
// Direct camera controls; no Three.js examples/addons are used.
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resetView() {
cameraState.yaw = 0.48;
cameraState.pitch = 0.68;
cameraState.radius = 18;
camera.zoom = 1;
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const drag = {
active: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0
};
function pointerToNDC(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickPlant(event) {
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(plantMeshes, false);
if (!hits.length) return;
let object = hits[0].object;
while (object && !object.userData.plantId) {
object = object.parent;
}
if (object?.userData.plantId) {
selectPlant(object.userData.plantId);
}
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
drag.active = true;
drag.moved = false;
drag.startX = event.clientX;
drag.startY = event.clientY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (drag.active) {
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
const totalDistance = Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
);
if (totalDistance > 4) drag.moved = true;
if (drag.moved) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.34,
1.08
);
updateCamera();
}
} else {
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(plantMeshes, false);
canvas.style.cursor = hits.length ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
if (!drag.active) return;
drag.active = false;
canvas.style.cursor = "grab";
if (!drag.moved) {
pickPlant(event);
}
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
drag.active = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.7
);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
renderer.setSize(width, height, false);
const halfHeight = Math.max(5.55, 7.65 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
updateCamera();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
labels.forEach((label) => {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
Object.values(plants).forEach((plant) => {
if (reducedMotion) {
plant.growth = 1;
} else {
plant.growth = THREE.MathUtils.lerp(plant.growth, 1, 0.075);
}
const growth = plant.scale * plant.growth;
plant.visual.scale.setScalar(growth);
plant.visual.rotation.z = Math.sin(elapsed * 1.15 + plant.phase) * 0.018;
plant.visual.rotation.x = Math.cos(elapsed * 0.85 + plant.phase) * 0.009;
});
const pollen = scene.getObjectByName("pollen");
if (pollen) {
pollen.rotation.y = elapsed * 0.018;
pollen.position.y = Math.sin(elapsed * 0.35) * 0.12;
}
selectionMaterial.opacity = 0.72 + Math.sin(elapsed * 2.4) * 0.17;
updateLabels();
renderer.render(scene, camera);
}
updateInterface();
selectPlant("child-0");
animate();
</script>
</body>
</html>
```