Prompt specification
Build or customize the Three.js 3D scene "Move the rainstorm across the ridge" 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: Move the rainstorm across the ridge
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/move-the-rainstorm-across-the-ridge-x1360
Scene Description Prompt:
Allow a rain cloud to slide across a drainage divide. Show the changing distribution of outlet flow with conserved illustrative particle counts and a clearly simplified runoff model. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (move-the-rainstorm-across-the-ridge-x1360):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ridgeline — Runoff Routing Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07131b;
--panel: rgba(10, 25, 34, 0.88);
--panel-border: rgba(180, 226, 236, 0.14);
--text: #eaf7fa;
--muted: #8ca8b2;
--west: #65bdf2;
--east: #70e0bb;
--rain: #b9efff;
--divide: #f3ca72;
--danger: #ffb88f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #17313d 0%, #0a1821 48%, #050d13 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app,
#stage {
position: absolute;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
.hero {
position: absolute;
z-index: 5;
top: 25px;
left: 28px;
width: min(460px, calc(100vw - 410px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #a9c6cf;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 2px;
content: "";
background: var(--divide);
box-shadow: 0 0 14px rgba(243, 202, 114, 0.55);
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 720;
letter-spacing: -0.055em;
line-height: 0.98;
}
.hero p {
max-width: 420px;
margin: 13px 0 0;
color: #a8bec6;
font-size: 13px;
line-height: 1.55;
}
.panel {
position: absolute;
z-index: 10;
top: 20px;
right: 20px;
width: 338px;
max-height: calc(100vh - 40px);
padding: 18px;
overflow: auto;
border: 1px solid var(--panel-border);
border-radius: 20px;
background:
linear-gradient(145deg, rgba(22, 47, 58, 0.65), rgba(7, 19, 27, 0.91)),
var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: #34525d transparent;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 17px;
}
.panel-head h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.panel-head p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.badge {
flex: 0 0 auto;
padding: 6px 8px;
border: 1px solid rgba(112, 224, 187, 0.24);
border-radius: 999px;
background: rgba(112, 224, 187, 0.08);
color: var(--east);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section {
padding: 15px 0;
border-top: 1px solid rgba(190, 225, 235, 0.09);
}
.section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #d5e8ed;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.position-readout {
color: var(--divide);
font-size: 10px;
letter-spacing: 0.02em;
text-transform: none;
}
.range-wrap {
position: relative;
padding: 5px 0 2px;
}
input[type="range"] {
width: 100%;
height: 22px;
margin: 0;
appearance: none;
border: 0;
outline: 0;
background: transparent;
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 6px;
border-radius: 999px;
background: linear-gradient(
90deg,
var(--west) 0%,
var(--west) 32%,
var(--divide) 50%,
var(--east) 68%,
var(--east) 100%
);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}
input[type="range"]::-moz-range-track {
height: 6px;
border-radius: 999px;
background: linear-gradient(
90deg,
var(--west) 0%,
var(--west) 32%,
var(--divide) 50%,
var(--east) 68%,
var(--east) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
margin-top: -6.5px;
appearance: none;
border: 3px solid #eafaff;
border-radius: 50%;
background: #16313c;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #eafaff;
border-radius: 50%;
background: #16313c;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #718b95;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 7px;
margin-top: 13px;
}
.button {
min-height: 35px;
padding: 7px 8px;
border: 1px solid rgba(183, 221, 230, 0.14);
border-radius: 10px;
background: rgba(157, 203, 215, 0.06);
color: #c7dde3;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.button:hover {
border-color: rgba(183, 221, 230, 0.28);
background: rgba(157, 203, 215, 0.12);
transform: translateY(-1px);
}
.button.active {
border-color: rgba(243, 202, 114, 0.38);
background: rgba(243, 202, 114, 0.12);
color: #ffe5a4;
}
.outlets {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.outlet-card {
padding: 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 12px;
background: rgba(2, 13, 19, 0.25);
}
.outlet-card.west {
border-color: rgba(101, 189, 242, 0.18);
}
.outlet-card.east {
border-color: rgba(112, 224, 187, 0.18);
}
.outlet-name {
display: flex;
align-items: center;
gap: 6px;
color: #9fb8c0;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.west .dot {
color: var(--west);
}
.east .dot {
color: var(--east);
}
.outlet-value {
display: flex;
align-items: baseline;
gap: 6px;
margin-top: 7px;
}
.outlet-value strong {
font-size: 25px;
font-weight: 720;
letter-spacing: -0.04em;
}
.outlet-value span {
color: #76919b;
font-size: 10px;
}
.bar {
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.bar i {
display: block;
width: 50%;
height: 100%;
border-radius: inherit;
transition: width 120ms linear;
}
.west .bar i {
background: var(--west);
box-shadow: 0 0 10px rgba(101, 189, 242, 0.45);
}
.east .bar i {
background: var(--east);
box-shadow: 0 0 10px rgba(112, 224, 187, 0.45);
}
.bias-text {
margin: 10px 0 0;
color: #8ca8b2;
font-size: 10px;
line-height: 1.45;
}
.ledger {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.ledger-item {
padding: 9px 8px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
text-align: center;
}
.ledger-item strong {
display: block;
font-size: 17px;
font-weight: 720;
}
.ledger-item span {
display: block;
margin-top: 2px;
color: #78939d;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.ledger-item.total {
border: 1px solid rgba(112, 224, 187, 0.16);
background: rgba(112, 224, 187, 0.06);
}
.conservation-note {
margin: 9px 0 0;
color: #829da6;
font-size: 9px;
line-height: 1.55;
}
.formula {
padding: 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 10px;
background: rgba(1, 10, 15, 0.3);
color: #aec7ce;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 9px;
line-height: 1.65;
}
.formula strong {
color: var(--divide);
font-weight: 700;
}
.limitations {
margin: 9px 0 0;
color: #718b95;
font-size: 9px;
line-height: 1.55;
}
.scene-label {
position: absolute;
z-index: 4;
top: 0;
left: 0;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 999px;
background: rgba(5, 16, 23, 0.72);
color: #d9ebef;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
}
.scene-label.west {
color: var(--west);
border-color: rgba(101, 189, 242, 0.25);
}
.scene-label.east {
color: var(--east);
border-color: rgba(112, 224, 187, 0.25);
}
.scene-label.divide {
color: var(--divide);
border-color: rgba(243, 202, 114, 0.25);
}
.hint {
position: absolute;
z-index: 4;
bottom: 21px;
left: 50%;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
background: rgba(4, 15, 22, 0.64);
color: #829ca6;
font-size: 9px;
letter-spacing: 0.03em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.hint b {
color: #bcd3da;
font-weight: 700;
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.hero p {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 14px;
border-radius: 17px;
}
.hint {
display: none;
}
.scene-label {
font-size: 7px;
}
}
</style>
</head>
<body>
<main id="app">
<div id="stage"></div>
<header class="hero">
<div class="eyebrow">Interactive watershed sketch</div>
<h1>Ridgeline</h1>
<p>
Slide the rain cloud across the divide. The two outlet streams rebalance
while the same fixed set of illustrative flow markers is reused.
</p>
</header>
<aside class="panel" aria-label="Runoff model controls">
<div class="panel-head">
<div>
<h2>Runoff routing lab</h2>
<p>A deliberately small, inspectable model.</p>
</div>
<div class="badge">Low-poly</div>
</div>
<section class="section">
<div class="section-title">
<span>Cloud position</span>
<span id="positionValue" class="position-readout">on the divide</span>
</div>
<div class="range-wrap">
<input
id="cloudRange"
type="range"
min="-9"
max="9"
step="0.1"
value="0"
aria-label="Cloud position relative to drainage divide"
>
<div class="range-labels">
<span>WEST</span>
<span>DIVIDE</span>
<span>EAST</span>
</div>
</div>
<div class="buttons">
<button id="sweepBtn" class="button" type="button">↔ Sweep</button>
<button id="pauseBtn" class="button" type="button">Pause</button>
<button id="resetBtn" class="button" type="button">Reset</button>
</div>
</section>
<section class="section">
<div class="section-title">
<span>Outlet flow split</span>
<span id="pEastValue" class="position-readout">p(E) = 0.50</span>
</div>
<div class="outlets">
<div class="outlet-card west">
<div class="outlet-name"><i class="dot"></i> West outlet</div>
<div class="outlet-value">
<strong id="westCount">48</strong>
<span id="westPct">50%</span>
</div>
<div class="bar"><i id="westBar"></i></div>
</div>
<div class="outlet-card east">
<div class="outlet-name"><i class="dot"></i> East outlet</div>
<div class="outlet-value">
<strong id="eastCount">48</strong>
<span id="eastPct">50%</span>
</div>
<div class="bar"><i id="eastBar"></i></div>
</div>
</div>
<p id="biasText" class="bias-text">
Near the divide: the modeled outlets are nearly balanced.
</p>
</section>
<section class="section">
<div class="section-title">
<span>Conservative marker ledger</span>
<span class="position-readout">N = 128 fixed</span>
</div>
<div class="ledger">
<div class="ledger-item">
<strong>32</strong>
<span>Airborne</span>
</div>
<div class="ledger-item">
<strong>96</strong>
<span>Runoff</span>
</div>
<div class="ledger-item total">
<strong>128</strong>
<span>Total</span>
</div>
</div>
<p class="conservation-note">
The same 96 runoff markers are repartitioned between the outlets:
west + east = 96. They depict instantaneous flux, not cumulative volume.
</p>
</section>
<section class="section">
<div class="section-title">
<span>Simplified model</span>
<span class="position-readout">linear bias</span>
</div>
<div class="formula">
x = cloud offset from divide<br>
<strong>p(E) = clamp(0.50 + 0.48x/9, 0.02, 0.98)</strong><br>
N(E) = round(96p(E))<br>
N(W) = 96 − N(E)
</div>
<p class="limitations">
No terrain routing, travel time, infiltration, storage, evaporation,
or momentum is modeled. Cloud position is the only control.
</p>
<div class="buttons">
<button id="cameraBtn" class="button" type="button" style="grid-column: 1 / -1">
Reset camera
</button>
</div>
</section>
</aside>
<div id="westLabel" class="scene-label west">West outlet</div>
<div id="eastLabel" class="scene-label east">East outlet</div>
<div id="divideLabel" class="scene-label divide">Drainage divide</div>
<div class="hint">
<b>Drag the cloud</b> to move it · <b>Drag the terrain</b> to orbit ·
<b>Scroll</b> to zoom
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const N_RAIN = 32;
const N_FLOW = 96;
const N_TOTAL = N_RAIN + N_FLOW;
const CLOUD_LIMIT = 9;
const stage = $("stage");
const cloudRange = $("cloudRange");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
stage.innerHTML =
'<div style="padding:2rem;color:#eaf7fa">WebGL is required to run this scene.</div>';
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x000000, 0);
stage.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly watershed. Drag the cloud to move rainfall across the divide."
);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x091720, 25, 52);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
yaw: 0.48,
pitch: 0.57,
radius: 26,
target: new THREE.Vector3(0, 2.0, 0)
};
function updateCamera() {
const cp = Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + orbit.radius * Math.sin(orbit.yaw) * cp,
orbit.target.y + orbit.radius * Math.sin(orbit.pitch),
orbit.target.z + orbit.radius * Math.cos(orbit.yaw) * cp
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xbfe8ff, 0x26372f, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d3, 3.1);
sun.position.set(-8, 16, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.001;
scene.add(sun);
const cloudLight = new THREE.PointLight(0x8edfff, 8, 11, 2);
cloudLight.position.set(0, 6.1, 0);
scene.add(cloudLight);
// A quiet floor beneath the floating terrain section.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 42),
new THREE.MeshStandardMaterial({
color: 0x091820,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.55;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x17323d, 0x102630);
grid.position.y = -1.52;
grid.material.transparent = true;
grid.material.opacity = 0.35;
scene.add(grid);
const base = new THREE.Mesh(
new THREE.BoxGeometry(23.4, 1.0, 12.4),
new THREE.MeshStandardMaterial({
color: 0x17292f,
roughness: 0.95
})
);
base.position.y = -1.0;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
// ---------------------------------------------------------------------
// Terrain: a deliberately simple ridge running along the Z axis.
// ---------------------------------------------------------------------
function heightAt(x, z) {
const ridge = 3.42 * Math.exp(-(x * x) / 18);
const undulation = 0.13 * Math.sin(z * 0.72) + 0.07 * Math.cos(x * 1.3 + z);
return 0.48 + ridge + undulation;
}
function createTerrain() {
const positions = [];
const colors = [];
const nx = 24;
const nz = 12;
const width = 22;
const depth = 12;
const west = new THREE.Color(0x3a6570);
const east = new THREE.Color(0x42766c);
const ridge = new THREE.Color(0x7b876e);
function addTriangle(a, b, c, color) {
positions.push(
a.x, a.y, a.z,
c.x, c.y, c.z,
b.x, b.y, b.z
);
for (let i = 0; i < 3; i++) colors.push(color.r, color.g, color.b);
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const x0 = -width / 2 + (ix / nx) * width;
const x1 = -width / 2 + ((ix + 1) / nx) * width;
const z0 = -depth / 2 + (iz / nz) * depth;
const z1 = -depth / 2 + ((iz + 1) / nz) * depth;
const a = new THREE.Vector3(x0, heightAt(x0, z0), z0);
const b = new THREE.Vector3(x1, heightAt(x1, z0), z0);
const c = new THREE.Vector3(x1, heightAt(x1, z1), z1);
const d = new THREE.Vector3(x0, heightAt(x0, z1), z1);
const centerX = (x0 + x1) * 0.5;
const baseColor = centerX < 0 ? west.clone() : east.clone();
baseColor.lerp(ridge, Math.exp(-(centerX * centerX) / 5) * 0.64);
baseColor.multiplyScalar(0.84 + Math.random() * 0.24);
if ((ix + iz) % 2 === 0) {
addTriangle(a, b, c, baseColor);
addTriangle(a, c, d, baseColor.clone().multiplyScalar(0.96));
} else {
addTriangle(a, b, d, baseColor);
addTriangle(b, c, d, baseColor.clone().multiplyScalar(0.96));
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.92,
metalness: 0
})
);
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
// Vertical earth-colored skirt around the terrain section.
const perimeter = [];
for (let i = 0; i <= 24; i++) {
const x = -11 + (i / 24) * 22;
perimeter.push(new THREE.Vector3(x, heightAt(x, 6), 6));
}
for (let i = 1; i <= 12; i++) {
const z = 6 - (i / 12) * 12;
perimeter.push(new THREE.Vector3(11, heightAt(11, z), z));
}
for (let i = 1; i <= 24; i++) {
const x = 11 - (i / 24) * 22;
perimeter.push(new THREE.Vector3(x, heightAt(x, -6), -6));
}
for (let i = 1; i <= 12; i++) {
const z = -6 + (i / 12) * 12;
perimeter.push(new THREE.Vector3(-11, heightAt(-11, z), z));
}
const skirtPositions = [];
const skirtColors = [];
const skirtA = new THREE.Color(0x263c3d);
const skirtB = new THREE.Color(0x1d3033);
for (let i = 0; i < perimeter.length - 1; i++) {
const a = perimeter[i];
const b = perimeter[i + 1];
const a2 = new THREE.Vector3(a.x, -0.5, a.z);
const b2 = new THREE.Vector3(b.x, -0.5, b.z);
const c = i % 2 ? skirtA : skirtB;
skirtPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
b2.x, b2.y, b2.z,
a.x, a.y, a.z,
b2.x, b2.y, b2.z,
a2.x, a2.y, a2.z
);
for (let j = 0; j < 6; j++) {
skirtColors.push(c.r, c.g, c.b);
}
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(skirtPositions, 3)
);
skirtGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(skirtColors, 3)
);
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1
})
);
skirt.castShadow = true;
skirt.receiveShadow = true;
scene.add(skirt);
}
createTerrain();
// Dashed divide line.
const dividePoints = [];
for (let i = 0; i <= 36; i++) {
const z = -5.8 + (i / 36) * 11.6;
dividePoints.push(new THREE.Vector3(0, heightAt(0, z) + 0.075, z));
}
const divideLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(dividePoints),
new THREE.LineDashedMaterial({
color: 0xf3ca72,
dashSize: 0.28,
gapSize: 0.16,
transparent: true,
opacity: 0.95
})
);
divideLine.computeLineDistances();
scene.add(divideLine);
// Small cairn stones emphasize the ridge without obscuring it.
const stoneGeometry = new THREE.DodecahedronGeometry(0.28, 0);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x9a957b,
flatShading: true,
roughness: 1
});
for (let i = 0; i < 8; i++) {
const z = -4.8 + i * 1.35;
const stone = new THREE.Mesh(stoneGeometry, stoneMaterial);
stone.scale.set(0.7 + Math.random() * 0.4, 0.8, 0.7);
stone.position.set(
(Math.random() - 0.5) * 0.18,
heightAt(0, z) + 0.16,
z
);
stone.rotation.set(Math.random(), Math.random(), Math.random());
stone.castShadow = true;
scene.add(stone);
}
// ---------------------------------------------------------------------
// Stylized channels and outlet mouths.
// ---------------------------------------------------------------------
function createChannel(side) {
const positions = [];
const steps = 34;
const halfWidth = 0.35;
function point(x, zOffset) {
return new THREE.Vector3(
x,
heightAt(x, zOffset) + 0.035,
zOffset
);
}
for (let i = 0; i < steps; i++) {
const t0 = i / steps;
const t1 = (i + 1) / steps;
const x0 = side * (0.64 + t0 * 9.53);
const x1 = side * (0.64 + t1 * 9.53);
const a = point(x0, -halfWidth);
const b = point(x0, halfWidth);
const c = point(x1, halfWidth);
const d = point(x1, -halfWidth);
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z,
a.x, a.y, a.z,
c.x, c.y, c.z,
d.x, d.y, d.z
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: side < 0 ? 0x164b61 : 0x175548,
roughness: 0.72,
metalness: 0.02,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
})
);
mesh.receiveShadow = true;
scene.add(mesh);
}
createChannel(-1);
createChannel(1);
function createOutlet(side) {
const group = new THREE.Group();
const color = side < 0 ? 0x65bdf2 : 0x70e0bb;
const y = heightAt(side * 10.35, 0);
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.72, 8, 1, true),
new THREE.MeshStandardMaterial({
color: 0x27434a,
roughness: 0.8,
side: THREE.DoubleSide
})
);
sleeve.rotation.z = Math.PI / 2;
sleeve.position.y = y;
sleeve.castShadow = true;
group.add(sleeve);
const mouth = new THREE.Mesh(
new THREE.CircleGeometry(0.49, 8),
new THREE.MeshBasicMaterial({
color: 0x071b25,
side: THREE.DoubleSide
})
);
mouth.rotation.y = side * Math.PI / 2;
mouth.position.set(side * 0.37, y, 0);
group.add(mouth);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.5, 0.075, 4, 8),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.32,
roughness: 0.5
})
);
rim.rotation.y = side * Math.PI / 2;
rim.position.set(side * 0.38, y, 0);
group.add(rim);
group.position.x = side * 10.35;
scene.add(group);
}
createOutlet(-1);
createOutlet(1);
// ---------------------------------------------------------------------
// Sparse low-poly trees.
// ---------------------------------------------------------------------
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x544638,
flatShading: true,
roughness: 1
});
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x315b52,
flatShading: true,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0x426d59,
flatShading: true,
roughness: 1
})
];
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.1, 0.48, 5),
trunkMaterial
);
trunk.position.y = 0.24;
tree.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.38, 0.95, 6),
leafMaterials[Math.floor(Math.random() * leafMaterials.length)]
);
crown.position.y = 0.85;
crown.castShadow = true;
tree.add(crown);
tree.position.set(x, heightAt(x, z), z);
tree.scale.setScalar(scale);
scene.add(tree);
}
[
[-7.7, 3.6, 0.8],
[-5.4, -3.8, 1.0],
[-3.2, 4.0, 0.72],
[-2.2, -4.5, 0.9],
[2.4, 4.2, 0.82],
[3.8, -4.1, 1.0],
[6.0, 3.7, 0.86],
[7.8, -3.4, 0.74]
].forEach((args) => addTree(...args));
// ---------------------------------------------------------------------
// Low-poly rain cloud.
// ---------------------------------------------------------------------
const cloudGroup = new THREE.Group();
const cloudMeshes = [];
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0x91a8b7,
flatShading: true,
roughness: 0.92
});
const cloudDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x627c8b,
flatShading: true,
roughness: 1
});
const cloudParts = [
[-1.05, 0.02, 0.02, 1.10, 0.70, 0.76],
[-0.25, 0.32, 0.02, 1.22, 0.90, 0.90],
[0.72, 0.26, -0.02, 1.12, 0.82, 0.84],
[1.45, -0.04, 0.04, 0.86, 0.62, 0.70],
[-0.05, -0.24, 0.22, 1.12, 0.52, 0.78]
];
for (const part of cloudParts) {
const [x, y, z, sx, sy, sz] = part;
const mesh = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
y < -0.1 ? cloudDarkMaterial : cloudMaterial
);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
cloudGroup.add(mesh);
cloudMeshes.push(mesh);
}
cloudGroup.position.set(0, 7.45, 0);
scene.add(cloudGroup);
const footprint = new THREE.Mesh(
new THREE.RingGeometry(0.72, 1.42, 32),
new THREE.MeshBasicMaterial({
color: 0x9be7ff,
transparent: true,
opacity: 0.09,
side: THREE.DoubleSide,
depthWrite: false
})
);
footprint.rotation.x = -Math.PI / 2;
footprint.position.set(0, 6.34, 0);
scene.add(footprint);
// ---------------------------------------------------------------------
// Fixed particle pools.
// ---------------------------------------------------------------------
const dummy = new THREE.Object3D();
const westColor = new THREE.Color(0x65bdf2);
const eastColor = new THREE.Color(0x70e0bb);
const rainMesh = new THREE.InstancedMesh(
new THREE.TetrahedronGeometry(0.11, 0),
new THREE.MeshStandardMaterial({
color: 0xb9efff,
emissive: 0x327f98,
emissiveIntensity: 0.42,
roughness: 0.38,
transparent: true,
opacity: 0.88
}),
N_RAIN
);
rainMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rainMesh.frustumCulled = false;
scene.add(rainMesh);
const flowMesh = new THREE.InstancedMesh(
new THREE.TetrahedronGeometry(0.14, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0x153d4a,
emissiveIntensity: 0.28,
roughness: 0.42
}),
N_FLOW
);
flowMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
flowMesh.frustumCulled = false;
scene.add(flowMesh);
const rainParticles = Array.from({ length: N_RAIN }, () => ({
phase: Math.random(),
speed: 0.68 + Math.random() * 0.48,
x: (Math.random() - 0.5) * 2.5,
z: (Math.random() - 0.5) * 2.0
}));
const flowParticles = Array.from({ length: N_FLOW }, () => ({
phase: Math.random(),
speed: 0.105 + Math.random() * 0.075,
z: (Math.random() - 0.5) * 0.48,
side: 1
}));
// Random ranks distribute each side evenly through the channel.
const ranks = Array.from({ length: N_FLOW }, (_, i) => i);
for (let i = ranks.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[ranks[i], ranks[j]] = [ranks[j], ranks[i]];
}
for (let i = 0; i < N_FLOW; i++) {
flowParticles[i].side = ranks[i] < N_FLOW / 2 ? -1 : 1;
flowMesh.setColorAt(
i,
flowParticles[i].side < 0 ? westColor : eastColor
);
}
flowMesh.instanceColor.needsUpdate = true;
// ---------------------------------------------------------------------
// Model and controls.
// ---------------------------------------------------------------------
let cloudX = 0;
let allocationFloat = N_FLOW / 2;
let leftCount = N_FLOW / 2;
let rightCount = N_FLOW / 2;
let paused = false;
let autoSweep = false;
let simulationTime = 0;
function eastProbability() {
return THREE.MathUtils.clamp(
0.5 + 0.48 * (cloudX / CLOUD_LIMIT),
0.02,
0.98
);
}
function setCloudPosition(value, stopSweep = true) {
cloudX = THREE.MathUtils.clamp(value, -CLOUD_LIMIT, CLOUD_LIMIT);
cloudGroup.position.x = cloudX;
footprint.position.x = cloudX;
cloudLight.position.x = cloudX;
cloudRange.value = cloudX.toFixed(1);
if (stopSweep) autoSweep = false;
updateInterface();
}
function resetSimulation() {
setCloudPosition(0, true);
allocationFloat = N_FLOW / 2;
leftCount = N_FLOW / 2;
rightCount = N_FLOW / 2;
paused = false;
simulationTime = 0;
rainParticles.forEach((p) => {
p.phase = Math.random();
p.x = (Math.random() - 0.5) * 2.5;
p.z = (Math.random() - 0.5) * 2.0;
});
flowParticles.forEach((p, i) => {
p.phase = Math.random();
p.side = ranks[i] < N_FLOW / 2 ? -1 : 1;
});
updateInterface();
}
cloudRange.addEventListener("input", () => {
setCloudPosition(Number(cloudRange.value));
});
$("sweepBtn").addEventListener("click", () => {
autoSweep = !autoSweep;
if (autoSweep) paused = false;
updateInterface();
});
$("pauseBtn").addEventListener("click", () => {
paused = !paused;
updateInterface();
});
$("resetBtn").addEventListener("click", resetSimulation);
$("cameraBtn").addEventListener("click", () => {
orbit.yaw = 0.48;
orbit.pitch = 0.57;
orbit.radius = 26;
orbit.target.set(0, 2, 0);
updateCamera();
});
function updateInterface() {
const pEast = eastProbability();
const westPercent = Math.round((leftCount / N_FLOW) * 100);
const eastPercent = 100 - westPercent;
$("westCount").textContent = leftCount;
$("eastCount").textContent = rightCount;
$("westPct").textContent = `${westPercent}%`;
$("eastPct").textContent = `${eastPercent}%`;
$("westBar").style.width = `${westPercent}%`;
$("eastBar").style.width = `${eastPercent}%`;
$("pEastValue").textContent = `p(E) = ${pEast.toFixed(2)}`;
if (Math.abs(cloudX) < 0.08) {
$("positionValue").textContent = "on the divide";
} else {
const amount = Math.abs(cloudX).toFixed(1);
const direction = cloudX < 0 ? "west" : "east";
$("positionValue").textContent = `${amount} m ${direction} of divide`;
}
if (Math.abs(cloudX) < 0.8) {
$("biasText").textContent =
"Near the divide: the modeled outlets are nearly balanced.";
} else if (cloudX < 0) {
$("biasText").textContent =
"West-biased rainfall: more modeled flow is assigned to the west outlet.";
} else {
$("biasText").textContent =
"East-biased rainfall: more modeled flow is assigned to the east outlet.";
}
$("sweepBtn").classList.toggle("active", autoSweep);
$("pauseBtn").classList.toggle("active", paused);
$("pauseBtn").textContent = paused ? "Resume" : "Pause";
$("sweepBtn").textContent = autoSweep ? "Sweeping" : "↔ Sweep";
}
// ---------------------------------------------------------------------
// Direct camera controls and cloud dragging. No examples/addons used.
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -7.1);
const dragPoint = new THREE.Vector3();
let pointerState = null;
function setPointer(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;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const cloudHit = raycaster.intersectObjects(cloudMeshes, false).length > 0;
pointerState = {
mode: cloudHit ? "cloud" : "orbit",
lastX: event.clientX,
lastY: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState) return;
if (pointerState.mode === "cloud") {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
setCloudPosition(dragPoint.x);
}
} else {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
orbit.yaw -= dx * 0.005;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.004,
0.24,
1.05
);
}
});
function endPointer(event) {
pointerState = null;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
16,
39
);
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Animation.
// ---------------------------------------------------------------------
function updateRain(dt) {
const cloudBottom = 6.42;
for (let i = 0; i < N_RAIN; i++) {
const p = rainParticles[i];
p.phase += dt * p.speed;
if (p.phase >= 1) {
p.phase -= 1;
p.x = cloudX + (Math.random() - 0.5) * 2.5;
p.z = (Math.random() - 0.5) * 2.0;
}
const ground = heightAt(p.x, p.z) + 0.06;
const y = THREE.MathUtils.lerp(cloudBottom, ground, p.phase);
dummy.position.set(p.x, y, p.z);
dummy.rotation.set(
simulationTime * 1.4 + i,
simulationTime * 0.8,
0
);
dummy.scale.set(0.65, 1.45, 0.65);
dummy.updateMatrix();
rainMesh.setMatrixAt(i, dummy.matrix);
}
rainMesh.instanceMatrix.needsUpdate = true;
}
function updateFlow(dt) {
for (let i = 0; i < N_FLOW; i++) {
const p = flowParticles[i];
const desiredSide = ranks[i] < leftCount ? -1 : 1;
if (desiredSide !== p.side) {
p.side = desiredSide;
p.phase = 0.015;
}
p.phase += dt * p.speed;
if (p.phase >= 1) p.phase -= 0.985;
const x = p.side * (0.66 + p.phase * 9.48);
const y = heightAt(x, p.z) + 0.17;
dummy.position.set(x, y, p.z);
dummy.rotation.set(
simulationTime * 1.8 + i * 0.13,
simulationTime * 1.1,
p.side * 0.35
);
dummy.scale.set(0.72, 1.2, 0.72);
dummy.updateMatrix();
flowMesh.setMatrixAt(i, dummy.matrix);
flowMesh.setColorAt(i, p.side < 0 ? westColor : eastColor);
}
flowMesh.instanceMatrix.needsUpdate = true;
flowMesh.instanceColor.needsUpdate = true;
}
const projected = new THREE.Vector3();
function positionLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${screenX}px`;
element.style.top = `${screenY}px`;
}
function updateLabels() {
positionLabel($("westLabel"), -10.45, 1.55, 0);
positionLabel($("eastLabel"), 10.45, 1.55, 0);
positionLabel($("divideLabel"), 0, 4.55, 3.7);
}
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
simulationTime += dt;
if (autoSweep) {
cloudX = Math.sin(simulationTime * 0.48) * 8.35;
cloudGroup.position.x = cloudX;
footprint.position.x = cloudX;
cloudLight.position.x = cloudX;
cloudRange.value = cloudX.toFixed(1);
}
const pEast = eastProbability();
const targetWest = N_FLOW * (1 - pEast);
allocationFloat +=
(targetWest - allocationFloat) * Math.min(1, dt * 2.5);
leftCount = THREE.MathUtils.clamp(
Math.round(allocationFloat),
0,
N_FLOW
);
rightCount = N_FLOW - leftCount;
updateRain(dt);
updateFlow(dt);
}
updateCamera();
updateLabels();
updateInterface();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
setCloudPosition(0);
updateInterface();
requestAnimationFrame(animate);
</script>
</body>
</html>
```