Prompt specification
Build or customize the Three.js 3D scene "Rain impact and cover comparison" 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: Rain impact and cover comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rain-impact-and-cover-comparison-x1086
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows mulch cover. Animate identical raindrops hitting both tiles; symbolic splash decreases beneath the cover while water follows visible gaps, with all behavior labeled as qualitative. Low-poly.
Working Three.js Starter (rain-impact-and-cover-comparison-x1086):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mulch Cover — Qualitative Rain Comparison</title>
<style>
:root {
color-scheme: dark;
--bg: #101923;
--panel: rgba(16, 25, 35, 0.86);
--border: rgba(188, 222, 231, 0.18);
--text: #eef6f5;
--muted: #a9bec3;
--cyan: #69dce9;
--tan: #c78a55;
--orange: #ef9c64;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
}
.intro {
top: 20px;
left: 20px;
width: min(430px, calc(100vw - 40px));
padding: 18px 20px 17px;
pointer-events: none;
}
.kicker {
display: block;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.intro p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
bottom: 20px;
left: 20px;
width: min(335px, calc(100vw - 40px));
padding: 14px 16px;
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
color: #d8e8e8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 7px;
color: var(--muted);
font-size: 12px;
line-height: 1.35;
}
.legend-row b {
color: #e6f1f0;
font-weight: 650;
}
.swatch {
position: relative;
display: inline-block;
flex: 0 0 22px;
width: 22px;
height: 22px;
}
.swatch-drop::before {
content: "";
position: absolute;
left: 8px;
top: 2px;
width: 7px;
height: 15px;
border-radius: 70% 35% 65% 45%;
background: var(--cyan);
transform: rotate(45deg);
box-shadow: 0 0 12px rgba(105, 220, 233, 0.45);
}
.swatch-splash::before {
content: "✦";
position: absolute;
inset: 0;
color: var(--cyan);
font-size: 22px;
line-height: 22px;
text-align: center;
}
.swatch-small::before {
content: "·";
position: absolute;
inset: 0;
color: var(--cyan);
font-size: 25px;
line-height: 19px;
text-align: center;
}
.swatch-mulch::before {
content: "";
position: absolute;
left: 2px;
top: 5px;
width: 18px;
height: 11px;
border-radius: 45% 55% 35% 60%;
background: var(--tan);
transform: rotate(-12deg);
box-shadow:
6px 4px 0 -2px #9c673f,
-2px 7px 0 -3px #d29a64;
}
.controls {
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 10px;
}
button {
border: 1px solid rgba(188, 222, 231, 0.24);
border-radius: 9px;
padding: 9px 12px;
color: var(--text);
background: rgba(36, 53, 65, 0.92);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
button:hover {
border-color: rgba(105, 220, 233, 0.55);
background: rgba(46, 73, 82, 0.96);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.status {
display: flex;
align-items: center;
gap: 7px;
padding: 0 5px 0 3px;
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px rgba(105, 220, 233, 0.65);
}
.status-dot.paused {
background: var(--orange);
box-shadow: none;
}
.disclaimer {
position: fixed;
z-index: 4;
top: 20px;
right: 20px;
max-width: 300px;
padding: 9px 12px;
border: 1px solid rgba(239, 156, 100, 0.28);
border-radius: 10px;
color: #e6c1a8;
background: rgba(48, 30, 24, 0.76);
font-size: 11px;
line-height: 1.4;
text-align: right;
pointer-events: none;
}
.scene-tag {
position: fixed;
z-index: 4;
min-width: 170px;
padding: 9px 11px;
border: 1px solid rgba(188, 222, 231, 0.18);
border-radius: 10px;
background: rgba(12, 21, 29, 0.88);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
pointer-events: none;
transform: translate(-50%, -100%);
}
.scene-tag span {
display: block;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-tag strong {
display: block;
margin-top: 3px;
color: #f1f7f5;
font-size: 13px;
font-weight: 650;
}
#bareTag {
border-color: rgba(239, 156, 100, 0.34);
}
#mulchTag {
border-color: rgba(201, 138, 85, 0.46);
}
@media (max-width: 760px) {
.intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 15px;
}
.intro p {
max-width: 88%;
font-size: 11px;
}
.legend {
bottom: 66px;
left: 10px;
width: calc(100vw - 20px);
padding: 10px 12px;
}
.legend-row:nth-of-type(3),
.legend-row:nth-of-type(4) {
display: none;
}
.controls {
right: 10px;
bottom: 10px;
left: 10px;
justify-content: flex-end;
}
button {
padding: 8px 10px;
font-size: 11px;
}
.status {
margin-right: auto;
}
.disclaimer {
top: 130px;
right: 10px;
max-width: 210px;
font-size: 9px;
}
.scene-tag {
min-width: 140px;
padding: 7px 9px;
}
.scene-tag strong {
font-size: 11px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="panel intro">
<span class="kicker">Qualitative comparison · not to scale</span>
<h1>Same rain.<br />Different splash.</h1>
<p>
Identical raindrops are launched toward both tiles. The bare surface
produces a wider symbolic splash, while mulch reduces the splash and
guides schematic water movement through exposed gaps.
</p>
</section>
<div class="disclaimer">
Drop size, speed, spacing, paths, and splash scale are illustrative only.
</div>
<div id="bareTag" class="scene-tag">
<span>Bare soil</span>
<strong>Wider symbolic splash</strong>
</div>
<div id="mulchTag" class="scene-tag">
<span>Mulch cover</span>
<strong>Smaller splash · gap-guided flow</strong>
</div>
<section class="panel legend">
<div class="legend-title">How to read the model</div>
<div class="legend-row">
<span class="swatch swatch-drop"></span>
<span><b>Paired drops</b> — identical shape, size, and launch</span>
</div>
<div class="legend-row">
<span class="swatch swatch-splash"></span>
<span><b>Wide splash</b> — larger symbolic bare-soil response</span>
</div>
<div class="legend-row">
<span class="swatch swatch-small"></span>
<span><b>Small splash</b> — reduced response beneath mulch</span>
</div>
<div class="legend-row">
<span class="swatch swatch-mulch"></span>
<span><b>Tan pieces</b> — mulch; visible channels guide schematic flow</span>
</div>
</section>
<section class="panel controls" aria-label="Animation controls">
<div class="status">
<span id="statusDot" class="status-dot"></span>
<span id="statusText">Running</span>
</div>
<button id="toggleButton" type="button">Pause</button>
<button id="restartButton" type="button">Restart</button>
<button id="viewButton" type="button">Reset view</button>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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.domElement.setAttribute(
"aria-label",
"Qualitative low-poly comparison of rain on bare soil and mulch-covered soil"
);
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101923);
scene.fog = new THREE.Fog(0x101923, 15, 32);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
let cameraTheta = 0.52;
let cameraPhi = 1.02;
let cameraRadius = 12.4;
let fitRadius = 12.4;
const hemisphere = new THREE.HemisphereLight(0xc9edff, 0x342319, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffeed4, 3.1);
keyLight.position.set(5.5, 9, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x69d6ea, 1.15);
fillLight.position.set(-5, 4, -5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0x14212a,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
let randomSeed = 82417;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const TILE_SIZE = 3.2;
const TILE_OFFSET = 2.25;
const soilBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x684535,
roughness: 1,
flatShading: true
});
const soilTopMaterial = new THREE.MeshStandardMaterial({
color: 0x8b5d42,
roughness: 1,
flatShading: true
});
const lowerSoilMaterial = new THREE.MeshStandardMaterial({
color: 0x50382d,
roughness: 1,
flatShading: true
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xc78e64,
transparent: true,
opacity: 0.26
});
const woodMaterials = [
0x9d6b43,
0xb27d4d,
0x805438,
0xc18b57,
0x8e5e3d
].map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.95,
flatShading: true
})
);
const chipGeometry = new THREE.DodecahedronGeometry(0.5, 0);
const clodGeometry = new THREE.DodecahedronGeometry(0.5, 0);
function createSoilTile(centerX, covered) {
const group = new THREE.Group();
group.position.x = centerX;
const base = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE, 0.72, TILE_SIZE),
soilBaseMaterial
);
base.position.y = 0.36;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const lowerBand = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE + 0.025, 0.07, TILE_SIZE + 0.025),
lowerSoilMaterial
);
lowerBand.position.y = 0.27;
lowerBand.castShadow = true;
group.add(lowerBand);
const top = new THREE.Mesh(
new THREE.BoxGeometry(TILE_SIZE + 0.04, 0.16, TILE_SIZE + 0.04),
soilTopMaterial
);
top.position.y = 0.80;
top.castShadow = true;
top.receiveShadow = true;
group.add(top);
const topEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(top.geometry),
edgeMaterial
);
topEdges.position.copy(top.position);
group.add(topEdges);
if (covered) {
const positions = [];
for (const z of [-1.16, -0.40, 0.36, 1.12]) {
for (const x of [-1.16, -0.38, 0.38, 1.16]) {
positions.push([x, z]);
}
}
for (const [x, z] of positions) {
const chip = new THREE.Mesh(
chipGeometry,
woodMaterials[Math.floor(random() * woodMaterials.length)]
);
chip.position.set(
x + (random() - 0.5) * 0.035,
1.14 + (random() - 0.5) * 0.018,
z + (random() - 0.5) * 0.035
);
chip.scale.set(
0.62 + random() * 0.09,
0.24 + random() * 0.035,
0.48 + random() * 0.10
);
chip.rotation.set(
(random() - 0.5) * 0.45,
random() * Math.PI,
(random() - 0.5) * 0.35
);
chip.castShadow = true;
chip.receiveShadow = true;
group.add(chip);
}
} else {
const reservedTargets = [
[-0.38, 0.36],
[0.77, -0.40],
[-0.77, 1.12],
[0.38, -1.16]
];
for (let i = 0; i < 15; i++) {
const x = (random() - 0.5) * 2.75;
const z = (random() - 0.5) * 2.75;
const tooClose = reservedTargets.some(
([tx, tz]) =>
Math.hypot(x - tx, z - tz) < 0.25
);
if (tooClose) continue;
const clod = new THREE.Mesh(
clodGeometry,
new THREE.MeshStandardMaterial({
color: random() > 0.5 ? 0x9b694a : 0x76503c,
roughness: 1,
flatShading: true
})
);
const size = 0.11 + random() * 0.09;
clod.position.set(x, 0.90 + size * 0.25, z);
clod.scale.set(size, size * 0.48, size * (0.7 + random() * 0.5));
clod.rotation.set(random(), random() * Math.PI, random());
clod.castShadow = true;
group.add(clod);
}
}
scene.add(group);
return group;
}
const bareTile = createSoilTile(-TILE_OFFSET, false);
const mulchTile = createSoilTile(TILE_OFFSET, true);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x69dce9,
emissive: 0x075362,
emissiveIntensity: 0.8,
roughness: 0.28,
metalness: 0.02,
transparent: true,
opacity: 0.9,
flatShading: true,
depthWrite: false
});
const dropGeometry = new THREE.OctahedronGeometry(0.1, 0);
const splashGeometry = new THREE.IcosahedronGeometry(1, 0);
const flowGeometry = new THREE.IcosahedronGeometry(0.06, 1);
const ringGeometry = new THREE.TorusGeometry(1, 0.025, 4, 18);
const rainDrops = [];
const splashParticles = [];
const splashRings = [];
const flowTracers = [];
const patterns = [
{ x: -0.38, z: 0.36 }, // lands on a mulch chip
{ x: 0.77, z: -0.40 }, // lands in a visible gap
{ x: -0.77, z: 1.12 }, // lands in a visible gap
{ x: 0.38, z: -1.16 } // lands on a mulch chip
];
const gapCenters = [-0.77, 0, 0.77];
function nearestGap(x) {
return gapCenters.reduce((nearest, gap) =>
Math.abs(gap - x) < Math.abs(nearest - x) ? gap : nearest
);
}
function worldPoint(centerX, local, y) {
return new THREE.Vector3(centerX + local.x, y, local.z);
}
function spawnDrop(centerX, local, targetY, type, onGap) {
const mesh = new THREE.Mesh(dropGeometry, waterMaterial);
mesh.scale.set(0.78, 1.95, 0.78);
mesh.position.set(centerX + local.x, 6.15, local.z);
mesh.castShadow = true;
scene.add(mesh);
rainDrops.push({
mesh,
centerX,
local,
targetY,
type,
onGap,
age: 0,
startY: 6.15,
fallSpeed: 4.25
});
}
function spawnPair() {
const local = patterns[patternIndex % patterns.length];
patternIndex++;
const gap = nearestGap(local.x);
const onGap = Math.abs(local.x - gap) < 0.14;
spawnDrop(-TILE_OFFSET, local, 0.90, "bare", false);
spawnDrop(
TILE_OFFSET,
local,
onGap ? 0.90 : 1.27,
"mulch",
onGap
);
}
function spawnBurst(origin, count, options) {
for (let i = 0; i < count; i++) {
const mesh = new THREE.Mesh(splashGeometry, waterMaterial);
const size =
options.minSize +
random() * (options.maxSize - options.minSize);
mesh.scale.setScalar(size);
mesh.position.copy(origin);
mesh.position.x += (random() - 0.5) * 0.09;
mesh.position.z += (random() - 0.5) * 0.09;
mesh.rotation.set(random() * 3, random() * 3, random() * 3);
scene.add(mesh);
const angle = random() * Math.PI * 2;
const horizontalSpeed =
options.minSpeed +
random() * (options.maxSpeed - options.minSpeed);
const velocity = new THREE.Vector3(
Math.cos(angle) * horizontalSpeed,
options.minUp +
random() * (options.maxUp - options.minUp),
Math.sin(angle) * horizontalSpeed
);
splashParticles.push({
mesh,
velocity,
age: 0,
life: options.life * (0.85 + random() * 0.3),
gravity: options.gravity,
baseSize: size
});
}
}
function spawnRing(origin, maxRadius, life = 0.46) {
const material = new THREE.MeshBasicMaterial({
color: 0x74e7f0,
transparent: true,
opacity: 0.75,
depthWrite: false
});
const mesh = new THREE.Mesh(ringGeometry, material);
mesh.rotation.x = Math.PI / 2;
mesh.position.copy(origin);
mesh.position.y += 0.018;
mesh.scale.setScalar(0.04);
scene.add(mesh);
splashRings.push({
mesh,
material,
age: 0,
life,
maxRadius
});
}
function spawnBareSplash(origin) {
spawnBurst(origin, 13, {
minSize: 0.045,
maxSize: 0.075,
minSpeed: 1.05,
maxSpeed: 2.15,
minUp: 1.0,
maxUp: 2.05,
gravity: 5.8,
life: 0.56
});
spawnRing(origin, 0.66, 0.52);
}
function spawnCoveredSurfaceSplash(origin, inGap) {
spawnBurst(origin, inGap ? 3 : 4, {
minSize: 0.016,
maxSize: 0.032,
minSpeed: 0.18,
maxSpeed: 0.52,
minUp: 0.18,
maxUp: 0.52,
gravity: 4.8,
life: 0.28
});
spawnRing(origin, inGap ? 0.12 : 0.15, 0.30);
}
function spawnUnderCoverSplash(origin) {
spawnBurst(origin, 3, {
minSize: 0.013,
maxSize: 0.024,
minSpeed: 0.12,
maxSpeed: 0.28,
minUp: 0.12,
maxUp: 0.27,
gravity: 4.5,
life: 0.25
});
spawnRing(origin, 0.105, 0.27);
}
function pathLength(points) {
let length = 0;
for (let i = 1; i < points.length; i++) {
length += points[i].distanceTo(points[i - 1]);
}
return length;
}
function pointOnPath(points, distance) {
if (points.length === 1) return points[0].clone();
for (let i = 1; i < points.length; i++) {
const segmentLength = points[i].distanceTo(points[i - 1]);
if (distance <= segmentLength) {
const t = segmentLength === 0
? 0
: distance / segmentLength;
return points[i - 1].clone().lerp(points[i], t);
}
distance -= segmentLength;
}
return points[points.length - 1].clone();
}
function spawnFlow(points, duration) {
const group = new THREE.Group();
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x69dce9,
transparent: true,
opacity: 0.24,
depthWrite: false
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
lineMaterial
);
group.add(line);
const head = new THREE.Mesh(flowGeometry, waterMaterial);
head.scale.setScalar(1);
group.add(head);
const trails = [];
for (let i = 0; i < 3; i++) {
const trail = new THREE.Mesh(flowGeometry, waterMaterial);
trail.scale.setScalar(0.65 - i * 0.13);
group.add(trail);
trails.push(trail);
}
scene.add(group);
flowTracers.push({
group,
lineMaterial,
head,
trails,
points,
length: pathLength(points),
age: 0,
duration
});
}
function spawnMulchResponse(local, onGap) {
const gap = nearestGap(local.x);
if (onGap) {
const origin = worldPoint(TILE_OFFSET, local, 0.91);
spawnCoveredSurfaceSplash(origin, true);
spawnFlow(
[
worldPoint(TILE_OFFSET, local, 0.99),
worldPoint(TILE_OFFSET, local, 0.95)
],
0.55
);
} else {
const origin = worldPoint(TILE_OFFSET, local, 1.27);
spawnCoveredSurfaceSplash(origin, false);
spawnFlow(
[
worldPoint(TILE_OFFSET, local, 1.27),
worldPoint(TILE_OFFSET, { x: gap, z: local.z }, 1.25),
worldPoint(TILE_OFFSET, { x: gap, z: local.z }, 0.95)
],
1.18
);
}
}
function removeFlow(flow) {
scene.remove(flow.group);
flow.lineMaterial.dispose();
}
function updateRainDrops(dt) {
for (let i = rainDrops.length - 1; i >= 0; i--) {
const drop = rainDrops[i];
drop.age += dt;
const y =
drop.startY -
drop.fallSpeed * drop.age;
drop.mesh.position.y = y;
drop.mesh.rotation.y += dt * 2.4;
if (y <= drop.targetY) {
const impact = new THREE.Vector3(
drop.centerX + drop.local.x,
drop.targetY,
drop.local.z
);
if (drop.type === "bare") {
spawnBareSplash(impact);
} else {
spawnMulchResponse(drop.local, drop.onGap);
}
scene.remove(drop.mesh);
rainDrops.splice(i, 1);
}
}
}
function updateSplashParticles(dt) {
for (let i = splashParticles.length - 1; i >= 0; i--) {
const particle = splashParticles[i];
particle.age += dt;
particle.velocity.y -= particle.gravity * dt;
particle.mesh.position.addScaledVector(
particle.velocity,
dt
);
particle.mesh.rotation.x += dt * 4;
particle.mesh.rotation.y += dt * 5;
const lifeRatio = Math.min(
particle.age / particle.life,
1
);
particle.mesh.scale.setScalar(
particle.baseSize * (1 - lifeRatio * 0.72)
);
if (particle.age >= particle.life) {
scene.remove(particle.mesh);
splashParticles.splice(i, 1);
}
}
}
function updateSplashRings(dt) {
for (let i = splashRings.length - 1; i >= 0; i--) {
const ring = splashRings[i];
ring.age += dt;
const t = Math.min(ring.age / ring.life, 1);
const eased = 1 - Math.pow(1 - t, 3);
const radius = THREE.MathUtils.lerp(
0.04,
ring.maxRadius,
eased
);
ring.mesh.scale.setScalar(radius);
ring.material.opacity = 0.72 * (1 - t);
if (t >= 1) {
scene.remove(ring.mesh);
ring.material.dispose();
splashRings.splice(i, 1);
}
}
}
function updateFlows(dt) {
for (let i = flowTracers.length - 1; i >= 0; i--) {
const flow = flowTracers[i];
flow.age += dt;
const progress = Math.min(
flow.age / flow.duration,
1
);
flow.head.position.copy(
pointOnPath(
flow.points,
progress * flow.length
)
);
flow.trails.forEach((trail, trailIndex) => {
const trailProgress = Math.max(
0,
progress - (trailIndex + 1) * 0.075
);
trail.position.copy(
pointOnPath(
flow.points,
trailProgress * flow.length
)
);
});
if (progress >= 1) {
spawnUnderCoverSplash(
flow.points[flow.points.length - 1]
);
removeFlow(flow);
flowTracers.splice(i, 1);
}
}
}
let running = true;
let simulationTime = 0;
let nextDropTime = 0.48;
let patternIndex = 0;
const toggleButton = document.getElementById("toggleButton");
const restartButton = document.getElementById("restartButton");
const viewButton = document.getElementById("viewButton");
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
function setRunning(value) {
running = value;
toggleButton.textContent = running ? "Pause" : "Resume";
statusText.textContent = running ? "Running" : "Paused";
statusDot.classList.toggle("paused", !running);
}
function clearDynamicObjects() {
for (const drop of rainDrops) {
scene.remove(drop.mesh);
}
rainDrops.length = 0;
for (const particle of splashParticles) {
scene.remove(particle.mesh);
}
splashParticles.length = 0;
for (const ring of splashRings) {
scene.remove(ring.mesh);
ring.material.dispose();
}
splashRings.length = 0;
for (const flow of flowTracers) {
removeFlow(flow);
}
flowTracers.length = 0;
}
function restartAnimation() {
clearDynamicObjects();
simulationTime = 0;
nextDropTime = 0.48;
patternIndex = 0;
setRunning(true);
}
toggleButton.addEventListener("click", () => {
setRunning(!running);
});
restartButton.addEventListener("click", restartAnimation);
function resetView() {
cameraTheta = 0.52;
cameraPhi = 1.02;
cameraRadius = fitRadius;
}
viewButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLButtonElement ||
event.target instanceof HTMLInputElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
setRunning(!running);
}
if (event.key.toLowerCase() === "r") {
restartAnimation();
}
});
// Direct camera controls: no external controls module is used.
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.005,
0.48,
1.40
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
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(
"contextmenu",
(event) => event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * factor,
fitRadius * 0.62,
fitRadius * 1.8
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.style.cursor = "grab";
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
const cosPhi = Math.cos(cameraPhi);
camera.position.set(
cameraTarget.x +
cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * cosPhi,
cameraTarget.z +
cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const oldFit = fitRadius;
const zoomRatio = cameraRadius / oldFit;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = aspect;
camera.updateProjectionMatrix();
const halfVerticalAngle = THREE.MathUtils.degToRad(
camera.fov * 0.5
);
fitRadius = Math.max(
12.4,
9.2 / (2 * Math.tan(halfVerticalAngle) * aspect)
);
cameraRadius = THREE.MathUtils.clamp(
fitRadius * zoomRatio,
fitRadius * 0.62,
fitRadius * 1.8
);
}
window.addEventListener("resize", resize);
resize();
const bareTag = document.getElementById("bareTag");
const mulchTag = document.getElementById("mulchTag");
const bareTagAnchor = new THREE.Vector3(
-TILE_OFFSET,
1.62,
-1.35
);
const mulchTagAnchor = new THREE.Vector3(
TILE_OFFSET,
1.62,
-1.35
);
function positionTag(element, anchor) {
const projected = anchor.clone().project(camera);
if (projected.z > 1) {
element.style.visibility = "hidden";
return;
}
element.style.visibility = "visible";
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
if (running) {
simulationTime += dt;
while (simulationTime >= nextDropTime) {
spawnPair();
nextDropTime += 1.43;
}
updateRainDrops(dt);
updateSplashParticles(dt);
updateSplashRings(dt);
updateFlows(dt);
}
updateCamera();
positionTag(bareTag, bareTagAnchor);
positionTag(mulchTag, mulchTagAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```