Prompt specification
Build or customize the Three.js 3D scene "Herd waits at a narrow passage" 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: Herd waits at a narrow passage
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/herd-waits-at-a-narrow-passage-x0678
Scene Description Prompt:
Animate low-poly elephants passing a narrow bank opening, with a calf beside an adult and clear spacing. Three.js from cdnjs; standalone HTML.
Working Three.js Starter (herd-waits-at-a-narrow-passage-x0678):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Elephants at the Bank Opening</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9bd91;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 2;
pointer-events: none;
color: #fff9eb;
text-shadow: 0 2px 14px rgba(38, 25, 12, 0.42);
}
.title-panel {
top: 28px;
left: 30px;
max-width: min(440px, calc(100vw - 60px));
}
.eyebrow {
margin: 0 0 7px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
opacity: 0.78;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
line-height: 0.96;
letter-spacing: -0.045em;
font-weight: 850;
}
.subtitle {
margin: 13px 0 0;
max-width: 360px;
font-size: 13px;
line-height: 1.55;
opacity: 0.86;
}
.controls {
position: fixed;
z-index: 3;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 14px;
transform: translateX(-50%);
padding: 9px 12px 9px 17px;
border: 1px solid rgba(255, 255, 255, 0.19);
border-radius: 999px;
color: #fffaf0;
background: rgba(38, 32, 25, 0.62);
box-shadow: 0 8px 30px rgba(38, 25, 12, 0.2);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
white-space: nowrap;
}
.hint {
font-size: 11px;
letter-spacing: 0.03em;
opacity: 0.78;
}
button {
pointer-events: auto;
min-width: 74px;
padding: 8px 13px;
border: 0;
border-radius: 999px;
color: #382c20;
background: #f5dfb5;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fff0ce;
}
button:active {
transform: translateY(0);
}
@media (max-width: 600px) {
.title-panel {
top: 20px;
left: 20px;
}
.subtitle {
display: none;
}
.controls {
bottom: 14px;
gap: 9px;
padding-left: 13px;
}
.hint {
font-size: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated low-poly elephants passing through a narrow opening in a riverbank"></canvas>
<section class="panel title-panel">
<p class="eyebrow">Riverbank crossing</p>
<h1>Quiet Passage</h1>
<p class="subtitle">
A calf keeps close beside an adult as the herd moves through the narrow opening.
</p>
</section>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom · Space to pause</span>
<button id="pauseButton" type="button">Pause</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const pauseButton = document.querySelector("#pauseButton");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8cba5);
scene.fog = new THREE.Fog(0xe8cba5, 28, 72);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemiLight = new THREE.HemisphereLight(0xffe8c3, 0x806b50, 2.15);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff1ce, 3.25);
sun.position.set(-10, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa7c9d8, 0.65);
fill.position.set(12, 7, -14);
scene.add(fill);
function standardMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...extra
});
}
const materials = {
ground: standardMaterial(0xbca06c),
path: standardMaterial(0xd8bd86),
bank: standardMaterial(0x9b7045),
bankDark: standardMaterial(0x795137),
bankLight: standardMaterial(0xb58b56),
grass: standardMaterial(0x697746),
grassLight: standardMaterial(0x879050),
trunk: standardMaterial(0x765038),
leaf: standardMaterial(0x536b42),
leafLight: standardMaterial(0x71804b),
water: standardMaterial(0x4e8990, {
roughness: 0.45,
metalness: 0.08,
transparent: true,
opacity: 0.9
}),
ripple: new THREE.MeshBasicMaterial({
color: 0xb7d5cf,
transparent: true,
opacity: 0.28,
depthWrite: false
}),
ivory: standardMaterial(0xf3dfb5),
eye: standardMaterial(0x171714, { roughness: 0.5 }),
cloud: standardMaterial(0xfff1d8)
};
let randomSeed = 91827;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const foliageGeometry = new THREE.DodecahedronGeometry(1, 0);
function addRock(parent, x, y, z, sx, sy, sz, material) {
const rock = new THREE.Mesh(rockGeometry, material);
rock.position.set(x, y, z);
rock.scale.set(sx, sy, sz);
rock.rotation.set(random() * 0.4, random() * Math.PI, random() * 0.25);
rock.castShadow = true;
rock.receiveShadow = true;
parent.add(rock);
return rock;
}
// Broad ground and the sandy track running through the opening.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(110, 110),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const path = new THREE.Mesh(
new THREE.BoxGeometry(3.95, 0.1, 82),
materials.path
);
path.position.set(0, -0.01, 0);
path.receiveShadow = true;
scene.add(path);
// River and shoreline on the right side of the landscape.
const river = new THREE.Mesh(
new THREE.PlaneGeometry(15, 110),
materials.water
);
river.rotation.x = -Math.PI / 2;
river.position.set(15, 0.025, 0);
river.receiveShadow = true;
scene.add(river);
const shoreline = new THREE.Mesh(
new THREE.BoxGeometry(3.2, 0.16, 90),
materials.bankLight
);
shoreline.position.set(7.2, 0.02, 0);
shoreline.receiveShadow = true;
scene.add(shoreline);
const ripples = [];
for (let i = 0; i < 30; i++) {
const ripple = new THREE.Mesh(
new THREE.PlaneGeometry(1.2 + random() * 2.2, 0.055),
materials.ripple
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(
9 + random() * 13,
0.075,
-38 + random() * 76
);
ripple.userData.speed = 0.08 + random() * 0.15;
ripple.userData.offset = random() * Math.PI * 2;
scene.add(ripple);
ripples.push(ripple);
}
// Two chunky earthen banks form a deliberately narrow gateway.
const bank = new THREE.Group();
scene.add(bank);
const leftBank = new THREE.Mesh(
new THREE.BoxGeometry(4.5, 4.15, 3.1),
materials.bank
);
leftBank.position.set(-4.48, 2.03, 0);
leftBank.castShadow = true;
leftBank.receiveShadow = true;
bank.add(leftBank);
const rightBank = new THREE.Mesh(
new THREE.BoxGeometry(4.5, 4.15, 3.1),
materials.bank
);
rightBank.position.set(4.48, 2.03, 0);
rightBank.castShadow = true;
rightBank.receiveShadow = true;
bank.add(rightBank);
// Faceted pillars clearly frame the opening without entering the path.
for (const side of [-1, 1]) {
const pillar = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.55, 4.55, 7),
side < 0 ? materials.bankDark : materials.bankLight
);
pillar.position.set(side * 2.53, 2.22, 0);
pillar.rotation.y = side * 0.15;
pillar.castShadow = true;
pillar.receiveShadow = true;
bank.add(pillar);
}
// Broken low-poly rocks soften the flat cliff silhouettes.
for (const side of [-1, 1]) {
for (let i = 0; i < 18; i++) {
const x = side * (3.15 + random() * 3.4);
const y = 4.05 + random() * 0.65;
const z = -1.65 + random() * 3.3;
const size = 0.55 + random() * 0.7;
addRock(
bank,
x,
y,
z,
size,
size * (0.65 + random() * 0.6),
size * (0.7 + random() * 0.5),
i % 3 === 0 ? materials.bankDark : materials.bank
);
}
for (let i = 0; i < 10; i++) {
addRock(
bank,
side * (2.75 + random() * 3.8),
0.22 + random() * 0.15,
-4 + random() * 8,
0.18 + random() * 0.32,
0.16 + random() * 0.28,
0.2 + random() * 0.35,
i % 2 ? materials.bankDark : materials.bankLight
);
}
}
function addGrassTuft(x, y, z, scale = 1) {
const tuft = new THREE.Group();
tuft.position.set(x, y, z);
tuft.scale.setScalar(scale);
for (let i = 0; i < 4; i++) {
const blade = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.58 + random() * 0.22, 3),
i % 2 ? materials.grass : materials.grassLight
);
blade.position.set((random() - 0.5) * 0.16, 0.25, (random() - 0.5) * 0.16);
blade.rotation.z = (random() - 0.5) * 0.48;
blade.rotation.x = (random() - 0.5) * 0.35;
blade.castShadow = true;
tuft.add(blade);
}
scene.add(tuft);
}
for (let i = 0; i < 48; i++) {
const side = random() > 0.5 ? 1 : -1;
addGrassTuft(
side * (3.1 + random() * 5.2),
0.02,
-19 + random() * 38,
0.65 + random() * 0.75
);
}
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 4.12, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.24, 2.2, 6),
materials.trunk
);
trunk.position.y = 1.05;
trunk.rotation.z = (random() - 0.5) * 0.14;
trunk.castShadow = true;
tree.add(trunk);
const crown1 = new THREE.Mesh(foliageGeometry, materials.leaf);
crown1.scale.set(1.15, 0.62, 0.9);
crown1.position.set(-0.3, 2.18, 0.05);
crown1.rotation.y = random() * Math.PI;
crown1.castShadow = true;
tree.add(crown1);
const crown2 = new THREE.Mesh(foliageGeometry, materials.leafLight);
crown2.scale.set(0.95, 0.58, 0.8);
crown2.position.set(0.48, 2.35, -0.08);
crown2.rotation.y = random() * Math.PI;
crown2.castShadow = true;
tree.add(crown2);
scene.add(tree);
}
addTree(-5.6, -0.8, 1.15);
addTree(-6.4, 0.75, 0.8);
addTree(5.5, -0.95, 1.05);
addTree(6.45, 0.75, 0.72);
// A few distant, faceted trees and clouds provide depth.
for (let i = 0; i < 9; i++) {
const tree = new THREE.Group();
const side = i % 2 ? 1 : -1;
tree.position.set(side * (9 + random() * 9), 0, -25 + random() * 50);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.16, 1.6, 5),
materials.trunk
);
trunk.position.y = 0.8;
tree.add(trunk);
const crown = new THREE.Mesh(foliageGeometry, materials.leaf);
crown.scale.set(0.9, 0.5, 0.75);
crown.position.y = 1.65;
tree.add(crown);
scene.add(tree);
}
const clouds = [];
for (let i = 0; i < 6; i++) {
const cloud = new THREE.Group();
cloud.position.set(-20 + random() * 40, 11 + random() * 5, -32 + random() * 35);
for (let j = 0; j < 4; j++) {
const puff = new THREE.Mesh(foliageGeometry, materials.cloud);
puff.position.set(j * 0.75 - 1.1, random() * 0.35, random() * 0.25);
puff.scale.set(0.9 + random() * 0.45, 0.38 + random() * 0.24, 0.55);
cloud.add(puff);
}
cloud.userData.speed = 0.12 + random() * 0.08;
scene.add(cloud);
clouds.push(cloud);
}
function createElephant({
scale = 1,
color = 0x777a70,
phase = 0,
tusks = true
} = {}) {
const root = new THREE.Group();
root.scale.setScalar(scale);
const bodyRig = new THREE.Group();
root.add(bodyRig);
const skin = standardMaterial(color);
const skinLight = standardMaterial(new THREE.Color(color).offsetHSL(0, 0, 0.055));
const skinDark = standardMaterial(new THREE.Color(color).offsetHSL(0, 0, -0.045));
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
skin
);
body.scale.set(0.74, 0.88, 1.22);
body.position.y = 1.62;
body.castShadow = true;
body.receiveShadow = true;
bodyRig.add(body);
const rump = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
skinLight
);
rump.scale.set(0.68, 0.76, 0.68);
rump.position.set(0, 1.65, 0.7);
rump.castShadow = true;
bodyRig.add(rump);
const headPivot = new THREE.Group();
headPivot.position.set(0, 1.85, -1.02);
bodyRig.add(headPivot);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
skinLight
);
head.scale.set(0.57, 0.64, 0.62);
head.castShadow = true;
head.receiveShadow = true;
headPivot.add(head);
const earPivots = [];
for (const side of [-1, 1]) {
const earPivot = new THREE.Group();
earPivot.position.set(side * 0.61, 0.05, 0.01);
headPivot.add(earPivot);
const ear = new THREE.Mesh(foliageGeometry, side < 0 ? skin : skinDark);
ear.scale.set(0.14, 0.56, 0.49);
ear.rotation.y = side * 0.12;
ear.castShadow = true;
earPivot.add(ear);
earPivots.push({ pivot: earPivot, side });
}
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 7, 5),
materials.eye
);
eye.position.set(side * 0.39, 0.13, -0.49);
headPivot.add(eye);
if (tusks) {
const tusk = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.095, 0.66, 5),
materials.ivory
);
tusk.position.set(side * 0.25, -0.25, -0.57);
tusk.rotation.x = Math.PI / 2;
tusk.rotation.z = side * 0.18;
tusk.castShadow = true;
headPivot.add(tusk);
}
}
// A segmented, flexible trunk.
const trunkRoot = new THREE.Group();
trunkRoot.position.set(0, -0.04, -0.56);
headPivot.add(trunkRoot);
const trunkPivots = [];
const trunkLengths = [0.36, 0.34, 0.31, 0.29, 0.26, 0.22];
let trunkParent = trunkRoot;
trunkLengths.forEach((length, index) => {
const pivot = new THREE.Group();
if (index === 0) {
trunkParent.add(pivot);
} else {
pivot.position.y = -trunkLengths[index - 1];
trunkParent.add(pivot);
}
const segment = new THREE.Mesh(
new THREE.CylinderGeometry(
0.16 - index * 0.019,
0.142 - index * 0.019,
length,
6
),
index % 2 ? skin : skinDark
);
segment.position.y = -length / 2;
segment.castShadow = true;
pivot.add(segment);
trunkPivots.push({
pivot,
baseX: 0.08 + index * 0.035
});
trunkParent = pivot;
});
// Four jointed legs.
const legPivots = [];
const legPositions = [
[-0.44, -0.67],
[0.44, -0.67],
[-0.44, 0.66],
[0.44, 0.66]
];
legPositions.forEach(([x, z], index) => {
const pivot = new THREE.Group();
pivot.position.set(x, 1.16, z);
root.add(pivot);
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.245, 1.05, 6),
index % 2 ? skin : skinDark
);
leg.position.y = -0.52;
leg.castShadow = true;
pivot.add(leg);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.28, 0.18, 6),
skinDark
);
foot.position.y = -1.07;
foot.castShadow = true;
pivot.add(foot);
legPivots.push(pivot);
});
// Short tail with a dark tuft.
const tailPivot = new THREE.Group();
tailPivot.position.set(0, 1.82, 1.22);
tailPivot.rotation.x = -0.72;
bodyRig.add(tailPivot);
const tail = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.075, 0.72, 5),
skinDark
);
tail.position.y = -0.34;
tail.castShadow = true;
tailPivot.add(tail);
const tuft = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.12, 0),
materials.eye
);
tuft.position.y = -0.72;
tailPivot.add(tuft);
root.userData = {
bodyRig,
headPivot,
earPivots,
trunkPivots,
legPivots,
tailPivot,
phase
};
scene.add(root);
return root;
}
function animateElephant(elephant, time) {
const data = elephant.userData;
const phase = time * 3.15 + data.phase;
data.bodyRig.position.y = Math.abs(Math.sin(phase)) * 0.027;
data.bodyRig.rotation.z = Math.sin(phase) * 0.008;
data.headPivot.rotation.x = -0.025 + Math.sin(phase * 0.5) * 0.022;
data.headPivot.rotation.y = Math.sin(phase * 0.5 + 1.2) * 0.018;
const gaitOffsets = [0, Math.PI, Math.PI, 0];
data.legPivots.forEach((leg, index) => {
leg.rotation.x = Math.sin(phase + gaitOffsets[index]) * 0.27;
});
data.earPivots.forEach(({ pivot, side }, index) => {
pivot.rotation.z = side * (0.055 + Math.sin(phase * 0.62 + index) * 0.055);
pivot.rotation.y = Math.sin(phase * 0.43 + index) * 0.035;
});
data.trunkPivots.forEach(({ pivot, baseX }, index) => {
pivot.rotation.x = baseX + Math.sin(phase * 0.72 + index * 0.65) * 0.045;
pivot.rotation.z = Math.sin(phase * 0.55 + index * 0.8) * 0.045;
});
data.tailPivot.rotation.z = Math.sin(phase * 0.85) * 0.12;
}
// The calf and its adult travel abreast, with a visible gap between them.
const leadingPair = new THREE.Group();
scene.add(leadingPair);
const pairAdult = createElephant({
scale: 1,
color: 0x73776e,
phase: 0.15,
tusks: true
});
pairAdult.position.x = -0.9;
const calf = createElephant({
scale: 0.68,
color: 0x85877c,
phase: 1.1,
tusks: false
});
calf.position.x = 0.9;
leadingPair.add(pairAdult, calf);
// Two more adults remain clearly separated in single file.
const adultTwo = createElephant({
scale: 0.97,
color: 0x696d65,
phase: 2.3,
tusks: true
});
const adultThree = createElephant({
scale: 1.03,
color: 0x7c7e73,
phase: 4.1,
tusks: true
});
const elephants = [pairAdult, calf, adultTwo, adultThree];
const loopLength = 46;
const walkingSpeed = 1.5;
function wrap(value) {
return ((value % loopLength) + loopLength) % loopLength - loopLength / 2;
}
// Camera controls implemented directly, without Three.js addons.
const cameraTarget = new THREE.Vector3(0, 1.45, 2.2);
let yaw = 0.72;
let pitch = 0.48;
let distance = 25;
let desiredYaw = yaw;
let desiredPitch = pitch;
let desiredDistance = distance;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-8 * delta);
yaw += (desiredYaw - yaw) * smoothing;
pitch += (desiredPitch - pitch) * smoothing;
distance += (desiredDistance - distance) * smoothing;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * distance,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
desiredYaw -= deltaX * 0.005;
desiredPitch = THREE.MathUtils.clamp(
desiredPitch + deltaY * 0.004,
0.22,
1.18
);
});
function stopDragging() {
dragging = false;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredDistance = THREE.MathUtils.clamp(
desiredDistance * Math.exp(event.deltaY * 0.001),
11,
39
);
},
{ passive: false }
);
let playing = true;
let simulationTime = 0;
function setPlaying(value) {
playing = value;
pauseButton.textContent = playing ? "Pause" : "Play";
}
pauseButton.addEventListener("click", () => setPlaying(!playing));
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setPlaying(!playing);
}
if (event.code === "KeyR") {
desiredYaw = 0.72;
desiredPitch = 0.48;
desiredDistance = 25;
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationTime += delta;
}
leadingPair.position.z = wrap(5.5 - walkingSpeed * simulationTime);
adultTwo.position.z = wrap(13.5 - walkingSpeed * simulationTime);
adultThree.position.z = wrap(21.5 - walkingSpeed * simulationTime);
elephants.forEach((elephant) => {
animateElephant(elephant, simulationTime);
});
ripples.forEach((ripple) => {
ripple.position.x += ripple.userData.speed * delta;
ripple.material.opacity =
0.17 + Math.sin(simulationTime * 0.7 + ripple.userData.offset) * 0.07;
if (ripple.position.x > 23) {
ripple.position.x = 8.2;
}
});
clouds.forEach((cloud) => {
cloud.position.x += cloud.userData.speed * delta;
if (cloud.position.x > 27) {
cloud.position.x = -27;
}
});
updateCamera(delta);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera(1);
animate();
</script>
</body>
</html>
```