Prompt specification
Build or customize the Three.js 3D scene "Plants Herbivores and Resource Counters" 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: Plants Herbivores and Resource Counters
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plants-herbivores-and-resource-counters-x3533
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows ecological feedback under fictional game rules. Display three population counters linked by labeled toy interaction arrows. State the simplified assumptions and avoid implying the counters fully represent a real ecosystem. Low-poly.
Working Three.js Starter (plants-herbivores-and-resource-counters-x3533):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Loop Grove — Ecological Feedback Toy</title>
<style>
:root {
--paper: #faf7ef;
--ink: #25352f;
--muted: #65736d;
--line: #dcd7ca;
--bloom: #d86478;
--pollinator: #dda735;
--bird: #3f9184;
--panel: rgba(250, 247, 239, 0.92);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
width: 100%;
height: 100vh;
height: 100dvh;
}
aside {
position: relative;
z-index: 5;
display: flex;
flex-direction: column;
gap: 18px;
min-height: 0;
padding: 24px;
overflow-y: auto;
background:
linear-gradient(180deg, #fffef9 0%, #f8f3e8 100%);
border-right: 1px solid var(--line);
box-shadow: 8px 0 30px rgba(49, 60, 49, 0.06);
}
.eyebrow {
margin: 0 0 7px;
color: #587267;
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.75rem, 4vw, 2.35rem);
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 0.91rem;
line-height: 1.5;
}
.fiction-badge {
display: inline-flex;
align-items: center;
gap: 7px;
align-self: flex-start;
margin-top: 13px;
padding: 6px 9px;
color: #6d5130;
background: #f3e5bd;
border: 1px solid #e4ce91;
border-radius: 999px;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.fiction-badge::before {
width: 7px;
height: 7px;
content: "";
background: #c38a2d;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(195, 138, 45, 0.13);
}
.section-title {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 0 0 9px;
font-size: 0.76rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-size: 0.66rem;
font-weight: 650;
letter-spacing: 0;
text-transform: none;
}
.counters {
display: grid;
gap: 9px;
}
.counter {
--accent: var(--bloom);
position: relative;
display: grid;
grid-template-columns: 1fr auto;
gap: 3px 12px;
width: 100%;
padding: 12px 13px 11px 15px;
overflow: hidden;
text-align: left;
background: rgba(255, 255, 255, 0.78);
border: 1px solid var(--line);
border-radius: 14px;
cursor: pointer;
transition:
transform 140ms ease,
border-color 140ms ease,
box-shadow 140ms ease;
}
.counter::before {
position: absolute;
inset: 0 auto 0 0;
width: 5px;
content: "";
background: var(--accent);
}
.counter:hover {
transform: translateY(-2px);
border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
box-shadow: 0 8px 18px rgba(43, 54, 47, 0.08);
}
.counter:active {
transform: translateY(0);
}
.counter:focus-visible,
.control:focus-visible,
input:focus-visible {
outline: 3px solid rgba(63, 145, 132, 0.35);
outline-offset: 2px;
}
.counter-heading {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.73rem;
font-weight: 850;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.counter-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
background: var(--accent);
border: 2px solid rgba(255, 255, 255, 0.8);
border-radius: 3px;
box-shadow: 0 0 0 1px var(--accent);
transform: rotate(45deg);
}
.counter-value {
grid-row: 1 / span 2;
grid-column: 2;
align-self: center;
min-width: 62px;
color: var(--accent);
font-size: 2rem;
font-weight: 850;
line-height: 1;
letter-spacing: -0.06em;
text-align: right;
font-variant-numeric: tabular-nums;
}
.counter-meta {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 0.68rem;
}
.trend {
min-width: 38px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
.trend.up {
color: #347d69;
}
.trend.down {
color: #b34f58;
}
.nudge-hint {
margin-left: auto;
color: #8b918c;
font-weight: 700;
}
.rules {
padding-top: 2px;
}
.rule-list {
display: grid;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
counter-reset: rule;
}
.rule-list li {
position: relative;
padding: 9px 10px 9px 33px;
color: #52605a;
background: rgba(255, 255, 255, 0.52);
border: 1px solid rgba(220, 215, 202, 0.78);
border-radius: 10px;
font-size: 0.74rem;
line-height: 1.38;
counter-increment: rule;
}
.rule-list li::before {
position: absolute;
top: 9px;
left: 9px;
display: grid;
width: 17px;
height: 17px;
place-items: center;
color: #fff;
background: #71857b;
border-radius: 50%;
content: counter(rule);
font-size: 0.58rem;
font-weight: 850;
}
.rule-list b {
color: #33473e;
}
.model-note {
padding: 13px 14px;
color: #526159;
background: #eaf1e9;
border: 1px solid #cfdfd2;
border-radius: 13px;
font-size: 0.73rem;
line-height: 1.45;
}
.model-note h2 {
margin: 0 0 6px;
color: #355448;
font-size: 0.74rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.model-note p {
margin: 0 0 7px;
}
.model-note p:last-child {
margin-bottom: 0;
}
.controls {
display: grid;
gap: 9px;
margin-top: auto;
padding-top: 2px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr 0.8fr;
gap: 7px;
}
.control {
min-height: 38px;
padding: 8px 10px;
color: #35483f;
background: #fffdf8;
border: 1px solid #d8d3c6;
border-radius: 10px;
cursor: pointer;
font-size: 0.75rem;
font-weight: 800;
transition:
background 130ms ease,
transform 130ms ease;
}
.control:hover {
background: #f0eadc;
transform: translateY(-1px);
}
.control.primary {
color: #fff;
background: #496f61;
border-color: #496f61;
}
.control.primary:hover {
background: #3d6154;
}
.speed-row {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 0.68rem;
font-weight: 750;
}
.speed-row output {
min-width: 36px;
color: #43564d;
text-align: right;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
accent-color: #496f61;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 35%, #fffdf7 0%, #eee7d7 73%, #e4dbc8 100%);
}
#stage canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#label-layer {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.stage-chrome {
position: absolute;
z-index: 3;
pointer-events: none;
}
.stage-status {
top: 18px;
left: 18px;
max-width: min(390px, calc(100% - 36px));
padding: 10px 12px;
background: var(--panel);
border: 1px solid rgba(207, 202, 188, 0.85);
border-radius: 12px;
box-shadow: 0 7px 22px rgba(49, 60, 49, 0.08);
backdrop-filter: blur(10px);
}
.turn-line {
display: flex;
align-items: center;
gap: 8px;
color: #3e5c50;
font-size: 0.68rem;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.turn-line::before {
width: 7px;
height: 7px;
content: "";
background: #4d8b76;
border-radius: 50%;
}
#event-text {
margin-top: 4px;
color: #6b756f;
font-size: 0.71rem;
line-height: 1.35;
}
.stage-help {
right: 18px;
bottom: 18px;
max-width: 310px;
padding: 9px 11px;
color: #647069;
background: rgba(250, 247, 239, 0.82);
border: 1px solid rgba(207, 202, 188, 0.8);
border-radius: 10px;
font-size: 0.67rem;
line-height: 1.4;
text-align: right;
backdrop-filter: blur(8px);
}
.node-tag,
.arrow-label {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
will-change: transform;
}
.node-tag {
padding: 5px 8px;
color: #fff;
background: rgba(43, 58, 51, 0.84);
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 7px;
box-shadow: 0 4px 12px rgba(28, 40, 34, 0.12);
font-size: 0.62rem;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(4px);
}
.arrow-label {
display: flex;
align-items: center;
gap: 5px;
padding: 5px 7px;
color: #35483f;
background: rgba(255, 253, 247, 0.91);
border: 1px solid rgba(207, 202, 188, 0.9);
border-radius: 7px;
box-shadow: 0 4px 12px rgba(45, 54, 47, 0.09);
font-size: 0.58rem;
font-weight: 850;
letter-spacing: 0.055em;
text-transform: uppercase;
backdrop-filter: blur(5px);
}
.arrow-label b {
color: var(--arrow-color);
font-size: 0.59rem;
}
.arrow-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
background: var(--arrow-color);
border-radius: 50%;
box-shadow: 0 0 0 2px color-mix(in srgb, var(--arrow-color) 22%, transparent);
}
@media (max-width: 850px) {
body {
overflow: auto;
}
#app {
display: flex;
flex-direction: column;
height: auto;
min-height: 100dvh;
}
aside {
max-height: 45dvh;
padding: 18px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.counters {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.counter {
grid-template-columns: 1fr;
padding: 10px;
}
.counter::before {
inset: 0 0 auto;
width: auto;
height: 4px;
}
.counter-value {
grid-row: auto;
grid-column: auto;
min-width: 0;
text-align: left;
}
.counter-meta {
display: none;
}
#stage {
height: 60dvh;
min-height: 500px;
}
}
@media (max-width: 520px) {
aside {
max-height: 52dvh;
}
.counters {
grid-template-columns: 1fr;
}
.counter {
grid-template-columns: 1fr auto;
}
.counter-value {
grid-row: 1 / span 2;
grid-column: 2;
text-align: right;
}
.counter-meta {
display: flex;
}
.stage-help {
right: 10px;
bottom: 10px;
max-width: 230px;
}
.stage-status {
top: 10px;
left: 10px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.001ms !important;
animation-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<div id="app">
<aside aria-label="Fictional ecosystem game controls and rules">
<header>
<p class="eyebrow">A feedback game</p>
<h1>Loop Grove</h1>
<p class="subtitle">
Tap a population, then watch four toy rules carry changes around the grove.
</p>
<span class="fiction-badge">Fictional game rules</span>
</header>
<section aria-labelledby="population-heading">
<h2 class="section-title" id="population-heading">
Population counters <span>click to add one token</span>
</h2>
<div class="counters">
<button class="counter" data-pop="blooms" style="--accent: var(--bloom)">
<span class="counter-heading">
<span class="counter-dot"></span>
Blooms
</span>
<span class="counter-value" id="value-blooms">120</span>
<span class="counter-meta">
<span class="trend" id="trend-blooms">— 0</span>
<span>abstract tokens</span>
<span class="nudge-hint">+1</span>
</span>
</button>
<button class="counter" data-pop="pollinators" style="--accent: var(--pollinator)">
<span class="counter-heading">
<span class="counter-dot"></span>
Pollinators
</span>
<span class="counter-value" id="value-pollinators">70</span>
<span class="counter-meta">
<span class="trend" id="trend-pollinators">— 0</span>
<span>abstract tokens</span>
<span class="nudge-hint">+1</span>
</span>
</button>
<button class="counter" data-pop="birds" style="--accent: var(--bird)">
<span class="counter-heading">
<span class="counter-dot"></span>
Songbirds
</span>
<span class="counter-value" id="value-birds">30</span>
<span class="counter-meta">
<span class="trend" id="trend-birds">— 0</span>
<span>abstract tokens</span>
<span class="nudge-hint">+1</span>
</span>
</button>
</div>
</section>
<section class="rules" aria-labelledby="rules-heading">
<h2 class="section-title" id="rules-heading">
Toy interaction rules <span>one turn at a time</span>
</h2>
<ol class="rule-list">
<li>
<b>Blossoms → Pollinators:</b> every 40 blossom tokens adds
1 pollinator token.
</li>
<li>
<b>Pollinators → Blossoms:</b> every 25 pollinator tokens adds
1 blossom token.
</li>
<li>
<b>Pollinators → Songbirds:</b> every 30 pollinator tokens adds
1 bird token; every 50 bird tokens removes 1 pollinator token.
</li>
<li>
<b>Songbirds → Blossoms:</b> every 35 bird tokens adds
1 blossom token.
</li>
</ol>
</section>
<section class="model-note" aria-labelledby="model-heading">
<h2 id="model-heading">Simplified assumptions</h2>
<p>
These are invented integer counters, not estimates of a real ecosystem.
Each turn also removes 1 token per group, and groups are capped at
240 blossoms, 180 pollinators, and 90 songbirds.
</p>
<p>
The toy omits habitat limits, age, climate, disease, migration,
decomposition, species diversity, and resource competition.
Clicking a counter or model is a player intervention, not biology.
</p>
</section>
<section class="controls" aria-label="Simulation controls">
<div class="button-row">
<button class="control primary" id="step-button">Step</button>
<button class="control" id="toggle-button">Pause</button>
<button class="control" id="reset-button">Reset</button>
</div>
<label class="speed-row" for="speed">
Turn speed
<input id="speed" type="range" min="900" max="5000" step="100" value="2600" />
<output id="speed-output" for="speed">2.6s</output>
</label>
</section>
</aside>
<main id="stage" aria-label="Interactive low-poly grove">
<div id="label-layer" aria-hidden="true"></div>
<div class="stage-chrome stage-status" aria-live="polite">
<div class="turn-line" id="turn-label">Turn 0 · playing</div>
<div id="event-text">Ready. Tap a population to begin nudging the loop.</div>
</div>
<div class="stage-chrome stage-help">
Drag to orbit · Wheel to zoom · Click a model or counter for +1<br />
Double-click the grove to reset the camera
</div>
</main>
</div>
<noscript>This toy requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Game state
// -------------------------------------------------------------------------
const MAX_POPULATION = {
blooms: 240,
pollinators: 180,
birds: 90
};
const INITIAL_POPULATION = {
blooms: 120,
pollinators: 70,
birds: 30
};
const POPULATION_NAMES = {
blooms: "Blossoms",
pollinators: "Pollinators",
birds: "Songbirds"
};
const populations = { ...INITIAL_POPULATION };
const lastChanges = { blooms: 0, pollinators: 0, birds: 0 };
let turn = 0;
let playing = true;
let nextTurnAt = performance.now() + 2600;
const stage = document.querySelector("#stage");
const labelLayer = document.querySelector("#label-layer");
const turnLabel = document.querySelector("#turn-label");
const eventText = document.querySelector("#event-text");
const toggleButton = document.querySelector("#toggle-button");
const stepButton = document.querySelector("#step-button");
const resetButton = document.querySelector("#reset-button");
const speedInput = document.querySelector("#speed");
const speedOutput = document.querySelector("#speed-output");
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xeee7d7, 13, 23);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 60);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0xeee7d7, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
stage.prepend(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.setAttribute(
"aria-label",
"Low-poly fictional grove. Drag to orbit, scroll to zoom, and click a population to add one token."
);
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x718575, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.1);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(1536, 1536);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xaed6d2, 1.1);
rim.position.set(7, 5, -8);
scene.add(rim);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xe6ddc6,
roughness: 1,
flatShading: true
}),
groundTop: new THREE.MeshStandardMaterial({
color: 0xeee6d3,
roughness: 1,
flatShading: true
}),
stone: new THREE.MeshStandardMaterial({
color: 0xb8b09b,
roughness: 0.96,
flatShading: true
}),
stem: new THREE.MeshStandardMaterial({
color: 0x557a54,
roughness: 0.92,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x6f995f,
roughness: 0.92,
flatShading: true
}),
bloom: new THREE.MeshStandardMaterial({
color: 0xd86478,
roughness: 0.78,
flatShading: true
}),
bloomDark: new THREE.MeshStandardMaterial({
color: 0xb94b64,
roughness: 0.82,
flatShading: true
}),
pollen: new THREE.MeshStandardMaterial({
color: 0xe4aa3d,
roughness: 0.75,
flatShading: true
}),
pollenDark: new THREE.MeshStandardMaterial({
color: 0x37342e,
roughness: 0.86,
flatShading: true
}),
wing: new THREE.MeshStandardMaterial({
color: 0xf8f5df,
roughness: 0.7,
transparent: true,
opacity: 0.7,
side: THREE.DoubleSide,
flatShading: true
}),
bird: new THREE.MeshStandardMaterial({
color: 0x3f9184,
roughness: 0.8,
flatShading: true
}),
birdWing: new THREE.MeshStandardMaterial({
color: 0x2f746b,
roughness: 0.86,
flatShading: true
}),
beak: new THREE.MeshStandardMaterial({
color: 0xe4aa3d,
roughness: 0.82,
flatShading: true
}),
eye: new THREE.MeshStandardMaterial({
color: 0x202925,
roughness: 0.65,
flatShading: true
})
};
const animatedObjects = [];
const clickableObjects = [];
const habitats = {};
const arrows = [];
function shadow(mesh, receive = true, cast = true) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function registerAnimation(object, type, phase = 0, baseY = object.position.y) {
animatedObjects.push({ object, type, phase, baseY });
object.userData.baseY = baseY;
}
// A small deterministic random generator keeps the composition stable.
function mulberry32(seed) {
return function () {
let value = seed += 0x6D2B79F5;
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(481516);
// -------------------------------------------------------------------------
// Ground and scenery
// -------------------------------------------------------------------------
const groundBase = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(6.8, 7.15, 0.5, 12),
materials.ground
)
);
groundBase.position.y = -0.28;
scene.add(groundBase);
const groundTop = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(6.72, 6.72, 0.08, 12),
materials.groundTop
)
);
groundTop.position.y = 0.02;
scene.add(groundTop);
const pebbleGeometry = new THREE.IcosahedronGeometry(0.16, 0);
const grassGeometry = new THREE.ConeGeometry(0.07, 0.42, 3);
for (let i = 0; i < 26; i++) {
const angle = random() * Math.PI * 2;
const radius = 5.45 + random() * 0.8;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
if (i % 2 === 0) {
const pebble = shadow(
new THREE.Mesh(pebbleGeometry, materials.stone),
true,
true
);
pebble.position.set(x, 0.13, z);
pebble.scale.set(
0.8 + random() * 0.9,
0.55 + random() * 0.55,
0.8 + random() * 0.8
);
pebble.rotation.set(random(), random(), random());
scene.add(pebble);
} else {
const tuft = new THREE.Group();
tuft.position.set(x, 0.08, z);
for (let j = 0; j < 3; j++) {
const blade = new THREE.Mesh(grassGeometry, materials.leaf);
blade.position.set(
(random() - 0.5) * 0.12,
0.17,
(random() - 0.5) * 0.12
);
blade.rotation.z = (random() - 0.5) * 0.38;
blade.castShadow = true;
tuft.add(blade);
}
scene.add(tuft);
}
}
// -------------------------------------------------------------------------
// Low-poly population models
// -------------------------------------------------------------------------
function makeFlower(scale = 1) {
const group = new THREE.Group();
const stem = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, 0.72, 6),
materials.stem
)
);
stem.position.y = 0.36;
group.add(stem);
const leafGeometry = new THREE.ConeGeometry(0.14, 0.38, 4);
const leafA = shadow(new THREE.Mesh(leafGeometry, materials.leaf));
leafA.position.set(0.12, 0.38, 0);
leafA.rotation.z = -Math.PI * 0.43;
leafA.scale.set(1, 1, 0.45);
group.add(leafA);
const leafB = shadow(new THREE.Mesh(leafGeometry, materials.leaf));
leafB.position.set(-0.1, 0.48, 0.03);
leafB.rotation.z = Math.PI * 0.46;
leafB.scale.set(0.9, 0.85, 0.42);
group.add(leafB);
const head = new THREE.Group();
head.position.y = 0.76;
const petalGeometry = new THREE.IcosahedronGeometry(0.19, 0);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = shadow(
new THREE.Mesh(
petalGeometry,
i % 2 === 0 ? materials.bloom : materials.bloomDark
)
);
petal.position.set(
Math.cos(angle) * 0.22,
0,
Math.sin(angle) * 0.22
);
petal.scale.set(1.1, 0.42, 0.72);
petal.rotation.y = angle;
head.add(petal);
}
const center = shadow(
new THREE.Mesh(
new THREE.DodecahedronGeometry(0.16, 0),
materials.pollen
)
);
center.position.y = 0.055;
center.scale.y = 0.65;
head.add(center);
group.add(head);
group.scale.setScalar(scale);
return group;
}
function makeBee(detailed = true) {
const group = new THREE.Group();
const body = shadow(
new THREE.Mesh(
new THREE.IcosahedronGeometry(0.36, 1),
materials.pollen
)
);
body.scale.set(1.45, 0.82, 0.9);
group.add(body);
const stripeGeometry = new THREE.BoxGeometry(0.09, 0.53, 0.62);
for (const x of [-0.17, 0.09]) {
const stripe = shadow(
new THREE.Mesh(stripeGeometry, materials.pollenDark)
);
stripe.position.x = x;
group.add(stripe);
}
const head = shadow(
new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 0),
materials.pollenDark
)
);
head.position.x = 0.47;
group.add(head);
const eyeGeometry = new THREE.IcosahedronGeometry(0.035, 0);
for (const z of [-0.1, 0.1]) {
const eye = new THREE.Mesh(eyeGeometry, materials.eye);
eye.position.set(0.62, 0.07, z);
group.add(eye);
}
const wingGeometry = new THREE.CircleGeometry(0.29, 5);
for (const side of [-1, 1]) {
const wing = new THREE.Mesh(wingGeometry, materials.wing);
wing.position.set(-0.02, 0.27, side * 0.23);
wing.rotation.x = -Math.PI * 0.5;
wing.rotation.z = side * 0.2;
wing.scale.set(0.9, 1.35, 1);
group.add(wing);
}
if (detailed) {
const antennaGeometry = new THREE.CylinderGeometry(0.012, 0.012, 0.24, 4);
for (const z of [-0.07, 0.07]) {
const antenna = new THREE.Mesh(antennaGeometry, materials.pollenDark);
antenna.position.set(0.56, 0.25, z);
antenna.rotation.z = -0.65;
group.add(antenna);
}
}
return group;
}
function makeBird(detailed = true) {
const group = new THREE.Group();
const body = shadow(
new THREE.Mesh(
new THREE.IcosahedronGeometry(0.52, 1),
materials.bird
)
);
body.position.y = 0.52;
body.scale.set(1.15, 0.88, 0.85);
group.add(body);
const head = shadow(
new THREE.Mesh(
new THREE.IcosahedronGeometry(0.29, 0),
materials.bird
)
);
head.position.set(0, 0.87, -0.29);
group.add(head);
const beak = shadow(
new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.36, 4),
materials.beak
)
);
beak.position.set(0, 0.83, -0.64);
beak.rotation.x = -Math.PI * 0.5;
group.add(beak);
const eye = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.045, 0),
materials.eye
);
eye.position.set(0.16, 0.94, -0.51);
group.add(eye);
if (detailed) {
const secondEye = eye.clone();
secondEye.position.x = -0.16;
group.add(secondEye);
}
for (const side of [-1, 1]) {
const wing = shadow(
new THREE.Mesh(
new THREE.TetrahedronGeometry(0.43, 0),
materials.birdWing
)
);
wing.position.set(side * 0.39, 0.56, 0.03);
wing.scale.set(0.5, 0.9, 1.2);
wing.rotation.z = side * 0.38;
group.add(wing);
}
const tailGeometry = new THREE.BoxGeometry(0.1, 0.08, 0.52);
for (const x of [-0.16, 0, 0.16]) {
const tail = shadow(
new THREE.Mesh(tailGeometry, materials.birdWing)
);
tail.position.set(x, 0.36, 0.58);
tail.rotation.y = x * 0.65;
group.add(tail);
}
return group;
}
function makePedestal(color) {
const group = new THREE.Group();
const lower = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(1.22, 1.32, 0.25, 8),
materials.stone
)
);
lower.position.y = 0.13;
group.add(lower);
const upperMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
flatShading: true
});
const upper = shadow(
new THREE.Mesh(
new THREE.CylinderGeometry(1.12, 1.18, 0.12, 8),
upperMaterial
)
);
upper.position.y = 0.29;
group.add(upper);
return group;
}
function createHabitat(key, position, pedestalColor) {
const group = new THREE.Group();
group.position.copy(position);
group.userData.population = key;
const pedestal = makePedestal(pedestalColor);
group.add(pedestal);
const visual = new THREE.Group();
visual.userData.population = key;
group.add(visual);
const tokens = [];
let main;
if (key === "blooms") {
main = makeFlower(1.2);
main.position.y = 0.34;
visual.add(main);
registerAnimation(main, "flower", 0.3, main.position.y);
const positions = [
[-0.73, 0, -0.58],
[0.72, 0, -0.52],
[-0.7, 0, 0.63],
[0.68, 0, 0.62],
[0, 0, -0.88],
[0.03, 0, 0.92],
[-0.2, 0, -1.08],
[0.26, 0, 1.04]
];
positions.forEach((coords, index) => {
const flower = makeFlower(0.48);
flower.position.set(coords[0], 0.35, coords[2]);
flower.rotation.y = index * 0.73;
visual.add(flower);
tokens.push(flower);
registerAnimation(flower, "flower", index * 0.8, flower.position.y);
});
}
if (key === "pollinators") {
main = makeBee(true);
main.position.set(-0.04, 1.12, 0.05);
main.rotation.y = -0.32;
visual.add(main);
registerAnimation(main, "bee", 0.5, main.position.y);
const positions = [
[-0.72, 0.83, -0.48],
[0.68, 0.92, -0.42],
[-0.72, 0.72, 0.57],
[0.68, 0.76, 0.62],
[0, 0.95, -0.83],
[0.08, 0.7, 0.88]
];
positions.forEach((coords, index) => {
const bee = makeBee(false);
bee.position.set(coords[0], coords[1], coords[2]);
bee.rotation.y = index * 0.8;
bee.scale.setScalar(0.68);
visual.add(bee);
tokens.push(bee);
registerAnimation(bee, "bee", index * 0.9, bee.position.y);
});
}
if (key === "birds") {
main = makeBird(true);
main.position.y = 0.34;
visual.add(main);
registerAnimation(main, "bird", 1.1, main.position.y);
const positions = [
[-0.72, 0.34, -0.45],
[0.7, 0.34, -0.46],
[-0.72, 0.34, 0.58],
[0.7, 0.34, 0.57],
[0.02, 0.34, 0.92]
];
positions.forEach((coords, index) => {
const bird = makeBird(false);
bird.position.set(coords[0], coords[1], coords[2]);
bird.rotation.y = index * 0.72;
bird.scale.setScalar(0.62);
visual.add(bird);
tokens.push(bird);
registerAnimation(bird, "bird", index * 0.76, bird.position.y);
});
}
scene.add(group);
const clickable = [];
visual.traverse((child) => {
if (child.isMesh) clickable.push(child);
});
clickableObjects.push(...clickable);
habitats[key] = {
group,
visual,
tokens,
main,
position: position.clone(),
baseScale: 1,
pulse: 0
};
}
createHabitat(
"blooms",
new THREE.Vector3(-3.0, 0, 1.75),
0xe4b4b9
);
createHabitat(
"pollinators",
new THREE.Vector3(3.0, 0, 1.75),
0xe6cf91
);
createHabitat(
"birds",
new THREE.Vector3(0, 0, -2.65),
0x9bc5ba
);
// -------------------------------------------------------------------------
// Labeled interaction arrows
// -------------------------------------------------------------------------
function makeNodeLabel(text, color) {
const element = document.createElement("div");
element.className = "node-tag";
element.textContent = text;
element.style.background = `${color}ed`;
labelLayer.appendChild(element);
return element;
}
habitats.blooms.label = makeNodeLabel("Blossoms", "#c7566d");
habitats.pollinators.label = makeNodeLabel("Pollinators", "#bd8421");
habitats.birds.label = makeNodeLabel("Songbirds", "#327d72");
function arcControl(start, end, bend, side) {
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const direction = end.clone().sub(start);
const perpendicular = new THREE.Vector3(
-direction.z,
0,
direction.x
).normalize();
return midpoint
.addScaledVector(perpendicular, side)
.add(new THREE.Vector3(0, bend, 0));
}
function createArrow({
key,
startNode,
endNode,
bend,
side,
color,
title,
effect,
labelOffset = [0, 0],
speed = 0.18
}) {
const start = habitats[startNode].position.clone().add(new THREE.Vector3(0, 1.02, 0));
const end = habitats[endNode].position.clone().add(new THREE.Vector3(0, 1.02, 0));
const control = arcControl(start, end, bend, side);
const curve = new THREE.QuadraticBezierCurve3(start, control, end);
const arrowMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.08,
roughness: 0.7,
flatShading: true
});
const tube = shadow(
new THREE.Mesh(
new THREE.TubeGeometry(curve, 40, 0.045, 5, false),
arrowMaterial
),
true,
true
);
scene.add(tube);
const tangent = curve.getTangent(1).normalize();
const head = shadow(
new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.38, 6),
arrowMaterial
)
);
head.position.copy(end).addScaledVector(tangent, -0.18);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
scene.add(head);
const particle = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075, 0),
new THREE.MeshBasicMaterial({ color: 0xfff9e9 })
);
scene.add(particle);
const label = document.createElement("div");
label.className = "arrow-label";
label.style.setProperty("--arrow-color", color);
label.innerHTML = `
<span class="arrow-dot"></span>
<span>${title}</span>
<b>${effect}</b>
`;
labelLayer.appendChild(label);
arrows.push({
key,
curve,
particle,
label,
labelWorld: curve.getPoint(0.52).add(new THREE.Vector3(0, 0.16, 0)),
labelOffset,
speed,
offset: Math.random() * 0.4
});
}
createArrow({
key: "nectar",
startNode: "blooms",
endNode: "pollinators",
bend: 2.45,
side: -1,
color: "#d49a27",
title: "Nectar",
effect: "+ Pollinators",
labelOffset: [0, -7],
speed: 0.17
});
createArrow({
key: "pollen",
startNode: "pollinators",
endNode: "blooms",
bend: 1.45,
side: 1,
color: "#c7566d",
title: "Pollen",
effect: "+ Blossoms",
labelOffset: [0, 10],
speed: 0.14
});
createArrow({
key: "forage",
startNode: "pollinators",
endNode: "birds",
bend: 2.2,
side: 1,
color: "#b65358",
title: "Forage",
effect: "+ Birds − Pollinators",
labelOffset: [10, -3],
speed: 0.2
});
createArrow({
key: "seed",
startNode: "birds",
endNode: "blooms",
bend: 2.25,
side: 1,
color: "#3f9184",
title: "Seed spread",
effect: "+ Blossoms",
labelOffset: [-10, -3],
speed: 0.16
});
// -------------------------------------------------------------------------
// Custom orbit, zoom, and picking controls — no Three.js addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
let cameraYaw = 0.62;
let cameraPitch = 0.48;
let cameraDistance = 11.7;
const defaultCamera = {
yaw: cameraYaw,
pitch: cameraPitch,
distance: cameraDistance
};
let dragging = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousPointerX = 0;
let previousPointerY = 0;
let dragDistance = 0;
let activePointerId = null;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function updateCamera() {
const horizontalDistance = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontalDistance,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontalDistance
);
camera.lookAt(cameraTarget);
}
function findPopulation(object) {
let current = object;
while (current) {
if (current.userData && current.userData.population) {
return current.userData.population;
}
current = current.parent;
}
return null;
}
function pickPopulation(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(clickableObjects, false);
for (const intersection of intersections) {
const population = findPopulation(intersection.object);
if (population) return population;
}
return null;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
dragging = true;
activePointerId = event.pointerId;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging && event.pointerId === activePointerId) {
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.005,
0.25,
1.12
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
dragDistance += Math.hypot(deltaX, deltaY);
updateCamera();
} else {
const population = pickPopulation(event.clientX, event.clientY);
canvas.style.cursor = population ? "pointer" : "grab";
}
});
function endPointer(event) {
if (!dragging || event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
canvas.style.cursor = "grab";
const totalMovement = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
if (totalMovement < 6 && dragDistance < 7) {
const population = pickPopulation(event.clientX, event.clientY);
if (population) nudgePopulation(population);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.008,
7.2,
15
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraYaw = defaultCamera.yaw;
cameraPitch = defaultCamera.pitch;
cameraDistance = defaultCamera.distance;
updateCamera();
});
canvas.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") cameraYaw += 0.1;
else if (event.key === "ArrowRight") cameraYaw -= 0.1;
else if (event.key === "ArrowUp") cameraPitch += 0.07;
else if (event.key === "ArrowDown") cameraPitch -= 0.07;
else if (event.key === "+" || event.key === "=") cameraDistance -= 0.5;
else if (event.key === "-" || event.key === "_") cameraDistance += 0.5;
else if (event.key === " ") stepSimulation();
else handled = false;
cameraPitch = THREE.MathUtils.clamp(cameraPitch, 0.25, 1.12);
cameraDistance = THREE.MathUtils.clamp(cameraDistance, 7.2, 15);
if (handled) {
event.preventDefault();
updateCamera();
}
});
// -------------------------------------------------------------------------
// Simulation and UI
// -------------------------------------------------------------------------
function updateCounterUI() {
for (const key of Object.keys(populations)) {
const valueElement = document.querySelector(`#value-${key}`);
const trendElement = document.querySelector(`#trend-${key}`);
const change = lastChanges[key];
valueElement.textContent = populations[key].toLocaleString();
trendElement.classList.remove("up", "down");
if (change > 0) {
trendElement.textContent = `▲ +${change}`;
trendElement.classList.add("up");
} else if (change < 0) {
trendElement.textContent = `▼ ${change}`;
trendElement.classList.add("down");
} else {
trendElement.textContent = "— 0";
}
}
}
function syncPopulationVisuals() {
for (const key of Object.keys(populations)) {
const habitat = habitats[key];
const ratio = populations[key] / MAX_POPULATION[key];
habitat.baseScale = 0.77 + Math.sqrt(ratio) * 0.47;
habitat.main.visible = populations[key] > 0;
const visibleTokens = Math.ceil(ratio * habitat.tokens.length);
habitat.tokens.forEach((token, index) => {
token.visible = index < visibleTokens;
});
}
}
function formatChange(value) {
return value > 0 ? `+${value}` : `${value}`;
}
function stepSimulation() {
const before = { ...populations };
const proposed = {
blooms:
Math.floor(populations.pollinators / 25) +
Math.floor(populations.birds / 35) -
1,
pollinators:
Math.floor(populations.blooms / 40) -
Math.floor(populations.birds / 50) -
1,
birds:
Math.floor(populations.pollinators / 30) -
1
};
for (const key of Object.keys(populations)) {
populations[key] = THREE.MathUtils.clamp(
populations[key] + proposed[key],
0,
MAX_POPULATION[key]
);
lastChanges[key] = populations[key] - before[key];
habitats[key].pulse = 1;
}
turn += 1;
eventText.textContent =
`Blossoms ${formatChange(lastChanges.blooms)} · ` +
`Pollinators ${formatChange(lastChanges.pollinators)} · ` +
`Songbirds ${formatChange(lastChanges.birds)}`;
turnLabel.textContent = `Turn ${turn} · ${playing ? "playing" : "paused"}`;
updateCounterUI();
syncPopulationVisuals();
}
function nudgePopulation(key) {
const before = populations[key];
populations[key] = Math.min(
populations[key] + 1,
MAX_POPULATION[key]
);
lastChanges[key] = populations[key] - before;
habitats[key].pulse = 1;
eventText.textContent =
`Player nudged ${POPULATION_NAMES[key]} by ` +
`${formatChange(lastChanges[key])}. The next turn will apply the toy rules.`;
updateCounterUI();
syncPopulationVisuals();
}
function resetSimulation() {
Object.assign(populations, INITIAL_POPULATION);
for (const key of Object.keys(lastChanges)) {
lastChanges[key] = 0;
habitats[key].pulse = 1;
}
turn = 0;
playing = false;
toggleButton.textContent = "Play";
turnLabel.textContent = "Turn 0 · paused";
eventText.textContent =
"Reset to the fictional starting values. Press Play or Step to continue.";
updateCounterUI();
syncPopulationVisuals();
}
document.querySelectorAll(".counter").forEach((button) => {
button.addEventListener("click", () => {
nudgePopulation(button.dataset.pop);
});
});
stepButton.addEventListener("click", () => {
stepSimulation();
nextTurnAt = performance.now() + Number(speedInput.value);
});
toggleButton.addEventListener("click", () => {
playing = !playing;
toggleButton.textContent = playing ? "Pause" : "Play";
turnLabel.textContent = `Turn ${turn} · ${playing ? "playing" : "paused"}`;
if (playing) {
nextTurnAt = performance.now() + Number(speedInput.value);
}
});
resetButton.addEventListener("click", resetSimulation);
speedInput.addEventListener("input", () => {
const seconds = Number(speedInput.value) / 1000;
speedOutput.textContent = `${seconds.toFixed(1)}s`;
nextTurnAt = performance.now() + Number(speedInput.value);
});
// -------------------------------------------------------------------------
// Projection, animation, and rendering
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function projectElement(element, worldPosition, offsetX = 0, offsetY = 0) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.3 &&
Math.abs(projected.y) < 1.3;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
element.style.transform =
`translate(${x + offsetX}px, ${y + offsetY}px) translate(-50%, -50%)`;
}
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let previousTime = performance.now();
const scaleTarget = new THREE.Vector3();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing && now >= nextTurnAt) {
stepSimulation();
nextTurnAt = now + Number(speedInput.value);
}
for (const habitat of Object.values(habitats)) {
habitat.pulse = Math.max(0, habitat.pulse - delta * 1.65);
const pulseScale = 1 + habitat.pulse * 0.085;
scaleTarget.setScalar(habitat.baseScale * pulseScale);
habitat.visual.scale.lerp(
scaleTarget,
1 - Math.pow(0.001, delta)
);
}
if (!reducedMotion) {
const time = now * 0.001;
for (const animated of animatedObjects) {
const { object, type, phase, baseY } = animated;
if (!object.visible) continue;
if (type === "flower") {
object.rotation.z = Math.sin(time * 1.4 + phase) * 0.07;
object.position.y = baseY + Math.sin(time * 1.8 + phase) * 0.018;
}
if (type === "bee") {
object.position.y = baseY + Math.sin(time * 2.5 + phase) * 0.13;
object.rotation.z = Math.sin(time * 2 + phase) * 0.055;
}
if (type === "bird") {
object.position.y = baseY + Math.sin(time * 1.65 + phase) * 0.055;
object.rotation.z = Math.sin(time * 1.4 + phase) * 0.025;
}
}
for (const arrow of arrows) {
const progress = (now * 0.001 * arrow.speed + arrow.offset) % 1;
arrow.particle.position.copy(arrow.curve.getPoint(progress));
}
}
updateCamera();
for (const key of Object.keys(habitats)) {
const habitat = habitats[key];
const world = habitat.position.clone().add(new THREE.Vector3(0, 2.55, 0));
projectElement(habitat.label, world);
}
for (const arrow of arrows) {
projectElement(
arrow.label,
arrow.labelWorld,
arrow.labelOffset[0],
arrow.labelOffset[1]
);
}
renderer.render(scene, camera);
}
updateCounterUI();
syncPopulationVisuals();
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```