Prompt specification
Build or customize the Three.js 3D scene "Windy polar colony vignette" 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: Windy polar colony vignette
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/windy-polar-colony-vignette-x0703
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows penguin huddles. Compose a snowy colony area with clustered adults and an open approach route; drifting snow and wind arrows remain secondary to readable individual movement within the group. Stylized solid forms.
Working Three.js Starter (windy-polar-colony-vignette-x0703):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Snowfield Penguin Colony</title>
<style>
:root {
color-scheme: light;
--ink: #183747;
--muted: #617c89;
--glass: rgba(244, 250, 252, 0.78);
--line: rgba(55, 91, 108, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cadde6;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--glass);
box-shadow: 0 12px 40px rgba(50, 78, 92, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #668694;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.2vw, 29px);
font-weight: 720;
letter-spacing: -0.035em;
line-height: 1.08;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.weather {
position: fixed;
top: 25px;
right: 25px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(244, 250, 252, 0.66);
color: #587887;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
pointer-events: none;
}
.weather-arrow {
color: #5d91a0;
font-size: 17px;
line-height: 1;
transform: translateY(-1px);
}
.hint {
position: fixed;
left: 24px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid rgba(55, 91, 108, 0.13);
border-radius: 10px;
background: rgba(244, 250, 252, 0.62);
color: #68828e;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.035em;
backdrop-filter: blur(8px);
pointer-events: none;
}
#reset {
position: fixed;
right: 24px;
bottom: 22px;
padding: 9px 13px;
border: 1px solid rgba(55, 91, 108, 0.16);
border-radius: 10px;
background: rgba(244, 250, 252, 0.76);
color: #496b7b;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
transition:
background 160ms ease,
transform 160ms ease;
}
#reset:hover {
background: rgba(255, 255, 255, 0.94);
transform: translateY(-1px);
}
#reset:active {
transform: translateY(0);
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
.weather {
top: auto;
right: 14px;
bottom: 62px;
}
.hint {
left: 14px;
bottom: 14px;
}
#reset {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive three-dimensional snowy penguin colony"></main>
<section class="title-card">
<div class="eyebrow">Snowfield Colony 04</div>
<h1>Close huddles, open ground</h1>
<p class="subtitle">
Three compact groups of adults shelter on the lee side of the colony,
while a clear packed-snow approach remains open.
</p>
</section>
<div class="weather" aria-hidden="true">
<span class="weather-arrow">↙</span>
<span>WIND 12 KM/H</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<button id="reset" type="button">Reset view</button>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene
// ---------------------------------------------------------------------
const stage = document.querySelector("#stage");
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Stylized snowy landscape with three penguin huddles and an open approach"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbdde6);
scene.fog = new THREE.Fog(0xcbdde6, 19, 39);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0.15, 0.45, -1.25);
let cameraYaw = 0.53;
let cameraPitch = 0.80;
let cameraRadius = window.innerWidth / window.innerHeight < 1 ? 34 : 19.5;
function applyCamera() {
const sinPitch = Math.sin(cameraPitch);
const cosPitch = Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(cameraYaw) * sinPitch,
cameraTarget.y + cameraRadius * cosPitch,
cameraTarget.z + cameraRadius * Math.cos(cameraYaw) * sinPitch
);
camera.lookAt(cameraTarget);
}
applyCamera();
const hemisphere = new THREE.HemisphereLight(
0xf5fbff,
0x829eae,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff9eb, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0xb8d9ed, 0.9);
coolFill.position.set(8, 5, -6);
scene.add(coolFill);
// ---------------------------------------------------------------------
// Materials and shared geometry
// ---------------------------------------------------------------------
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xe8f1f2,
roughness: 0.96,
metalness: 0
}),
islandRim: new THREE.MeshStandardMaterial({
color: 0xaec8d4,
roughness: 0.98
}),
backgroundGround: new THREE.MeshStandardMaterial({
color: 0xc6dbe4,
roughness: 1
}),
drift: new THREE.MeshStandardMaterial({
color: 0xe1edf0,
roughness: 0.98
}),
driftShade: new THREE.MeshStandardMaterial({
color: 0xd2e3e9,
roughness: 0.98
}),
colonyPatch: new THREE.MeshStandardMaterial({
color: 0xf1f6f4,
roughness: 0.98
}),
routeEdge: new THREE.MeshStandardMaterial({
color: 0xa8c8d4,
roughness: 0.96,
side: THREE.DoubleSide
}),
route: new THREE.MeshStandardMaterial({
color: 0xc5dce4,
roughness: 0.94,
side: THREE.DoubleSide
}),
belly: new THREE.MeshStandardMaterial({
color: 0xf2f4eb,
roughness: 0.86
}),
face: new THREE.MeshStandardMaterial({
color: 0xf7f5e9,
roughness: 0.88
}),
beak: new THREE.MeshStandardMaterial({
color: 0xee9633,
roughness: 0.74
}),
feet: new THREE.MeshStandardMaterial({
color: 0xc87928,
roughness: 0.8
}),
eye: new THREE.MeshStandardMaterial({
color: 0x07141c,
roughness: 0.55
}),
rock: new THREE.MeshStandardMaterial({
color: 0x9ebbc7,
roughness: 0.95,
flatShading: true
})
};
const bodyMaterials = [
new THREE.MeshStandardMaterial({
color: 0x172c3b,
roughness: 0.84
}),
new THREE.MeshStandardMaterial({
color: 0x1c3342,
roughness: 0.87
}),
new THREE.MeshStandardMaterial({
color: 0x122633,
roughness: 0.82
})
];
const wingMaterial = new THREE.MeshStandardMaterial({
color: 0x102633,
roughness: 0.88
});
const geometry = {
sphere: new THREE.SphereGeometry(1, 18, 14),
body: new THREE.SphereGeometry(1, 18, 14),
head: new THREE.SphereGeometry(1, 18, 14),
face: new THREE.SphereGeometry(1, 16, 12),
belly: new THREE.SphereGeometry(1, 18, 14),
wing: new THREE.SphereGeometry(1, 16, 12),
foot: new THREE.SphereGeometry(1, 14, 10),
eye: new THREE.SphereGeometry(1, 10, 8),
beak: new THREE.ConeGeometry(0.105, 0.28, 8),
drift: new THREE.SphereGeometry(1, 22, 14),
rock: new THREE.IcosahedronGeometry(0.45, 0)
};
function addMesh(parent, geo, material, position, scale, rotation) {
const mesh = new THREE.Mesh(geo, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(scale[0], scale[1], scale[2]);
if (rotation) {
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Snowfield
// ---------------------------------------------------------------------
const backgroundGround = addMesh(
scene,
new THREE.PlaneGeometry(90, 90),
materials.backgroundGround,
[0, -0.88, 0],
[1, 1, 1],
[-Math.PI / 2, 0, 0]
);
backgroundGround.castShadow = false;
const islandRim = addMesh(
scene,
new THREE.CylinderGeometry(12.75, 13.2, 0.72, 64),
materials.islandRim,
[0, -0.43, -1],
[1, 1, 0.77]
);
const island = addMesh(
scene,
new THREE.CylinderGeometry(12.65, 12.75, 0.74, 64),
materials.ground,
[0, -0.37, -1],
[1, 1, 0.77]
);
function addDrift(x, z, sx, sz, rotation = 0, shade = false) {
return addMesh(
scene,
geometry.drift,
shade ? materials.driftShade : materials.drift,
[x, 0.015, z],
[sx, 0.15 + Math.min(sx, sz) * 0.035, sz],
[0, rotation, 0]
);
}
// Background snow forms.
addDrift(-7.0, -5.1, 2.1, 1.05, -0.22);
addDrift(-3.2, -5.7, 2.0, 0.95, 0.13);
addDrift(0.7, -5.5, 1.8, 0.86, -0.12);
addDrift(4.0, -5.0, 1.65, 0.82, 0.19);
addDrift(7.2, -3.9, 1.55, 0.88, -0.18);
addDrift(-9.1, -1.9, 1.1, 1.7, 0.22, true);
addDrift(-8.3, 2.8, 1.4, 1.5, -0.1, true);
// Low banks frame the approach without obstructing it.
addDrift(7.65, 6.8, 1.45, 1.0, 0.14);
addDrift(7.05, 4.25, 1.25, 0.9, -0.12);
addDrift(6.55, 1.45, 1.18, 0.88, 0.08);
addDrift(5.75, -1.2, 1.08, 0.82, -0.1);
addDrift(3.45, 6.25, 1.18, 0.78, 0.1, true);
addDrift(3.15, 3.72, 1.08, 0.76, -0.08, true);
addDrift(3.05, 0.92, 0.96, 0.68, 0.08, true);
addDrift(2.95, -1.75, 0.86, 0.66, -0.1, true);
// A few faceted ice-and-rock forms in the distance.
const rockPositions = [
[-7.7, -4.0, 0.62],
[-6.7, -4.7, 0.42],
[5.6, -4.7, 0.5],
[6.8, -3.8, 0.36]
];
for (const [x, z, s] of rockPositions) {
addMesh(
scene,
geometry.rock,
materials.rock,
[x, 0.12, z],
[s, s * 0.7, s * 0.82],
[0.12, x * 0.31, 0.08]
);
}
// ---------------------------------------------------------------------
// Open packed-snow approach
// ---------------------------------------------------------------------
function createRibbon(points, width, height, material) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, z]) => new THREE.Vector3(x, height, z)),
false,
"catmullrom",
0.4
);
const positions = [];
const indices = [];
const segments = 72;
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const left = point.clone().addScaledVector(side, width * 0.5);
const right = point.clone().addScaledVector(side, -width * 0.5);
positions.push(left.x, height, left.z);
positions.push(right.x, height, right.z);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, d, c);
}
const ribbonGeometry = new THREE.BufferGeometry();
ribbonGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
ribbonGeometry.setIndex(indices);
ribbonGeometry.computeVertexNormals();
const ribbon = new THREE.Mesh(ribbonGeometry, material);
ribbon.receiveShadow = true;
scene.add(ribbon);
return ribbon;
}
const approachPoints = [
[6.35, 8.15],
[5.85, 5.55],
[5.20, 3.00],
[4.78, 0.20],
[4.08, -2.15],
[3.18, -4.18]
];
createRibbon(approachPoints, 2.95, 0.014, materials.routeEdge);
createRibbon(approachPoints, 2.25, 0.026, materials.route);
// ---------------------------------------------------------------------
// Penguin model
// ---------------------------------------------------------------------
function createPenguin(scale, materialIndex = 0) {
const root = new THREE.Group();
const motion = new THREE.Group();
root.add(motion);
// Torso.
addMesh(
motion,
geometry.body,
bodyMaterials[materialIndex % bodyMaterials.length],
[0, 0.74, 0],
[0.45, 0.64, 0.40]
);
// Pale belly.
addMesh(
motion,
geometry.belly,
materials.belly,
[0, 0.75, 0.385],
[0.47, 0.73, 0.19]
);
// Head pivot allows subtle individual head turns.
const headPivot = new THREE.Group();
headPivot.position.set(0, 1.16, 0);
motion.add(headPivot);
addMesh(
headPivot,
geometry.head,
bodyMaterials[materialIndex % bodyMaterials.length],
[0, 0.25, 0],
[0.37, 0.38, 0.36]
);
addMesh(
headPivot,
geometry.face,
materials.face,
[-0.145, 0.28, 0.275],
[0.155, 0.255, 0.075]
);
addMesh(
headPivot,
geometry.face,
materials.face,
[0.145, 0.28, 0.275],
[0.155, 0.255, 0.075]
);
addMesh(
headPivot,
geometry.eye,
materials.eye,
[-0.16, 0.335, 0.342],
[0.037, 0.041, 0.030]
);
addMesh(
headPivot,
geometry.eye,
materials.eye,
[0.16, 0.335, 0.342],
[0.037, 0.041, 0.030]
);
addMesh(
headPivot,
geometry.beak,
materials.beak,
[0, 0.205, 0.465],
[1, 1, 1],
[Math.PI / 2, 0, 0]
);
// Flippers.
addMesh(
motion,
geometry.wing,
wingMaterial,
[-0.435, 0.73, 0.015],
[0.17, 0.54, 0.28],
[0, 0, -0.14]
);
addMesh(
motion,
geometry.wing,
wingMaterial,
[0.435, 0.73, 0.015],
[0.17, 0.54, 0.28],
[0, 0, 0.14]
);
// Feet.
addMesh(
motion,
geometry.foot,
materials.feet,
[-0.19, 0.075, 0.19],
[0.24, 0.075, 0.34]
);
addMesh(
motion,
geometry.foot,
materials.feet,
[0.19, 0.075, 0.19],
[0.24, 0.075, 0.34]
);
root.scale.setScalar(scale);
scene.add(root);
return {
root,
motion,
headPivot,
phase: Math.random() * Math.PI * 2,
headBias: (Math.random() - 0.5) * 0.08
};
}
// ---------------------------------------------------------------------
// Three compact adult huddles
// ---------------------------------------------------------------------
const clusters = [
{
center: [-4.25, -2.85],
points: [
[-5.35, -2.65],
[-5.05, -3.55],
[-4.20, -4.05],
[-3.35, -3.65],
[-2.95, -2.85],
[-3.35, -2.05],
[-4.25, -1.80],
[-4.95, -2.05]
]
},
{
center: [-1.55, -3.75],
points: [
[-2.75, -3.45],
[-2.40, -4.30],
[-1.55, -4.55],
[-0.70, -4.25],
[-0.25, -3.55],
[-0.60, -2.75],
[-1.50, -2.65],
[-2.20, -3.00]
]
},
{
center: [1.45, -2.75],
points: [
[0.25, -2.60],
[0.45, -3.45],
[1.20, -3.85],
[2.05, -3.50],
[2.65, -2.80],
[2.25, -1.95],
[1.35, -1.70],
[0.60, -1.90]
]
}
];
const agents = [];
clusters.forEach((cluster, clusterIndex) => {
addMesh(
scene,
geometry.drift,
materials.colonyPatch,
[cluster.center[0], -0.045, cluster.center[1]],
[2.45, 0.12, 1.95],
[0, 0.08 * clusterIndex, 0]
);
cluster.points.forEach(([x, z], index) => {
const scale = 0.91 + ((index * 7 + clusterIndex * 3) % 8) * 0.025;
const penguin = createPenguin(scale, index + clusterIndex);
penguin.root.position.set(x, 0.075, z);
const towardCenterX = cluster.center[0] - x;
const towardCenterZ = cluster.center[1] - z;
const yaw =
Math.atan2(towardCenterX, towardCenterZ) +
(((index % 3) - 1) * 0.12);
penguin.root.rotation.y = yaw;
penguin.static = true;
agents.push(penguin);
});
});
// Three adults move through separate gaps within the colony.
// Their small, contrasting paths remain legible without disturbing
// the dense silhouettes of the huddles.
const moverDefinitions = [
{
from: [-3.05, -1.63],
to: [-2.30, -1.20],
speed: 0.075,
phase: 0.08
},
{
from: [-1.05, -2.33],
to: [-0.18, -1.93],
speed: 0.067,
phase: 0.39
},
{
from: [0.10, -1.22],
to: [1.03, -0.83],
speed: 0.071,
phase: 0.68
}
];
const movers = moverDefinitions.map((definition, index) => {
const penguin = createPenguin(0.98 + index * 0.025, index + 1);
penguin.root.position.set(
definition.from[0],
0.075,
definition.from[1]
);
penguin.static = false;
penguin.path = definition;
agents.push(penguin);
return penguin;
});
// ---------------------------------------------------------------------
// Secondary wind indicators
// ---------------------------------------------------------------------
const windArrows = [];
const windDirection = new THREE.Vector3(-1, 0, 0.12).normalize();
function addWindArrow(x, y, z, length) {
const arrow = new THREE.ArrowHelper(
windDirection,
new THREE.Vector3(x, y, z),
length,
0x628f9f,
0.22,
0.13
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.19;
arrow.line.material.depthWrite = false;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.23;
arrow.cone.material.depthWrite = false;
scene.add(arrow);
windArrows.push(arrow);
}
addWindArrow(6.65, 0.72, 4.55, 1.18);
addWindArrow(6.85, 1.03, 1.35, 1.30);
addWindArrow(5.85, 1.35, -2.75, 1.12);
// ---------------------------------------------------------------------
// Lightweight drifting snow
// ---------------------------------------------------------------------
const snowCount = 520;
const snowPositions = new Float32Array(snowCount * 3);
const snowSpeeds = new Float32Array(snowCount);
for (let i = 0; i < snowCount; i++) {
snowPositions[i * 3] = -13 + Math.random() * 26;
snowPositions[i * 3 + 1] = 0.2 + Math.random() * 9.5;
snowPositions[i * 3 + 2] = -12 + Math.random() * 21;
snowSpeeds[i] = 0.55 + Math.random() * 0.8;
}
const snowGeometry = new THREE.BufferGeometry();
snowGeometry.setAttribute(
"position",
new THREE.BufferAttribute(snowPositions, 3)
);
const snowMaterial = new THREE.PointsMaterial({
color: 0xffffff,
size: 0.055,
transparent: true,
opacity: 0.43,
depthWrite: false,
sizeAttenuation: true
});
const snow = new THREE.Points(snowGeometry, snowMaterial);
snow.frustumCulled = false;
scene.add(snow);
// ---------------------------------------------------------------------
// Custom camera controls: no imported control addons
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.0048,
0.43,
1.16
);
applyCamera();
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
12,
48
);
applyCamera();
},
{ passive: false }
);
function resetCamera() {
cameraYaw = 0.53;
cameraPitch = 0.80;
cameraRadius =
window.innerWidth / window.innerHeight < 1 ? 34 : 19.5;
applyCamera();
}
document.querySelector("#reset").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.045);
const elapsed = clock.elapsedTime;
// Settled huddle birds make small, distinct breathing and head motions.
agents.forEach((penguin) => {
if (penguin.static) {
penguin.motion.position.y =
Math.sin(elapsed * 1.18 + penguin.phase) * 0.008;
penguin.motion.rotation.z =
Math.sin(elapsed * 0.72 + penguin.phase) * 0.012;
penguin.headPivot.rotation.y =
penguin.headBias +
Math.sin(elapsed * 0.48 + penguin.phase) * 0.085;
penguin.headPivot.rotation.z =
Math.sin(elapsed * 0.36 + penguin.phase) * 0.018;
}
});
// Moving adults travel short, separate paths and turn into motion.
movers.forEach((penguin) => {
const path = penguin.path;
const cycle = (elapsed * path.speed + path.phase) % 1;
const rawPingPong = cycle < 0.5 ? cycle * 2 : (1 - cycle) * 2;
const eased = rawPingPong * rawPingPong * (3 - 2 * rawPingPong);
const direction = cycle < 0.5 ? 1 : -1;
const x = THREE.MathUtils.lerp(path.from[0], path.to[0], eased);
const z = THREE.MathUtils.lerp(path.from[1], path.to[1], eased);
const dx = (path.to[0] - path.from[0]) * direction;
const dz = (path.to[1] - path.from[1]) * direction;
penguin.root.position.x = x;
penguin.root.position.z = z;
penguin.root.rotation.y = Math.atan2(dx, dz);
const gait = elapsed * 7.1 + penguin.phase * 3;
const movementAmount = Math.sin(rawPingPong * Math.PI);
penguin.motion.position.y =
Math.abs(Math.sin(gait)) * 0.034 * movementAmount;
penguin.motion.rotation.z =
Math.sin(gait) * 0.05 * movementAmount;
penguin.headPivot.rotation.y =
Math.sin(elapsed * 0.65 + penguin.phase) * 0.055;
penguin.headPivot.rotation.z = 0;
});
// Snow drifts from right to left, matching the understated wind arrows.
const positions = snowGeometry.attributes.position.array;
for (let i = 0; i < snowCount; i++) {
const offset = i * 3;
positions[offset] -= delta * (0.13 + snowSpeeds[i] * 0.12);
positions[offset + 1] -= delta * (0.17 + snowSpeeds[i] * 0.16);
positions[offset + 2] += delta * 0.035;
if (positions[offset] < -13) positions[offset] = 13;
if (positions[offset + 1] < 0.12) {
positions[offset + 1] = 8.5 + Math.random() * 2.2;
}
}
snowGeometry.attributes.position.needsUpdate = true;
windArrows.forEach((arrow, index) => {
const opacity = 0.16 + Math.sin(elapsed * 0.75 + index) * 0.035;
arrow.line.material.opacity = opacity;
arrow.cone.material.opacity = opacity + 0.06;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```