Prompt specification
Build or customize the Three.js 3D scene "Fictional garden treatment experiment" 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 treatment experiment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fictional-garden-treatment-experiment-x1819
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows random assignment to experimental groups. Compose matched plant plots assigned to two harmless synthetic growth conditions using a visible random seed; distinguish treatment effects from background variability in the toy data. Voxel style.
Working Three.js Starter (fictional-garden-treatment-experiment-x1819):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Field Trial — Randomized Matched Plots</title>
<style>
:root {
color-scheme: dark;
--bg: #07111c;
--panel: rgba(13, 26, 40, 0.92);
--panel-solid: #0d1a28;
--border: rgba(151, 190, 217, 0.16);
--text: #eaf6ff;
--muted: #91a8b9;
--a: #ff8066;
--b: #51d4cf;
--green: #82d784;
--background: #91a8b9;
--shadow: rgba(0, 0, 0, 0.35);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 15% 0%, #142b40 0, transparent 36rem),
radial-gradient(circle at 95% 10%, #102b32 0, transparent 30rem),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
padding: 20px;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
.app {
width: min(1580px, 100%);
margin: 0 auto;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
margin-bottom: 16px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--b);
font-size: 0.73rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.65rem, 3vw, 2.65rem);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
max-width: 720px;
margin: 9px 0 0;
color: var(--muted);
font-size: 0.94rem;
line-height: 1.55;
}
.safe-badge {
flex: 0 0 auto;
padding: 9px 12px;
border: 1px solid rgba(129, 215, 132, 0.3);
border-radius: 999px;
background: rgba(129, 215, 132, 0.08);
color: #b8edb8;
font-size: 0.76rem;
font-weight: 750;
white-space: nowrap;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
gap: 16px;
align-items: start;
}
.viewport-shell,
.card {
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px var(--shadow);
overflow: hidden;
backdrop-filter: blur(16px);
}
.viewport-shell {
position: relative;
height: calc(100vh - 150px);
min-height: 620px;
max-height: 960px;
background: #09131d;
}
#viewport {
position: absolute;
inset: 0;
overflow: hidden;
}
#viewport canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.scene-hud {
position: absolute;
top: 14px;
left: 14px;
z-index: 2;
max-width: calc(100% - 130px);
padding: 11px 13px;
border: 1px solid rgba(151, 190, 217, 0.18);
border-radius: 12px;
background: rgba(5, 14, 23, 0.78);
pointer-events: none;
backdrop-filter: blur(10px);
}
.scene-hud strong {
display: block;
overflow: hidden;
color: #f3fbff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.83rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.scene-hud span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 0.73rem;
}
.camera-tools {
position: absolute;
top: 14px;
right: 14px;
z-index: 3;
display: flex;
gap: 6px;
}
.camera-tools button {
min-width: 38px;
height: 36px;
padding: 0 10px;
border: 1px solid rgba(151, 190, 217, 0.2);
border-radius: 9px;
background: rgba(7, 17, 28, 0.84);
color: var(--text);
font-size: 0.75rem;
font-weight: 700;
backdrop-filter: blur(10px);
}
.camera-tools button:hover,
.camera-tools button:focus-visible {
border-color: rgba(81, 212, 207, 0.65);
outline: none;
}
.scene-help {
position: absolute;
left: 14px;
bottom: 14px;
z-index: 2;
padding: 8px 10px;
border: 1px solid rgba(151, 190, 217, 0.14);
border-radius: 9px;
background: rgba(5, 14, 23, 0.72);
color: var(--muted);
font-size: 0.72rem;
pointer-events: none;
backdrop-filter: blur(8px);
}
.toast {
position: absolute;
left: 50%;
bottom: 58px;
z-index: 4;
padding: 9px 13px;
border: 1px solid rgba(81, 212, 207, 0.4);
border-radius: 999px;
background: rgba(8, 30, 35, 0.94);
color: #d9ffff;
font-size: 0.78rem;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 8px);
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.panel {
display: flex;
flex-direction: column;
gap: 12px;
max-height: calc(100vh - 150px);
min-height: 620px;
max-height: 960px;
overflow-y: auto;
padding-right: 3px;
scrollbar-color: #294153 transparent;
}
.card {
padding: 15px;
}
.card h2 {
margin: 0 0 12px;
font-size: 0.9rem;
letter-spacing: 0.01em;
}
.card p {
margin: 0;
color: var(--muted);
font-size: 0.79rem;
line-height: 1.55;
}
.seed-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 8px;
}
.seed-row input {
width: 100%;
min-width: 0;
height: 40px;
padding: 0 11px;
border: 1px solid rgba(151, 190, 217, 0.22);
border-radius: 9px;
background: #07131f;
color: #effaff;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.83rem;
}
.seed-row input:focus {
border-color: var(--b);
outline: none;
box-shadow: 0 0 0 3px rgba(81, 212, 207, 0.1);
}
.primary,
.secondary {
min-height: 40px;
padding: 0 12px;
border-radius: 9px;
font-size: 0.76rem;
font-weight: 800;
}
.primary {
border: 1px solid #60ded9;
background: var(--b);
color: #062124;
}
.primary:hover,
.primary:focus-visible {
background: #78e2de;
outline: none;
}
.secondary {
border: 1px solid rgba(151, 190, 217, 0.23);
background: rgba(151, 190, 217, 0.07);
color: var(--text);
}
.secondary:hover,
.secondary:focus-visible {
border-color: rgba(151, 190, 217, 0.55);
outline: none;
}
.secondary.full {
width: 100%;
margin-top: 8px;
}
.microcopy {
margin-top: 9px !important;
font-size: 0.7rem !important;
}
.legend {
display: grid;
gap: 9px;
}
.legend-row {
display: grid;
grid-template-columns: 22px minmax(0, 1fr);
gap: 9px;
align-items: start;
color: var(--muted);
font-size: 0.75rem;
line-height: 1.45;
}
.swatch {
width: 16px;
height: 16px;
margin-top: 1px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
}
.swatch.a {
background: var(--a);
}
.swatch.b {
background: var(--b);
}
.swatch.green {
background: var(--green);
}
.swatch.pair {
background: #66798b;
}
.legend-row b {
color: var(--text);
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.stat {
min-width: 0;
padding: 10px 8px;
border: 1px solid rgba(151, 190, 217, 0.12);
border-radius: 10px;
background: rgba(151, 190, 217, 0.045);
}
.stat span {
display: block;
color: var(--muted);
font-size: 0.65rem;
white-space: nowrap;
}
.stat strong {
display: block;
margin-top: 5px;
font-size: 1.05rem;
}
.stat.a strong {
color: var(--a);
}
.stat.b strong {
color: var(--b);
}
.chart {
width: 100%;
height: auto;
margin-top: 4px;
overflow: visible;
}
.chart text {
fill: #91a8b9;
font-family: ui-sans-serif, system-ui, sans-serif;
font-size: 9px;
}
.chart .pair-label {
fill: #d8e9f5;
font-weight: 700;
}
.table-wrap {
max-height: 310px;
overflow: auto;
border: 1px solid rgba(151, 190, 217, 0.1);
border-radius: 10px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.7rem;
font-variant-numeric: tabular-nums;
}
th,
td {
padding: 8px 6px;
border-bottom: 1px solid rgba(151, 190, 217, 0.08);
text-align: right;
white-space: nowrap;
}
th {
position: sticky;
top: 0;
z-index: 1;
background: #102131;
color: #9fb6c7;
font-size: 0.64rem;
letter-spacing: 0.04em;
text-transform: uppercase;
}
th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3) {
text-align: left;
}
tbody tr:last-child td {
border-bottom: 0;
}
.condition-chip {
display: inline-grid;
width: 19px;
height: 19px;
margin-right: 4px;
place-items: center;
border-radius: 5px;
color: #07131c;
font-size: 0.68rem;
font-weight: 900;
}
.condition-chip.a {
background: var(--a);
}
.condition-chip.b {
background: var(--b);
}
.positive {
color: #a6efaa;
}
.method {
border-color: rgba(81, 212, 207, 0.2);
}
.method h2 {
color: #c6ffff;
}
.method p + p {
margin-top: 8px;
}
.method b {
color: #e7fbff;
}
@media (max-width: 1050px) {
.layout {
grid-template-columns: 1fr;
}
.viewport-shell {
height: 65vh;
min-height: 510px;
}
.panel {
max-height: none;
min-height: 0;
overflow: visible;
padding-right: 0;
}
.panel-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.method {
grid-column: 1 / -1;
}
}
@media (max-width: 650px) {
body {
padding: 10px;
}
header {
align-items: flex-start;
flex-direction: column;
gap: 10px;
}
.safe-badge {
white-space: normal;
}
.viewport-shell {
height: 58vh;
min-height: 430px;
}
.panel-grid {
grid-template-columns: 1fr;
}
.method {
grid-column: auto;
}
.scene-help {
max-width: calc(100% - 28px);
}
.stats {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div>
<p class="eyebrow">Randomized block experiment · synthetic data</p>
<h1>Voxel Field Trial</h1>
<p class="subtitle">
Eight matched pairs of plots receive one of two harmless synthetic growth
recipes. A visible seed reproduces the block backgrounds, plot noise, and
random treatment assignments.
</p>
</div>
<div class="safe-badge">Synthetic conditions only · no real-world intervention</div>
</header>
<main class="layout">
<section class="viewport-shell" aria-label="Interactive voxel experiment">
<div id="viewport"></div>
<div class="scene-hud">
<strong id="seed-display">SEED · VOXEL-2048</strong>
<span id="assignment-display">8 matched pairs · balanced 4 A / 4 B</span>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button id="reset-camera" type="button" title="Reset camera">Reset</button>
<button id="top-camera" type="button" title="Top view">Top</button>
</div>
<div class="scene-help">Drag to orbit · wheel to zoom · double-click to reset</div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
</section>
<aside class="panel">
<div class="panel-grid">
<section class="card">
<h2>Visible random seed</h2>
<div class="seed-row">
<label for="seed-input" hidden>Random seed</label>
<input
id="seed-input"
type="text"
value="VOXEL-2048"
maxlength="64"
spellcheck="false"
aria-describedby="seed-help"
>
<button id="apply-seed" class="primary" type="button">Assign</button>
</div>
<button id="new-seed" class="secondary full" type="button">
Generate new seed & randomize
</button>
<p id="seed-help" class="microcopy">
The same seed always produces the same data and assignment.
</p>
</section>
<section class="card">
<h2>How to read the field</h2>
<div class="legend">
<div class="legend-row">
<span class="swatch a"></span>
<span><b>A · synthetic amber-light recipe</b><br>Modeled effect: +4.0 g biomass</span>
</div>
<div class="legend-row">
<span class="swatch b"></span>
<span><b>B · synthetic neutral-light reference</b><br>Modeled effect: 0 g biomass</span>
</div>
<div class="legend-row">
<span class="swatch pair"></span>
<span><b>Pair tint</b> shows shared background variation</span>
</div>
<div class="legend-row">
<span class="swatch green"></span>
<span><b>Plant height</b> shows synthetic biomass</span>
</div>
</div>
</section>
<section class="card">
<h2>Observed paired result</h2>
<div id="stats" class="stats"></div>
<p class="microcopy">
The paired A − B difference cancels the background shared by each block.
</p>
</section>
<section class="card">
<h2>Paired biomass · g</h2>
<svg
id="pair-chart"
class="chart"
viewBox="0 0 320 238"
role="img"
aria-label="Paired biomass chart"
></svg>
<p class="microcopy">
Each connector joins the two plots in one matched block.
Circle = A; square = B.
</p>
</section>
<section class="card">
<h2>Randomization ledger</h2>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Pair</th>
<th>Left plot</th>
<th>Right plot</th>
<th>Background</th>
<th>A − B</th>
</tr>
</thead>
<tbody id="ledger-body"></tbody>
</table>
</div>
</section>
<section class="card method">
<h2>Treatment versus background</h2>
<p>
Each pair contains two compositionally matched plots. A random,
balanced sequence assigns exactly one A and one B to every pair.
</p>
<p>
A shared block background of roughly <b>±2.8 g</b> affects both
plots, while independent plot noise of roughly <b>±1.3 g</b> is
added. Only the assignment and its <b>+4.0 g</b> modeled treatment
effect are intended to differ between conditions.
</p>
<p>
This is an illustrative randomization experiment, not biological
evidence or a statistical analysis of real plants.
</p>
</section>
</div>
</aside>
</main>
</div>
<noscript>This visualization requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const seedInput = document.getElementById("seed-input");
const seedDisplay = document.getElementById("seed-display");
const assignmentDisplay = document.getElementById("assignment-display");
const ledgerBody = document.getElementById("ledger-body");
const pairChart = document.getElementById("pair-chart");
const statsElement = document.getElementById("stats");
const toast = document.getElementById("toast");
const COLORS = {
conditionA: "#ff8066",
conditionB: "#51d4cf",
leaf0: "#79c96b",
leaf1: "#96dc7e",
leaf2: "#5eaf64",
stem0: "#5ca35a",
stem1: "#70b967",
soil0: "#493a31",
soil1: "#554136",
soil2: "#3f332c"
};
const BLOCKS = 8;
const COLUMNS = 4;
const ROWS = 2;
const MODEL_EFFECT = 4;
const BASE_BIOMASS = 12;
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
let currentSeed = "VOXEL-2048";
let experiment;
let fieldGroup;
let toastTimer;
const growthItems = [];
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#09131d");
scene.fog = new THREE.Fog("#09131d", 32, 64);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Voxel field showing matched plant plots with randomized treatment assignments"
);
renderer.domElement.tabIndex = 0;
viewport.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(46, 1, 0.1, 100);
const controls = {
theta: 0,
phi: 0.88,
radius: 33,
target: new THREE.Vector3(0, 1.0, 0)
};
const hemisphere = new THREE.HemisphereLight(0xc8e8ff, 0x17221e, 2.3);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d7, 3.4);
sun.position.set(13, 22, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0008;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x70d8e5, 1.25);
rimLight.position.set(-12, 9, -15);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1924,
roughness: 0.98,
metalness: 0
});
const ground = new THREE.Mesh(unitBox, groundMaterial);
ground.position.set(0, -0.15, 0);
ground.scale.set(36, 0.28, 25);
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x284051, 0x182b3a);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
function cube(parent, material, x, y, z, sx, sy, sz, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeTextSprite(text, options = {}) {
const {
width = 512,
height = 128,
background = "#132638",
foreground = "#eaf6ff",
fontSize = 52,
border = null,
scale = [2, 0.5]
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRectPath(ctx, 3, 3, width - 6, height - 6, 20);
ctx.fillStyle = background;
ctx.fill();
if (border) {
ctx.lineWidth = 7;
ctx.strokeStyle = border;
ctx.stroke();
}
ctx.fillStyle = foreground;
ctx.font = `800 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 2);
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(scale[0], scale[1], 1);
sprite.renderOrder = 20;
return sprite;
}
function makePlotBadge(condition, value) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const color = condition === "A" ? COLORS.conditionA : COLORS.conditionB;
roundedRectPath(ctx, 4, 4, 248, 120, 18);
ctx.fillStyle = color;
ctx.fill();
ctx.lineWidth = 6;
ctx.strokeStyle = "rgba(255,255,255,0.55)";
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#07131c";
ctx.font = "900 62px ui-sans-serif, system-ui, sans-serif";
ctx.fillText(condition, 128, 43);
ctx.font = "800 25px ui-monospace, monospace";
ctx.fillText(`${value.toFixed(1)} g`, 128, 92);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.24, 0.62, 1);
sprite.renderOrder = 21;
return sprite;
}
function hashSeed(text) {
let hash = 2166136261;
for (let i = 0; i < text.length; i++) {
hash ^= text.charCodeAt(i);
hash = Math.imul(hash, 16777619);
}
return hash >>> 0;
}
function mulberry32(seed) {
return function random() {
let value = (seed += 0x6d2b79f5);
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const round1 = value => Math.round(value * 10) / 10;
const average = values =>
values.reduce((sum, value) => sum + value, 0) / values.length;
function createExperiment(seed) {
const random = mulberry32(hashSeed(seed));
const blocks = [];
for (let i = 0; i < BLOCKS; i++) {
const background = round1((random() * 2 - 1) * 2.8);
const leftNoise = (random() * 2 - 1) * 1.3;
const rightNoise = (random() * 2 - 1) * 1.3;
blocks.push({
id: i + 1,
background,
leftNoise,
rightNoise,
leftBase: BASE_BIOMASS + background + leftNoise,
rightBase: BASE_BIOMASS + background + rightNoise
});
}
// Four A and four B overall, with exactly one of each inside every pair.
const assignments = [
"A", "A", "A", "A",
"B", "B", "B", "B"
];
for (let i = assignments.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[assignments[i], assignments[j]] = [assignments[j], assignments[i]];
}
blocks.forEach((block, index) => {
const leftCondition = assignments[index];
const rightCondition = leftCondition === "A" ? "B" : "A";
block.leftCondition = leftCondition;
block.rightCondition = rightCondition;
block.leftValue = round1(
block.leftBase + (leftCondition === "A" ? MODEL_EFFECT : 0)
);
block.rightValue = round1(
block.rightBase + (rightCondition === "A" ? MODEL_EFFECT : 0)
);
});
return { seed, blocks };
}
function blockTint(background) {
const low = new THREE.Color("#344657");
const high = new THREE.Color("#536779");
const t = THREE.MathUtils.clamp((background + 2.8) / 5.6, 0, 1);
return low.lerp(high, t);
}
function clearField() {
if (!fieldGroup) return;
const materials = new Set();
const textures = new Set();
fieldGroup.traverse(object => {
if (object.material) {
const list = Array.isArray(object.material)
? object.material
: [object.material];
list.forEach(material => {
materials.add(material);
if (material.map) textures.add(material.map);
});
}
});
scene.remove(fieldGroup);
textures.forEach(texture => texture.dispose());
materials.forEach(material => material.dispose());
growthItems.length = 0;
}
function createPlant(parent, x, z, height, variant, startTime) {
const group = new THREE.Group();
group.position.set(x, 0.67, z);
parent.add(group);
const stemMaterial = new THREE.MeshStandardMaterial({
color: variant % 2 ? COLORS.stem1 : COLORS.stem0,
roughness: 0.9
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: [COLORS.leaf0, COLORS.leaf1, COLORS.leaf2][variant % 3],
roughness: 0.88
});
const segmentHeight = height / 4;
for (let i = 0; i < 4; i++) {
cube(
group,
stemMaterial,
0,
segmentHeight * (i + 0.5),
0,
0.13,
segmentHeight * 0.9,
0.13
);
}
const leafLevels = [0.34, 0.51, 0.68, 0.83];
leafLevels.forEach((level, index) => {
const direction = index % 2 === 0 ? -1 : 1;
cube(
group,
leafMaterial,
direction * 0.18,
height * level,
0,
0.42,
0.14,
0.22
);
cube(
group,
leafMaterial,
0,
height * level + 0.055,
direction * 0.12,
0.20,
0.12,
0.35
);
});
cube(group, leafMaterial, 0, height * 0.98, 0, 0.24, 0.24, 0.24);
group.scale.set(0.72, 0.03, 0.72);
growthItems.push({
group,
start: startTime + variant * 32,
duration: reducedMotion ? 1 : 900
});
}
function buildField() {
clearField();
fieldGroup = new THREE.Group();
scene.add(fieldGroup);
const localRandom = mulberry32(hashSeed(`${currentSeed}:plants`));
const soilBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x302720,
roughness: 1
});
const soilMaterials = [0, 1, 2].map(index =>
new THREE.MeshStandardMaterial({
color: [COLORS.soil0, COLORS.soil1, COLORS.soil2][index],
roughness: 1
})
);
const frameA = new THREE.MeshStandardMaterial({
color: COLORS.conditionA,
emissive: 0x35100a,
emissiveIntensity: 0.25,
roughness: 0.65
});
const frameB = new THREE.MeshStandardMaterial({
color: COLORS.conditionB,
emissive: 0x083331,
emissiveIntensity: 0.25,
roughness: 0.65
});
const dividerMaterial = new THREE.MeshStandardMaterial({
color: 0x6f8291,
roughness: 0.85
});
const startTime = performance.now();
experiment.blocks.forEach((block, index) => {
const row = Math.floor(index / COLUMNS);
const column = index % COLUMNS;
const x = (column - (COLUMNS - 1) / 2) * 7.25;
const z = (row - (ROWS - 1) / 2) * 7.15;
const pair = new THREE.Group();
pair.position.set(x, 0, z);
fieldGroup.add(pair);
const baseMaterial = new THREE.MeshStandardMaterial({
color: blockTint(block.background),
roughness: 0.92
});
cube(pair, baseMaterial, 0, 0.22, 0, 6.45, 0.44, 5.55, false);
cube(pair, dividerMaterial, 0, 0.47, 0, 0.07, 0.06, 4.65, false);
const plots = [
{
x: -1.48,
condition: block.leftCondition,
value: block.leftValue
},
{
x: 1.48,
condition: block.rightCondition,
value: block.rightValue
}
];
plots.forEach((plot, plotIndex) => {
const frameMaterial = plot.condition === "A" ? frameA : frameB;
cube(
pair,
soilBaseMaterial,
plot.x,
0.53,
0,
2.64,
0.18,
4.42,
false
);
// Small voxel soil tiles.
for (let tileX = 0; tileX < 2; tileX++) {
for (let tileZ = 0; tileZ < 3; tileZ++) {
const shade = Math.floor(localRandom() * soilMaterials.length);
cube(
pair,
soilMaterials[shade],
plot.x + (tileX - 0.5) * 1.29,
0.65,
(tileZ - 1) * 1.43,
1.21,
0.075,
1.35,
false
);
}
}
// Colored frame communicates assignment independently of height.
cube(
pair,
frameMaterial,
plot.x,
0.70,
-2.23,
2.76,
0.11,
0.11,
false
);
cube(
pair,
frameMaterial,
plot.x,
0.70,
2.23,
2.76,
0.11,
0.11,
false
);
cube(
pair,
frameMaterial,
plot.x - 1.36,
0.70,
0,
0.11,
0.11,
4.56,
false
);
cube(
pair,
frameMaterial,
plot.x + 1.36,
0.70,
0,
0.11,
0.11,
4.56,
false
);
const normalized = THREE.MathUtils.clamp(
(plot.value - 8) / 12,
0,
1
);
const plotHeight = 1.45 + normalized * 2.45;
const plantPositions = [
[-0.62, -0.92],
[0.62, -0.92],
[-0.62, 0.92],
[0.62, 0.92]
];
plantPositions.forEach(([plantX, plantZ], plantIndex) => {
const variation = 0.88 + localRandom() * 0.23;
createPlant(
pair,
plot.x + plantX,
plantZ,
plotHeight * variation,
index * 7 + plotIndex * 3 + plantIndex,
startTime
);
});
const badge = makePlotBadge(plot.condition, plot.value);
badge.position.set(plot.x, 1.02, 2.48);
pair.add(badge);
});
const backgroundText = `${block.background >= 0 ? "+" : ""}${block.background.toFixed(1)} g`;
const label = makeTextSprite(`P${block.id} · bg ${backgroundText}`, {
background: "#172a39",
foreground: "#c9dce9",
fontSize: 42,
border: "rgba(151,190,217,0.25)",
scale: [1.78, 0.44]
});
label.position.set(0, 0.40, 2.78);
pair.add(label);
});
}
function conditionValue(block, side) {
return side === "left" ? block.leftValue : block.rightValue;
}
function updateChart() {
const width = 320;
const height = 238;
const x0 = 31;
const x1 = 304;
const min = 8;
const max = 20;
const scaleX = value => x0 + ((value - min) / (max - min)) * (x1 - x0);
let svg = `
<line x1="${x0}" y1="16" x2="${x1}" y2="16"
stroke="rgba(151,190,217,.14)" />
`;
[8, 12, 16, 20].forEach(tick => {
const x = scaleX(tick);
svg += `
<line x1="${x}" y1="16" x2="${x}" y2="205"
stroke="rgba(151,190,217,.10)" />
<text x="${x}" y="222" text-anchor="middle">${tick}</text>
`;
});
experiment.blocks.forEach((block, index) => {
const y = 31 + index * 23;
const leftValue = conditionValue(block, "left");
const rightValue = conditionValue(block, "right");
const aValue = block.leftCondition === "A" ? leftValue : rightValue;
const bValue = block.leftCondition === "B" ? leftValue : rightValue;
const ax = scaleX(aValue);
const bx = scaleX(bValue);
svg += `
<text x="3" y="${y + 3}" class="pair-label">P${block.id}</text>
<line x1="${ax}" y1="${y}" x2="${bx}" y2="${y}"
stroke="#6c8496" stroke-width="2" />
<circle cx="${ax}" cy="${y}" r="5"
fill="${COLORS.conditionA}" stroke="#07131c" stroke-width="1.5" />
<rect x="${bx - 4.5}" y="${y - 4.5}" width="9" height="9"
rx="1" fill="${COLORS.conditionB}" stroke="#07131c" stroke-width="1.5" />
`;
});
svg += `
<text x="${x0}" y="236" text-anchor="start">grams</text>
<text x="${x1}" y="236" text-anchor="end">synthetic biomass</text>
`;
pairChart.innerHTML = svg;
}
function updateLedger() {
ledgerBody.replaceChildren();
experiment.blocks.forEach(block => {
const row = document.createElement("tr");
const pairCell = document.createElement("td");
pairCell.textContent = `P${block.id}`;
const leftCell = document.createElement("td");
const leftChip = document.createElement("span");
leftChip.className = `condition-chip ${block.leftCondition.toLowerCase()}`;
leftChip.textContent = block.leftCondition;
leftCell.append(leftChip, document.createTextNode(`${block.leftValue.toFixed(1)} g`));
const rightCell = document.createElement("td");
const rightChip = document.createElement("span");
rightChip.className = `condition-chip ${block.rightCondition.toLowerCase()}`;
rightChip.textContent = block.rightCondition;
rightCell.append(rightChip, document.createTextNode(`${block.rightValue.toFixed(1)} g`));
const backgroundCell = document.createElement("td");
const sign = block.background >= 0 ? "+" : "";
backgroundCell.textContent = `${sign}${block.background.toFixed(1)} g`;
const aValue = block.leftCondition === "A"
? block.leftValue
: block.rightValue;
const bValue = block.leftCondition === "B"
? block.leftValue
: block.rightValue;
const deltaCell = document.createElement("td");
const delta = aValue - bValue;
deltaCell.textContent = `${delta >= 0 ? "+" : ""}${delta.toFixed(1)} g`;
if (delta > 0) deltaCell.className = "positive";
row.append(pairCell, leftCell, rightCell, backgroundCell, deltaCell);
ledgerBody.append(row);
});
}
function updateStats() {
const aValues = [];
const bValues = [];
const deltas = [];
experiment.blocks.forEach(block => {
const aValue = block.leftCondition === "A"
? block.leftValue
: block.rightValue;
const bValue = block.leftCondition === "B"
? block.leftValue
: block.rightValue;
aValues.push(aValue);
bValues.push(bValue);
deltas.push(aValue - bValue);
});
statsElement.innerHTML = `
<div class="stat a">
<span>Mean A</span>
<strong>${average(aValues).toFixed(2)} g</strong>
</div>
<div class="stat b">
<span>Mean B</span>
<strong>${average(bValues).toFixed(2)} g</strong>
</div>
<div class="stat">
<span>Paired A − B</span>
<strong>${average(deltas) >= 0 ? "+" : ""}${average(deltas).toFixed(2)} g</strong>
</div>
`;
}
function updateInterface() {
const countA = experiment.blocks.filter(
block => block.leftCondition === "A"
).length;
seedDisplay.textContent = `SEED · ${currentSeed}`;
assignmentDisplay.textContent =
`8 matched pairs · balanced ${countA} A / ${8 - countA} B`;
updateStats();
updateChart();
updateLedger();
}
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 1800);
}
function applySeed() {
currentSeed = seedInput.value.trim() || "VOXEL-2048";
seedInput.value = currentSeed;
experiment = createExperiment(currentSeed);
buildField();
updateInterface();
showToast(`Assigned 8 matched pairs from seed “${currentSeed}”`);
}
function createNewSeed() {
let value;
if (window.crypto && window.crypto.getRandomValues) {
const numbers = new Uint32Array(1);
window.crypto.getRandomValues(numbers);
value = numbers[0].toString(36).toUpperCase().padStart(7, "0");
} else {
value = Date.now().toString(36).toUpperCase();
}
seedInput.value = `VOXEL-${value}`;
applySeed();
}
seedInput.addEventListener("keydown", event => {
if (event.key === "Enter") {
event.preventDefault();
applySeed();
}
});
document.getElementById("apply-seed").addEventListener("click", applySeed);
document.getElementById("new-seed").addEventListener("click", createNewSeed);
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.theta = 0;
controls.phi = 0.88;
controls.radius = 33;
controls.target.set(0, 1, 0);
updateCamera();
}
function topCamera() {
controls.theta = 0;
controls.phi = 0.12;
controls.radius = 31;
controls.target.set(0, 0, 0);
updateCamera();
}
document.getElementById("reset-camera").addEventListener("click", resetCamera);
document.getElementById("top-camera").addEventListener("click", topCamera);
// Camera interaction is implemented locally without Three.js addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.12,
1.35
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
20,
50
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function resizeRenderer() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
resizeRenderer();
function animate(now) {
requestAnimationFrame(animate);
growthItems.forEach(item => {
const t = THREE.MathUtils.clamp(
(now - item.start) / item.duration,
0,
1
);
const eased = 1 - Math.pow(1 - t, 3);
item.group.scale.set(
0.72 + 0.28 * eased,
Math.max(0.03, eased),
0.72 + 0.28 * eased
);
});
updateCamera();
renderer.render(scene, camera);
}
experiment = createExperiment(currentSeed);
buildField();
updateInterface();
updateCamera();
animate(performance.now());
</script>
</body>
</html>
```