Prompt specification
Build or customize the Three.js 3D scene "Coordinate a field-watering rotation" 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: Coordinate a field-watering rotation
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/coordinate-a-field-watering-rotation-x2368
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a low-poly field-watering rotation puzzle in a historical-style landscape. A shared channel passes three fictional plots with different initial water levels, each reached through a small gate. Let users assign the order and duration of irrigation turns. Track water entering each plot, remaining in storage, and leaving through a stated drainage rule; the total accounting must remain consistent. Add narrow field paths and a small gathering area beside the main channel. Treat the arrangement as an illustrative scenario rather than a universal account of historical practice. The layout should make individual field needs and dependence on the shared channel visible together.
Working Three.js Starter (coordinate-a-field-watering-rotation-x2368):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Shared Channel — Field-Watering Rotation Puzzle</title>
<style>
:root {
--ink: #302b24;
--muted: #71685b;
--paper: #f2ead9;
--paper-dark: #e6dac3;
--line: #cdbf9f;
--water: #3f8796;
--water-dark: #285e6d;
--green: #57734d;
--gold: #aa7b36;
--red: #a5523f;
--shadow: rgba(51, 40, 25, 0.16);
}
* {
box-sizing: border-box;
}
html, body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
}
body {
height: 100vh;
display: grid;
grid-template-columns: 390px minmax(0, 1fr);
overflow: hidden;
}
aside {
position: relative;
z-index: 3;
height: 100vh;
overflow-y: auto;
padding: 25px 24px 30px;
background:
linear-gradient(rgba(242, 234, 217, 0.96), rgba(242, 234, 217, 0.96)),
repeating-linear-gradient(
0deg,
transparent,
transparent 23px,
rgba(99, 79, 49, 0.05) 24px
);
border-right: 1px solid var(--line);
box-shadow: 6px 0 22px var(--shadow);
}
.eyebrow {
margin-bottom: 7px;
color: var(--water-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 35px;
font-weight: 500;
line-height: 1.04;
}
.intro {
margin: 13px 0 16px;
color: #5f574d;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.48;
}
.scenario-note {
margin: 0 0 15px;
padding: 11px 12px;
border: 1px solid #c7b78f;
border-left: 4px solid var(--gold);
border-radius: 5px;
background: rgba(255, 252, 240, 0.65);
color: #625742;
font-size: 12px;
line-height: 1.45;
}
.rule-box {
margin-bottom: 19px;
padding: 12px 13px;
border-radius: 6px;
background: #e2dac7;
color: #50483d;
font-size: 12px;
line-height: 1.48;
}
.rule-box strong {
display: block;
margin-bottom: 5px;
color: #3d372f;
font-size: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.section-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin: 18px 0 9px;
}
.section-head h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.small-note {
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
#planCards {
display: grid;
gap: 9px;
}
.turn-card {
display: grid;
grid-template-columns: 31px minmax(0, 1fr);
gap: 10px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 252, 242, 0.65);
}
.turn-number {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 50%;
background: var(--ink);
color: #fff9eb;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
}
.turn-fields {
min-width: 0;
}
.turn-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
select {
min-width: 0;
width: 100%;
padding: 6px 25px 6px 8px;
border: 1px solid #bfb092;
border-radius: 4px;
background: #fbf6e9;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
}
.duration-label {
flex: 0 0 auto;
color: var(--water-dark);
font-size: 11px;
font-weight: 800;
}
.range-row {
display: grid;
grid-template-columns: minmax(0, 1fr) 66px;
align-items: center;
gap: 9px;
margin-top: 7px;
}
input[type="range"] {
width: 100%;
accent-color: var(--water);
cursor: pointer;
}
.duration-output {
color: #685f52;
font-size: 10px;
line-height: 1.25;
text-align: right;
}
.turn-meta {
margin-top: 5px;
color: #7c7264;
font-size: 10px;
}
.buttons {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 12px;
}
button {
border: 0;
border-radius: 5px;
padding: 10px 12px;
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 800;
transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: default;
opacity: 0.55;
}
#runButton {
background: var(--water-dark);
color: white;
box-shadow: 0 3px 8px rgba(40, 94, 109, 0.22);
}
#resetButton {
background: #ded1b8;
color: #504639;
}
#status {
min-height: 39px;
margin-top: 9px;
padding: 9px 10px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.34);
color: #63594b;
font-size: 11px;
line-height: 1.4;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin: 9px 0 11px;
}
.stat {
padding: 9px 6px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(255, 252, 243, 0.58);
text-align: center;
}
.stat span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 3px;
color: var(--water-dark);
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
}
.ledger {
padding: 10px 11px;
border: 1px solid #b7c6b1;
border-radius: 6px;
background: rgba(225, 235, 217, 0.62);
color: #475341;
font-size: 11px;
line-height: 1.4;
}
.ledger strong {
display: block;
margin-bottom: 3px;
color: #3f5438;
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#ledgerEquation {
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
}
#conservation {
display: inline-block;
margin-top: 5px;
padding: 2px 6px;
border-radius: 10px;
background: #54764f;
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.goal-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 9px 0;
padding: 8px 10px;
border-radius: 5px;
background: #eadfc8;
font-size: 11px;
}
#goalStatus {
font-weight: 800;
text-align: right;
}
.goal-met {
color: #426a3d;
}
.goal-missed {
color: var(--red);
}
.table-wrap {
overflow-x: auto;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(255, 252, 243, 0.55);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th, td {
padding: 8px 7px;
border-bottom: 1px solid #ded2b9;
text-align: right;
vertical-align: top;
white-space: nowrap;
}
th {
background: #e8dec9;
color: #5d5346;
font-size: 9px;
letter-spacing: 0.03em;
text-transform: uppercase;
}
th:first-child, td:first-child {
text-align: left;
}
tbody tr:last-child td {
border-bottom: 0;
}
.plot-name {
display: block;
color: #3d372f;
font-weight: 800;
}
.plot-target {
display: block;
margin-top: 2px;
color: #8a7d6a;
font-size: 9px;
}
.stored-met {
color: #426b3e;
font-weight: 800;
}
.stored-missed {
color: var(--red);
font-weight: 800;
}
#turnLog {
display: grid;
gap: 5px;
margin-top: 10px;
}
.log-row {
display: grid;
grid-template-columns: 22px minmax(0, 1fr);
gap: 7px;
color: #655b4e;
font-size: 10px;
line-height: 1.35;
}
.log-index {
display: grid;
place-items: center;
width: 21px;
height: 21px;
border: 1px solid #bbae91;
border-radius: 50%;
color: #4e463b;
font-family: Georgia, "Times New Roman", serif;
}
.log-row strong {
color: #3f382f;
}
.footnote {
margin-top: 20px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #776c5d;
font-family: Georgia, "Times New Roman", serif;
font-size: 11px;
line-height: 1.5;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d8d4bd;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.legend {
position: absolute;
top: 17px;
right: 18px;
z-index: 2;
display: grid;
gap: 5px;
padding: 10px 12px;
border: 1px solid rgba(88, 73, 48, 0.22);
border-radius: 6px;
background: rgba(246, 240, 224, 0.87);
box-shadow: 0 4px 14px rgba(53, 42, 27, 0.12);
color: #5c5142;
font-size: 10px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 13px;
height: 8px;
border-radius: 2px;
background: #5ca0aa;
}
.swatch.target {
width: 5px;
height: 13px;
background: #8a6436;
}
.swatch.path {
background: #c8ae7f;
}
.scene-caption {
position: absolute;
left: 18px;
bottom: 15px;
z-index: 2;
max-width: 420px;
padding: 8px 11px;
border-radius: 5px;
background: rgba(246, 240, 224, 0.84);
color: #5b5142;
font-family: Georgia, "Times New Roman", serif;
font-size: 11px;
line-height: 1.4;
pointer-events: none;
}
@media (max-width: 880px) {
body {
height: auto;
min-height: 100vh;
display: flex;
flex-direction: column;
overflow: auto;
}
#stage {
order: -1;
height: 58vh;
min-height: 430px;
}
aside {
width: 100%;
height: auto;
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.legend {
top: 10px;
right: 10px;
}
.scene-caption {
left: 10px;
bottom: 10px;
max-width: 320px;
}
}
</style>
</head>
<body>
<aside aria-label="Puzzle controls and water accounting">
<div class="eyebrow">Illustrative irrigation puzzle</div>
<h1>The Shared Channel</h1>
<p class="intro">
Three fictional plots draw from one communal channel. Decide whose field
receives water first, how long each turn lasts, and how drainage changes
the balance.
</p>
<div class="scenario-note">
<strong>A teaching abstraction, not a universal history.</strong>
The landscape and names are fictional. This scenario is only a simplified
model of shared irrigation and should not be read as a reconstruction of
one particular historical community.
</div>
<div class="rule-box">
<strong>Stated rules</strong>
Each irrigation day requests <b>2 water units</b>. After every turn,
<b>all three plots drain 1 unit</b>. A plot with more than 15 units after
delivery drains <b>1 additional unit</b>. Drainage cannot exceed what is
stored; it enters a lower ditch and is counted as leaving the system.
</div>
<div class="section-head">
<h2>Choose the rotation</h2>
<span class="small-note">One turn per plot</span>
</div>
<p class="small-note" style="margin: 0 0 9px;">
Changing a plot in another slot swaps their positions.
</p>
<div id="planCards"></div>
<div class="buttons">
<button id="runButton" type="button">Run irrigation rotation</button>
<button id="resetButton" type="button" title="Restore the example plan">
Example
</button>
</div>
<div id="status" role="status" aria-live="polite">
The projected result updates as the plan changes.
</div>
<div class="section-head">
<h2>Water ledger</h2>
<span class="small-note">Projected end state</span>
</div>
<div class="stats">
<div class="stat">
<span>Channel</span>
<strong id="channelStat">72</strong>
</div>
<div class="stat">
<span>In fields</span>
<strong id="fieldsStat">23</strong>
</div>
<div class="stat">
<span>Drained</span>
<strong id="drainStat">0</strong>
</div>
</div>
<div class="ledger">
<strong>Conservation check</strong>
<div id="ledgerEquation">72 + 23 + 0 = 95</div>
<span id="conservation">Balanced</span>
</div>
<div class="goal-line">
<span>Reference storage levels reached</span>
<span id="goalStatus">—</span>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th scope="col">Plot</th>
<th scope="col">Entered</th>
<th scope="col">Stored</th>
<th scope="col">Left</th>
</tr>
</thead>
<tbody id="resultRows"></tbody>
</table>
</div>
<div class="section-head">
<h2>Turn log</h2>
<span class="small-note">Requested → actually delivered</span>
</div>
<div id="turnLog"></div>
<div class="footnote">
The wooden stakes mark each plot’s reference storage level. The blue
surface and side gauge show current storage. Drag the landscape to
rotate the view; use the mouse wheel to zoom. Water units and
irrigation days are deliberately abstract rather than historical
measurements.
</div>
</aside>
<main id="stage" aria-label="Interactive low-poly landscape">
<div id="viewport"></div>
<div class="legend" aria-hidden="true">
<div class="legend-row">
<span class="swatch"></span>
<span>Stored water</span>
</div>
<div class="legend-row">
<span class="swatch target"></span>
<span>Reference target</span>
</div>
<div class="legend-row">
<span class="swatch path"></span>
<span>Narrow field path</span>
</div>
</div>
<div class="scene-caption">
A communal channel links Mill Bank, Lower Rye, and Orchard Close.
Their different needs compete for the same finite reserve.
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const INITIAL_CHANNEL = 72;
const DELIVERY_PER_DAY = 2;
const INITIAL_TOTAL = 95;
const PLOTS = [
{
id: "mill",
name: "Mill Bank",
short: "Mill",
initial: 7,
capacity: 30,
target: 17,
x: -9,
crop: 0x899457
},
{
id: "rye",
name: "Lower Rye",
short: "Rye",
initial: 5,
capacity: 30,
target: 16,
x: 0,
crop: 0xb59a55
},
{
id: "orchard",
name: "Orchard Close",
short: "Orchard",
initial: 11,
capacity: 30,
target: 17,
x: 9,
crop: 0x728958
}
];
const plotById = Object.fromEntries(PLOTS.map(plot => [plot.id, plot]));
const DEFAULT_PLAN = [
{ plotId: "orchard", duration: 5 },
{ plotId: "mill", duration: 6 },
{ plotId: "rye", duration: 7 }
];
let plan = DEFAULT_PLAN.map(turn => ({ ...turn }));
let projection = null;
let running = false;
let activePlotId = null;
const viewport = document.getElementById("viewport");
const planCards = document.getElementById("planCards");
const runButton = document.getElementById("runButton");
const resetButton = document.getElementById("resetButton");
const statusElement = document.getElementById("status");
// ---------------------------------------------------------------------
// Deterministic accounting
// ---------------------------------------------------------------------
function makeInitialState() {
return {
channel: INITIAL_CHANNEL,
stores: Object.fromEntries(PLOTS.map(plot => [plot.id, plot.initial])),
entered: Object.fromEntries(PLOTS.map(plot => [plot.id, 0])),
drained: Object.fromEntries(PLOTS.map(plot => [plot.id, 0]))
};
}
function simulatePlan(candidatePlan) {
const state = makeInitialState();
const turns = [];
candidatePlan.forEach((turn, turnIndex) => {
const plot = plotById[turn.plotId];
const requested = turn.duration * DELIVERY_PER_DAY;
const availableSpace = plot.capacity - state.stores[plot.id];
const actual = Math.min(
requested,
state.channel,
availableSpace
);
state.channel -= actual;
state.stores[plot.id] += actual;
state.entered[plot.id] += actual;
const postDelivery = { ...state.stores };
const drainThisTurn = {};
// Every plot drains after every irrigation turn.
PLOTS.forEach(otherPlot => {
const available = state.stores[otherPlot.id];
const ruleDrain = 1 + (available > 15 ? 1 : 0);
const drained = Math.min(available, ruleDrain);
drainThisTurn[otherPlot.id] = drained;
state.stores[otherPlot.id] -= drained;
state.drained[otherPlot.id] += drained;
});
turns.push({
index: turnIndex,
plotId: plot.id,
duration: turn.duration,
requested,
actual,
unmet: requested - actual,
postDelivery,
drainThisTurn,
channelAfter: state.channel,
storesAfter: { ...state.stores }
});
});
const totalEntered = Object.values(state.entered)
.reduce((sum, value) => sum + value, 0);
const totalDrained = Object.values(state.drained)
.reduce((sum, value) => sum + value, 0);
const fieldTotal = Object.values(state.stores)
.reduce((sum, value) => sum + value, 0);
return {
final: state,
turns,
totalEntered,
totalDrained,
fieldTotal,
conserved: state.channel + fieldTotal + totalDrained === INITIAL_TOTAL
};
}
// ---------------------------------------------------------------------
// Interface
// ---------------------------------------------------------------------
function buildPlanCards() {
planCards.innerHTML = "";
plan.forEach((turn, index) => {
const card = document.createElement("article");
card.className = "turn-card";
const number = document.createElement("div");
number.className = "turn-number";
number.textContent = index + 1;
const fields = document.createElement("div");
fields.className = "turn-fields";
const top = document.createElement("div");
top.className = "turn-top";
const select = document.createElement("select");
select.id = `plot-${index}`;
select.setAttribute("aria-label", `Plot for turn ${index + 1}`);
PLOTS.forEach(plot => {
const option = document.createElement("option");
option.value = plot.id;
option.textContent = plot.name;
select.appendChild(option);
});
select.value = turn.plotId;
const durationLabel = document.createElement("span");
durationLabel.className = "duration-label";
durationLabel.id = `duration-label-${index}`;
top.append(select, durationLabel);
const rangeRow = document.createElement("div");
rangeRow.className = "range-row";
const range = document.createElement("input");
range.type = "range";
range.min = "1";
range.max = "8";
range.step = "1";
range.value = turn.duration;
range.id = `duration-${index}`;
range.setAttribute("aria-label", `Duration in days for turn ${index + 1}`);
const output = document.createElement("div");
output.className = "duration-output";
output.id = `duration-output-${index}`;
rangeRow.append(range, output);
const meta = document.createElement("div");
meta.className = "turn-meta";
meta.id = `turn-meta-${index}`;
fields.append(top, rangeRow, meta);
card.append(number, fields);
planCards.appendChild(card);
select.addEventListener("change", () => {
const newPlotId = select.value;
const otherIndex = plan.findIndex(
(candidate, candidateIndex) =>
candidateIndex !== index && candidate.plotId === newPlotId
);
// Swap plots rather than allowing a plot to occur twice.
if (otherIndex !== -1) {
const otherPlotId = plan[otherIndex].plotId;
plan[otherIndex].plotId = newPlotId;
plan[index].plotId = otherPlotId;
syncPlanControls();
} else {
plan[index].plotId = newPlotId;
}
onPlanChanged();
});
range.addEventListener("input", () => {
plan[index].duration = Number(range.value);
onPlanChanged();
});
});
syncPlanControls();
}
function syncPlanControls() {
plan.forEach((turn, index) => {
const plot = plotById[turn.plotId];
document.getElementById(`plot-${index}`).value = turn.plotId;
document.getElementById(`duration-${index}`).value = turn.duration;
document.getElementById(`duration-label-${index}`).textContent =
`${turn.duration} day${turn.duration === 1 ? "" : "s"}`;
document.getElementById(`duration-output-${index}`).textContent =
`${turn.duration * DELIVERY_PER_DAY} units requested`;
document.getElementById(`turn-meta-${index}`).textContent =
`Starts with ${plot.initial} · target ${plot.target} · capacity ${plot.capacity}`;
});
}
function onPlanChanged() {
syncPlanControls();
projection = simulatePlan(plan);
renderSummary(projection);
if (!running) {
setSceneState(projection.final, true);
statusElement.textContent =
"Projected result updated. Run the rotation to watch the gates, deliveries, and drainage.";
}
}
function renderSummary(result) {
const fieldTotal = result.fieldTotal;
const drainTotal = result.totalDrained;
const goalsMet = PLOTS.filter(
plot => result.final.stores[plot.id] >= plot.target
).length;
document.getElementById("channelStat").textContent = result.final.channel;
document.getElementById("fieldsStat").textContent = fieldTotal;
document.getElementById("drainStat").textContent = drainTotal;
document.getElementById("ledgerEquation").textContent =
`${result.final.channel} + ${fieldTotal} + ${drainTotal} = ${INITIAL_TOTAL}`;
const conservation = document.getElementById("conservation");
conservation.textContent = result.conserved ? "Balanced" : "Check accounting";
conservation.style.background = result.conserved ? "#54764f" : "#a5523f";
const goalStatus = document.getElementById("goalStatus");
goalStatus.textContent = `${goalsMet} of ${PLOTS.length} reached`;
goalStatus.className = goalsMet === PLOTS.length ? "goal-met" : "goal-missed";
const rows = PLOTS.map(plot => {
const finalStore = result.final.stores[plot.id];
const met = finalStore >= plot.target;
return `
<tr>
<td>
<span class="plot-name">${plot.name}</span>
<span class="plot-target">target ${plot.target}</span>
</td>
<td>${result.final.entered[plot.id]}</td>
<td class="${met ? "stored-met" : "stored-missed"}">
${finalStore} / ${plot.capacity}
</td>
<td>${result.final.drained[plot.id]}</td>
</tr>
`;
}).join("");
document.getElementById("resultRows").innerHTML = rows;
const log = result.turns.map(turn => {
const plot = plotById[turn.plotId];
const turnDrain = Object.values(turn.drainThisTurn)
.reduce((sum, value) => sum + value, 0);
const requestText = turn.actual === turn.requested
? `${turn.requested} delivered`
: `${turn.requested} requested; ${turn.actual} delivered`;
return `
<div class="log-row">
<span class="log-index">${turn.index + 1}</span>
<span>
<strong>${plot.name}</strong> · ${turn.duration}d ·
${requestText}. Drainage this turn: ${turnDrain}.
</span>
</div>
`;
}).join("");
document.getElementById("turnLog").innerHTML = log;
}
function setControlsDisabled(disabled) {
planCards.querySelectorAll("select, input").forEach(element => {
element.disabled = disabled;
});
runButton.disabled = disabled;
resetButton.disabled = disabled;
}
const sleep = milliseconds =>
new Promise(resolve => window.setTimeout(resolve, milliseconds));
async function runRotation() {
if (running) return;
running = true;
setControlsDisabled(true);
const result = simulatePlan(plan);
const state = makeInitialState();
setSceneState(state, true);
statusElement.textContent = "Opening the shared channel for the first turn…";
for (const turn of result.turns) {
const plot = plotById[turn.plotId];
activePlotId = plot.id;
statusElement.textContent =
`Turn ${turn.index + 1}: ${plot.name} — delivering up to ${turn.requested} units.`;
await sleep(720);
if (turn.actual > 0) {
state.channel -= turn.actual;
state.stores[plot.id] += turn.actual;
state.entered[plot.id] += turn.actual;
setSceneState(state);
await sleep(520);
}
PLOTS.forEach(otherPlot => {
const drained = turn.drainThisTurn[otherPlot.id];
state.stores[otherPlot.id] -= drained;
state.drained[otherPlot.id] += drained;
});
setSceneState(state);
const turnDrain = Object.values(turn.drainThisTurn)
.reduce((sum, value) => sum + value, 0);
statusElement.textContent =
`Turn ${turn.index + 1}: drainage applied to every plot (${turnDrain} units total).`;
await sleep(690);
activePlotId = null;
}
setSceneState(result.final);
renderSummary(result);
const goalsMet = PLOTS.filter(
plot => result.final.stores[plot.id] >= plot.target
).length;
const totalUnmet = result.turns
.reduce((sum, turn) => sum + turn.unmet, 0);
statusElement.textContent =
`Rotation complete. ${goalsMet} of 3 reference levels reached.` +
(totalUnmet > 0
? ` ${totalUnmet} requested units could not be delivered.`
: " All requested deliveries were made.");
running = false;
setControlsDisabled(false);
}
resetButton.addEventListener("click", () => {
if (running) return;
plan = DEFAULT_PLAN.map(turn => ({ ...turn }));
onPlanChanged();
statusElement.textContent =
"The example plan has been restored: Orchard, Mill, then Rye.";
});
runButton.addEventListener("click", runRotation);
// ---------------------------------------------------------------------
// Three.js landscape
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d4bd);
scene.fog = new THREE.Fog(0xd8d4bd, 48, 90);
const renderer = new THREE.WebGLRenderer({
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.13;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.3, 0);
const hemisphere = new THREE.HemisphereLight(0xf6edd3, 0x6e7358, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3aa, 3.1);
sun.position.set(-14, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -26;
sun.shadow.camera.right = 26;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
scene.add(sun);
const materials = {
earth: new THREE.MeshStandardMaterial({
color: 0x92946b,
roughness: 1,
flatShading: true
}),
soil: new THREE.MeshStandardMaterial({
color: 0x94734d,
roughness: 1,
flatShading: true
}),
soilDark: new THREE.MeshStandardMaterial({
color: 0x735637,
roughness: 1,
flatShading: true
}),
path: new THREE.MeshStandardMaterial({
color: 0xc7ad7d,
roughness: 1,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x765438,
roughness: 0.92,
flatShading: true
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xa17b4e,
roughness: 0.9,
flatShading: true
}),
stone: new THREE.MeshStandardMaterial({
color: 0x9b9480,
roughness: 1,
flatShading: true
}),
water: new THREE.MeshStandardMaterial({
color: 0x4f9eaa,
roughness: 0.4,
metalness: 0.05,
transparent: true,
opacity: 0.86
}),
darkWater: new THREE.MeshStandardMaterial({
color: 0x2f7180,
roughness: 0.5,
transparent: true,
opacity: 0.9
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x526f46,
roughness: 1,
flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x718652,
roughness: 1,
flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0xa47b46,
roughness: 1,
flatShading: true
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe4d6b5,
roughness: 1,
flatShading: true
})
};
function addBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
x,
y,
z,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addLabelSprite(width = 5.4, height = 1.25) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 180;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
function update(title, subtitle, accent = "#567c77") {
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(45, 39, 30, 0.91)";
context.beginPath();
context.roundRect(6, 6, 756, 168, 16);
context.fill();
context.strokeStyle = "rgba(235, 218, 177, 0.55)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = accent;
context.fillRect(24, 25, 7, 130);
context.fillStyle = "#fff5dc";
context.font = "600 38px Georgia";
context.textAlign = "left";
context.textBaseline = "middle";
context.fillText(title, 52, 68, 680);
context.fillStyle = "#d8c9aa";
context.font = "25px Arial";
context.fillText(subtitle, 52, 123, 680);
texture.needsUpdate = true;
}
return { sprite, update };
}
// Terrain slab.
addBox(38, 0.65, 27, materials.earth, 0, -0.38, 0);
// Low, faceted hills behind the fields.
const hillMaterial = new THREE.MeshStandardMaterial({
color: 0x7d8962,
roughness: 1,
flatShading: true
});
[
[-14, -11.2, 6.2, 2.1, 2.6],
[-5.5, -12.1, 7.5, 2.8, 2.4],
[4.5, -11.4, 6.8, 2.2, 2.8],
[14, -11.8, 7.0, 2.5, 2.2]
].forEach(([x, z, sx, sy, sz]) => {
const hill = new THREE.Mesh(
new THREE.SphereGeometry(1, 9, 5),
hillMaterial
);
hill.position.set(x, 0.05, z);
hill.scale.set(sx, sy, sz);
hill.castShadow = true;
hill.receiveShadow = true;
scene.add(hill);
});
// Main shared channel, banks, and adjacent lower ditch.
addBox(33, 0.22, 2.55, materials.soilDark, 0, -0.02, 2);
addBox(32, 0.18, 1.42, materials.water, 0, 0.11, 2);
addBox(33, 0.22, 0.35, materials.path, 0, 0.08, 0.75);
addBox(33, 0.22, 0.35, materials.path, 0, 0.08, 3.25);
// Lower ditch records drainage without returning it to the channel.
addBox(31, 0.14, 0.65, materials.soilDark, 0, -0.03, 5.0);
addBox(30, 0.08, 0.32, materials.darkWater, 0, 0.05, 5.0);
// Narrow paths: behind the fields, between plots, and toward the gathering area.
addBox(31, 0.11, 0.64, materials.path, 0, 0.04, -7.25);
addBox(0.62, 0.10, 5.9, materials.path, -4.5, 0.035, -4.55);
addBox(0.62, 0.10, 5.9, materials.path, 4.5, 0.035, -4.55);
addBox(0.78, 0.10, 4.0, materials.path, 13.2, 0.04, 5.1);
// Communal basin at the upstream end.
addCylinder(1.55, 1.75, 0.72, 12, materials.stone, -16.1, 0.28, 2);
const reservoirWater = addCylinder(
1.18,
1.18,
1,
12,
materials.darkWater,
-16.1,
0.35,
2
);
reservoirWater.castShadow = false;
const channelLabel = addLabelSprite(5.4, 1.2);
channelLabel.sprite.position.set(-12.7, 3.0, 4.25);
scene.add(channelLabel.sprite);
const fieldVisuals = {};
const gateVisuals = {};
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
addCylinder(
0.16,
0.23,
1.6,
6,
materials.wood,
0,
0.8,
0,
group
);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.9, 2.1, 7),
materials.leaf
);
crown.position.y = 2.0;
crown.castShadow = true;
group.add(crown);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.68, 1.55, 7),
materials.leafLight
);
upper.position.y = 2.75;
upper.castShadow = true;
group.add(upper);
scene.add(group);
}
[
[-16, -6.1, 0.9],
[-14.2, -9.4, 1.15],
[-11.5, -9.5, 0.78],
[-6.2, -9.4, 0.95],
[-1.8, -9.7, 0.72],
[2.3, -9.5, 1.0],
[6.5, -9.6, 0.82],
[11.3, -9.6, 1.1],
[16.2, -6.8, 0.92],
[-15.7, 6.8, 0.8],
[-11.8, 9.4, 0.95],
[-7.8, 11.2, 0.72],
[2.0, 10.7, 0.9],
[7.0, 10.7, 0.72],
[16.4, 8.8, 0.86]
].forEach(args => createTree(...args));
function createGate(plot) {
const gate = new THREE.Group();
gate.position.set(plot.x, 0.12, -1.66);
addBox(0.18, 1.7, 0.18, materials.wood, -0.62, 0.85, 0, gate);
addBox(0.18, 1.7, 0.18, materials.wood, 0.62, 0.85, 0, gate);
addBox(1.48, 0.18, 0.20, materials.woodLight, 0, 1.68, 0, gate);
const pivot = new THREE.Group();
pivot.position.set(-0.54, 0, 0);
addBox(1.08, 0.92, 0.14, materials.woodLight, 0.54, 0.72, 0, pivot);
addBox(0.12, 0.94, 0.18, materials.wood, 0.54, 0.72, -0.02, pivot);
gate.add(pivot);
scene.add(gate);
const branchMaterial = materials.water.clone();
branchMaterial.opacity = 0.66;
const branch = addBox(
0.88,
0.13,
2.95,
branchMaterial,
plot.x,
0.11,
-0.2
);
branch.castShadow = false;
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0x8bd0d5,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const pulse = new THREE.Mesh(
new THREE.RingGeometry(0.33, 0.48, 24),
pulseMaterial
);
pulse.rotation.x = -Math.PI / 2;
pulse.position.set(plot.x, 0.24, -1.65);
scene.add(pulse);
gateVisuals[plot.id] = { pivot, branch, pulse };
}
PLOTS.forEach(plot => {
const group = new THREE.Group();
group.position.set(plot.x, 0, -4.35);
scene.add(group);
addBox(7.25, 0.27, 5.0, materials.soil, 0, 0.10, 0, group);
// Low raised crop rows.
for (let row = 0; row < 8; row++) {
const cropMaterial = new THREE.MeshStandardMaterial({
color: plot.crop,
roughness: 1,
flatShading: true
});
addBox(
0.28,
0.18,
4.25,
cropMaterial,
-2.8 + row * 0.8,
0.30,
0,
group
);
}
// The translucent overlay shows the stored fraction.
const waterOverlay = new THREE.Mesh(
new THREE.PlaneGeometry(6.7, 4.55),
new THREE.MeshBasicMaterial({
color: 0x5ca9b4,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
})
);
waterOverlay.rotation.x = -Math.PI / 2;
waterOverlay.position.y = 0.405;
waterOverlay.renderOrder = 2;
group.add(waterOverlay);
// A visible side gauge makes different storage levels easy to compare.
const gaugeOuter = addCylinder(
0.19,
0.19,
1.8,
10,
new THREE.MeshStandardMaterial({
color: 0x6e6252,
transparent: true,
opacity: 0.42,
roughness: 0.8
}),
plot.x + 3.95,
1.05,
-1.7
);
gaugeOuter.castShadow = false;
const gaugeFill = addCylinder(
0.115,
0.115,
1,
10,
materials.darkWater.clone(),
plot.x + 3.95,
0.5,
-1.7
);
gaugeFill.castShadow = false;
// Target stake.
addBox(0.10, 1.8, 0.10, materials.wood, plot.x + 3.35, 0.9, -6.35);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0x9b7139,
roughness: 0.9,
flatShading: true
});
addBox(
0.9,
0.38,
0.09,
markerMaterial,
plot.x + 3.66,
1.58,
-6.35
);
// Low boundary stones and fencing.
for (let i = 0; i < 7; i++) {
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.18 + (i % 2) * 0.04, 0),
materials.stone
);
stone.position.set(plot.x - 3.45 + i * 1.15, 0.22, -6.72);
stone.rotation.set(i * 0.4, i * 0.7, i * 0.2);
stone.castShadow = true;
scene.add(stone);
}
const label = addLabelSprite(5.45, 1.2);
label.sprite.position.set(plot.x, 4.25, -7.05);
scene.add(label.sprite);
createGate(plot);
fieldVisuals[plot.id] = {
overlay: waterOverlay,
gaugeFill,
markerMaterial,
label
};
});
// Small gathering area beside the main channel.
addCylinder(
2.65,
2.8,
0.16,
18,
materials.path,
13.2,
0.05,
8.0
);
// Simple open shelter.
const shelter = new THREE.Group();
shelter.position.set(14.3, 0, 8.6);
scene.add(shelter);
[
[-1.25, -0.9],
[1.25, -0.9],
[-1.25, 0.9],
[1.25, 0.9]
].forEach(([x, z]) => {
addBox(0.15, 2.1, 0.15, materials.wood, x, 1.05, z, shelter);
});
const shelterRoof = new THREE.Mesh(
new THREE.ConeGeometry(2.25, 1.25, 4),
materials.roof
);
shelterRoof.position.y = 2.35;
shelterRoof.rotation.y = Math.PI / 4;
shelterRoof.castShadow = true;
shelter.add(shelterRoof);
addBox(2.2, 0.17, 0.46, materials.woodLight, -0.7, 0.48, 0, shelter);
addBox(2.2, 0.17, 0.46, materials.woodLight, 0.7, 0.48, 0, shelter);
// Well-like water point.
addCylinder(0.62, 0.68, 0.62, 10, materials.stone, 11.7, 0.34, 8.1);
addCylinder(0.45, 0.45, 0.10, 10, materials.darkWater, 11.7, 0.68, 8.1);
function createPerson(x, z, color, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
});
addCylinder(0.17, 0.25, 0.7, 6, bodyMaterial, 0, 0.55, 0, group);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 6, 4),
new THREE.MeshStandardMaterial({
color: 0xc39a73,
roughness: 1,
flatShading: true
})
);
head.position.y = 1.03;
head.castShadow = true;
group.add(head);
const hat = new THREE.Mesh(
new THREE.ConeGeometry(0.29, 0.22, 6),
materials.roof
);
hat.position.y = 1.24;
hat.castShadow = true;
group.add(hat);
scene.add(group);
}
createPerson(12.1, 7.4, 0x6d6048, 0.9);
createPerson(13.0, 7.8, 0x7d4e3d, 0.82);
createPerson(14.4, 7.4, 0x4e6a60, 0.95);
createPerson(12.8, 9.2, 0x8b7044, 0.74);
const gatheringLabel = addLabelSprite(4.5, 1.05);
gatheringLabel.sprite.position.set(13.3, 3.65, 10.0);
gatheringLabel.update(
"Gathering area",
"By the shared channel"
);
scene.add(gatheringLabel.sprite);
// Small water glints moving along the main channel.
const glints = [];
const glintMaterial = new THREE.MeshBasicMaterial({
color: 0xb8e0dc,
transparent: true,
opacity: 0.46,
depthWrite: false
});
for (let i = 0; i < 15; i++) {
const glint = new THREE.Mesh(
new THREE.PlaneGeometry(0.9, 0.055),
glintMaterial
);
glint.rotation.x = -Math.PI / 2;
glint.position.set(-15 + i * 2.15, 0.225, 1.72 + (i % 3) * 0.22);
scene.add(glint);
glints.push(glint);
}
// ---------------------------------------------------------------------
// Scene state and visual feedback
// ---------------------------------------------------------------------
const targetStores = Object.fromEntries(
PLOTS.map(plot => [plot.id, plot.initial])
);
const visualStores = { ...targetStores };
let targetChannel = INITIAL_CHANNEL;
let visualChannel = INITIAL_CHANNEL;
function setSceneState(state, snap = false) {
targetChannel = state.channel;
PLOTS.forEach(plot => {
targetStores[plot.id] = state.stores[plot.id];
const met = state.stores[plot.id] >= plot.target;
const visual = fieldVisuals[plot.id];
visual.markerMaterial.color.setHex(met ? 0x66844d : 0xa27435);
visual.label.update(
`${plot.name} — ${state.stores[plot.id]}/${plot.capacity}`,
`target ${plot.target} · in ${state.entered[plot.id]} · drained ${state.drained[plot.id]}`,
met ? "#71945c" : "#b18448"
);
});
channelLabel.update(
"Shared channel",
`${state.channel} of ${INITIAL_CHANNEL} units remaining`
);
if (snap) {
visualChannel = state.channel;
PLOTS.forEach(plot => {
visualStores[plot.id] = state.stores[plot.id];
});
}
}
function updateSceneFrame(delta, elapsed) {
const smoothing = 1 - Math.exp(-delta * 6);
visualChannel += (targetChannel - visualChannel) * smoothing;
PLOTS.forEach(plot => {
visualStores[plot.id] +=
(targetStores[plot.id] - visualStores[plot.id]) * smoothing;
const ratio = THREE.MathUtils.clamp(
visualStores[plot.id] / plot.capacity,
0,
1
);
const visual = fieldVisuals[plot.id];
visual.overlay.material.opacity = ratio * 0.62;
const gaugeHeight = Math.max(0.015, ratio * 1.45);
visual.gaugeFill.scale.y = gaugeHeight;
visual.gaugeFill.position.y = 0.23 + gaugeHeight * 0.5;
const gate = gateVisuals[plot.id];
const isActive = activePlotId === plot.id;
const targetRotation = isActive ? -1.32 : 0;
gate.pivot.rotation.y +=
(targetRotation - gate.pivot.rotation.y) * smoothing;
gate.branch.material.opacity = isActive ? 0.96 : 0.58;
const pulse = gate.pulse;
if (isActive) {
const phase = (elapsed * 1.5) % 1;
pulse.scale.setScalar(1 + phase * 1.7);
pulse.material.opacity = (1 - phase) * 0.78;
} else {
pulse.material.opacity *= 0.88;
}
});
const reservoirRatio = THREE.MathUtils.clamp(
visualChannel / INITIAL_CHANNEL,
0.08,
1
);
reservoirWater.scale.y = reservoirRatio;
reservoirWater.position.y = 0.2 + reservoirRatio * 0.5;
glints.forEach((glint, index) => {
glint.position.x += delta * (0.62 + index % 3 * 0.08);
if (glint.position.x > 16) {
glint.position.x = -16;
}
});
}
// ---------------------------------------------------------------------
// Direct camera controls: no external examples or addons
// ---------------------------------------------------------------------
const view = {
azimuth: 0.66,
polar: 0.73,
zoom: 1,
dragging: false,
pointerX: 0,
pointerY: 0,
moved: false
};
function updateCamera() {
const radius = 38;
const horizontal = Math.cos(view.polar) * radius;
camera.position.set(
cameraTarget.x + Math.sin(view.azimuth) * horizontal,
cameraTarget.y + Math.sin(view.polar) * radius,
cameraTarget.z + Math.cos(view.azimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
renderer.setSize(width, height, false);
const halfHeight = Math.max(14.5, 20.5 / aspect) / view.zoom;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
renderer.domElement.addEventListener("pointerdown", event => {
view.dragging = true;
view.moved = false;
view.pointerX = event.clientX;
view.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!view.dragging) return;
const dx = event.clientX - view.pointerX;
const dy = event.clientY - view.pointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
view.moved = true;
}
view.azimuth -= dx * 0.006;
view.polar = THREE.MathUtils.clamp(
view.polar + dy * 0.004,
0.48,
1.12
);
view.pointerX = event.clientX;
view.pointerY = event.clientY;
});
function endPointer(event) {
view.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.75
);
resize();
}, { passive: false });
// ---------------------------------------------------------------------
// Start
// ---------------------------------------------------------------------
buildPlanCards();
projection = simulatePlan(plan);
renderSummary(projection);
setSceneState(projection.final, true);
resize();
updateCamera();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateSceneFrame(delta, elapsed);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```