Prompt specification
Build or customize the Three.js 3D scene "Stopover replenishes a travel budget" 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: Stopover replenishes a travel budget
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stopover-replenishes-a-travel-budget-x0658
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows bird migration stopovers. Animate a bird-like marker moving between patches using a fictional energy counter; resting at a resource patch restores the counter under an explicitly stated game rule. Low-poly.
Working Three.js Starter (stopover-replenishes-a-travel-budget-x0658):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flyway — Migration Stopovers</title>
<style>
:root {
--ink: #ecf8f2;
--muted: #a9c5c4;
--glass: rgba(10, 31, 38, 0.82);
--glass-border: rgba(183, 239, 222, 0.18);
--mint: #7ff0cc;
--amber: #ffc477;
--coral: #ff8d70;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #173e49;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 45%, rgba(4, 20, 26, 0.24)),
linear-gradient(180deg, rgba(5, 21, 27, 0.12), transparent 28%);
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: 360px;
text-shadow: 0 2px 18px rgba(0, 20, 24, 0.5);
}
.eyebrow {
margin-bottom: 7px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.23em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(28px, 4vw, 48px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 0.98;
}
.brand p {
margin: 10px 0 0;
color: #d0e7e3;
font-size: 13px;
line-height: 1.5;
}
.panel {
pointer-events: auto;
border: 1px solid var(--glass-border);
border-radius: 17px;
background: var(--glass);
box-shadow: 0 18px 50px rgba(3, 18, 24, 0.25);
backdrop-filter: blur(13px);
-webkit-backdrop-filter: blur(13px);
}
.status-panel {
position: absolute;
top: 22px;
right: 22px;
width: 285px;
padding: 17px;
}
.status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.status-top strong {
font-size: 12px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.tiny-chip {
padding: 4px 7px;
border: 1px solid rgba(127, 240, 204, 0.26);
border-radius: 999px;
color: var(--mint);
background: rgba(127, 240, 204, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.energy-number {
display: flex;
align-items: baseline;
gap: 8px;
margin: 4px 0 9px;
}
#energyValue {
font-size: 45px;
font-weight: 760;
letter-spacing: -0.06em;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.unit {
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.energy-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
#energyFill {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #42c8a4, #9bffdc);
box-shadow: 0 0 14px rgba(127, 240, 204, 0.5);
transition: width 0.12s linear, background 0.2s;
}
.status-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 14px;
}
.stat {
min-width: 0;
padding: 10px;
border-radius: 11px;
background: rgba(255, 255, 255, 0.045);
}
.stat span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat b {
display: block;
overflow: hidden;
color: #f4fffb;
font-size: 12px;
font-weight: 650;
text-overflow: ellipsis;
white-space: nowrap;
}
.controls {
display: flex;
gap: 7px;
margin-top: 12px;
}
.mini-btn {
flex: 1;
padding: 8px 10px;
border: 1px solid rgba(218, 248, 238, 0.15);
border-radius: 9px;
color: #e8faf4;
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition: background 0.16s, transform 0.16s;
}
.mini-btn:hover {
background: rgba(127, 240, 204, 0.12);
transform: translateY(-1px);
}
.rule-panel {
position: absolute;
left: 22px;
bottom: 22px;
width: min(360px, calc(100vw - 44px));
padding: 16px 17px;
}
.rule-heading {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--amber);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.rule-dot {
width: 9px;
height: 9px;
border: 2px solid var(--amber);
border-radius: 50%;
box-shadow: 0 0 12px rgba(255, 196, 119, 0.55);
}
.rule-panel p {
margin: 0;
color: #c8ded9;
font-size: 12px;
line-height: 1.55;
}
.rule-panel strong {
color: #fff5e4;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-swatch {
width: 8px;
height: 8px;
border-radius: 50%;
}
.legend-swatch.resource {
background: var(--mint);
box-shadow: 0 0 8px rgba(127, 240, 204, 0.55);
}
.legend-swatch.rest {
background: var(--amber);
}
.route-panel {
position: absolute;
right: 22px;
bottom: 22px;
width: 285px;
padding: 14px 16px;
}
.route-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#routeSteps {
display: flex;
gap: 5px;
}
.route-step {
flex: 1;
min-width: 0;
padding-top: 7px;
border-top: 3px solid rgba(255, 255, 255, 0.11);
color: #799a9a;
font-size: 8px;
font-weight: 750;
line-height: 1.25;
text-align: center;
text-transform: uppercase;
transition: color 0.2s, border-color 0.2s;
}
.route-step.active {
border-color: var(--mint);
color: #eafff7;
}
.route-step.resource::after {
content: "";
display: block;
width: 4px;
height: 4px;
margin: 5px auto 0;
border-radius: 50%;
background: var(--mint);
}
.route-step.rest::after {
content: "";
display: block;
width: 4px;
height: 4px;
margin: 5px auto 0;
border-radius: 50%;
background: var(--amber);
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(223, 255, 245, 0.18);
border-radius: 999px;
color: #effdf8;
background: rgba(9, 35, 42, 0.76);
box-shadow: 0 5px 16px rgba(4, 20, 24, 0.2);
font-size: 9px;
font-weight: 760;
letter-spacing: 0.045em;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 0.15s, border-color 0.2s, background 0.2s;
}
.map-label.active {
border-color: rgba(127, 240, 204, 0.7);
background: rgba(15, 60, 62, 0.92);
}
.label-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
}
.label-dot.resource {
background: var(--mint);
box-shadow: 0 0 7px rgba(127, 240, 204, 0.7);
}
#toast {
position: absolute;
top: 19%;
left: 50%;
padding: 10px 15px;
border: 1px solid rgba(127, 240, 204, 0.45);
border-radius: 999px;
color: #ecfff7;
background: rgba(18, 92, 79, 0.88);
box-shadow: 0 0 30px rgba(127, 240, 204, 0.22);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
opacity: 0;
pointer-events: none;
text-transform: uppercase;
transform: translate(-50%, -8px);
transition: opacity 0.18s, transform 0.18s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.camera-hint {
position: absolute;
bottom: 23px;
left: 50%;
color: rgba(232, 251, 246, 0.62);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.05em;
text-shadow: 0 2px 9px rgba(0, 20, 24, 0.8);
transform: translateX(-50%);
white-space: nowrap;
}
@media (max-width: 800px) {
.brand {
top: 18px;
left: 18px;
max-width: 240px;
}
.brand p {
display: none;
}
.status-panel {
top: 15px;
right: 15px;
width: 230px;
padding: 13px;
}
#energyValue {
font-size: 35px;
}
.route-panel {
display: none;
}
.rule-panel {
left: 15px;
bottom: 15px;
width: calc(100vw - 30px);
}
.camera-hint {
display: none;
}
}
@media (max-width: 520px) {
.brand h1 {
font-size: 26px;
}
.brand .eyebrow {
font-size: 8px;
}
.status-panel {
top: auto;
right: 15px;
bottom: 176px;
width: 210px;
}
.status-grid {
display: none;
}
.rule-panel {
padding: 13px;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<div id="labels"></div>
<main class="hud">
<header class="brand">
<div class="eyebrow">Flyway 07 · Low-poly migration</div>
<h1>Stopover Atlas</h1>
<p>Follow a small migratory bird across a chain of seasonal islands.</p>
</header>
<section class="panel status-panel" aria-label="Migration status">
<div class="status-top">
<strong>Thermal Units</strong>
<span class="tiny-chip">Fictional counter</span>
</div>
<div class="energy-number">
<span id="energyValue">086</span>
<span class="unit">TU</span>
</div>
<div class="energy-track">
<div id="energyFill"></div>
</div>
<div class="status-grid">
<div class="stat">
<span>Current state</span>
<b id="phaseText">Resting</b>
</div>
<div class="stat">
<span>Next stop</span>
<b id="nextText">Pine Bend</b>
</div>
</div>
<div class="controls">
<button class="mini-btn" id="pauseBtn" type="button">Pause</button>
<button class="mini-btn" id="restartBtn" type="button">Restart</button>
<button class="mini-btn" id="cameraBtn" type="button">Reset view</button>
</div>
</section>
<section class="panel rule-panel">
<div class="rule-heading">
<span class="rule-dot"></span>
Explicit rest rule
</div>
<p>
When the bird lands on a <strong>teal resource patch</strong> and stays for
<strong>2.0 seconds</strong>, its fictional Thermal Unit counter
<strong>resets to 100 TU</strong>. Flight drains <strong>3.2 TU/s</strong>;
perched time drains <strong>0.6 TU/s</strong>.
</p>
<div class="legend">
<div class="legend-item">
<span class="legend-swatch resource"></span>
Resource patch
</div>
<div class="legend-item">
<span class="legend-swatch rest"></span>
Perch / rest stop
</div>
</div>
</section>
<section class="panel route-panel">
<div class="route-title">Migration circuit</div>
<div id="routeSteps"></div>
</section>
<div id="toast">+100 TU · Rest rule activated</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, lighting, and camera
// -------------------------------------------------------------------------
const sceneContainer = document.getElementById("scene");
const labelContainer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x8fbec4);
scene.fog = new THREE.FogExp2(0x8fbec4, 0.026);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly migration stopover map"
);
sceneContainer.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff4d6, 0x315f6c, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd5a2, 3.1);
sun.position.set(-10, 18, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0008;
scene.add(sun);
const cameraTarget = new THREE.Vector3(0, 0.3, 1.4);
const cameraState = {
azimuth: 0.64,
elevation: 0.57,
radius: 23.5
};
function updateCamera() {
const { azimuth, elevation, radius } = cameraState;
const horizontal = Math.cos(elevation) * radius;
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * horizontal,
cameraTarget.y + Math.sin(elevation) * radius,
cameraTarget.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Low-poly ocean
// -------------------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(54, 54, 24, 24).toNonIndexed();
waterGeometry.rotateX(-Math.PI / 2);
const waterPosition = waterGeometry.attributes.position;
const waterColors = new Float32Array(waterPosition.count * 3);
const waterColor = new THREE.Color();
for (let i = 0; i < waterPosition.count; i += 3) {
const variation = Math.random() * 0.045;
waterColor.setHSL(0.505 + Math.random() * 0.015, 0.34, 0.52 + variation);
for (let j = 0; j < 3; j++) {
const index = (i + j) * 3;
waterColors[index] = waterColor.r;
waterColors[index + 1] = waterColor.g;
waterColors[index + 2] = waterColor.b;
}
}
waterGeometry.setAttribute("color", new THREE.BufferAttribute(waterColors, 3));
waterGeometry.computeVertexNormals();
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.9,
metalness: 0.04
})
);
water.position.y = -0.25;
water.receiveShadow = true;
scene.add(water);
// Small pale wave marks break up the faceted ocean.
const waveMaterial = new THREE.LineBasicMaterial({
color: 0xd5f4ed,
transparent: true,
opacity: 0.2
});
for (let i = 0; i < 52; i++) {
const x = (Math.random() - 0.5) * 44;
const z = (Math.random() - 0.5) * 44;
const length = 0.25 + Math.random() * 0.8;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, -0.225, z),
new THREE.Vector3(x + length, -0.225, z + 0.08)
]);
scene.add(new THREE.Line(geometry, waveMaterial));
}
// -------------------------------------------------------------------------
// Stopovers
// -------------------------------------------------------------------------
const stops = [
{
name: "Reed Bay",
type: "resource",
radius: 1.55,
position: new THREE.Vector3(-8.0, 0.69, 5.0)
},
{
name: "Foothill Spring",
type: "resource",
radius: 1.7,
position: new THREE.Vector3(-2.8, 0.69, -5.7)
},
{
name: "Pine Bend",
type: "rest",
radius: 1.45,
position: new THREE.Vector3(2.8, 0.69, 4.5)
},
{
name: "Salt Marsh",
type: "resource",
radius: 1.75,
position: new THREE.Vector3(7.3, 0.69, -2.7)
},
{
name: "Hilltop Rest",
type: "rest",
radius: 1.4,
position: new THREE.Vector3(8.4, 0.69, 5.5)
},
{
name: "Dawn Grove",
type: "resource",
radius: 1.65,
position: new THREE.Vector3(0.2, 0.69, 8.2)
}
];
const trunkGeometry = new THREE.CylinderGeometry(0.075, 0.11, 0.48, 5);
const canopyGeometry = new THREE.ConeGeometry(0.34, 0.9, 6);
const upperCanopyGeometry = new THREE.ConeGeometry(0.24, 0.65, 6);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x654a35,
flatShading: true
});
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function createTree(parent, x, z, random, index) {
const tree = new THREE.Group();
tree.position.set(x, 0.31, z);
tree.rotation.y = random() * Math.PI * 2;
const trunk = new THREE.Mesh(trunkGeometry, trunkMaterial);
trunk.position.y = 0.24;
trunk.castShadow = true;
tree.add(trunk);
const leafColors = [0x376f52, 0x3f7f58, 0x2e654e, 0x4b8658];
const leafMaterial = new THREE.MeshStandardMaterial({
color: leafColors[index % leafColors.length],
flatShading: true,
roughness: 1
});
const lower = new THREE.Mesh(canopyGeometry, leafMaterial);
lower.position.y = 0.77;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(upperCanopyGeometry, leafMaterial);
upper.position.y = 1.08;
upper.castShadow = true;
tree.add(upper);
parent.add(tree);
}
function createStop(stop, index) {
const random = seededRandom(400 + index * 97);
const group = new THREE.Group();
group.position.set(stop.position.x, 0, stop.position.z);
scene.add(group);
stop.group = group;
const shoreMaterial = new THREE.MeshStandardMaterial({
color: index % 2 ? 0xc5a36b : 0xc9aa76,
flatShading: true,
roughness: 1
});
const landMaterial = new THREE.MeshStandardMaterial({
color: index % 2 ? 0x6e995f : 0x779f63,
flatShading: true,
roughness: 1
});
const shore = new THREE.Mesh(
new THREE.CylinderGeometry(
stop.radius * 1.2,
stop.radius * 1.08,
0.2,
9
),
shoreMaterial
);
shore.position.y = -0.05;
shore.receiveShadow = true;
group.add(shore);
const land = new THREE.Mesh(
new THREE.CylinderGeometry(
stop.radius,
stop.radius * 0.89,
0.36,
9
),
landMaterial
);
land.position.y = 0.13;
land.receiveShadow = true;
land.castShadow = true;
group.add(land);
if (stop.type === "resource") {
const patch = new THREE.Mesh(
new THREE.CylinderGeometry(0.73, 0.77, 0.065, 12),
new THREE.MeshStandardMaterial({
color: 0x258b7c,
emissive: 0x0e4039,
emissiveIntensity: 0.4,
flatShading: true
})
);
patch.position.y = 0.335;
group.add(patch);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.73, 0.83, 24),
new THREE.MeshBasicMaterial({
color: 0x91f7d8,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.375;
group.add(ring);
stop.ring = ring;
const beacon = new THREE.Mesh(
new THREE.OctahedronGeometry(0.24),
new THREE.MeshStandardMaterial({
color: 0xa9ffe1,
emissive: 0x49d5b2,
emissiveIntensity: 1.1,
flatShading: true
})
);
beacon.position.y = 0.86;
beacon.castShadow = true;
group.add(beacon);
stop.beacon = beacon;
} else {
const perch = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.61, 0.065, 8),
new THREE.MeshStandardMaterial({
color: 0xb88b4c,
flatShading: true
})
);
perch.position.y = 0.335;
group.add(perch);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x9d8d76,
flatShading: true
});
[0.14, 0.27, 0.37].forEach((height, stoneIndex) => {
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.23 - stoneIndex * 0.035, 0),
stoneMaterial
);
stone.position.y = 0.43 + height;
stone.scale.y = 0.72;
stone.rotation.y = stoneIndex * 0.7;
stone.castShadow = true;
group.add(stone);
});
}
const treeCount = stop.type === "resource" ? 6 : 7;
for (let i = 0; i < treeCount; i++) {
const angle = random() * Math.PI * 2;
const distance = stop.radius * (0.55 + random() * 0.33);
const x = Math.cos(angle) * distance;
const z = Math.sin(angle) * distance;
createTree(group, x, z, random, i + index);
}
// Small faceted rocks around the shoreline.
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x807c6d,
flatShading: true
});
for (let i = 0; i < 4; i++) {
const angle = random() * Math.PI * 2;
const distance = stop.radius * (0.9 + random() * 0.12);
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.12 + random() * 0.1, 0),
rockMaterial
);
rock.position.set(
Math.cos(angle) * distance,
0.02,
Math.sin(angle) * distance
);
rock.scale.y = 0.65;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
group.add(rock);
}
// HTML labels projected from world space.
const label = document.createElement("div");
label.className = "map-label";
label.innerHTML = `
<span class="label-dot ${stop.type === "resource" ? "resource" : ""}"></span>
<span>${stop.name}</span>
`;
labelContainer.appendChild(label);
stop.label = label;
}
stops.forEach(createStop);
// -------------------------------------------------------------------------
// Distant low-poly landforms
// -------------------------------------------------------------------------
const mountainMaterials = [0x648b83, 0x73958a, 0x587d78].map(
(color) =>
new THREE.MeshStandardMaterial({
color,
flatShading: true,
roughness: 1
})
);
for (let i = 0; i < 11; i++) {
const angle = (i / 11) * Math.PI * 2 + 0.25;
const radius = 21 + (i % 3) * 1.8;
const height = 2.4 + (i % 4) * 0.75;
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(1.5 + (i % 3) * 0.45, height, 5),
mountainMaterials[i % mountainMaterials.length]
);
mountain.position.set(
Math.cos(angle) * radius,
height * 0.5 - 0.25,
Math.sin(angle) * radius
);
mountain.rotation.y = angle;
scene.add(mountain);
}
// -------------------------------------------------------------------------
// Flight route lines
// -------------------------------------------------------------------------
const journey = [0, 2, 1, 4, 3, 5];
const routeSegments = [];
function routePoint(a, b, t) {
const point = a.position.clone().lerp(b.position, t);
const direction = b.position.clone().sub(a.position);
const perpendicular = new THREE.Vector3(
-direction.z,
0,
direction.x
).normalize();
point.y = -0.08 + Math.sin(Math.PI * t) * 0.25;
point.addScaledVector(perpendicular, Math.sin(Math.PI * t) * 0.55);
return point;
}
for (let i = 0; i < journey.length; i++) {
const a = stops[journey[i]];
const b = stops[journey[(i + 1) % journey.length]];
const points = [];
for (let j = 0; j <= 48; j++) {
points.push(routePoint(a, b, j / 48));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: 0xe1fff5,
transparent: true,
opacity: 0.3,
dashSize: 0.25,
gapSize: 0.16
})
);
line.computeLineDistances();
scene.add(line);
const dotMaterial = new THREE.MeshBasicMaterial({
color: 0xb9f6e3,
transparent: true,
opacity: 0.45
});
for (let j = 3; j < 48; j += 6) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.04, 5, 4),
dotMaterial
);
dot.position.copy(points[j]);
scene.add(dot);
}
routeSegments.push(line);
}
// -------------------------------------------------------------------------
// Low-poly bird marker
// -------------------------------------------------------------------------
const bird = new THREE.Group();
scene.add(bird);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xf1e7cf,
flatShading: true,
roughness: 0.95
});
const wingMaterial = new THREE.MeshStandardMaterial({
color: 0x263f48,
flatShading: true,
side: THREE.DoubleSide
});
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.28, 7, 5),
bodyMaterial
);
body.scale.set(0.86, 0.72, 1.3);
body.castShadow = true;
bird.add(body);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.19, 0),
bodyMaterial
);
head.position.set(0, 0.08, 0.35);
head.castShadow = true;
bird.add(head);
const beak = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.25, 4),
new THREE.MeshStandardMaterial({
color: 0xf29b58,
flatShading: true
})
);
beak.rotation.x = Math.PI / 2;
beak.position.z = 0.61;
bird.add(beak);
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.17, 0.45, 3),
wingMaterial
);
tail.rotation.x = -Math.PI / 2;
tail.position.z = -0.43;
bird.add(tail);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.035, 4, 9),
new THREE.MeshStandardMaterial({
color: 0xff805f,
flatShading: true
})
);
collar.position.z = 0.24;
bird.add(collar);
const eyeMaterial = new THREE.MeshBasicMaterial({ color: 0x142a31 });
[-1, 1].forEach((side) => {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.028, 5, 4),
eyeMaterial
);
eye.position.set(side * 0.145, 0.12, 0.43);
bird.add(eye);
});
function createWing(side) {
const pivot = new THREE.Group();
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0, 0, 0.05,
side * 0.95, 0, 0.08,
side * 0.43, 0, -0.4
],
3
)
);
geometry.computeVertexNormals();
const wing = new THREE.Mesh(geometry, wingMaterial);
wing.castShadow = true;
pivot.add(wing);
bird.add(pivot);
return pivot;
}
const leftWing = createWing(-1);
const rightWing = createWing(1);
bird.scale.setScalar(0.85);
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.42, 8),
new THREE.MeshBasicMaterial({
color: 0x173239,
transparent: true,
opacity: 0.2,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
scene.add(shadow);
// -------------------------------------------------------------------------
// Migration state and game rules
// -------------------------------------------------------------------------
const FLIGHT_DRAIN = 3.2; // fictional TU per second
const PERCHED_DRAIN = 0.6; // fictional TU per second
const REST_RESET_SECONDS = 2.0;
let legIndex = 0;
let phase = "rest";
let phaseElapsed = 0;
let flightElapsed = 0;
let flightDuration = 4;
let energy = 86;
let paused = false;
let restoredThisStop = false;
let toastTimer = 0;
let simulationTime = 0;
function currentStop() {
return stops[journey[legIndex]];
}
function nextStop() {
return stops[journey[(legIndex + 1) % journey.length]];
}
function beginFlight() {
const a = currentStop();
const b = nextStop();
flightDuration = THREE.MathUtils.clamp(
a.position.distanceTo(b.position) * 0.4,
3.2,
6.4
);
flightElapsed = 0;
phase = "flying";
}
function arriveAtNextStop() {
legIndex = (legIndex + 1) % journey.length;
phase = "rest";
phaseElapsed = 0;
restoredThisStop = false;
}
function restartJourney() {
legIndex = 0;
phase = "rest";
phaseElapsed = 0;
flightElapsed = 0;
energy = 86;
paused = false;
restoredThisStop = false;
toastTimer = 0;
document.getElementById("pauseBtn").textContent = "Pause";
}
// -------------------------------------------------------------------------
// HUD
// -------------------------------------------------------------------------
const energyValue = document.getElementById("energyValue");
const energyFill = document.getElementById("energyFill");
const phaseText = document.getElementById("phaseText");
const nextText = document.getElementById("nextText");
const toast = document.getElementById("toast");
const pauseButton = document.getElementById("pauseBtn");
const routeSteps = document.getElementById("routeSteps");
const routeStepElements = journey.map((stopIndex, index) => {
const element = document.createElement("div");
element.className = `route-step ${stops[stopIndex].type}`;
element.textContent = stops[stopIndex].name.replace(" ", "\n");
element.title = stops[stopIndex].name;
routeSteps.appendChild(element);
return element;
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.getElementById("restartBtn").addEventListener("click", restartJourney);
document.getElementById("cameraBtn").addEventListener("click", () => {
cameraState.azimuth = 0.64;
cameraState.elevation = 0.57;
cameraState.radius = 23.5;
updateCamera();
});
function updateHUD() {
energyValue.textContent = String(Math.max(0, Math.round(energy))).padStart(
3,
"0"
);
energyFill.style.width = `${THREE.MathUtils.clamp(energy, 0, 100)}%`;
if (energy < 30) {
energyFill.style.background = "linear-gradient(90deg, #e56f5d, #ffb078)";
} else {
energyFill.style.background = "linear-gradient(90deg, #42c8a4, #9bffdc)";
}
if (paused) {
phaseText.textContent = "Paused";
} else if (phase === "flying") {
phaseText.textContent = `Flying to ${nextStop().name}`;
} else if (currentStop().type === "resource") {
if (restoredThisStop) {
phaseText.textContent = "Resource restored";
} else {
const remaining = Math.max(
0,
REST_RESET_SECONDS - phaseElapsed
).toFixed(1);
phaseText.textContent = `Resting · reset in ${remaining}s`;
}
} else {
phaseText.textContent = `Perched at ${currentStop().name}`;
}
nextText.textContent = nextStop().name;
routeStepElements.forEach((element, index) => {
element.classList.toggle("active", index === legIndex);
});
stops.forEach((stop, index) => {
stop.label.classList.toggle(
"active",
index === journey[legIndex]
);
});
}
// -------------------------------------------------------------------------
// Direct camera controls: pointer orbit, wheel zoom, double-click reset
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.0045,
0.28,
1.15
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
13,
34
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.azimuth = 0.64;
cameraState.elevation = 0.57;
cameraState.radius = 23.5;
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateBird(dt) {
const a = currentStop();
const b = nextStop();
if (phase === "flying") {
const t = THREE.MathUtils.clamp(flightElapsed / flightDuration, 0, 1);
const direction = b.position.clone().sub(a.position);
const distance = direction.length();
const perpendicular = new THREE.Vector3(
-direction.z,
0,
direction.x
).normalize();
const arcHeight = 2.1 + distance * 0.075;
const lateralArc = Math.sin(Math.PI * t) * 0.55;
bird.position.copy(a.position).lerp(b.position, t);
bird.position.addScaledVector(perpendicular, lateralArc);
bird.position.y += Math.sin(Math.PI * t) * arcHeight;
const tangent = direction
.clone()
.addScaledVector(
perpendicular,
Math.cos(Math.PI * t) * Math.PI * 0.55
);
tangent.y = Math.cos(Math.PI * t) * arcHeight * Math.PI;
const lookTarget = bird.position.clone().add(tangent);
bird.lookAt(lookTarget);
const flap = Math.sin(simulationTime * 15) * 0.65;
leftWing.rotation.z = -flap;
rightWing.rotation.z = flap;
} else {
bird.position.copy(a.position);
bird.position.y += Math.sin(simulationTime * 2.2) * 0.025;
const lookTarget = new THREE.Vector3(
b.position.x,
a.position.y,
b.position.z
);
bird.lookAt(lookTarget);
leftWing.rotation.z = -0.08;
rightWing.rotation.z = 0.08;
}
// Ground shadow follows the bird and softens as altitude increases.
let shadowY = -0.215;
for (const stop of stops) {
const dx = bird.position.x - stop.position.x;
const dz = bird.position.z - stop.position.z;
if (dx * dx + dz * dz < stop.radius * stop.radius * 1.2) {
shadowY = 0.35;
break;
}
}
const altitude = Math.max(0, bird.position.y - shadowY);
shadow.position.set(bird.position.x, shadowY + 0.012, bird.position.z);
shadow.scale.setScalar(1 + altitude * 0.12);
shadow.material.opacity = 0.2 / (1 + altitude * 0.18);
}
function updateSimulation(dt) {
if (paused) return;
simulationTime += dt;
if (phase === "flying") {
flightElapsed += dt;
energy = Math.max(0, energy - FLIGHT_DRAIN * dt);
if (flightElapsed >= flightDuration) {
arriveAtNextStop();
}
} else {
phaseElapsed += dt;
energy = Math.max(0, energy - PERCHED_DRAIN * dt);
if (
currentStop().type === "resource" &&
!restoredThisStop &&
phaseElapsed >= REST_RESET_SECONDS
) {
energy = 100;
restoredThisStop = true;
toastTimer = 2.2;
toast.classList.add("show");
}
const dwellTime =
currentStop().type === "resource" ? 2.8 : 1.3;
if (phaseElapsed >= dwellTime) {
beginFlight();
}
}
if (toastTimer > 0) {
toastTimer -= dt;
if (toastTimer <= 0) {
toast.classList.remove("show");
}
}
}
function updateStopAnimations() {
for (const stop of stops) {
if (stop.type === "resource") {
const pulse = 1 + Math.sin(simulationTime * 2.6) * 0.07;
stop.ring.scale.setScalar(pulse);
stop.ring.material.opacity = 0.57 + Math.sin(simulationTime * 2.6) * 0.14;
stop.beacon.rotation.y = simulationTime * 0.85;
stop.beacon.position.y =
0.86 + Math.sin(simulationTime * 2.2 + stop.position.x) * 0.075;
}
}
routeSegments.forEach((line, index) => {
line.material.color.setHex(index === legIndex ? 0x8ff2d5 : 0xe1fff5);
line.material.opacity = index === legIndex ? 0.62 : 0.24;
});
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const stop of stops) {
projected.set(stop.position.x, 1.75, stop.position.z).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
stop.label.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
stop.label.style.left = `${x}px`;
stop.label.style.top = `${y}px`;
}
}
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
updateSimulation(dt);
updateBird(dt);
updateStopAnimations();
updateHUD();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```