Prompt specification
Build or customize the Three.js 3D scene "Drought Changes the Rotation Plan" 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: Drought Changes the Rotation Plan
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/drought-changes-the-rotation-plan-x3572
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing crop rotation and land recovery between harvests. Run the same farm board with a visible reduced-water scenario. Let players revise crop choices and compare outcomes without presenting the game as agricultural advice. Low-poly.
Working Three.js Starter (drought-changes-the-rotation-plan-x3572):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#244b3b">
<title>Harvest Loop — Crop Rotation Game</title>
<style>
:root {
--ink: #20352c;
--muted: #6c786f;
--paper: #f7f5ec;
--panel: #fffdf7;
--line: #dfe3d8;
--green: #315c47;
--green-dark: #244b3b;
--green-soft: #dce9dd;
--blue: #287b99;
--blue-soft: #dceef3;
--gold: #d6a63d;
--gold-soft: #f7ebc9;
--orange: #c66d38;
--orange-soft: #f5e1d4;
--shadow: 0 18px 50px rgba(39, 62, 49, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid rgba(40, 123, 153, 0.35);
outline-offset: 2px;
}
[hidden] {
display: none !important;
}
.app {
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
height: 100dvh;
}
.topbar {
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
min-height: 70px;
padding: 12px 22px;
color: #f8f7ed;
background: var(--green-dark);
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
background: var(--gold);
border-radius: 12px 12px 12px 3px;
transform: rotate(-4deg);
box-shadow: inset 0 -8px 0 rgba(91, 65, 18, 0.12);
}
.brand-mark::before,
.brand-mark::after {
position: absolute;
content: "";
background: var(--green-dark);
border-radius: 999px;
transform: rotate(35deg);
}
.brand-mark::before {
width: 4px;
height: 22px;
left: 17px;
top: 8px;
}
.brand-mark::after {
width: 18px;
height: 4px;
left: 10px;
top: 17px;
}
.brand-copy {
min-width: 0;
}
.brand-copy strong {
display: block;
overflow: hidden;
font-size: 18px;
line-height: 1.1;
letter-spacing: 0.01em;
text-overflow: ellipsis;
white-space: nowrap;
}
.brand-copy span {
display: block;
margin-top: 3px;
color: #bcd0c2;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.top-status {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 9px;
flex-wrap: wrap;
}
.status-pill,
.score-pill {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 34px;
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 999px;
color: #edf3eb;
background: rgba(255, 255, 255, 0.07);
font-size: 12px;
font-weight: 750;
}
.status-dot {
width: 7px;
height: 7px;
background: var(--gold);
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(214, 166, 61, 0.13);
}
.status-pill.result .status-dot {
background: #9ad4a6;
box-shadow: 0 0 0 4px rgba(154, 212, 166, 0.13);
}
.score-pill {
color: #f7e5ac;
border-color: rgba(214, 166, 61, 0.25);
background: rgba(214, 166, 61, 0.08);
}
.ghost-button {
min-height: 34px;
padding: 7px 12px;
color: #edf3eb;
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 999px;
cursor: pointer;
font-size: 12px;
font-weight: 750;
}
.ghost-button:hover {
background: rgba(255, 255, 255, 0.08);
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
min-height: 0;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dce8dc;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 5;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.lens {
width: min(390px, calc(100% - 92px));
padding: 12px;
background: rgba(255, 253, 247, 0.91);
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 16px;
box-shadow: 0 10px 28px rgba(45, 68, 54, 0.12);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.lens-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scenario-badge {
padding: 4px 7px;
color: var(--blue);
background: var(--blue-soft);
border-radius: 999px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 4px;
background: #e9ece3;
border-radius: 11px;
}
.segmented button {
min-height: 34px;
padding: 7px 10px;
color: #5f6c63;
background: transparent;
border: 0;
border-radius: 8px;
cursor: pointer;
font-size: 12px;
font-weight: 800;
}
.segmented button.active {
color: var(--green-dark);
background: #fffdf7;
box-shadow: 0 2px 8px rgba(43, 65, 51, 0.09);
}
.segmented button[data-scenario="reduced"].active {
color: #15556d;
background: #e6f4f7;
}
.lens p {
margin: 8px 1px 0;
color: #5d6b62;
font-size: 11px;
line-height: 1.4;
}
.view-tools {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.view-hint {
max-width: 170px;
padding: 8px 10px;
color: #41584b;
background: rgba(255, 253, 247, 0.78);
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 10px;
font-size: 10px;
font-weight: 700;
line-height: 1.35;
text-align: right;
backdrop-filter: blur(8px);
}
.icon-button {
display: grid;
width: 38px;
height: 38px;
place-items: center;
color: var(--green-dark);
background: rgba(255, 253, 247, 0.9);
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 11px;
cursor: pointer;
box-shadow: 0 8px 20px rgba(45, 68, 54, 0.1);
}
.icon-button:hover {
background: #fff;
}
#plotLabels {
position: absolute;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.plot-label {
position: absolute;
min-width: 88px;
padding: 7px 8px 6px;
color: #f8f6ec;
background: rgba(30, 49, 40, 0.9);
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 9px;
box-shadow: 0 7px 16px rgba(24, 38, 30, 0.17);
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, -100%);
transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
backdrop-filter: blur(7px);
}
.plot-label:hover {
background: rgba(30, 49, 40, 0.97);
}
.plot-label.selected {
background: rgba(214, 166, 61, 0.96);
border-color: #fff3c7;
box-shadow: 0 0 0 3px rgba(214, 166, 61, 0.22), 0 9px 22px rgba(24, 38, 30, 0.2);
}
.plot-index {
display: inline-block;
margin-right: 5px;
color: #b8cdbd;
font-size: 9px;
font-weight: 850;
}
.plot-label.selected .plot-index {
color: #6f551c;
}
.plot-crop {
font-size: 10px;
font-weight: 900;
letter-spacing: 0.07em;
}
.plot-meta {
display: flex;
align-items: center;
gap: 4px;
margin-top: 3px;
color: #c8d7cc;
font-size: 9px;
font-weight: 700;
white-space: nowrap;
}
.plot-label.selected .plot-meta {
color: #684f19;
}
.water-dot {
width: 6px;
height: 6px;
flex: 0 0 auto;
background: #6bc1df;
border-radius: 50%;
}
.water-dot.stress {
background: #e89b62;
}
.recovery-badge {
position: absolute;
z-index: 5;
left: 18px;
bottom: 18px;
max-width: min(420px, calc(100% - 36px));
padding: 10px 13px;
color: #315c47;
background: rgba(255, 253, 247, 0.9);
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 12px;
box-shadow: 0 10px 24px rgba(45, 68, 54, 0.1);
font-size: 11px;
font-weight: 800;
line-height: 1.4;
backdrop-filter: blur(10px);
pointer-events: none;
}
.toast {
position: absolute;
z-index: 10;
left: 50%;
bottom: 22px;
padding: 10px 14px;
color: white;
background: rgba(29, 50, 39, 0.94);
border-radius: 999px;
box-shadow: var(--shadow);
font-size: 12px;
font-weight: 750;
opacity: 0;
transform: translate(-50%, 10px);
transition: opacity 180ms ease, transform 180ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: absolute;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--green-dark);
background: #dce8dc;
font-size: 13px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
aside {
z-index: 10;
min-height: 0;
overflow-y: auto;
padding: 18px;
background: var(--panel);
border-left: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #bac6ba transparent;
}
.sidebar-title {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.sidebar-title h1 {
margin: 2px 0 0;
font-size: 22px;
line-height: 1.08;
letter-spacing: -0.03em;
}
.loop-tag {
flex: 0 0 auto;
padding: 5px 8px;
color: var(--green);
background: var(--green-soft);
border-radius: 999px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.flow-note {
margin: 0 0 17px;
padding: 10px 11px;
color: #55645a;
background: #f1f3ec;
border: 1px solid #e3e7dd;
border-radius: 11px;
font-size: 11px;
line-height: 1.45;
}
.flow-note strong {
color: var(--ink);
}
.panel-section {
padding: 15px 0;
border-top: 1px solid var(--line);
}
.panel-section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 10px;
}
.section-head h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.02em;
}
.section-number {
color: #9aa49c;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.water-track {
height: 7px;
margin-top: 10px;
overflow: hidden;
background: #e4e8df;
border-radius: 999px;
}
.water-track span {
display: block;
width: 50%;
height: 100%;
background: linear-gradient(90deg, #54a8c2, #287b99);
border-radius: inherit;
transition: width 250ms ease;
}
.micro-copy {
margin: 6px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.crop-palette {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.crop-button {
display: grid;
grid-template-columns: 28px 1fr;
grid-template-rows: auto auto;
gap: 1px 8px;
min-height: 64px;
padding: 9px;
color: var(--ink);
text-align: left;
background: #f7f7f0;
border: 1px solid #e2e5dc;
border-radius: 12px;
cursor: pointer;
transition: transform 130ms ease, border-color 130ms ease, background 130ms ease;
}
.crop-button:hover {
transform: translateY(-1px);
border-color: #bbc9bb;
}
.crop-button.active {
background: #edf3e9;
border-color: #7d9d85;
box-shadow: inset 0 0 0 1px #7d9d85;
}
.crop-swatch {
grid-row: 1 / 3;
width: 27px;
height: 27px;
align-self: center;
border-radius: 8px 8px 8px 3px;
box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.08);
}
.crop-swatch.corn {
background: #deb04a;
}
.crop-swatch.legume {
background: #699a53;
}
.crop-swatch.cover {
background: #4d8d72;
}
.crop-swatch.rest {
background: #a79070;
}
.crop-name {
align-self: end;
font-size: 11px;
font-weight: 850;
}
.crop-stat {
align-self: start;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
white-space: nowrap;
}
.selected-card {
margin-top: 10px;
padding: 11px;
background: #f5f4ec;
border: 1px solid #e2e3da;
border-radius: 12px;
}
.rotation-flow {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 8px;
margin-bottom: 11px;
}
.rotation-step {
min-width: 0;
padding: 8px;
background: #fffdf7;
border: 1px solid #e3e4dc;
border-radius: 9px;
}
.rotation-step span {
display: block;
color: #8a958d;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.rotation-step strong {
display: block;
overflow: hidden;
margin-top: 3px;
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.rotation-arrow {
color: #89978e;
font-weight: 900;
}
.meter-row {
display: grid;
grid-template-columns: 65px 1fr 32px;
align-items: center;
gap: 7px;
margin-top: 7px;
font-size: 10px;
}
.meter-row > span:first-child {
color: var(--muted);
font-weight: 700;
}
.meter-row > span:last-child {
font-weight: 850;
text-align: right;
}
.meter {
height: 6px;
overflow: hidden;
background: #dde2d8;
border-radius: 999px;
}
.meter span {
display: block;
height: 100%;
background: #6f9c70;
border-radius: inherit;
transition: width 220ms ease;
}
.meter.residue span {
background: #b38a55;
}
.projection-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 11px;
}
.projection {
padding: 8px 6px;
text-align: center;
background: #fffdf7;
border: 1px solid #e5e5dc;
border-radius: 9px;
}
.projection span {
display: block;
color: #879189;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.projection strong {
display: block;
margin-top: 4px;
font-size: 12px;
}
.secondary-button,
.primary-button {
width: 100%;
min-height: 40px;
border-radius: 11px;
cursor: pointer;
font-size: 11px;
font-weight: 850;
}
.secondary-button {
margin-top: 9px;
color: var(--green-dark);
background: #edf2e9;
border: 1px solid #d4dfd0;
}
.secondary-button:hover {
background: #e3ece0;
}
.primary-button {
margin-top: 11px;
color: white;
background: var(--green-dark);
border: 1px solid var(--green-dark);
box-shadow: 0 7px 16px rgba(36, 75, 59, 0.16);
}
.primary-button:hover {
background: #193e2f;
}
.primary-button:disabled {
cursor: default;
opacity: 0.55;
box-shadow: none;
}
.result-cards {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.result-card {
position: relative;
padding: 11px;
background: #f5f5ed;
border: 1px solid #e2e4dc;
border-radius: 12px;
}
.result-card.reduced {
background: #edf7f8;
border-color: #cce6eb;
}
.result-card h3 {
margin: 0 0 2px;
font-size: 11px;
}
.result-card .result-subtitle {
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.main-result {
margin: 10px 0 8px;
font-size: 24px;
line-height: 1;
letter-spacing: -0.04em;
}
.main-result small {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0;
}
.result-stats {
display: grid;
gap: 5px;
margin: 0;
}
.result-stats div {
display: flex;
justify-content: space-between;
gap: 7px;
color: var(--muted);
font-size: 9px;
}
.result-stats dt,
.result-stats dd {
margin: 0;
}
.result-stats dd {
color: var(--ink);
font-weight: 800;
}
.comparison-note {
margin: 10px 0 0;
padding: 9px 10px;
color: #56645a;
background: #f1f3ec;
border-radius: 9px;
font-size: 10px;
line-height: 1.45;
}
.revision-note {
margin-top: 7px;
color: #8b5c29;
font-size: 10px;
font-weight: 750;
line-height: 1.4;
}
.result-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 10px;
}
.result-actions button {
min-height: 39px;
padding: 8px;
border-radius: 10px;
cursor: pointer;
font-size: 10px;
font-weight: 850;
}
.revise-button {
color: var(--green-dark);
background: #edf2e9;
border: 1px solid #d4dfd0;
}
.next-button {
color: white;
background: var(--green-dark);
border: 1px solid var(--green-dark);
}
.history {
display: grid;
gap: 5px;
}
.history-row {
display: grid;
grid-template-columns: 42px 1fr 1fr;
align-items: center;
gap: 7px;
padding: 7px 8px;
color: var(--muted);
background: #f5f5ee;
border-radius: 8px;
font-size: 9px;
}
.history-row strong {
color: var(--ink);
}
.history-row span:last-child {
color: var(--blue);
font-weight: 750;
}
.history-empty {
color: #8b958e;
font-size: 10px;
font-style: italic;
}
footer {
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
min-height: 38px;
padding: 8px 20px;
color: #66746b;
background: #eeefe7;
border-top: 1px solid #dce0d7;
font-size: 10px;
line-height: 1.35;
}
footer strong {
color: #46584c;
}
.footer-tag {
flex: 0 0 auto;
padding: 4px 7px;
color: #765622;
background: #f4e5bd;
border-radius: 999px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.05em;
text-transform: uppercase;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100dvh;
}
main {
grid-template-columns: 1fr;
grid-template-rows: minmax(500px, 62dvh) auto;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.top-status .score-pill {
display: none;
}
}
@media (max-width: 640px) {
.topbar {
min-height: 62px;
padding: 10px 12px;
}
.brand-copy span,
.status-pill,
.view-hint {
display: none;
}
.brand-copy strong {
font-size: 15px;
}
.brand-mark {
width: 33px;
height: 33px;
}
main {
grid-template-rows: 58dvh auto;
}
.stage-top {
top: 10px;
left: 10px;
right: 10px;
}
.lens {
width: calc(100% - 48px);
padding: 9px;
}
.lens p {
display: none;
}
.recovery-badge {
left: 10px;
bottom: 10px;
max-width: calc(100% - 20px);
}
aside {
padding: 16px 13px;
}
footer {
align-items: flex-start;
padding: 9px 12px;
}
.footer-tag {
display: none;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>Harvest Loop</strong>
<span>Rotation & Recovery Lab</span>
</div>
</div>
<div class="top-status">
<div class="status-pill" id="statusPill">
<span class="status-dot"></span>
<span id="statusText">Planning</span>
</div>
<div class="status-pill">
Season <strong id="seasonText">1</strong>
</div>
<div class="score-pill">
Loop score <strong id="scoreText">0</strong>
</div>
<button class="ghost-button" id="resetBtn" type="button">Reset board</button>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive low-poly farm board">
<div id="scene"></div>
<div class="stage-top">
<div class="lens">
<div class="lens-heading">
<span class="eyebrow">Scenario lens</span>
<span class="scenario-badge" id="lensBadge">REDUCED · 50%</span>
</div>
<div class="segmented" aria-label="Choose scenario shown on board">
<button type="button" data-scenario="standard">Standard water</button>
<button type="button" data-scenario="reduced" class="active">Reduced water</button>
</div>
<p id="scenarioHint">
One plan, two runs. Reduced water provides half the allocation per plot.
</p>
<div class="water-track" aria-hidden="true">
<span id="waterFill"></span>
</div>
<p class="micro-copy" id="waterText">Preparing water budget…</p>
</div>
<div class="view-tools">
<div class="view-hint">Drag to orbit · Scroll to zoom · Click a plot</div>
<button class="icon-button" id="resetViewBtn" type="button" title="Reset camera view" aria-label="Reset camera view">
↺
</button>
</div>
</div>
<div id="plotLabels" aria-label="Farm plot labels"></div>
<div class="recovery-badge" id="recoveryBadge">
↻ Between-harvest recovery is calculated after each harvest.
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div id="loading">Building the low-poly farm…</div>
</section>
<aside aria-label="Game controls">
<div class="sidebar-title">
<div>
<div class="eyebrow">Board command</div>
<h1>Plan the next harvest</h1>
</div>
<span class="loop-tag">9 plots</span>
</div>
<p class="flow-note">
<strong>Choose a plot → assign a crop → run both water cases.</strong>
Then revise the same board to see how different plans compare.
</p>
<section class="panel-section">
<div class="section-head">
<h2>Water lens</h2>
<span class="section-number">01 / Scenario</span>
</div>
<p class="micro-copy" id="scenarioDescription">
The lens changes the board view. Every harvest still runs both scenarios.
</p>
</section>
<section class="panel-section">
<div class="section-head">
<h2>Crop palette</h2>
<span class="section-number">02 / Plan</span>
</div>
<div class="crop-palette" id="cropPalette"></div>
<div class="selected-card">
<div class="rotation-flow">
<div class="rotation-step">
<span>Last crop</span>
<strong id="lastCropText">Cover mix</strong>
</div>
<div class="rotation-arrow">→</div>
<div class="rotation-step">
<span>Next crop</span>
<strong id="chosenCropText">Corn</strong>
</div>
</div>
<div class="meter-row">
<span>Soil</span>
<div class="meter"><span id="soilBar"></span></div>
<span id="soilValue">66</span>
</div>
<div class="meter-row">
<span>Residue</span>
<div class="meter residue"><span id="residueBar"></span></div>
<span id="residueValue">32</span>
</div>
<div class="projection-row">
<div class="projection">
<span>Water met</span>
<strong id="previewWater">100%</strong>
</div>
<div class="projection">
<span>Yield</span>
<strong id="previewYield">93</strong>
</div>
<div class="projection">
<span>Recovery</span>
<strong id="previewRecovery">+3</strong>
</div>
</div>
</div>
<button class="secondary-button" id="rotateBtn" type="button">
Apply the board’s rotation rule
</button>
<button class="primary-button" id="harvestBtn" type="button">
Harvest & compare both scenarios
</button>
<p class="micro-copy">
The rotation rule and all numbers are fictional game mechanics.
</p>
</section>
<section class="panel-section" id="resultsSection" hidden>
<div class="section-head">
<h2 id="resultsTitle">Harvest comparison</h2>
<span class="section-number">03 / Compare</span>
</div>
<div class="result-cards" id="resultCards"></div>
<p class="comparison-note" id="comparisonNote"></p>
<p class="revision-note" id="revisionNote" hidden></p>
<div class="result-actions" id="resultActions">
<button class="revise-button" id="reviseBtn" type="button">
Revise this plan
</button>
<button class="next-button" id="nextBtn" type="button">
Next harvest →
</button>
</div>
</section>
<section class="panel-section">
<div class="section-head">
<h2>Season ledger</h2>
<span class="section-number">Saved runs</span>
</div>
<div class="history" id="history"></div>
</section>
</aside>
</main>
<footer>
<span>
<strong>Simulation only:</strong> crop values, water needs, rotation rules, and recovery
are fictional. This game is not agricultural advice.
</span>
<span class="footer-tag">Learning game · Not agronomic guidance</span>
</footer>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const CROPS = {
corn: {
name: "Corn",
water: 52,
yield: 100,
soil: -16,
residue: 14,
stat: "52 water · 100 yield",
leaf: 0x6f9f43,
leafStress: 0x9a9148
},
legume: {
name: "Legume",
water: 36,
yield: 64,
soil: 12,
residue: 9,
stat: "36 water · soil +12",
leaf: 0x679a51,
leafStress: 0x8b9958
},
cover: {
name: "Cover mix",
water: 26,
yield: 30,
soil: 17,
residue: 24,
stat: "26 water · residue +24",
leaf: 0x3f8468,
leafStress: 0x73895a
},
rest: {
name: "Rest plot",
water: 10,
yield: 0,
soil: 8,
residue: 0,
stat: "10 water · recovery +8",
leaf: 0xa79070,
leafStress: 0xa79070
}
};
const SCENARIOS = {
standard: {
name: "Standard water",
budget: 70,
shortName: "Standard",
color: "#315c47"
},
reduced: {
name: "Reduced water",
budget: 35,
shortName: "Reduced",
color: "#287b99"
}
};
const INITIAL_CHOICES = [
"corn", "corn", "legume",
"cover", "corn", "corn",
"legume", "cover", "rest"
];
const INITIAL_LAST = [
"cover", "rest", "corn",
"legume", "cover", "rest",
"corn", "legume", "corn"
];
const INITIAL_SOIL = [66, 58, 72, 61, 55, 68, 74, 60, 63];
const INITIAL_RESIDUE = [32, 24, 38, 29, 18, 34, 41, 27, 22];
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const stage = $("#stage");
const sceneHost = $("#scene");
const plotLabelsHost = $("#plotLabels");
const toast = $("#toast");
const clamp = THREE.MathUtils.clamp;
const clone = (value) => JSON.parse(JSON.stringify(value));
const signed = (value) => `${value >= 0 ? "+" : ""}${Math.round(value)}`;
let season = 1;
let phase = "planning";
let choices = [...INITIAL_CHOICES];
let lastCrops = [...INITIAL_LAST];
let scenarios = createInitialScenarios();
let activeScenario = "reduced";
let selectedPlot = 0;
let latestRun = null;
let revisionBaseline = null;
let runSnapshot = null;
let history = [];
let toastTimer = null;
function createInitialScenarios() {
return {
standard: {
soil: [...INITIAL_SOIL],
residue: [...INITIAL_RESIDUE]
},
reduced: {
soil: [...INITIAL_SOIL],
residue: [...INITIAL_RESIDUE]
}
};
}
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2300);
}
// ---------- Three.js scene ----------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8dc);
scene.fog = new THREE.Fog(0xdce8dc, 34, 70);
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 120);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const cameraState = {
theta: 0.72,
phi: 0.88,
radius: 27,
target: new THREE.Vector3(0, 0.55, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 0.88;
cameraState.radius = 27;
cameraState.target.set(0, 0.55, 0);
updateCamera();
}
const hemisphere = new THREE.HemisphereLight(0xf6fff1, 0x7b684d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3cf, 3.2);
sun.position.set(-14, 24, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.0004;
scene.add(sun);
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
flatShading: true,
...extra
});
}
function makeBox(width, height, depth, color, x, y, z, parent = scene, extra = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, extra)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCylinder(
topRadius,
bottomRadius,
height,
color,
x,
y,
z,
parent = scene,
segments = 7,
extra = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
material(color, extra)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
material(0xb8cba9)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.78;
ground.receiveShadow = true;
scene.add(ground);
const farm = new THREE.Group();
scene.add(farm);
makeBox(17.6, 0.72, 17.6, 0x8e9b6f, 0, -0.4, 0, farm);
// Narrow paths between the nine plots.
for (const p of [-2.3, 2.3]) {
makeBox(0.48, 0.055, 14.3, 0xb9aa84, p, 0.015, 0, farm);
makeBox(14.3, 0.055, 0.48, 0xb9aa84, 0, 0.018, p, farm);
}
const plotPositions = [];
const plotMeshes = [];
const plotRecords = [];
const plotLabels = [];
const spacing = 4.6;
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 3; col++) {
const index = row * 3 + col;
const x = (col - 1) * spacing;
const z = (row - 1) * spacing;
plotPositions.push({ x, z });
const soil = makeBox(4.05, 0.3, 4.05, 0x76543b, x, 0.15, z, farm);
soil.userData.plotIndex = index;
plotMeshes.push(soil);
const cropRoot = new THREE.Group();
cropRoot.position.set(x, 0.31, z);
farm.add(cropRoot);
const outlineGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(4.16, 0.22, 4.16)
);
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0xffdc78,
transparent: true,
opacity: 0.95
});
const outline = new THREE.LineSegments(outlineGeometry, outlineMaterial);
outline.position.set(x, 0.43, z);
outline.visible = false;
farm.add(outline);
const label = document.createElement("button");
label.type = "button";
label.className = "plot-label";
label.setAttribute("aria-label", `Select farm plot ${index + 1}`);
label.addEventListener("click", () => selectPlot(index));
plotLabelsHost.appendChild(label);
plotLabels.push(label);
plotRecords.push({
index,
x,
z,
soil,
cropRoot,
outline,
cropKey: ""
});
}
}
// Low-poly perimeter fence.
const fenceColor = 0x8d6847;
for (const side of [-1, 1]) {
for (let p = -7.2; p <= 7.21; p += 2.4) {
makeBox(0.18, 1.45, 0.18, fenceColor, p, 0.7, side * 7.55, farm);
makeBox(0.18, 1.45, 0.18, fenceColor, side * 7.55, 0.7, p, farm);
}
makeBox(15.4, 0.13, 0.12, fenceColor, 0, 0.78, side * 7.55, farm);
makeBox(15.4, 0.13, 0.12, fenceColor, 0, 1.18, side * 7.55, farm);
makeBox(0.12, 0.13, 15.4, fenceColor, side * 7.55, 0.78, 0, farm);
makeBox(0.12, 0.13, 15.4, fenceColor, side * 7.55, 1.18, 0, farm);
}
// Barn.
const barn = new THREE.Group();
barn.position.set(-6.1, 0, -6.25);
farm.add(barn);
makeBox(2.65, 1.9, 2.3, 0xa84f3d, 0, 0.95, 0, barn);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.02, 1.25, 4),
material(0x4e5a50)
);
roof.position.y = 2.52;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.9;
roof.castShadow = true;
barn.add(roof);
makeBox(0.78, 1.25, 0.08, 0x6f4a36, 0, 0.64, 1.19, barn);
makeBox(1.75, 0.13, 0.08, 0xf2d7a0, 0, 1.74, 1.19, barn);
// Water tower with a visible scenario gauge.
const tower = new THREE.Group();
tower.position.set(6.25, 0, 6.05);
farm.add(tower);
for (const x of [-0.52, 0.52]) {
for (const z of [-0.52, 0.52]) {
makeBox(0.14, 2.3, 0.14, 0x5f6759, x, 1.15, z, tower);
}
}
makeCylinder(0.88, 0.88, 2.05, 0x3f93ad, 0, 2.75, 0, tower, 8);
makeCylinder(0, 1.02, 0.65, 0x325f6d, 0, 4.05, 0, tower, 8);
const waterGauge = makeBox(0.25, 1.5, 0.12, 0xd8f6ff, 0, 1.25, 0.84, tower);
// Low-poly trees.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
farm.add(tree);
makeCylinder(0.18, 0.24, 1.5, 0x79523b, 0, 0.72, 0, tree, 6);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.95, 0),
material(0x4e825d)
);
crown.position.y = 2.0;
crown.scale.set(0.9, 1.18, 0.9);
crown.castShadow = true;
tree.add(crown);
const crown2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.66, 0),
material(0x63936a)
);
crown2.position.set(0.35, 2.35, 0.05);
crown2.castShadow = true;
tree.add(crown2);
}
addTree(-7.7, 5.7, 0.92);
addTree(7.7, -6.6, 0.78);
addTree(7.9, 7.7, 0.62);
// ---------- Low-poly crop models ----------
function clearGroup(group) {
const geometries = new Set();
const materials = new Set();
group.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
const list = Array.isArray(object.material) ? object.material : [object.material];
list.forEach((entry) => materials.add(entry));
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((entry) => entry.dispose());
group.clear();
}
function cropPositions(count) {
const positions = [];
for (let i = 0; i < count; i++) {
const row = Math.floor(i / 3);
const col = i % 3;
positions.push({
x: -1.05 + col * 1.05 + (row % 2) * 0.1,
z: -0.95 + row * 1.05
});
}
return positions;
}
function buildCropVisual(cropId, ratio) {
const group = new THREE.Group();
const crop = CROPS[cropId];
const stressed = ratio < 0.8;
const leafColor = stressed ? crop.leafStress : crop.leaf;
if (cropId === "corn") {
for (const p of cropPositions(8)) {
const plant = new THREE.Group();
plant.position.set(p.x, 0, p.z);
plant.scale.setScalar(stressed ? 0.82 : 1);
group.add(plant);
makeCylinder(0.055, 0.08, 1.35, leafColor, 0, 0.67, 0, plant, 5);
const leftLeaf = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 0.66, 4),
material(leafColor)
);
leftLeaf.position.set(-0.16, 0.72, 0);
leftLeaf.rotation.z = -1.05;
leftLeaf.castShadow = true;
plant.add(leftLeaf);
const rightLeaf = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 0.66, 4),
material(leafColor)
);
rightLeaf.position.set(0.16, 0.95, 0);
rightLeaf.rotation.z = 1.05;
rightLeaf.castShadow = true;
plant.add(rightLeaf);
const ear = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.32, 5),
material(stressed ? 0xb69b48 : 0xe6b94f)
);
ear.position.set(0, 1.06, 0.04);
ear.rotation.z = 0.18;
ear.castShadow = true;
plant.add(ear);
}
}
if (cropId === "legume") {
for (const p of cropPositions(6)) {
const plant = new THREE.Group();
plant.position.set(p.x, 0, p.z);
group.add(plant);
makeCylinder(0.045, 0.06, 0.58, 0x5d7c42, 0, 0.29, 0, plant, 5);
const bush = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.36, 0),
material(stressed ? 0x8a9857 : 0x659751)
);
bush.position.y = 0.58;
bush.scale.set(1, 0.8, 0.9);
bush.castShadow = true;
plant.add(bush);
for (const offset of [-0.15, 0.13]) {
const pod = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 5, 4),
material(0xd87842)
);
pod.scale.set(0.65, 1.8, 0.65);
pod.position.set(offset, 0.6, 0.29);
pod.rotation.z = offset * 1.2;
pod.castShadow = true;
plant.add(pod);
}
}
}
if (cropId === "cover") {
for (const p of cropPositions(12)) {
const clump = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.27, 0),
material(stressed ? 0x778b5d : (p.x > 0 ? 0x46866d : 0x5a9672))
);
clump.position.set(p.x, 0.12, p.z);
clump.scale.set(1.15, 0.45, 1.05);
clump.rotation.y = p.x * 2.7;
clump.castShadow = true;
group.add(clump);
}
}
if (cropId === "rest") {
for (const p of cropPositions(10)) {
const stubble = new THREE.Mesh(
new THREE.ConeGeometry(0.07, 0.28, 4),
material(stressed ? 0xa38d6c : 0xb59a75)
);
stubble.position.set(p.x, 0.13, p.z);
stubble.rotation.z = (p.x % 0.3) - 0.15;
stubble.castShadow = true;
group.add(stubble);
}
}
return group;
}
function rebuildCrop(record, cropId, ratio) {
const bucket = ratio < 0.8 ? "stress" : ratio < 0.95 ? "watch" : "healthy";
const key = `${cropId}-${bucket}`;
if (record.cropKey === key) return;
record.cropKey = key;
clearGroup(record.cropRoot);
const visual = buildCropVisual(cropId, ratio);
record.cropRoot.add(visual);
}
// ---------- Game calculations ----------
function waterRatio(cropId, scenarioName) {
const crop = CROPS[cropId];
return Math.min(1, SCENARIOS[scenarioName].budget / crop.water);
}
function projectPlot(index, scenarioName) {
const cropId = choices[index];
const crop = CROPS[cropId];
const state = scenarios[scenarioName];
const soil = state.soil[index];
const residue = state.residue[index];
const ratio = waterRatio(cropId, scenarioName);
// The water factor changes at 92% coverage.
const waterFactor = ratio >= 0.92 ? 1 : Math.max(0.25, ratio / 0.92);
const soilFactor = 0.78 + soil * 0.0022;
const projectedYield = Math.round(crop.yield * waterFactor * soilFactor);
const soilAfter = clamp(
soil + crop.soil + residue * 0.06,
0,
100
);
const residueContribution = crop.residue * (0.55 + ratio * 0.45);
const residueAfter = clamp(
residue * 0.30 + residueContribution,
0,
100
);
const recovery = Math.min(9, residueAfter * 0.10);
const nextSoil = clamp(soilAfter + recovery, 0, 100);
const nextResidue = clamp(residueAfter * 0.58, 0, 100);
return {
index,
cropId,
ratio,
supplied: Math.min(crop.water, SCENARIOS[scenarioName].budget),
demand: crop.water,
yield: projectedYield,
soil,
residue,
soilAfter,
residueAfter,
recovery,
nextSoil,
nextResidue,
stressed: ratio < 0.8
};
}
function simulateScenario(scenarioName) {
const plots = choices.map((_, index) => projectPlot(index, scenarioName));
const waterDemand = plots.reduce((sum, plot) => sum + plot.demand, 0);
const waterUsed = plots.reduce((sum, plot) => sum + plot.supplied, 0);
const waterCapacity = SCENARIOS[scenarioName].budget * plots.length;
const totalYield = plots.reduce((sum, plot) => sum + plot.yield, 0);
const avgSoil = plots.reduce((sum, plot) => sum + plot.soilAfter, 0) / plots.length;
const avgNextSoil = plots.reduce((sum, plot) => sum + plot.nextSoil, 0) / plots.length;
const totalRecovery = plots.reduce((sum, plot) => sum + plot.recovery, 0);
const stressPlots = plots.filter((plot) => plot.stressed).length;
const score = Math.round(totalYield + avgNextSoil * 4 + totalRecovery * 3);
return {
scenario: scenarioName,
plots,
waterDemand,
waterUsed,
waterCapacity,
totalYield,
avgSoil,
avgNextSoil,
totalRecovery,
stressPlots,
score,
nextStates: {
soil: plots.map((plot) => plot.nextSoil),
residue: plots.map((plot) => plot.nextResidue)
}
};
}
function suggestedRotation(previousCrops) {
const rule = {
corn: "legume",
legume: "cover",
cover: "corn",
rest: "corn"
};
return previousCrops.map((cropId) => rule[cropId] || "cover");
}
// ---------- Board and UI rendering ----------
function refreshBoard() {
const isResult = phase === "result" && latestRun;
plotRecords.forEach((record, index) => {
const projection = isResult
? latestRun.results[activeScenario].plots[index]
: projectPlot(index, activeScenario);
const soil = isResult ? projection.soilAfter : scenarios[activeScenario].soil[index];
const ratio = projection.ratio;
const drySoil = new THREE.Color(0x958064);
const healthySoil = new THREE.Color(0x6d4b35);
const soilColor = drySoil.clone().lerp(
healthySoil,
clamp(ratio, 0, 1)
);
soilColor.lerp(new THREE.Color(0x82745d), (100 - soil) / 250);
record.soil.material.color.copy(soilColor);
rebuildCrop(record, choices[index], ratio);
const meta = isResult
? `↻ +${Math.round(projection.recovery)}`
: `S${Math.round(soil)}`;
plotLabels[index].innerHTML = `
<span class="plot-index">${String(index + 1).padStart(2, "0")}</span>
<span class="plot-crop">${CROPS[choices[index]].name.toUpperCase()}</span>
<span class="plot-meta">
<i class="water-dot ${ratio < 0.8 ? "stress" : ""}"></i>
${Math.round(ratio * 100)}% · ${meta}
</span>
`;
});
updateSelectionVisuals();
const level = activeScenario === "reduced" ? 0.43 : 0.92;
waterGauge.scale.y = level;
waterGauge.position.y = 0.45 + (1.5 * level) / 2;
}
function updateSelectionVisuals() {
plotRecords.forEach((record, index) => {
const selected = index === selectedPlot;
record.outline.visible = selected;
plotLabels[index].classList.toggle("selected", selected);
});
}
function buildCropPalette() {
$("#cropPalette").innerHTML = Object.entries(CROPS).map(([id, crop]) => `
<button class="crop-button" type="button" data-crop="${id}">
<span class="crop-swatch ${id}" aria-hidden="true"></span>
<span class="crop-name">${crop.name}</span>
<span class="crop-stat">${crop.stat}</span>
</button>
`).join("");
$$(".crop-button").forEach((button) => {
button.addEventListener("click", () => {
choices[selectedPlot] = button.dataset.crop;
refreshBoard();
updateUI();
showToast(`${CROPS[button.dataset.crop].name} assigned to plot ${selectedPlot + 1}`);
});
});
}
function selectPlot(index) {
selectedPlot = index;
updateSelectionVisuals();
updateUI();
}
function updateUI() {
const scenario = SCENARIOS[activeScenario];
const projection = projectPlot(selectedPlot, activeScenario);
const state = scenarios[activeScenario];
const cropId = choices[selectedPlot];
$("#seasonText").textContent = season;
$("#statusText").textContent = phase === "result" ? "Harvest complete" : "Planning";
$("#statusPill").classList.toggle("result", phase === "result");
$("#lensBadge").textContent = activeScenario === "reduced"
? "REDUCED · 50%"
: "STANDARD · 100%";
$("#scenarioHint").textContent = activeScenario === "reduced"
? "One plan, two runs. Reduced water provides half the allocation per plot."
: "One plan, two runs. This lens shows the standard allocation per plot.";
$("#scenarioDescription").textContent = activeScenario === "reduced"
? "Reduced lens: 35 water units per plot. Every harvest still runs both scenarios."
: "Standard lens: 70 water units per plot. Every harvest still runs both scenarios.";
$$(".segmented button").forEach((button) => {
button.classList.toggle("active", button.dataset.scenario === activeScenario);
});
const totalDemand = choices.reduce(
(sum, id) => sum + CROPS[id].water,
0
);
const totalSupplied = choices.reduce(
(sum, id) => sum + Math.min(CROPS[id].water, scenario.budget),
0
);
const demandCovered = totalDemand ? totalSupplied / totalDemand : 1;
$("#waterFill").style.width = `${activeScenario === "reduced" ? 50 : 100}%`;
$("#waterText").textContent = `${scenario.budget} units per plot · ${Math.round(demandCovered * 100)}% of planned demand met`;
$("#lastCropText").textContent = CROPS[lastCrops[selectedPlot]].name;
$("#chosenCropText").textContent = CROPS[cropId].name;
$("#soilValue").textContent = Math.round(state.soil[selectedPlot]);
$("#soilBar").style.width = `${state.soil[selectedPlot]}%`;
$("#residueValue").textContent = Math.round(state.residue[selectedPlot]);
$("#residueBar").style.width = `${state.residue[selectedPlot]}%`;
$("#previewWater").textContent = `${Math.round(projection.ratio * 100)}%`;
$("#previewYield").textContent = projection.yield;
$("#previewRecovery").textContent = `+${Math.round(projection.recovery)}`;
$$(".crop-button").forEach((button) => {
button.classList.toggle("active", button.dataset.crop === cropId);
});
$("#harvestBtn").disabled = phase === "result";
$("#harvestBtn").textContent = phase === "result"
? "Harvest complete — compare below"
: "Harvest & compare both scenarios";
let activeScore = 0;
if (phase === "result" && latestRun) {
activeScore = latestRun.results[activeScenario].score;
} else {
const projected = choices.map((_, index) => projectPlot(index, activeScenario));
activeScore = Math.round(
projected.reduce((sum, plot) => sum + plot.yield, 0) +
projected.reduce((sum, plot) => sum + plot.nextSoil, 0) / projected.length * 4 +
projected.reduce((sum, plot) => sum + plot.recovery, 0) * 3
);
}
$("#scoreText").textContent = activeScore;
if (phase === "result" && latestRun) {
$("#recoveryBadge").textContent =
`↻ ${scenario.shortName} between-harvest recovery: +${Math.round(latestRun.results[activeScenario].totalRecovery)} total soil points before the next season.`;
} else {
const projectedRecovery = choices.reduce(
(sum, _, index) => sum + projectPlot(index, activeScenario).recovery,
0
);
$("#recoveryBadge").textContent =
`↻ Projected between-harvest recovery: +${Math.round(projectedRecovery)} total soil points.`;
}
renderResults();
renderHistory();
}
function resultCard(result) {
const reduced = result.scenario === "reduced";
return `
<article class="result-card ${reduced ? "reduced" : ""}">
<h3>${SCENARIOS[result.scenario].shortName}</h3>
<div class="result-subtitle">${reduced ? "50% allocation" : "Full allocation"}</div>
<div class="main-result">
${result.totalYield}<small> yield</small>
</div>
<dl class="result-stats">
<div><dt>Water</dt><dd>${result.waterUsed} / ${result.waterCapacity}</dd></div>
<div><dt>Avg. soil</dt><dd>${Math.round(result.avgNextSoil)}</dd></div>
<div><dt>Recovery</dt><dd>+${Math.round(result.totalRecovery)}</dd></div>
<div><dt>Stressed</dt><dd>${result.stressPlots} / 9</dd></div>
<div><dt>Loop score</dt><dd>${result.score}</dd></div>
</dl>
</article>
`;
}
function renderResults() {
if (!latestRun) {
$("#resultsSection").hidden = true;
return;
}
$("#resultsSection").hidden = false;
$("#resultsTitle").textContent = phase === "result"
? "Harvest comparison"
: "Saved harvest comparison";
const standard = latestRun.results.standard;
const reduced = latestRun.results.reduced;
$("#resultCards").innerHTML = resultCard(standard) + resultCard(reduced);
const yieldDifference = reduced.totalYield - standard.totalYield;
const recoveryDifference = reduced.totalRecovery - standard.totalRecovery;
$("#comparisonNote").innerHTML = `
Same 9-plot plan in both runs.
<strong>Reduced water:</strong> ${signed(yieldDifference)} yield and
${signed(recoveryDifference)} recovery compared with standard water.
`;
const revisionNote = $("#revisionNote");
if (revisionBaseline && phase === "result") {
const baseStandard = revisionBaseline.results.standard;
const baseReduced = revisionBaseline.results.reduced;
const standardDelta = standard.totalYield - baseStandard.totalYield;
const reducedDelta = reduced.totalYield - baseReduced.totalYield;
revisionNote.hidden = false;
revisionNote.textContent =
`Revision vs saved plan: ${signed(standardDelta)} standard yield, ${signed(reducedDelta)} reduced yield.`;
} else if (phase === "planning") {
revisionNote.hidden = false;
revisionNote.textContent =
"Saved for comparison. Adjust any crop, then harvest again to see the revision delta.";
} else {
revisionNote.hidden = true;
}
$("#resultActions").hidden = phase !== "result";
}
function renderHistory() {
const host = $("#history");
if (!history.length) {
host.innerHTML = `<div class="history-empty">No completed seasons yet.</div>`;
return;
}
host.innerHTML = history.slice().reverse().map((entry) => `
<div class="history-row">
<strong>S${entry.season}</strong>
<span>${entry.standardYield} yield</span>
<span>${entry.reducedYield} yield</span>
</div>
`).join("");
}
// ---------- Game flow ----------
function runHarvest() {
if (phase !== "planning") return;
runSnapshot = {
scenarios: clone(scenarios),
choices: [...choices],
lastCrops: [...lastCrops]
};
latestRun = {
season,
choices: [...choices],
results: {
standard: simulateScenario("standard"),
reduced: simulateScenario("reduced")
}
};
phase = "result";
refreshBoard();
updateUI();
showToast("Both water scenarios completed. Compare, revise, or advance.");
}
function revisePlan() {
if (!latestRun || !runSnapshot) return;
if (!revisionBaseline) revisionBaseline = clone(latestRun);
scenarios = clone(runSnapshot.scenarios);
phase = "planning";
refreshBoard();
updateUI();
showToast("Board restored. Change crop choices and run again.");
}
function nextHarvest() {
if (!latestRun || phase !== "result") return;
history = history.filter((entry) => entry.season !== season);
history.push({
season,
standardYield: latestRun.results.standard.totalYield,
reducedYield: latestRun.results.reduced.totalYield,
standardScore: latestRun.results.standard.score,
reducedScore: latestRun.results.reduced.score
});
scenarios = {
standard: clone(latestRun.results.standard.nextStates),
reduced: clone(latestRun.results.reduced.nextStates)
};
lastCrops = [...latestRun.choices];
choices = suggestedRotation(lastCrops);
season += 1;
phase = "planning";
latestRun = null;
revisionBaseline = null;
runSnapshot = null;
refreshBoard();
updateUI();
showToast(`Season ${season} ready. The rotation rule has proposed a new plan.`);
}
function resetGame() {
season = 1;
phase = "planning";
choices = [...INITIAL_CHOICES];
lastCrops = [...INITIAL_LAST];
scenarios = createInitialScenarios();
activeScenario = "reduced";
selectedPlot = 0;
latestRun = null;
revisionBaseline = null;
runSnapshot = null;
history = [];
refreshBoard();
updateUI();
showToast("Farm board reset.");
}
// ---------- Direct camera controls ----------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerStart = null;
let pointerMoved = false;
function raycastPlot(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(plotMeshes, false)[0];
return hit ? hit.object.userData.plotIndex : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerStart = { x: event.clientX, y: event.clientY };
pointerMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerStart) {
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
if (Math.hypot(dx, dy) > 4) pointerMoved = true;
if (pointerMoved) {
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.52, 1.25);
updateCamera();
}
return;
}
const hovered = raycastPlot(event);
renderer.domElement.style.cursor = hovered === null ? "grab" : "pointer";
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerStart && !pointerMoved) {
const index = raycastPlot(event);
if (index !== null) selectPlot(index);
}
pointerStart = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerStart = null;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.018,
17,
38
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// ---------- Interface events ----------
$$(".segmented button").forEach((button) => {
button.addEventListener("click", () => {
activeScenario = button.dataset.scenario;
refreshBoard();
updateUI();
});
});
$("#rotateBtn").addEventListener("click", () => {
choices = suggestedRotation(lastCrops);
refreshBoard();
updateUI();
showToast("The board’s fictional rotation rule was applied to all plots.");
});
$("#harvestBtn").addEventListener("click", runHarvest);
$("#reviseBtn").addEventListener("click", revisePlan);
$("#nextBtn").addEventListener("click", nextHarvest);
$("#resetBtn").addEventListener("click", resetGame);
$("#resetViewBtn").addEventListener("click", resetCamera);
// ---------- Resize and render loop ----------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
plotRecords.forEach((record, index) => {
projected.set(record.x, 2.25, record.z).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
plotLabels[index].style.left = `${x}px`;
plotLabels[index].style.top = `${y}px`;
plotLabels[index].style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
});
}
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
plotRecords.forEach((record, index) => {
record.cropRoot.rotation.z = Math.sin(time * 0.85 + index * 0.9) * 0.009;
record.cropRoot.rotation.x = Math.cos(time * 0.7 + index) * 0.005;
if (record.outline.visible) {
record.outline.material.opacity = 0.72 + Math.sin(time * 3.2) * 0.2;
}
});
updateLabels();
renderer.render(scene, camera);
}
buildCropPalette();
resetCamera();
resize();
refreshBoard();
updateUI();
renderer.setAnimationLoop(animate);
$("#loading").remove();
</script>
</body>
</html>
```