Prompt specification
Build or customize the Three.js 3D scene "Coastal nesting habitat 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: Coastal nesting habitat vignette
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/coastal-nesting-habitat-vignette-x0711
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring sea-turtle nesting. Compose a quiet beach, dunes, vegetation, and offshore water; separate nesting area from a distant observation path and show a condensed nocturnal life-stage sequence. Stylized solid forms.
Working Three.js Starter (coastal-nesting-habitat-vignette-x0711):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nocturne — Sea Turtle Nesting</title>
<style>
:root {
--ink: #e8eee8;
--muted: #aab9b8;
--accent: #e7d6a6;
--panel: rgba(8, 20, 29, 0.78);
--line: rgba(222, 235, 230, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131e;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.masthead {
position: absolute;
top: 28px;
left: 32px;
max-width: 420px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 1px;
background: currentColor;
opacity: 0.75;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4.2vw, 58px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 360px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
letter-spacing: 0.025em;
}
.night-badge {
position: absolute;
top: 30px;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 18, 27, 0.46);
color: #c9d5d1;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.moon-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #f2e4b8;
box-shadow: 0 0 14px 3px rgba(242, 228, 184, 0.3);
}
.sequence {
position: absolute;
right: 30px;
bottom: 30px;
left: 30px;
display: grid;
grid-template-columns: minmax(190px, 0.8fr) minmax(360px, 1.7fr) auto;
gap: 22px;
align-items: center;
padding: 17px 20px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.phase-kicker {
margin-bottom: 4px;
color: var(--accent);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#phase-title {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 400;
}
#phase-description {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.timeline-wrap {
min-width: 0;
}
.timeline-labels {
display: flex;
justify-content: space-between;
gap: 5px;
margin-bottom: 10px;
}
.timeline-labels span {
position: relative;
flex: 1;
color: #718181;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
transition: color 180ms ease;
}
.timeline-labels span.active { color: var(--accent); }
.timeline {
position: relative;
height: 3px;
overflow: hidden;
border-radius: 99px;
background: rgba(231, 235, 225, 0.13);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: var(--accent);
box-shadow: 0 0 14px rgba(231, 214, 166, 0.45);
}
.timeline-foot {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: #718181;
font-size: 8px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.controls {
display: flex;
align-items: center;
gap: 8px;
}
button {
height: 36px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: var(--ink);
cursor: pointer;
font: inherit;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(231, 214, 166, 0.48);
background: rgba(231, 214, 166, 0.08);
}
#toggle {
min-width: 83px;
padding: 0 13px;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#restart {
width: 38px;
font-size: 18px;
}
.help {
position: absolute;
right: 31px;
bottom: 153px;
color: rgba(213, 224, 219, 0.55);
font-size: 9px;
letter-spacing: 0.07em;
}
#fade {
position: fixed;
inset: 0;
z-index: 3;
background: #06111a;
opacity: 1;
pointer-events: none;
}
@media (max-width: 850px) {
.masthead {
top: 20px;
left: 20px;
max-width: 300px;
}
.subtitle { display: none; }
.night-badge {
top: 20px;
right: 20px;
}
.sequence {
right: 14px;
bottom: 14px;
left: 14px;
grid-template-columns: 1fr auto;
gap: 13px;
padding: 14px;
}
.timeline-wrap {
grid-column: 1 / -1;
grid-row: 2;
}
.help { display: none; }
}
@media (max-width: 520px) {
.night-badge {
padding: 8px 10px;
font-size: 8px;
}
.masthead { max-width: 220px; }
h1 { font-size: 34px; }
.timeline-labels span { font-size: 7px; }
#phase-description { display: none; }
}
</style>
</head>
<body>
<div id="hud">
<header class="masthead">
<div class="eyebrow">A nocturnal field study</div>
<h1>Nocturne</h1>
<p class="subtitle">
A condensed journey from moonlit surf to the small, synchronized
procession of hatchlings returning to the sea.
</p>
</header>
<div class="night-badge">
<span class="moon-dot"></span>
<span>Night cycle · 56 seconds</span>
</div>
<div class="help">Drag to orbit · Scroll to zoom · Arrow keys to pan</div>
<section class="sequence" aria-label="Nesting sequence timeline">
<div>
<div class="phase-kicker" id="phase-kicker">01 / Arrival</div>
<h2 id="phase-title">Beyond the breakers</h2>
<p id="phase-description">
The adult turtle follows the reflected moon toward the nesting beach.
</p>
</div>
<div class="timeline-wrap">
<div class="timeline-labels" id="timeline-labels">
<span class="active">Arrival</span>
<span>Nesting</span>
<span>Covering</span>
<span>Hatching</span>
<span>Sea</span>
<span>Quiet</span>
</div>
<div class="timeline"><div id="progress"></div></div>
<div class="timeline-foot">
<span>Moonrise</span>
<span id="time-label">00:00 / 00:56</span>
<span>Daybreak</span>
</div>
</div>
<div class="controls">
<button id="toggle" type="button">Pause</button>
<button id="restart" type="button" aria-label="Restart sequence">↺</button>
</div>
</section>
</div>
<div id="fade"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071522);
scene.fog = new THREE.Fog(0x091a27, 42, 118);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive moonlit beach scene showing sea turtles nesting"
);
document.body.prepend(renderer.domElement);
const clock = new THREE.Clock();
let seed = 17421;
function random() {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(edge0, edge1, value) {
const x = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return x * x * (3 - 2 * x);
}
function terrainHeight(x, z) {
const duneMix = smoothstep(4, 28, -z);
const duneShape =
2.45 +
0.72 * Math.sin(x * 0.105 + 0.7) +
0.34 * Math.sin(x * 0.27 - z * 0.08);
const beach = 0.24 + Math.sin(x * 0.16) * 0.035;
return beach + duneMix * duneShape;
}
function shoreZ(x) {
return 24 + Math.sin(x * 0.14) * 1.15 + Math.sin(x * 0.31) * 0.48;
}
// -------------------------------------------------------------------------
// Lighting and sky
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0x6f91ad, 0x75644c, 1.15);
scene.add(hemisphere);
const moonlight = new THREE.DirectionalLight(0xc5dcff, 2.15);
moonlight.position.set(18, 31, -25);
moonlight.castShadow = true;
moonlight.shadow.mapSize.set(2048, 2048);
moonlight.shadow.camera.left = -43;
moonlight.shadow.camera.right = 43;
moonlight.shadow.camera.top = 43;
moonlight.shadow.camera.bottom = -43;
moonlight.shadow.camera.near = 1;
moonlight.shadow.camera.far = 100;
moonlight.shadow.bias = -0.00045;
moonlight.shadow.normalBias = 0.025;
scene.add(moonlight);
const rimLight = new THREE.DirectionalLight(0x395f82, 0.65);
rimLight.position.set(-25, 12, 24);
scene.add(rimLight);
const moon = new THREE.Mesh(
new THREE.IcosahedronGeometry(3.15, 3),
new THREE.MeshStandardMaterial({
color: 0xf1e5bd,
emissive: 0xcbbd8b,
emissiveIntensity: 1.1,
roughness: 1
})
);
moon.position.set(20, 29, -43);
scene.add(moon);
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128, 128, 8, 128, 128, 128
);
gradient.addColorStop(0, "rgba(238,230,190,0.65)");
gradient.addColorStop(0.22, "rgba(214,224,205,0.22)");
gradient.addColorStop(0.55, "rgba(153,192,203,0.07)");
gradient.addColorStop(1, "rgba(153,192,203,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
return new THREE.CanvasTexture(canvas);
}
const moonHalo = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeGlowTexture(),
transparent: true,
opacity: 0.8,
depthWrite: false,
blending: THREE.AdditiveBlending,
fog: false
})
);
moonHalo.position.copy(moon.position);
moonHalo.scale.set(14, 14, 1);
scene.add(moonHalo);
const starPositions = [];
for (let i = 0; i < 520; i++) {
const angle = random() * Math.PI * 2;
const y = 12 + random() * 68;
const radius = 70 + random() * 42;
starPositions.push(
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xc5d8e8,
size: 0.22,
transparent: true,
opacity: 0.75,
depthWrite: false,
fog: false
})
);
scene.add(stars);
// -------------------------------------------------------------------------
// Beach terrain
// -------------------------------------------------------------------------
const terrainGeometry = new THREE.PlaneGeometry(90, 60, 90, 60);
terrainGeometry.rotateX(-Math.PI / 2);
terrainGeometry.translate(0, 0, -5);
const terrainPosition = terrainGeometry.attributes.position;
const terrainColors = [];
const lowSand = new THREE.Color(0xb5a382);
const highSand = new THREE.Color(0x8d826f);
const wetSand = new THREE.Color(0x6f746e);
const color = new THREE.Color();
for (let i = 0; i < terrainPosition.count; i++) {
const x = terrainPosition.getX(i);
const z = terrainPosition.getZ(i);
const y = terrainHeight(x, z);
terrainPosition.setY(i, y);
color.copy(lowSand).lerp(highSand, smoothstep(0.5, 3.4, y));
color.lerp(wetSand, smoothstep(17, 24, z) * 0.7);
color.multiplyScalar(0.95 + Math.sin(x * 0.27 + z * 0.31) * 0.035);
terrainColors.push(color.r, color.g, color.b);
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0
})
);
terrain.receiveShadow = true;
scene.add(terrain);
const duneMaterial = new THREE.MeshStandardMaterial({
color: 0x978b75,
roughness: 1,
flatShading: true
});
const duneForms = [
[-27, -20, 8, 2.5, 5],
[-8, -25, 10, 2.9, 5.5],
[14, -23, 11, 2.6, 6],
[31, -18, 7, 2.2, 5],
[-39, -8, 7, 1.8, 5]
];
for (const [x, z, sx, sy, sz] of duneForms) {
const mound = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 2),
duneMaterial
);
mound.position.set(x, terrainHeight(x, z) - 0.55, z);
mound.scale.set(sx, sy, sz);
mound.rotation.y = random() * Math.PI;
mound.castShadow = true;
mound.receiveShadow = true;
scene.add(mound);
}
// -------------------------------------------------------------------------
// Stylized ocean
// -------------------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(120, 80, 60, 24);
waterGeometry.rotateX(-Math.PI / 2);
waterGeometry.translate(0, 0, 65);
const waterPosition = waterGeometry.attributes.position;
for (let i = 0; i < waterPosition.count; i++) {
const x = waterPosition.getX(i);
const localZ = waterPosition.getZ(i);
const t = clamp((localZ + 40) / 80, 0, 1);
const boundary = shoreZ(x);
const z = lerp(boundary, 104, t);
waterPosition.setXYZ(i, x, -0.28, z);
}
waterGeometry.computeVertexNormals();
const waterBase = new Float32Array(
waterPosition.array
);
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
color: 0x123a50,
roughness: 0.36,
metalness: 0.18,
side: THREE.DoubleSide
})
);
water.receiveShadow = true;
scene.add(water);
function makeFoam(offset, opacity, radius) {
const points = [];
for (let x = -59; x <= 59; x += 2) {
points.push(
new THREE.Vector3(
x,
-0.12,
shoreZ(x) + offset + Math.sin(x * 0.22) * 0.15
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const material = new THREE.MeshBasicMaterial({
color: 0xc6d9d8,
transparent: true,
opacity,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 190, radius, 5, false),
material
);
scene.add(mesh);
return mesh;
}
const foamA = makeFoam(0.15, 0.72, 0.085);
const foamB = makeFoam(1.6, 0.26, 0.055);
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0x537f91,
transparent: true,
opacity: 0.26,
depthWrite: false
});
const waveMarks = [];
for (let i = 0; i < 24; i++) {
const mark = new THREE.Mesh(
new THREE.BoxGeometry(3 + random() * 7, 0.025, 0.07),
waveMaterial
);
mark.position.set(
-48 + random() * 96,
-0.13,
31 + random() * 60
);
mark.rotation.y = (random() - 0.5) * 0.15;
mark.userData.baseZ = mark.position.z;
mark.userData.speed = 0.25 + random() * 0.45;
scene.add(mark);
waveMarks.push(mark);
}
// -------------------------------------------------------------------------
// Coastal plants and rocks
// -------------------------------------------------------------------------
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x4c4032,
roughness: 1,
flatShading: true
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x294a43,
roughness: 0.92,
flatShading: true
});
const leafLightMaterial = new THREE.MeshStandardMaterial({
color: 0x3b5d50,
roughness: 0.95,
flatShading: true
});
function addPalm(x, z, height, scale = 1) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z), z);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.31, height, 7),
trunkMaterial
);
trunk.position.y = height * 0.5;
trunk.rotation.z = (random() - 0.5) * 0.14;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Group();
crown.position.set(0, height, 0);
group.add(crown);
for (let i = 0; i < 7; i++) {
const angle = i / 7 * Math.PI * 2 + random() * 0.22;
const direction = new THREE.Vector3(
Math.cos(angle),
-0.12 - random() * 0.25,
Math.sin(angle)
).normalize();
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.55, 4.9, 5),
i % 2 ? leafMaterial : leafLightMaterial
);
leaf.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
leaf.position.copy(direction).multiplyScalar(2.2);
leaf.castShadow = true;
crown.add(leaf);
}
group.scale.setScalar(scale);
scene.add(group);
}
addPalm(-34, -18, 7.4, 1.05);
addPalm(-27, -25, 8.2, 1.12);
addPalm(29, -20, 7.0, 0.95);
addPalm(37, -11, 5.7, 0.85);
addPalm(-43, -5, 6.1, 0.95);
const shrubGeometry = new THREE.IcosahedronGeometry(1, 1);
function addShrub(x, z, size = 1) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z), z);
for (let i = 0; i < 5; i++) {
const clump = new THREE.Mesh(
shrubGeometry,
i % 2 ? leafMaterial : leafLightMaterial
);
const angle = i / 5 * Math.PI * 2;
clump.position.set(
Math.cos(angle) * 0.55 * size,
(0.35 + random() * 0.65) * size,
Math.sin(angle) * 0.55 * size
);
clump.scale.set(
(0.65 + random() * 0.35) * size,
(0.55 + random() * 0.4) * size,
(0.65 + random() * 0.35) * size
);
clump.castShadow = true;
group.add(clump);
}
scene.add(group);
}
for (let i = 0; i < 17; i++) {
const x = -42 + random() * 84;
const z = -27 + random() * 17;
addShrub(x, z, 0.65 + random() * 0.8);
}
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x53674e,
roughness: 1,
flatShading: true
});
const grassGeometry = new THREE.ConeGeometry(0.075, 1.35, 4);
for (let i = 0; i < 90; i++) {
const x = -43 + random() * 86;
const z = -25 + random() * 15;
if (Math.abs(x + 18) < 7 && Math.abs(z + 14) < 3) continue;
const blade = new THREE.Mesh(grassGeometry, grassMaterial);
blade.position.set(
x,
terrainHeight(x, z) + 0.48,
z
);
blade.rotation.z = (random() - 0.5) * 0.7;
blade.rotation.x = (random() - 0.5) * 0.45;
blade.castShadow = true;
scene.add(blade);
}
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x4b5352,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 19; i++) {
const x = -38 + random() * 76;
const z = 18 + random() * 5;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.35 + random() * 0.65, 0),
rockMaterial
);
rock.position.set(x, terrainHeight(x, z) + 0.18, z);
rock.scale.y = 0.55 + random() * 0.4;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// Distant observation path
// -------------------------------------------------------------------------
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x4a3d32,
roughness: 0.95
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x292722,
roughness: 1
});
function beamBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 7),
material
);
beam.position.copy(a).add(b).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
beam.castShadow = true;
return beam;
}
const deck = new THREE.Group();
const deckX = -18;
const deckZ = -14;
deck.position.set(deckX, terrainHeight(deckX, deckZ) + 0.25, deckZ);
scene.add(deck);
const deckBase = new THREE.Mesh(
new THREE.BoxGeometry(12, 0.28, 2.8),
woodMaterial
);
deckBase.castShadow = true;
deckBase.receiveShadow = true;
deck.add(deckBase);
for (let i = -5; i <= 5; i++) {
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.012, 2.78),
darkWoodMaterial
);
seam.position.set(i * 1.02, 0.147, 0);
deck.add(seam);
}
for (const x of [-5.4, 5.4]) {
for (const z of [-1.05, 1.05]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 3.0, 0.19),
woodMaterial
);
post.position.set(x, -1.15, z);
post.castShadow = true;
deck.add(post);
}
}
for (const z of [-1.12, 1.12]) {
deck.add(beamBetween(
new THREE.Vector3(-5.5, 0.25, z),
new THREE.Vector3(5.5, 0.25, z),
0.07,
woodMaterial
));
for (const x of [-5.4, -2.7, 0, 2.7, 5.4]) {
const railPost = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 1.15, 0.12),
woodMaterial
);
railPost.position.set(x, 0.72, z);
railPost.castShadow = true;
deck.add(railPost);
}
}
function makeSignTexture(title, subtitle) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 384;
const context = canvas.getContext("2d");
context.fillStyle = "#172321";
context.fillRect(0, 0, 768, 384);
context.strokeStyle = "#c6b887";
context.lineWidth = 8;
context.strokeRect(18, 18, 732, 348);
context.textAlign = "center";
context.fillStyle = "#e7ddbd";
context.font = "600 49px Georgia";
context.fillText(title, 384, 153);
context.fillStyle = "#aeb9ad";
context.font = "600 24px sans-serif";
context.fillText(subtitle, 384, 228);
context.fillStyle = "#d2c493";
context.font = "19px sans-serif";
context.fillText("PLEASE KEEP TO THE PATH", 384, 292);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addSign(x, y, z, title, subtitle, width = 3.5) {
const group = new THREE.Group();
group.position.set(x, y, z);
const board = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.14, width * 0.52 + 0.14, 0.13),
woodMaterial
);
board.castShadow = true;
group.add(board);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.52),
new THREE.MeshBasicMaterial({
map: makeSignTexture(title, subtitle)
})
);
face.position.z = 0.075;
group.add(face);
scene.add(group);
return group;
}
addSign(
-12.3,
terrainHeight(-12.3, -12.2) + 1.6,
-12.2,
"OBSERVATION",
"DISTANT VIEWING AREA",
3.1
);
// Two very small, distant human silhouettes.
const observerMaterial = new THREE.MeshStandardMaterial({
color: 0x182323,
roughness: 1
});
for (const offset of [-0.65, 0.5]) {
const observer = new THREE.Group();
observer.position.set(offset, 0.2, -0.1);
const body = new THREE.Mesh(
new THREE.CapsuleGeometry(0.18, 0.55, 4, 7),
observerMaterial
);
body.position.y = 0.65;
observer.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 8, 6),
observerMaterial
);
head.position.y = 1.15;
observer.add(head);
deck.add(observer);
}
// -------------------------------------------------------------------------
// Turtle construction
// -------------------------------------------------------------------------
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0x344c3e,
roughness: 0.72,
flatShading: true
});
const shellLightMaterial = new THREE.MeshStandardMaterial({
color: 0x4d6450,
roughness: 0.76,
flatShading: true
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0x62705a,
roughness: 0.82,
flatShading: true
});
const hatchShellMaterial = new THREE.MeshStandardMaterial({
color: 0x4b5e4c,
roughness: 0.8,
flatShading: true
});
const eyeMaterial = new THREE.MeshBasicMaterial({ color: 0x090d0b });
function createTurtle(scale = 1, young = false) {
const turtle = new THREE.Group();
const shellMat = young ? hatchShellMaterial : shellMaterial;
const skinMat = young
? new THREE.MeshStandardMaterial({
color: 0x6c775d,
roughness: 0.85,
flatShading: true
})
: skinMaterial;
const body = new THREE.Mesh(
new THREE.SphereGeometry(1, 12, 8),
skinMat
);
body.scale.set(0.72, 0.34, 1.06);
body.position.y = 0.37;
body.castShadow = true;
turtle.add(body);
const shell = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 2),
shellMat
);
shell.position.y = 0.69;
shell.scale.set(1.2, 0.53, 1.35);
shell.castShadow = true;
shell.receiveShadow = true;
turtle.add(shell);
const plateGeometry = new THREE.CylinderGeometry(0.23, 0.25, 0.09, 6);
const plateLayout = [
[0, 1.19, 0.15],
[-0.38, 1.12, 0.45],
[0.38, 1.12, 0.45],
[-0.43, 1.05, -0.25],
[0.43, 1.05, -0.25],
[0, 1.18, -0.58]
];
for (const [x, y, z] of plateLayout) {
const plate = new THREE.Mesh(
plateGeometry,
young ? shellMat : shellLightMaterial
);
plate.position.set(x, y, z);
plate.scale.set(1, 1, 1.12);
plate.castShadow = true;
turtle.add(plate);
}
const head = new THREE.Group();
head.position.set(0, 0.44, 1.32);
const headMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.38, 10, 7),
skinMat
);
headMesh.scale.set(0.88, 0.78, 1.12);
headMesh.castShadow = true;
head.add(headMesh);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.052, 7, 5),
eyeMaterial
);
eye.position.set(side * 0.18, 0.09, 0.28);
head.add(eye);
}
turtle.add(head);
const flippers = [];
for (const side of [-1, 1]) {
const frontPivot = new THREE.Group();
frontPivot.position.set(side * 0.62, 0.32, 0.72);
const front = new THREE.Mesh(
new THREE.SphereGeometry(1, 10, 6),
skinMat
);
front.scale.set(0.78, 0.13, 0.39);
front.position.x = side * 0.38;
front.position.z = 0.08;
front.rotation.y = side * 0.2;
front.castShadow = true;
frontPivot.add(front);
turtle.add(frontPivot);
flippers.push(frontPivot);
const rearPivot = new THREE.Group();
rearPivot.position.set(side * 0.55, 0.29, -0.85);
const rear = new THREE.Mesh(
new THREE.SphereGeometry(1, 9, 6),
skinMat
);
rear.scale.set(0.43, 0.11, 0.27);
rear.position.x = side * 0.24;
rear.castShadow = true;
rearPivot.add(rear);
turtle.add(rearPivot);
flippers.push(rearPivot);
}
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.46, 5),
skinMat
);
tail.position.set(0, 0.28, -1.36);
tail.rotation.x = -Math.PI / 2;
turtle.add(tail);
turtle.scale.setScalar(scale);
turtle.userData.flippers = flippers;
turtle.userData.head = head;
turtle.userData.shell = shell;
return turtle;
}
function animateTurtle(turtle, t, intensity = 1) {
const flippers = turtle.userData.flippers;
flippers.forEach((flipper, index) => {
flipper.rotation.z =
Math.sin(t * 6.4 + index * Math.PI * 0.75) *
0.34 * intensity;
flipper.rotation.x =
Math.sin(t * 3.2 + index) * 0.08 * intensity;
});
}
const adult = createTurtle(1.18);
scene.add(adult);
const arrivalCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-10, 0, shoreZ(-10) - 1.1),
new THREE.Vector3(-9, 0, 17.4),
new THREE.Vector3(-5.4, 0, 12.3),
new THREE.Vector3(-1.4, 0, 8.0),
new THREE.Vector3(4.8, 0, 5.1)
]);
const exitCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(4.8, 0, 5.1),
new THREE.Vector3(9.2, 0, 2.8),
new THREE.Vector3(13.0, 0, -2.5),
new THREE.Vector3(18.8, 0, -10.7)
]);
// -------------------------------------------------------------------------
// Nest and eggs
// -------------------------------------------------------------------------
const nestX = 5;
const nestZ = 5;
const nestY = terrainHeight(nestX, nestZ);
const nest = new THREE.Group();
nest.position.set(nestX, nestY, nestZ);
scene.add(nest);
const patch = new THREE.Mesh(
new THREE.CircleGeometry(1.55, 40),
new THREE.MeshStandardMaterial({
color: 0x7e765f,
roughness: 1
})
);
patch.rotation.x = -Math.PI / 2;
patch.scale.set(1.25, 0.92, 1);
patch.position.y = 0.012;
patch.receiveShadow = true;
nest.add(patch);
const nestRing = new THREE.Mesh(
new THREE.TorusGeometry(1.03, 0.17, 6, 28),
new THREE.MeshStandardMaterial({
color: 0x9c8c6e,
roughness: 1,
flatShading: true
})
);
nestRing.rotation.x = Math.PI / 2;
nestRing.scale.y = 0.9;
nestRing.position.y = 0.06;
nestRing.castShadow = true;
nestRing.receiveShadow = true;
nest.add(nestRing);
const mound = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 2),
new THREE.MeshStandardMaterial({
color: 0xa08e6e,
roughness: 1,
flatShading: true
})
);
mound.position.y = -0.08;
mound.scale.set(0.1, 0.08, 0.1);
mound.receiveShadow = true;
nest.add(mound);
const eggGeometry = new THREE.SphereGeometry(0.13, 10, 8);
const eggMaterial = new THREE.MeshStandardMaterial({
color: 0xe6d7ad,
roughness: 0.78
});
const eggs = [];
for (let i = 0; i < 18; i++) {
const angle = i / 18 * Math.PI * 2 + (random() - 0.5) * 0.2;
const radius = 0.2 + random() * 0.58;
const egg = new THREE.Mesh(eggGeometry, eggMaterial);
egg.position.set(
Math.cos(angle) * radius,
0.1,
Math.sin(angle) * radius * 0.82
);
egg.scale.set(0.8, 1.12, 0.8);
egg.visible = false;
egg.castShadow = true;
nest.add(egg);
eggs.push(egg);
}
const sandParticles = [];
const particleGeometry = new THREE.IcosahedronGeometry(0.07, 0);
for (let i = 0; i < 18; i++) {
const particle = new THREE.Mesh(
particleGeometry,
new THREE.MeshStandardMaterial({
color: 0xad9a78,
roughness: 1,
flatShading: true
})
);
particle.visible = false;
nest.add(particle);
sandParticles.push(particle);
}
const shellFragments = [];
for (let i = 0; i < 12; i++) {
const fragment = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.08, 0),
eggMaterial
);
const angle = random() * Math.PI * 2;
const radius = 0.35 + random() * 1.15;
fragment.position.set(
Math.cos(angle) * radius,
0.08,
Math.sin(angle) * radius
);
fragment.scale.set(1, 0.25, 0.75);
fragment.visible = false;
nest.add(fragment);
shellFragments.push(fragment);
}
// -------------------------------------------------------------------------
// Hatchlings and their paths to the ocean
// -------------------------------------------------------------------------
const hatchlings = [];
for (let i = 0; i < 9; i++) {
const hatchling = createTurtle(0.21, true);
hatchling.visible = false;
scene.add(hatchling);
const lane = (i - 4) * 0.72;
const endX = 3 + lane + (random() - 0.5) * 1.5;
const path = new THREE.CatmullRomCurve3([
new THREE.Vector3(nestX + (random() - 0.5) * 0.5, 0, nestZ),
new THREE.Vector3(nestX + lane * 0.35, 0, nestZ + 2.5),
new THREE.Vector3(nestX + lane * 0.75, 0, 11.8),
new THREE.Vector3(endX * 0.75 + 2, 0, 17.2),
new THREE.Vector3(endX, 0, shoreZ(endX) - 0.25)
]);
hatchlings.push({
turtle: hatchling,
path,
spawn: 27.4 + i * 0.48,
end: 42.7 + i * 0.38
});
}
// -------------------------------------------------------------------------
// Rope boundary distinguishing the nesting area
// -------------------------------------------------------------------------
const stakeMaterial = new THREE.MeshStandardMaterial({
color: 0x5b4b39,
roughness: 1
});
const ropeMaterial = new THREE.MeshStandardMaterial({
color: 0xb3a27b,
roughness: 1
});
const barrierPoints = [
new THREE.Vector3(-0.2, 0, 2.6),
new THREE.Vector3(0.5, 0, -1.4),
new THREE.Vector3(5.0, 0, -2.5),
new THREE.Vector3(9.3, 0, -0.4),
new THREE.Vector3(10.1, 0, 3.4)
];
const barrierCurve = new THREE.CatmullRomCurve3(barrierPoints);
const rope = new THREE.Mesh(
new THREE.TubeGeometry(barrierCurve, 70, 0.035, 5, false),
ropeMaterial
);
scene.add(rope);
for (const point of barrierPoints) {
const stake = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 0.9, 7),
stakeMaterial
);
stake.position.set(
point.x,
terrainHeight(point.x, point.z) + 0.43,
point.z
);
stake.castShadow = true;
scene.add(stake);
}
addSign(
10.1,
terrainHeight(10.1, 4.6) + 1.25,
4.6,
"NESTING",
"KEEP TO THE BEACH",
2.55
);
// -------------------------------------------------------------------------
// Sequence definition
// -------------------------------------------------------------------------
const DURATION = 56;
const phases = [
{
start: 0,
end: 11,
kicker: "01 / Arrival",
title: "Beyond the breakers",
description:
"The adult turtle follows the reflected moon toward the nesting beach."
},
{
start: 11,
end: 20,
kicker: "02 / Nesting",
title: "A chamber in the sand",
description:
"She digs a deep chamber and lays a small clutch beneath the moon."
},
{
start: 20,
end: 27,
kicker: "03 / Covering",
title: "The sand returns",
description:
"Loose sand is swept back over the eggs, leaving only a quiet mound."
},
{
start: 27,
end: 38,
kicker: "04 / Hatching",
title: "The first small shells",
description:
"Hatchlings break through together, beginning their dash toward the sea."
},
{
start: 38,
end: 50,
kicker: "05 / Return",
title: "Into the moonlit water",
description:
"The young turtles cross the open beach and disappear into the surf."
},
{
start: 50,
end: 56,
kicker: "06 / Quiet",
title: "Only the beach remains",
description:
"The nesting ground settles back into darkness as the tide continues."
}
];
const phaseElements = [...document.querySelectorAll("#timeline-labels span")];
const phaseKicker = document.getElementById("phase-kicker");
const phaseTitle = document.getElementById("phase-title");
const phaseDescription = document.getElementById("phase-description");
const progress = document.getElementById("progress");
const timeLabel = document.getElementById("time-label");
const fade = document.getElementById("fade");
let currentPhase = -1;
function setPhase(index) {
if (index === currentPhase) return;
currentPhase = index;
const phase = phases[index];
phaseKicker.textContent = phase.kicker;
phaseTitle.textContent = phase.title;
phaseDescription.textContent = phase.description;
phaseElements.forEach((element, i) => {
element.classList.toggle("active", i === index);
});
}
function setTurtleOnCurve(turtle, curve, progress, bob = 0) {
const point = curve.getPointAt(clamp(progress, 0, 1));
const tangent = curve.getTangentAt(clamp(progress, 0, 1));
turtle.position.set(
point.x,
terrainHeight(point.x, point.z) + bob,
point.z
);
turtle.rotation.y = Math.atan2(tangent.x, tangent.z);
}
function updateSequence(time) {
const phaseIndex = phases.findIndex(
phase => time >= phase.start && time < phase.end
);
setPhase(phaseIndex < 0 ? phases.length - 1 : phaseIndex);
// Adult arrival.
if (time < 11) {
const progress = time / 11;
setTurtleOnCurve(
adult,
arrivalCurve,
progress,
Math.sin(time * 7) * 0.025
);
animateTurtle(adult, time, 1);
adult.userData.head.rotation.x = 0;
} else {
// The adult settles over the nest.
adult.position.set(
nestX - 0.05,
nestY,
nestZ + 0.05
);
adult.rotation.y = -0.82;
}
// Digging and egg laying.
if (time >= 11 && time < 27) {
const digging = smoothstep(11, 13, time) *
(1 - smoothstep(19.5, 21, time));
adult.position.y = nestY - digging * 0.14;
adult.userData.head.rotation.x =
Math.sin(time * 1.7) * digging * 0.34;
animateTurtle(
adult,
time,
time < 20 ? 0.9 : 0.35
);
const layingProgress = clamp((time - 11.6) / 7.2, 0, 1);
eggs.forEach((egg, index) => {
const threshold = index / eggs.length;
const reveal = smoothstep(threshold, threshold + 0.08, layingProgress);
const covered = 1 - smoothstep(20.2, 24.1, time);
egg.visible = reveal > 0.01 && covered > 0.01;
egg.scale.set(
0.8 * reveal,
1.12 * reveal * covered,
0.8 * reveal
);
egg.position.y = 0.1 - (1 - covered) * 0.08;
});
} else {
eggs.forEach(egg => { egg.visible = false; });
}
// Covering mound.
const moundAmount =
0.1 +
smoothstep(20, 24.5, time) * 0.9 -
smoothstep(32, 38, time) * 0.62;
mound.scale.set(
Math.max(0.1, moundAmount * 1.12),
Math.max(0.08, moundAmount * 0.43),
Math.max(0.1, moundAmount * 0.92)
);
mound.position.y = -0.08 + moundAmount * 0.035;
// The adult returns toward the dunes.
if (time >= 27) {
const departure = smoothstep(27, 35, time);
setTurtleOnCurve(adult, exitCurve, departure);
animateTurtle(adult, time * 0.65, departure < 0.95 ? 0.65 : 0.08);
}
// Sand particles during excavation.
sandParticles.forEach((particle, index) => {
const active = time > 11.5 && time < 20.5;
particle.visible = active;
if (active) {
const localTime = (time - 11.5) * 2.4 + index * 0.73;
const angle = index * 2.399;
const radius = 0.55 + (localTime % 1.3) * 0.75;
particle.position.set(
Math.cos(angle) * radius,
0.12 + Math.max(0, Math.sin(localTime)) * 0.45,
Math.sin(angle) * radius * 0.8
);
particle.scale.setScalar(0.7 + Math.sin(localTime) * 0.25);
}
});
// Broken shell fragments after hatching.
shellFragments.forEach((fragment, index) => {
fragment.visible = time > 29 + index * 0.35;
});
// Hatchling emergence and movement.
hatchlings.forEach((hatchling, index) => {
const { turtle, path, spawn, end } = hatchling;
if (time < spawn) {
turtle.visible = false;
return;
}
turtle.visible = true;
const emergence = smoothstep(spawn, spawn + 1.55, time);
const movement = clamp((time - (spawn + 1.3)) / (end - spawn - 1.3), 0, 1);
if (movement <= 0) {
turtle.position.set(
nestX + (index - 4) * 0.07,
nestY + 0.05,
nestZ
);
turtle.rotation.y = Math.PI;
} else {
setTurtleOnCurve(
turtle,
path,
movement,
Math.sin(time * 10 + index) * 0.018
);
}
turtle.scale.setScalar(0.01 + emergence * 0.20);
animateTurtle(turtle, time + index * 0.4, emergence);
if (time > end + 2.8) {
turtle.visible = false;
}
});
// UI progress.
const percent = clamp(time / DURATION, 0, 1) * 100;
progress.style.width = `${percent}%`;
const seconds = Math.floor(time);
timeLabel.textContent =
`00:${String(seconds).padStart(2, "0")} / 00:56`;
// Brief fade hides the loop reset.
const fadeOpacity =
time < 1.1
? 1 - smoothstep(0, 1.1, time)
: smoothstep(DURATION - 1.2, DURATION, time);
fade.style.opacity = fadeOpacity.toFixed(3);
}
// -------------------------------------------------------------------------
// Camera controls, implemented directly without addons
// -------------------------------------------------------------------------
const orbit = {
theta: 0.64,
phi: 1.13,
radius: 58,
target: new THREE.Vector3(0, 1.2, -1.5),
desiredTheta: 0.64,
desiredPhi: 1.13,
desiredRadius: 58
};
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.desiredTheta -= deltaX * 0.0052;
orbit.desiredPhi = clamp(
orbit.desiredPhi - deltaY * 0.0042,
0.62,
1.43
);
});
function endDrag(event) {
dragging = false;
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();
orbit.desiredRadius = clamp(
orbit.desiredRadius * Math.exp(event.deltaY * 0.001),
28,
84
);
}, { passive: false });
const pressedKeys = new Set();
addEventListener("keydown", event => {
pressedKeys.add(event.key);
});
addEventListener("keyup", event => {
pressedKeys.delete(event.key);
});
function updateCamera(dt) {
if (pressedKeys.has("ArrowLeft")) {
orbit.desiredTheta += dt * 0.5;
}
if (pressedKeys.has("ArrowRight")) {
orbit.desiredTheta -= dt * 0.5;
}
if (pressedKeys.has("ArrowUp")) {
orbit.desiredPhi = clamp(orbit.desiredPhi - dt * 0.38, 0.62, 1.43);
}
if (pressedKeys.has("ArrowDown")) {
orbit.desiredPhi = clamp(orbit.desiredPhi + dt * 0.38, 0.62, 1.43);
}
const smoothing = 1 - Math.exp(-dt * 8);
orbit.theta = lerp(orbit.theta, orbit.desiredTheta, smoothing);
orbit.phi = lerp(orbit.phi, orbit.desiredPhi, smoothing);
orbit.radius = lerp(orbit.radius, orbit.desiredRadius, smoothing);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
// -------------------------------------------------------------------------
// UI controls and animation loop
// -------------------------------------------------------------------------
let cycleTime = 0;
let playing = true;
const toggleButton = document.getElementById("toggle");
const restartButton = document.getElementById("restart");
toggleButton.addEventListener("click", () => {
playing = !playing;
toggleButton.textContent = playing ? "Pause" : "Play";
});
restartButton.addEventListener("click", () => {
cycleTime = 0;
playing = true;
toggleButton.textContent = "Pause";
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
let waterNormalFrame = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const visualTime = clock.elapsedTime;
if (playing) {
cycleTime = (cycleTime + dt) % DURATION;
}
updateSequence(cycleTime);
updateCamera(dt);
// Gentle wave motion.
const position = waterGeometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const index = i * 3;
const x = waterBase[index];
const z = waterBase[index + 2];
const wave =
Math.sin(x * 0.12 + visualTime * 0.65) * 0.065 +
Math.cos(z * 0.16 - visualTime * 0.48) * 0.035;
position.setY(i, waterBase[index + 1] + wave);
}
position.needsUpdate = true;
waterNormalFrame++;
if (waterNormalFrame % 8 === 0) {
waterGeometry.computeVertexNormals();
}
foamA.material.opacity = 0.62 + Math.sin(visualTime * 0.8) * 0.1;
foamB.material.opacity = 0.2 + Math.sin(visualTime * 0.65 + 1.2) * 0.07;
waveMarks.forEach(mark => {
mark.position.z = mark.userData.baseZ +
Math.sin(visualTime * mark.userData.speed) * 1.4;
mark.position.y = -0.11 + Math.sin(visualTime * 0.7 + mark.position.x) * 0.02;
});
stars.material.opacity = 0.7 + Math.sin(visualTime * 0.45) * 0.08;
moonHalo.material.opacity = 0.74 + Math.sin(visualTime * 0.55) * 0.07;
renderer.render(scene, camera);
}
updateSequence(0);
animate();
</script>
</body>
</html>
```