Prompt specification
Build or customize the Three.js 3D scene "One Garden Hose for Two Beds" 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: One Garden Hose for Two Beds
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/one-garden-hose-for-two-beds-x3158
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts allocation of scarce resources among competing uses. Build two planted beds sharing one movable hose and a short watering schedule. Moving service time between beds must visibly preserve the total available minutes. Voxel style.
Working Three.js Starter (one-garden-hose-for-two-beds-x3158):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Eight Minutes, Two Beds</title>
<style>
:root {
--ink: #213a35;
--paper: #fff9e9;
--cream: #efe4c4;
--amber: #f2b84b;
--teal: #43c6b5;
--blue: #56b9dc;
--shadow: rgba(25, 49, 43, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e8d3;
color: var(--ink);
font-family: "Courier New", Courier, monospace;
}
button,
input {
font: inherit;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:focus-visible {
outline: 4px solid var(--amber);
outline-offset: -4px;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 2;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
will-change: transform;
}
.bed-tag {
display: flex;
align-items: center;
gap: 8px;
padding: 7px 9px;
background: var(--paper);
border: 3px solid var(--ink);
box-shadow: 4px 4px 0 rgba(33, 58, 53, 0.28);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
}
.bed-tag::before {
content: "";
width: 8px;
align-self: stretch;
background: var(--amber);
}
.bed-tag.b::before {
background: var(--teal);
}
.bed-tag strong {
padding-left: 7px;
border-left: 2px solid rgba(33, 58, 53, 0.2);
color: var(--ink);
font-size: 13px;
}
.plan-tag {
padding: 5px 8px;
background: var(--ink);
border: 2px solid var(--paper);
color: var(--paper);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
box-shadow: 3px 3px 0 rgba(33, 58, 53, 0.25);
}
.rack-tag {
padding: 4px 7px;
background: rgba(255, 249, 233, 0.9);
border: 2px solid var(--ink);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 3;
max-width: 520px;
pointer-events: none;
}
.eyebrow {
display: block;
margin-bottom: 7px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(26px, 4vw, 50px);
line-height: 0.96;
letter-spacing: -0.07em;
text-transform: uppercase;
text-shadow: 2px 2px 0 rgba(255, 249, 233, 0.65);
}
.brand p {
margin: 10px 0 0;
max-width: 430px;
font-size: 12px;
line-height: 1.5;
}
.budget {
position: fixed;
top: 22px;
right: 24px;
z-index: 3;
min-width: 190px;
padding: 12px 14px;
display: grid;
grid-template-columns: auto 1fr;
gap: 4px 12px;
align-items: center;
background: var(--paper);
border: 4px solid var(--ink);
box-shadow: 6px 6px 0 var(--shadow);
pointer-events: none;
}
.budget-number {
grid-row: 1 / 3;
font-size: 48px;
line-height: 0.9;
font-weight: 900;
color: var(--blue);
}
.budget-copy {
font-size: 10px;
line-height: 1.25;
font-weight: 700;
letter-spacing: 0.1em;
}
.budget-equation {
margin-top: 3px;
padding-top: 5px;
border-top: 2px solid rgba(33, 58, 53, 0.16);
font-size: 10px;
}
.panel {
position: fixed;
z-index: 4;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
width: min(760px, calc(100vw - 28px));
padding: 15px 17px 14px;
background: rgba(255, 249, 233, 0.96);
border: 4px solid var(--ink);
box-shadow: 7px 7px 0 rgba(25, 49, 43, 0.28);
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 12px;
}
.panel-head .eyebrow {
margin-bottom: 4px;
}
#status {
min-height: 17px;
font-size: 12px;
line-height: 1.35;
}
.fixed-total {
flex: 0 0 auto;
display: flex;
align-items: baseline;
gap: 6px;
padding: 5px 8px;
border: 2px solid var(--ink);
background: #dff2ef;
font-size: 10px;
font-weight: 700;
}
.fixed-total b {
font-size: 20px;
line-height: 1;
}
.allocation {
display: grid;
grid-template-columns: 145px 1fr 145px;
gap: 12px;
align-items: center;
}
.bed-stat {
padding: 8px 10px;
border: 3px solid var(--ink);
background: #fff3cf;
box-shadow: 3px 3px 0 rgba(33, 58, 53, 0.18);
}
.bed-stat.b {
background: #d8f3ec;
}
.bed-stat span {
display: block;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
.bed-stat strong {
display: block;
margin-top: 3px;
font-size: 21px;
}
.slider-area {
min-width: 0;
}
.slider-title {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
}
input[type="range"] {
--split: 50%;
display: block;
width: 100%;
height: 16px;
margin: 0;
appearance: none;
-webkit-appearance: none;
border: 3px solid var(--ink);
border-radius: 0;
background: linear-gradient(
to right,
var(--amber) 0%,
var(--amber) var(--split),
var(--teal) var(--split),
var(--teal) 100%
);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 30px;
appearance: none;
-webkit-appearance: none;
border: 3px solid var(--ink);
border-radius: 0;
background: var(--paper);
box-shadow: 2px 2px 0 rgba(33, 58, 53, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 27px;
border: 3px solid var(--ink);
border-radius: 0;
background: var(--paper);
box-shadow: 2px 2px 0 rgba(33, 58, 53, 0.3);
}
input[type="range"]:disabled {
cursor: not-allowed;
filter: saturate(0.55);
}
.slider-help {
margin-top: 6px;
text-align: center;
font-size: 9px;
line-height: 1.3;
}
.timeline-row {
display: flex;
align-items: center;
gap: 12px;
margin-top: 12px;
}
.timeline {
flex: 1;
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 4px;
}
.chip {
position: relative;
height: 28px;
display: grid;
place-items: center;
border: 2px solid var(--ink);
background: #f4c963;
font-size: 10px;
font-weight: 900;
transition: transform 120ms, filter 120ms;
}
.chip.b {
background: #66d0c1;
}
.chip.current {
transform: translateY(-3px);
outline: 3px solid var(--paper);
box-shadow: 0 0 0 5px var(--ink);
}
.chip.done {
filter: brightness(0.65);
}
.legend {
flex: 0 0 auto;
display: flex;
gap: 10px;
font-size: 9px;
font-weight: 700;
}
.legend span::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
margin-right: 4px;
border: 1px solid var(--ink);
background: var(--amber);
}
.legend span:last-child::before {
background: var(--teal);
}
.actions {
display: flex;
align-items: center;
gap: 9px;
margin-top: 12px;
}
.action {
min-height: 36px;
padding: 8px 13px;
border: 3px solid var(--ink);
border-radius: 0;
background: var(--ink);
color: var(--paper);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.05em;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(33, 58, 53, 0.22);
}
.action:hover {
transform: translate(1px, 1px);
box-shadow: 2px 2px 0 rgba(33, 58, 53, 0.22);
}
.action:active {
transform: translate(3px, 3px);
box-shadow: none;
}
.action.secondary {
background: var(--paper);
color: var(--ink);
}
.action.primary {
flex: 1;
background: var(--amber);
color: var(--ink);
}
.camera-help {
margin-left: auto;
color: rgba(33, 58, 53, 0.68);
font-size: 9px;
text-align: right;
line-height: 1.35;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d9e8d3;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 250ms;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 14px;
left: 14px;
max-width: calc(100vw - 150px);
}
.brand h1 {
font-size: 26px;
}
.brand p {
display: none;
}
.budget {
top: 14px;
right: 14px;
min-width: 125px;
padding: 8px;
border-width: 3px;
}
.budget-number {
font-size: 36px;
}
.budget-copy,
.budget-equation {
font-size: 8px;
}
.panel {
bottom: 9px;
width: calc(100vw - 18px);
padding: 11px;
border-width: 3px;
}
.allocation {
grid-template-columns: 92px 1fr 92px;
gap: 7px;
}
.bed-stat {
padding: 6px;
}
.bed-stat strong {
font-size: 17px;
}
.slider-help,
.legend,
.camera-help {
display: none;
}
.timeline-row {
margin-top: 9px;
}
.chip {
height: 23px;
}
.actions {
margin-top: 9px;
}
}
@media (max-height: 660px) {
.brand p,
.slider-help,
.camera-help {
display: none;
}
.panel {
bottom: 8px;
padding: 9px 11px;
}
.panel-head {
margin-bottom: 7px;
}
.timeline-row,
.actions {
margin-top: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel garden"></canvas>
<div id="labels" aria-hidden="true">
<div id="tagA" class="scene-label bed-tag">
<span>BED A<br>ROOTS</span><strong id="tagAMin">4 min</strong>
</div>
<div id="tagB" class="scene-label bed-tag b">
<span>BED B<br>FRUIT</span><strong id="tagBMin">4 min</strong>
</div>
<div id="planA" class="scene-label plan-tag">PLAN A · 4 MIN</div>
<div id="planB" class="scene-label plan-tag">PLAN B · 4 MIN</div>
<div id="rackTag" class="scene-label rack-tag">1 CUBE = 1 MINUTE</div>
<div id="tankTag" class="scene-label plan-tag">8 MIN WATER TANK</div>
</div>
<header class="brand">
<span class="eyebrow">Scarce resources / voxel garden</span>
<h1>Eight Minutes,<br>Two Beds</h1>
<p>
Transfer service time between the beds, then run the short schedule.
One hose serves both. The available time never changes.
</p>
</header>
<aside class="budget" aria-label="Fixed water budget">
<div class="budget-number">8</div>
<div class="budget-copy">MINUTES<br>AVAILABLE</div>
<div class="budget-equation">
A <b id="budgetA">4</b> + B <b id="budgetB">4</b> = <b>8</b>
</div>
</aside>
<main class="panel">
<div class="panel-head">
<div>
<span class="eyebrow">Shared hose plan</span>
<strong id="status" aria-live="polite">Ready — 4 min roots + 4 min fruit</strong>
</div>
<div class="fixed-total">
FIXED TOTAL <b>8</b> MIN
</div>
</div>
<div class="allocation">
<div class="bed-stat">
<span>BED A · ROOTS</span>
<strong id="aMinutes">4 min</strong>
</div>
<div class="slider-area">
<div class="slider-title">
<span>MORE FOR A</span>
<span>MORE FOR B</span>
</div>
<input
id="allocation"
type="range"
min="0"
max="8"
step="1"
value="4"
aria-label="Transfer service minutes from Bed A to Bed B"
>
<div class="slider-help">
Drag to transfer · Click a bed to move 1 minute · A + B always equals 8
</div>
</div>
<div class="bed-stat b">
<span>BED B · FRUIT</span>
<strong id="bMinutes">4 min</strong>
</div>
</div>
<div class="timeline-row">
<div id="timeline" class="timeline" aria-label="Eight-minute watering schedule"></div>
<div class="legend">
<span>BED A</span>
<span>BED B</span>
</div>
</div>
<div class="actions">
<button id="runButton" class="action primary" type="button">▶ RUN 8-MIN PLAN</button>
<button id="resetButton" class="action secondary" type="button">RESET</button>
<div class="camera-help">
Drag scene to orbit<br>Scroll to zoom
</div>
</div>
</main>
<div id="loading">Building the garden…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and state
// -------------------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const canvas = $("#scene");
const loading = $("#loading");
const state = {
transfer: 4,
a: 4,
b: 4,
elapsed: 0,
running: false,
completed: false,
served: [0, 0],
hoseSettled: true
};
const SECONDS_PER_MINUTE = 1.05;
const TOTAL_MINUTES = 8;
// -------------------------------------------------------------------------
// Renderer, scene, and custom orthographic camera controls
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d9e8d3");
scene.fog = new THREE.Fog("#d9e8d3", 22, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.1, -0.2);
const cameraState = {
yaw: 0.56,
polar: 0.82,
radius: 18
};
function updateCameraPosition() {
const { yaw, polar, radius } = cameraState;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * Math.sin(polar) * radius,
cameraTarget.y + Math.cos(polar) * radius,
cameraTarget.z + Math.cos(yaw) * Math.sin(polar) * radius
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const desiredWidth = 21;
const desiredHeight = 12;
const viewHeight = aspect < desiredWidth / desiredHeight
? desiredWidth / aspect
: desiredHeight;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateCameraPosition();
const pointer = {
active: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0
};
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.moved = false;
pointer.startX = pointer.lastX = event.clientX;
pointer.startY = pointer.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (pointer.active) {
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
if (
Math.abs(event.clientX - pointer.startX) +
Math.abs(event.clientY - pointer.startY) > 5
) {
pointer.moved = true;
}
cameraState.yaw -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.48,
1.24
);
updateCameraPosition();
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
} else {
const bed = pickBed(event);
canvas.style.cursor = bed === null ? "grab" : "pointer";
}
});
canvas.addEventListener("pointerup", (event) => {
const wasClick = pointer.active && !pointer.moved;
pointer.active = false;
canvas.style.cursor = "grab";
if (wasClick) {
const bed = pickBed(event);
if (bed !== null && !state.running) {
const next = bed === 0 ? state.transfer - 1 : state.transfer + 1;
setTransfer(next);
}
}
});
canvas.addEventListener("pointercancel", () => {
pointer.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.8
);
camera.updateProjectionMatrix();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
cameraState.yaw += 0.08;
} else if (event.key === "ArrowRight") {
cameraState.yaw -= 0.08;
} else if (event.key === "ArrowUp") {
cameraState.polar = Math.max(0.48, cameraState.polar - 0.06);
} else if (event.key === "ArrowDown") {
cameraState.polar = Math.min(1.24, cameraState.polar + 0.06);
} else {
return;
}
event.preventDefault();
updateCameraPosition();
});
// -------------------------------------------------------------------------
// Lighting and voxel construction helpers
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight("#fff9e7", "#547054", 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cf", 3.0);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addBox(parent, material, x, y, z, width, height, depth) {
const mesh = new THREE.Mesh(
unitBox,
typeof material === "string" ? getMaterial(material) : material
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addPlant(parent, bed, x, z, phase) {
const group = new THREE.Group();
group.position.set(x, 0.46, z);
parent.add(group);
if (bed === 0) {
// Carrot: orange root with blocky green leaves.
addBox(group, "#eb8735", 0, 0.19, 0, 0.31, 0.42, 0.31);
addBox(group, "#3f8f49", 0, 0.58, 0, 0.12, 0.55, 0.12);
const leafA = addBox(group, "#4eaa51", -0.15, 0.87, 0, 0.42, 0.12, 0.17);
leafA.rotation.z = 0.52;
const leafB = addBox(group, "#62bd55", 0.15, 0.9, 0.02, 0.42, 0.12, 0.17);
leafB.rotation.z = -0.52;
const leafC = addBox(group, "#398743", 0, 1.02, -0.02, 0.16, 0.35, 0.16);
leafC.rotation.x = 0.38;
} else {
// Tomato: taller stem, leaves, and small fruit cubes.
addBox(group, "#347d43", 0, 0.63, 0, 0.15, 1.16, 0.15);
addBox(group, "#4d9d49", -0.2, 0.75, 0, 0.48, 0.13, 0.18);
addBox(group, "#62ad50", 0.22, 0.97, 0, 0.46, 0.13, 0.18);
addBox(group, "#3f9149", -0.1, 1.16, 0, 0.35, 0.13, 0.17);
addBox(group, "#e6533e", 0.19, 0.62, 0.12, 0.27, 0.27, 0.27);
addBox(group, "#f07a45", -0.17, 0.98, -0.08, 0.23, 0.23, 0.23);
}
plantGroups.push({ group, bed, phase });
}
// -------------------------------------------------------------------------
// Ground and paths
// -------------------------------------------------------------------------
addBox(scene, "#5f7f59", 0, -0.48, 0, 22, 0.55, 18);
const tileColors = ["#82a76e", "#78a066", "#89ad74", "#7da46a"];
for (let ix = 0; ix < 11; ix++) {
for (let iz = 0; iz < 8; iz++) {
const tile = addBox(
scene,
tileColors[(ix + iz * 2) % tileColors.length],
-10 + ix * 2,
-0.16,
-7 + iz * 2,
1.96,
0.18,
1.96
);
tile.castShadow = false;
}
}
// Pale voxel path in front of and between the beds.
for (let i = 0; i < 5; i++) {
addBox(scene, "#d9c99c", -4.8 + i * 2.4, -0.045, 3.1, 2.3, 0.12, 1.35);
}
addBox(scene, "#c8b787", 0, -0.04, 1.9, 1.65, 0.12, 6.5);
// -------------------------------------------------------------------------
// The two planted beds
// -------------------------------------------------------------------------
const clickTargets = [];
const frameMaterials = [];
const soilMaterials = [];
const waterMaterials = [];
const plantGroups = [];
const waterTiles = [[], []];
const bedX = [-2.7, 2.7];
function buildBed(bed, x) {
const group = new THREE.Group();
group.position.set(x, 0, 0.15);
scene.add(group);
const soilMaterial = getMaterial("#8a5a39").clone();
const frameMaterial = getMaterial("#b77b43").clone();
const waterMaterial = new THREE.MeshStandardMaterial({
color: "#65c7e3",
transparent: true,
opacity: 0,
roughness: 0.32,
depthWrite: false
});
soilMaterials.push(soilMaterial);
frameMaterials.push(frameMaterial);
waterMaterials.push(waterMaterial);
addBox(group, "#745034", 0, 0.12, 0, 3.62, 0.24, 3.86);
addBox(group, soilMaterial, 0, 0.35, 0, 3.20, 0.38, 3.45);
addBox(group, frameMaterial, -1.70, 0.48, 0, 0.28, 0.78, 3.83);
addBox(group, frameMaterial, 1.70, 0.48, 0, 0.28, 0.78, 3.83);
addBox(group, frameMaterial, 0, 0.48, -1.80, 3.65, 0.78, 0.28);
addBox(group, frameMaterial, 0, 0.48, 1.80, 3.65, 0.78, 0.28);
// Dark corner posts give the beds a chunky voxel silhouette.
for (const px of [-1.7, 1.7]) {
for (const pz of [-1.8, 1.8]) {
addBox(group, "#815332", px, 0.52, pz, 0.38, 0.92, 0.38);
}
}
// Soil rows.
for (const rowZ of [-1.12, 0, 1.12]) {
addBox(group, "#67432f", 0, 0.555, rowZ, 2.96, 0.035, 0.10);
}
let phase = bed * 1.7;
for (const pz of [-1.08, 0, 1.08]) {
for (const px of [-0.98, 0, 0.98]) {
addPlant(group, bed, px, pz, phase);
phase += 0.63;
const puddle = addBox(
group,
waterMaterial,
px,
0.578,
pz,
0.60,
0.025,
0.60
);
puddle.castShadow = false;
waterTiles[bed].push(puddle);
}
}
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hitBox = new THREE.Mesh(unitBox, hitMaterial);
hitBox.position.set(0, 0.75, 0);
hitBox.scale.set(3.8, 1.55, 4.0);
hitBox.userData.bed = bed;
group.add(hitBox);
clickTargets.push(hitBox);
}
buildBed(0, bedX[0]);
buildBed(1, bedX[1]);
// -------------------------------------------------------------------------
// Water tank with eight visible resource cells
// -------------------------------------------------------------------------
const tank = new THREE.Group();
tank.position.set(0, 0, -4.25);
scene.add(tank);
addBox(tank, "#765237", 0, 0.12, 0, 2.75, 0.34, 1.55);
addBox(tank, "#315e59", 0, 1.45, 0, 2.35, 2.02, 1.25);
addBox(tank, "#4a7771", 0, 2.52, 0, 2.58, 0.22, 1.43);
const tankWaterMaterial = new THREE.MeshStandardMaterial({
color: "#56b9dc",
roughness: 0.48,
metalness: 0.03
});
addBox(tank, tankWaterMaterial, 0, 1.37, 0.69, 1.92, 1.48, 0.14);
addBox(tank, "#274d49", 0, 1.36, 0.79, 1.48, 1.65, 0.12);
const resourceCells = [];
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 2; col++) {
const material = new THREE.MeshStandardMaterial({
color: "#65d3ed",
emissive: "#164b57",
emissiveIntensity: 0.28,
roughness: 0.48
});
const cell = addBox(
tank,
material,
col === 0 ? -0.39 : 0.39,
0.82 + row * 0.38,
0.89,
0.62,
0.28,
0.15
);
resourceCells.push(cell);
}
}
addBox(tank, "#e4a63c", 0, 0.55, 0.93, 0.38, 0.27, 0.42);
addBox(tank, "#315e59", 0, 0.36, 0.88, 0.18, 0.42, 0.18);
// -------------------------------------------------------------------------
// Two allocation rails and eight transferable minute cubes
// -------------------------------------------------------------------------
const rackY = 3.25;
const rackZ = -1.42;
addBox(scene, "#36514a", -2.65, rackY, rackZ, 4.25, 0.14, 0.20);
addBox(scene, "#36514a", 2.65, rackY, rackZ, 4.25, 0.14, 0.20);
for (const x of [-4.72, -0.58, 0.58, 4.72]) {
addBox(scene, "#526c60", x, 1.68, rackZ, 0.09, 3.18, 0.10);
}
const allocationTokens = [];
const colorA = new THREE.Color("#f2b84b");
const colorB = new THREE.Color("#43c6b5");
for (let i = 0; i < TOTAL_MINUTES; i++) {
const group = new THREE.Group();
scene.add(group);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: colorA,
roughness: 0.68
});
addBox(group, bodyMaterial, 0, 0, 0, 0.42, 0.42, 0.42);
addBox(group, "#fff8dc", 0, 0.225, 0, 0.44, 0.055, 0.44);
allocationTokens.push({
group,
material: bodyMaterial,
target: new THREE.Vector3()
});
}
const leftStart = -4.55;
const rightStart = 0.70;
const tokenSpacing = 0.55;
// -------------------------------------------------------------------------
// The single segmented voxel hose
// -------------------------------------------------------------------------
const hoseOrigin = new THREE.Vector3(0, 0.43, -3.25);
const hoseTargets = [
new THREE.Vector3(-2.7, 0.77, 1.35),
new THREE.Vector3( 2.7, 0.77, 1.35)
];
const currentHoseTarget = hoseTargets[0].clone();
const desiredHoseTarget = hoseTargets[0].clone();
const hoseMaterial = getMaterial("#237f79");
const hoseSegments = [];
for (let i = 0; i < 34; i++) {
const segment = new THREE.Mesh(unitBox, hoseMaterial);
segment.castShadow = true;
segment.receiveShadow = true;
scene.add(segment);
hoseSegments.push(segment);
}
const nozzle = new THREE.Group();
scene.add(nozzle);
addBox(nozzle, "#f2b84b", 0, 0.04, 0, 0.38, 0.29, 0.34);
addBox(nozzle, "#e9eee5", 0, 0.04, 0.23, 0.19, 0.19, 0.32);
addBox(nozzle, "#237f79", 0, 0.22, -0.06, 0.20, 0.15, 0.22);
// -------------------------------------------------------------------------
// Voxel water particles
// -------------------------------------------------------------------------
const particleMaterial = new THREE.MeshBasicMaterial({
color: "#73d9f3",
transparent: true,
opacity: 0.88,
depthWrite: false
});
const particles = [];
for (let i = 0; i < 54; i++) {
const mesh = new THREE.Mesh(unitBox, particleMaterial);
mesh.visible = false;
mesh.scale.setScalar(0.11);
scene.add(mesh);
particles.push({
mesh,
velocity: new THREE.Vector3(),
life: 0,
maxLife: 1
});
}
let particleCursor = 0;
let particleSpawnAccumulator = 0;
function spawnParticle() {
const particle = particles[particleCursor];
particleCursor = (particleCursor + 1) % particles.length;
particle.mesh.visible = true;
particle.mesh.position.copy(nozzle.position);
particle.mesh.position.y -= 0.03;
particle.mesh.position.z += 0.25;
particle.mesh.position.x += (Math.random() - 0.5) * 0.10;
particle.velocity.set(
(Math.random() - 0.5) * 0.45,
-1.25 - Math.random() * 0.65,
(Math.random() - 0.5) * 0.38
);
particle.life = 0.72 + Math.random() * 0.28;
particle.maxLife = particle.life;
}
function updateParticles(dt) {
for (const particle of particles) {
if (!particle.mesh.visible) continue;
particle.life -= dt;
if (particle.life <= 0) {
particle.mesh.visible = false;
continue;
}
particle.velocity.y -= 4.2 * dt;
particle.mesh.position.addScaledVector(particle.velocity, dt);
const ratio = particle.life / particle.maxLife;
particle.mesh.scale.setScalar(0.035 + ratio * 0.085);
if (particle.mesh.position.y < 0.52) {
particle.mesh.visible = false;
}
}
}
// -------------------------------------------------------------------------
// Timeline DOM
// -------------------------------------------------------------------------
const timeline = $("#timeline");
const chips = [];
for (let i = 0; i < TOTAL_MINUTES; i++) {
const chip = document.createElement("div");
chip.className = "chip";
chip.textContent = i + 1;
chip.title = `Minute ${i + 1}`;
timeline.appendChild(chip);
chips.push(chip);
}
const allocationInput = $("#allocation");
const runButton = $("#runButton");
const resetButton = $("#resetButton");
const statusElement = $("#status");
// -------------------------------------------------------------------------
// Picking and interaction
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
function pickBed(event) {
const rect = canvas.getBoundingClientRect();
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(clickTargets, false);
return hits.length ? hits[0].object.userData.bed : null;
}
// -------------------------------------------------------------------------
// Allocation and schedule logic
// -------------------------------------------------------------------------
function activeBedAt(elapsed) {
if (elapsed >= TOTAL_MINUTES) {
return state.a > 0 ? 0 : 1;
}
return elapsed < state.a ? 0 : 1;
}
function resetSimulation() {
state.elapsed = 0;
state.running = false;
state.completed = false;
state.served = [0, 0];
state.hoseSettled = true;
updateButton();
}
function setTransfer(value) {
if (state.running) return;
state.transfer = THREE.MathUtils.clamp(Math.round(value), 0, TOTAL_MINUTES);
state.a = TOTAL_MINUTES - state.transfer;
state.b = state.transfer;
resetSimulation();
updateTokenTargets();
renderAllocation();
}
function updateTokenTargets() {
allocationTokens.forEach((token, index) => {
const belongsToA = index < state.a;
const x = belongsToA
? leftStart + index * tokenSpacing
: rightStart + (index - state.a) * tokenSpacing;
token.target.set(x, rackY + 0.30, rackZ + 0.08);
token.material.color.copy(belongsToA ? colorA : colorB);
});
}
function renderAllocation() {
allocationInput.value = String(state.transfer);
allocationInput.style.setProperty("--split", `${state.transfer / 8 * 100}%`);
$("#aMinutes").textContent = `${state.a} min`;
$("#bMinutes").textContent = `${state.b} min`;
$("#tagAMin").textContent = `${state.a} min`;
$("#tagBMin").textContent = `${state.b} min`;
$("#budgetA").textContent = String(state.a);
$("#budgetB").textContent = String(state.b);
$("#planA").textContent = `PLAN A · ${state.a} MIN`;
$("#planB").textContent = `PLAN B · ${state.b} MIN`;
chips.forEach((chip, index) => {
const isA = index < state.a;
chip.classList.toggle("a", isA);
chip.classList.toggle("b", !isA);
chip.textContent = isA ? `A${index + 1}` : `B${index - state.a + 1}`;
chip.title = isA
? `Minute ${index + 1}: Bed A`
: `Minute ${index + 1}: Bed B`;
});
updateStatus();
updateTimeline();
}
function updateButton() {
allocationInput.disabled = state.running;
if (state.running) {
runButton.textContent = "Ⅱ PAUSE";
} else if (state.completed) {
runButton.textContent = "↻ RUN AGAIN";
} else if (state.elapsed > 0) {
runButton.textContent = "▶ RESUME";
} else {
runButton.textContent = "▶ RUN 8-MIN PLAN";
}
}
function updateStatus() {
let message;
if (state.completed) {
message = "Plan complete — all 8 service minutes used";
} else if (state.running) {
const bed = activeBedAt(state.elapsed);
const bedName = bed === 0 ? "Bed A · roots" : "Bed B · fruit";
const allocation = bed === 0 ? state.a : state.b;
if (!state.hoseSettled) {
message = "Moving the single hose…";
} else {
const minuteNumber = Math.min(allocation, state.served[bed] + 1);
message = `Watering ${bedName} — minute ${minuteNumber} of ${allocation}`;
}
} else if (state.elapsed > 0) {
message = `Paused at ${state.elapsed.toFixed(1)} / 8 minutes`;
} else {
message = `Ready — ${state.a} min roots + ${state.b} min fruit`;
}
if (statusElement.textContent !== message) {
statusElement.textContent = message;
}
}
function updateTimeline() {
const completedMinutes = state.completed
? TOTAL_MINUTES
: Math.min(TOTAL_MINUTES, Math.floor(state.elapsed));
chips.forEach((chip, index) => {
chip.classList.toggle("done", index < completedMinutes);
const isCurrent =
state.running &&
index === Math.floor(state.elapsed) &&
index < TOTAL_MINUTES;
chip.classList.toggle("current", isCurrent);
});
}
allocationInput.addEventListener("input", () => {
setTransfer(Number(allocationInput.value));
});
runButton.addEventListener("click", () => {
if (state.running) {
state.running = false;
} else {
if (state.completed) resetSimulation();
state.running = true;
}
updateButton();
updateStatus();
});
resetButton.addEventListener("click", () => {
resetSimulation();
updateStatus();
});
// -------------------------------------------------------------------------
// Simulation and visual updates
// -------------------------------------------------------------------------
function updateSimulation(dt) {
if (!state.running) return;
const before = Math.floor(state.elapsed);
state.elapsed = Math.min(
TOTAL_MINUTES,
state.elapsed + dt / SECONDS_PER_MINUTE
);
const after = Math.floor(state.elapsed);
for (let minute = before; minute < after && minute < TOTAL_MINUTES; minute++) {
const bed = minute < state.a ? 0 : 1;
state.served[bed] += 1;
}
if (state.elapsed >= TOTAL_MINUTES) {
state.running = false;
state.completed = true;
updateButton();
}
}
const xAxis = new THREE.Vector3(1, 0, 0);
const segmentDirection = new THREE.Vector3();
const segmentMidpoint = new THREE.Vector3();
const curvePoints = [
new THREE.Vector3(),
new THREE.Vector3(),
new THREE.Vector3(),
new THREE.Vector3()
];
function updateHose(dt) {
const activeBed = activeBedAt(state.elapsed);
desiredHoseTarget.copy(hoseTargets[activeBed]);
const smoothing = 1 - Math.exp(-dt * 5.5);
currentHoseTarget.lerp(desiredHoseTarget, smoothing);
state.hoseSettled =
currentHoseTarget.distanceTo(desiredHoseTarget) < 0.12;
curvePoints[0].copy(hoseOrigin);
curvePoints[1].set(0, 0.30, -2.45);
curvePoints[2].set(currentHoseTarget.x, 0.28, -0.62);
curvePoints[3].copy(currentHoseTarget);
const curve = new THREE.CatmullRomCurve3(
curvePoints,
false,
"catmullrom",
0.18
);
hoseSegments.forEach((segment, index) => {
const t0 = index / hoseSegments.length;
const t1 = (index + 1) / hoseSegments.length;
const p0 = curve.getPoint(t0);
const p1 = curve.getPoint(t1);
segmentDirection.subVectors(p1, p0);
const length = segmentDirection.length();
segmentMidpoint.addVectors(p0, p1).multiplyScalar(0.5);
segment.position.copy(segmentMidpoint);
segment.quaternion.setFromUnitVectors(
xAxis,
segmentDirection.normalize()
);
segment.scale.set(length * 1.10, 0.13, 0.13);
});
nozzle.position.copy(currentHoseTarget);
}
function updateAllocationTokens(dt, time) {
const smoothing = 1 - Math.exp(-dt * 8);
allocationTokens.forEach((token, index) => {
token.group.position.x = THREE.MathUtils.lerp(
token.group.position.x,
token.target.x,
smoothing
);
token.group.position.y = token.target.y + Math.sin(time * 2.2 + index) * 0.025;
token.group.position.z = token.target.z;
const targetColor = index < state.a ? colorA : colorB;
token.material.color.lerp(targetColor, smoothing);
});
}
const drySoil = new THREE.Color("#8a5a39");
const wetSoil = new THREE.Color("#493429");
const tankFull = new THREE.Color("#56b9dc");
const tankEmpty = new THREE.Color("#416d73");
const cellOn = new THREE.Color("#65d3ed");
const cellOff = new THREE.Color("#31514e");
function updateVisuals(dt, time) {
const activeBed = activeBedAt(state.elapsed);
for (let bed = 0; bed < 2; bed++) {
const allocation = bed === 0 ? state.a : state.b;
let moisture = allocation > 0 ? state.served[bed] / allocation : 0;
if (
state.running &&
activeBed === bed &&
state.elapsed < TOTAL_MINUTES
) {
const minuteIndex = Math.floor(state.elapsed);
const fraction = state.elapsed - minuteIndex;
moisture += fraction / allocation;
}
moisture = THREE.MathUtils.clamp(moisture, 0, 1);
soilMaterials[bed].color.lerpColors(drySoil, wetSoil, moisture);
waterMaterials[bed].opacity = moisture * 0.28;
waterTiles[bed].forEach((tile) => {
tile.scale.z = 0.3 + moisture * 0.7;
tile.scale.x = 0.35 + moisture * 0.85;
});
}
for (const plant of plantGroups) {
const allocation = plant.bed === 0 ? state.a : state.b;
const moisture = allocation
? state.served[plant.bed] / allocation
: 0;
const sway = Math.sin(time * 2.4 + plant.phase) *
(activeBed === plant.bed && state.running ? 0.045 : 0.015);
plant.group.rotation.z = sway;
plant.group.rotation.x = Math.cos(time * 1.8 + plant.phase) * 0.018;
plant.group.scale.setScalar(1 + moisture * 0.055);
}
const remaining = Math.max(
0,
TOTAL_MINUTES - Math.floor(state.elapsed)
);
resourceCells.forEach((cell, index) => {
cell.material.color.copy(index < remaining ? cellOn : cellOff);
cell.material.emissiveIntensity = index < remaining ? 0.28 : 0.04;
});
tankWaterMaterial.color.lerpColors(
tankEmpty,
tankFull,
remaining / TOTAL_MINUTES
);
if (state.running && state.hoseSettled) {
particleSpawnAccumulator += dt;
while (particleSpawnAccumulator > 0.035) {
spawnParticle();
spawnParticle();
particleSpawnAccumulator -= 0.035;
}
}
}
// -------------------------------------------------------------------------
// Project HTML labels into the 3D scene
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(${screenX}px, ${screenY}px) translate(-50%, -50%)`;
}
function updateLabels() {
placeLabel($("#tagA"), bedX[0], 0.90, 2.35);
placeLabel($("#tagB"), bedX[1], 0.90, 2.35);
placeLabel($("#planA"), -2.65, 3.92, rackZ);
placeLabel($("#planB"), 2.65, 3.92, rackZ);
placeLabel($("#rackTag"), 0, 4.08, rackZ);
placeLabel($("#tankTag"), 0, 3.00, -4.15);
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
updateTokenTargets();
renderAllocation();
allocationTokens.forEach((token) => {
token.group.position.copy(token.target);
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateSimulation(dt);
updateHose(dt);
updateAllocationTokens(dt, time);
updateParticles(dt);
updateVisuals(dt, time);
updateTimeline();
updateStatus();
updateLabels();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```