Back to the app
The code
Swim the Kelp Garden by Claude Haiku 5.5
Exactly as the AI wrote it. Shown as text, so nothing runs on this page.
index.html
works · auto-checked (Checked by an automated pass. Not hand-played yet.)<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Kelp Garden Swim</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#0b4a63;font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}
canvas{position:fixed;inset:0;z-index:0;display:block;touch-action:none}
#hint{position:fixed;top:18px;left:0;right:0;z-index:5;text-align:center;color:#ffe2a0;font-size:17px;text-shadow:0 1px 8px #052536;pointer-events:none;opacity:1;transition:opacity 1.2s}
#demoTag{position:fixed;left:16px;top:16px;z-index:5;color:#ffd27a;font-size:14px;letter-spacing:.12em;display:none;pointer-events:none;text-shadow:0 1px 6px #052536}
#reset{position:fixed;right:16px;bottom:16px;z-index:10;min-width:132px;min-height:64px;padding:0 22px;border:0;border-radius:18px;background:#e0823a;color:#fff6e4;font-size:20px;font-weight:600;box-shadow:0 4px 16px rgba(0,0,0,.35);cursor:pointer;touch-action:manipulation}
#reset:active{transform:scale(.96)}
#fade{position:fixed;inset:0;z-index:20;background:#031a2a;opacity:0;pointer-events:none;transition:opacity .4s}
</style>
</head>
<body>
<div id="hint">Press and hold to glide ahead · drag to turn</div>
<div id="demoTag">DEMO</div>
<button id="reset" type="button">Reset</button>
<div id="fade"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
(function () {
const TAU = Math.PI * 2;
const rnd = (a, b) => a + Math.random() * (b - a);
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
// ---------- Renderer / scene ----------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.insertBefore(renderer.domElement, document.body.firstChild);
const cv = renderer.domElement;
cv.style.zIndex = '0';
const scene = new THREE.Scene();
const WATER = 0x0b4a63;
scene.background = new THREE.Color(WATER);
scene.fog = new THREE.FogExp2(WATER, 0.011);
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 400);
scene.add(new THREE.HemisphereLight(0x8ff0e6, 0x0a2a44, 0.8));
const sun = new THREE.DirectionalLight(0xffdc8c, 0.9);
sun.position.set(0.3, 1, 0.2);
scene.add(sun);
// ---------- Caustic texture (light ripples, tileable) ----------
function makeCaustic() {
const N = 256;
const c = document.createElement('canvas');
c.width = c.height = N;
const g = c.getContext('2d');
const img = g.createImageData(N, N);
const d = img.data;
for (let y = 0; y < N; y++) {
for (let x = 0; x < N; x++) {
const u = (x / N) * TAU, v = (y / N) * TAU;
const a = Math.sin(3 * u + 2 * Math.sin(2 * v)) + Math.sin(2 * v + 1.5 * Math.sin(3 * u)) + 0.5 * Math.sin(5 * u + 4 * v + 0.7);
const w = Math.pow(0.5 + 0.5 * Math.cos(a * 2.2), 8);
const val = Math.round(255 * (0.7 + 0.3 * w));
const i = (y * N + x) * 4;
d[i] = d[i + 1] = d[i + 2] = val;
d[i + 3] = 255;
}
}
g.putImageData(img, 0, 0);
const t = new THREE.CanvasTexture(c);
t.wrapS = t.wrapT = THREE.RepeatWrapping;
return t;
}
// ---------- Terrain (sand) ----------
function groundY(x, z) {
return -20 + 3.2 * Math.sin(x * 0.045 + 1.3) * Math.cos(z * 0.038) +
1.8 * Math.sin(x * 0.11 - z * 0.09) + 2.2 * Math.cos(z * 0.07 + 0.5);
}
const sandTex = makeCaustic();
sandTex.repeat.set(12, 12);
const terrainGeo = new THREE.PlaneGeometry(440, 440, 110, 110);
terrainGeo.rotateX(-Math.PI / 2);
const tp = terrainGeo.attributes.position;
for (let i = 0; i < tp.count; i++) tp.setY(i, groundY(tp.getX(i), tp.getZ(i)));
terrainGeo.computeVertexNormals();
const terrain = new THREE.Mesh(terrainGeo, new THREE.MeshLambertMaterial({ color: 0xd9ae62, map: sandTex }));
scene.add(terrain);
// ---------- Sea surface with rippling light ----------
const surfTex = makeCaustic();
surfTex.repeat.set(4, 4);
const surface = new THREE.Mesh(
new THREE.PlaneGeometry(700, 700).rotateX(-Math.PI / 2),
new THREE.MeshBasicMaterial({ map: surfTex, color: 0x9fe7e2, transparent: true, opacity: 0.22, depthWrite: false, side: THREE.DoubleSide })
);
surface.position.y = 38;
scene.add(surface);
// ---------- Sunbeams ----------
const beams = [];
for (let i = 0; i < 10; i++) {
const mat = new THREE.MeshBasicMaterial({
color: 0xffd27a, transparent: true, opacity: 0.08, depthWrite: false,
blending: THREE.AdditiveBlending, side: THREE.DoubleSide
});
const g = new THREE.Group();
g.position.set(rnd(-110, 110), 0, rnd(-110, 110));
g.rotation.set(0, rnd(0, TAU), 0.3);
const m = new THREE.Mesh(new THREE.PlaneGeometry(rnd(5, 11), 70), mat);
m.position.y = 8;
g.add(m);
scene.add(g);
beams.push({ mat, ph: rnd(0, TAU) });
}
// ---------- Kelp (hierarchical segments that sway) ----------
const kelpGeo = new THREE.CylinderGeometry(0.14, 0.22, 1, 5);
kelpGeo.translate(0, 0.5, 0);
const kelpMats = [0x3f8a3a, 0x2e6e3a, 0x5a9a3f].map(c => new THREE.MeshLambertMaterial({ color: c }));
const kelps = [];
const START = { x: 0, y: 14, z: 70 };
for (let k = 0; k < 50; k++) {
const x = rnd(-150, 150), z = rnd(-150, 150);
if (Math.hypot(x - START.x, z - START.z) < 20) continue;
const root = new THREE.Group();
root.position.set(x, groundY(x, z), z);
scene.add(root);
const H = rnd(22, 32), N = 8, sh = H / N;
const mat = kelpMats[k % 3];
let parent = root;
const segs = [];
for (let i = 0; i < N; i++) {
const seg = new THREE.Group();
seg.position.y = i === 0 ? 0 : sh;
parent.add(seg);
const m = new THREE.Mesh(kelpGeo, mat);
m.scale.set(1, sh, 1);
seg.add(m);
segs.push(seg);
parent = seg;
}
kelps.push({ segs, ph: rnd(0, TAU) });
}
// ---------- Rocks, arches, colliders ----------
const colliders = [];
const PLAYER_R = 1.0;
const rockGeo = new THREE.DodecahedronGeometry(1, 0);
const rockMat = new THREE.MeshLambertMaterial({ color: 0x2c6a7a, flatShading: true });
const rockMat2 = new THREE.MeshLambertMaterial({ color: 0x1b3f66, flatShading: true });
function addRock(x, z, s) {
const m = new THREE.Mesh(rockGeo, Math.random() < 0.5 ? rockMat : rockMat2);
m.scale.set(s * rnd(0.8, 1.3), s, s * rnd(0.8, 1.3));
m.position.set(x, groundY(x, z) + s * 0.2, z);
m.rotation.set(rnd(0, 3), rnd(0, 3), rnd(0, 3));
scene.add(m);
colliders.push({ c: new THREE.Vector3(x, groundY(x, z) + s * 0.4, z), r: s * 0.85 });
}
for (let i = 0; i < 40; i++) {
const x = rnd(-150, 150), z = rnd(-150, 150);
if (Math.hypot(x - START.x, z - START.z) < 14) continue;
addRock(x, z, rnd(2, 6));
}
function addArch(x, z, ang, s) {
const g = new THREE.Group();
g.position.set(x, groundY(x, z), z);
g.rotation.y = ang;
scene.add(g);
const pl = new THREE.Mesh(rockGeo, rockMat2);
const pr = new THREE.Mesh(rockGeo, rockMat2);
const top = new THREE.Mesh(rockGeo, rockMat);
pl.scale.set(3 * s, 8 * s, 3 * s); pl.position.set(-6 * s, 6 * s, 0);
pr.scale.set(3 * s, 8 * s, 3 * s); pr.position.set(6 * s, 6 * s, 0);
top.scale.set(9 * s, 2.6 * s, 3.2 * s); top.position.set(0, 13 * s, 0);
g.add(pl, pr, top);
g.updateMatrixWorld(true);
const spots = [
[-6 * s, 1 * s, 0, 3.3 * s], [-6 * s, 6 * s, 0, 3.3 * s], [-6 * s, 11 * s, 0, 3.3 * s],
[6 * s, 1 * s, 0, 3.3 * s], [6 * s, 6 * s, 0, 3.3 * s], [6 * s, 11 * s, 0, 3.3 * s],
[-4 * s, 13 * s, 0, 2.8 * s], [4 * s, 13 * s, 0, 2.8 * s], [0, 13 * s, 0, 3.2 * s]
];
for (const [px, py, pz, r] of spots) {
const v = new THREE.Vector3(px, py, pz).applyMatrix4(g.matrixWorld);
colliders.push({ c: v, r: r });
}
}
addArch(-70, -30, 0.4, 1.4);
addArch(60, -20, 1.2, 1.2);
addArch(10, -110, -0.3, 1.6);
// ---------- Sunken wooden ship ----------
const ship = new THREE.Group();
ship.position.set(-35, groundY(-35, -45) + 0.8, -45);
ship.rotation.set(0.08, 0.6, 0.22);
scene.add(ship);
const hullGeo = new THREE.BoxGeometry(18, 4, 7, 6, 1, 2);
const hp = hullGeo.attributes.position;
for (let i = 0; i < hp.count; i++) {
const x = hp.getX(i);
const f = x > 0 ? 1 - 0.55 * (x / 9) : 1;
hp.setZ(i, hp.getZ(i) * f);
if (x > 0) hp.setY(i, hp.getY(i) + (x / 9) * 1.2);
}
hullGeo.computeVertexNormals();
const hull = new THREE.Mesh(hullGeo, new THREE.MeshLambertMaterial({ color: 0xd9702e, flatShading: true }));
ship.add(hull);
const deck = new THREE.Mesh(new THREE.BoxGeometry(16, 0.5, 6), new THREE.MeshLambertMaterial({ color: 0xd7a441 }));
deck.position.y = 2.3;
ship.add(deck);
const mast = new THREE.Mesh(new THREE.CylinderGeometry(0.22, 0.28, 16, 6), new THREE.MeshLambertMaterial({ color: 0xe0b048 }));
mast.position.set(0, 10, 0);
ship.add(mast);
const sail = new THREE.Mesh(new THREE.PlaneGeometry(7, 8), new THREE.MeshLambertMaterial({ color: 0xe9c46a, side: THREE.DoubleSide }));
sail.position.set(0.3, 10, 0);
sail.rotation.y = Math.PI / 2;
ship.add(sail);
ship.updateMatrixWorld(true);
[[-7, 0.5, 0, 3.4], [-3, 0.5, 0, 3.4], [1, 0.5, 0, 3.4], [5, 0.8, 0, 3.0], [0, 6, 0, 2.5], [0, 9, 0, 4]].forEach(([x, y, z, r]) => {
colliders.push({ c: new THREE.Vector3(x, y, z).applyMatrix4(ship.matrixWorld), r: r });
});
// ---------- Coral (warm orange, decorative) ----------
const coralMat = new THREE.MeshLambertMaterial({ color: 0xe8702f });
const coralTipMat = new THREE.MeshLambertMaterial({ color: 0xf2b04a });
const branchGeo = new THREE.CylinderGeometry(0.12, 0.3, 1, 5);
branchGeo.translate(0, 0.5, 0);
const tipGeo = new THREE.SphereGeometry(0.35, 6, 5);
for (let c = 0; c < 22; c++) {
const x = rnd(-140, 140), z = rnd(-140, 140);
if (Math.hypot(x - START.x, z - START.z) < 12) continue;
const g = new THREE.Group();
g.position.set(x, groundY(x, z), z);
scene.add(g);
for (let b = 0; b < 4; b++) {
const h = rnd(1.5, 3.5);
const m = new THREE.Mesh(branchGeo, coralMat);
m.scale.set(1, h, 1);
const bx = rnd(-0.8, 0.8), bz = rnd(-0.8, 0.8);
m.position.set(bx, 0, bz);
m.rotation.set(rnd(-0.5, 0.5), rnd(0, TAU), rnd(-0.5, 0.5));
g.add(m);
const tip = new THREE.Mesh(tipGeo, coralTipMat);
tip.position.set(bx, h, bz);
g.add(tip);
}
}
// ---------- Manta rays ----------
const mantaShape = new THREE.Shape();
mantaShape.moveTo(0, -2.5);
mantaShape.quadraticCurveTo(3.4, -1.2, 4.2, 0.5);
mantaShape.quadraticCurveTo(3.0, 1.8, 0.8, 2.8);
mantaShape.lineTo(0, 2.2);
mantaShape.lineTo(-0.8, 2.8);
mantaShape.quadraticCurveTo(-3.0, 1.8, -4.2, 0.5);
mantaShape.quadraticCurveTo(-3.4, -1.2, 0, -2.5);
const mantaGeo = new THREE.ShapeGeometry(mantaShape, 8);
mantaGeo.rotateX(-Math.PI / 2);
const mantaMat = new THREE.MeshLambertMaterial({ color: 0x17607a, side: THREE.DoubleSide });
const mantas = [];
for (let i = 0; i < 4; i++) {
const m = new THREE.Mesh(mantaGeo, mantaMat);
m.scale.setScalar(rnd(1.4, 2));
scene.add(m);
const w = rnd(0.08, 0.14) * (i % 2 ? 1 : -1);
mantas.push({ m, cx: rnd(-60, 60), cz: rnd(-60, 60), R: rnd(55, 100), y0: rnd(10, 22), w, ph: rnd(0, TAU) });
}
// ---------- Fish schools (boid-like) ----------
const FISH_PER = 24;
const schoolColors = [0xe9b44c, 0xe2713a, 0x2fb5a8];
const fishGeo = new THREE.ConeGeometry(0.45, 2, 5);
fishGeo.rotateX(Math.PI / 2);
const fishMesh = new THREE.InstancedMesh(fishGeo, new THREE.MeshLambertMaterial({ color: 0xffffff }), FISH_PER * 3);
const fishCol = new THREE.Color();
const schools = [];
let fidx = 0;
for (let s = 0; s < 3; s++) {
const sc = {
cx: rnd(-60, 60), cz: rnd(-60, 60), R: rnd(40, 70), y0: rnd(14, 24),
w: rnd(0.05, 0.09) * (s % 2 ? 1 : -1), ph: rnd(0, TAU), fish: []
};
fishCol.setHex(schoolColors[s]);
for (let f = 0; f < FISH_PER; f++) {
const p = { x: sc.cx + rnd(-6, 6), y: sc.y0 + rnd(-2, 2), z: sc.cz + rnd(-6, 6) };
const v = { x: rnd(-1, 1), y: rnd(-0.2, 0.2), z: rnd(-1, 1) };
sc.fish.push({ p, v });
fishMesh.setColorAt(fidx++, fishCol);
}
schools.push(sc);
}
scene.add(fishMesh);
const fdummy = new THREE.Object3D();
function updateFish(dt, t) {
let idx = 0;
for (const sc of schools) {
const a = sc.ph + t * sc.w;
const cxT = sc.cx + sc.R * Math.cos(a);
const cyT = sc.y0 + Math.sin(t * 0.4 + sc.ph) * 3;
const czT = sc.cz + sc.R * Math.sin(a);
let ax0 = 0, ay0 = 0, az0 = 0, vx0 = 0, vy0 = 0, vz0 = 0;
for (const f of sc.fish) {
ax0 += f.p.x; ay0 += f.p.y; az0 += f.p.z;
vx0 += f.v.x; vy0 += f.v.y; vz0 += f.v.z;
}
const n = sc.fish.length;
ax0 /= n; ay0 /= n; az0 /= n; vx0 /= n; vy0 /= n; vz0 /= n;
for (const f of sc.fish) {
let ax = (cxT - f.p.x) * 0.08 + (ax0 - f.p.x) * 0.05 + (vx0 - f.v.x) * 0.6;
let ay = (cyT - f.p.y) * 0.08 + (ay0 - f.p.y) * 0.05 + (vy0 - f.v.y) * 0.6;
let az = (czT - f.p.z) * 0.08 + (az0 - f.p.z) * 0.05 + (vz0 - f.v.z) * 0.6;
for (const g of sc.fish) {
if (g === f) continue;
const dx = f.p.x - g.p.x, dy = f.p.y - g.p.y, dz = f.p.z - g.p.z;
const l2 = dx * dx + dy * dy + dz * dz;
if (l2 < 9 && l2 > 0.0001) {
ax += dx * (4 / l2); ay += dy * (4 / l2); az += dz * (4 / l2);
}
}
for (const c of colliders) {
const dx = f.p.x - c.c.x, dy = f.p.y - c.c.y, dz = f.p.z - c.c.z;
const d = Math.sqrt(dx * dx + dy * dy + dz * dz) || 0.0001;
const lim = c.r + 4;
if (d < lim) {
const k = (lim - d) * 6 / d;
ax += dx * k; ay += dy * k; az += dz * k;
}
}
const gy = groundY(f.p.x, f.p.z);
if (f.p.y < gy + 4) ay += (gy + 4 - f.p.y) * 4;
if (f.p.y > 30) ay -= (f.p.y - 30) * 2;
f.v.x += ax * dt; f.v.y += ay * dt; f.v.z += az * dt;
const sp = Math.hypot(f.v.x, f.v.y, f.v.z) || 0.0001;
const target = clamp(sp, 3, 7);
f.v.x *= target / sp; f.v.y *= target / sp; f.v.z *= target / sp;
f.p.x += f.v.x * dt; f.p.y += f.v.y * dt; f.p.z += f.v.z * dt;
fdummy.position.set(f.p.x, f.p.y, f.p.z);
fdummy.scale.set(1, 1, 1);
fdummy.lookAt(f.p.x + f.v.x, f.p.y + f.v.y, f.p.z + f.v.z);
fdummy.updateMatrix();
fishMesh.setMatrixAt(idx++, fdummy.matrix);
}
}
fishMesh.instanceMatrix.needsUpdate = true;
}
// ---------- Bubbles ----------
const BUB = 140;
const bubMesh = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.2, 6, 5),
new THREE.MeshBasicMaterial({ color: 0xcff6ff, transparent: true, opacity: 0.5 }),
BUB
);
scene.add(bubMesh);
const bubs = [];
for (let i = 0; i < BUB; i++) {
bubs.push({ x: rnd(-140, 140), y: rnd(-20, 36), z: rnd(-140, 140), s: rnd(0.6, 1.6), sp: rnd(2, 4), ph: rnd(0, TAU) });
}
const bdummy = new THREE.Object3D();
// ---------- Player ----------
const player = { x: START.x, y: START.y, z: START.z, yaw: 0, pitch: 0 };
let holding = false, lastX = 0, lastY = 0;
let demo = window.location.hash === '#demo';
let demoT = 0;
const hint = document.getElementById('hint');
const demoTag = document.getElementById('demoTag');
const fadeEl = document.getElementById('fade');
const resetBtn = document.getElementById('reset');
if (demo) demoTag.style.display = 'block';
function resetPlayer() {
player.x = START.x; player.y = START.y; player.z = START.z;
player.yaw = 0; player.pitch = 0;
}
function endDemo() {
if (!demo) return;
demo = false;
holding = false;
demoTag.style.display = 'none';
fadeEl.style.opacity = '0';
hint.style.opacity = '0';
}
['pointerdown', 'touchstart', 'wheel', 'keydown'].forEach(ev =>
window.addEventListener(ev, endDemo, { capture: true, passive: true })
);
cv.addEventListener('pointerdown', e => {
e.preventDefault();
holding = true;
lastX = e.clientX; lastY = e.clientY;
hint.style.opacity = '0';
try { cv.setPointerCapture(e.pointerId); } catch (err) { /* ignore */ }
});
const release = () => { holding = false; };
cv.addEventListener('pointerup', release);
cv.addEventListener('pointercancel', release);
cv.addEventListener('lostpointercapture', release);
cv.addEventListener('pointermove', e => {
if (!holding || demo) return;
const dx = e.clientX - lastX, dy = e.clientY - lastY;
lastX = e.clientX; lastY = e.clientY;
player.yaw -= dx * 0.006;
player.pitch = clamp(player.pitch - dy * 0.004, -0.6, 0.6);
});
cv.addEventListener('contextmenu', e => e.preventDefault());
resetBtn.addEventListener('click', resetPlayer);
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------- Animation loop ----------
let last = performance.now();
let tt = 0;
let demoFadeTimer = null;
function frame(now) {
const dt = Math.min(0.05, (now - last) / 1000);
last = now;
tt += dt;
if (demo) {
demoT += dt;
holding = true;
if (demoT > 20) {
demoT = 0;
resetPlayer();
fadeEl.style.opacity = '1';
clearTimeout(demoFadeTimer);
demoFadeTimer = setTimeout(() => { if (demo) fadeEl.style.opacity = '0'; }, 400);
}
player.yaw = 0.9 * Math.sin(demoT * 0.45);
player.pitch = 0.15 * Math.sin(demoT * 0.3);
}
if (tt > 6) hint.style.opacity = '0';
// Movement while holding
if (holding) {
const cp = Math.cos(player.pitch);
const sp = (demo ? 6 : 9) * dt;
player.x += Math.sin(player.yaw) * cp * sp;
player.y += Math.sin(player.pitch) * sp;
player.z += -Math.cos(player.yaw) * cp * sp;
}
// Bounds
const rr = Math.hypot(player.x, player.z);
if (rr > 165) { player.x *= 165 / rr; player.z *= 165 / rr; }
// Solid objects: rocks, arches, ship can never be entered
for (let it = 0; it < 2; it++) {
for (const c of colliders) {
const dx = player.x - c.c.x, dy = player.y - c.c.y, dz = player.z - c.c.z;
const d = Math.sqrt(dx * dx + dy * dy + dz * dz) || 0.0001;
const min = c.r + PLAYER_R;
if (d < min) {
const k = (min - d) / d;
player.x += dx * k; player.y += dy * k; player.z += dz * k;
}
}
}
// Sand floor and surface limits
const floor = groundY(player.x, player.z) + 1.2;
if (player.y < floor) player.y = floor;
if (player.y > 34) player.y = 34;
// Camera
const cp2 = Math.cos(player.pitch);
camera.position.set(player.x, player.y + Math.sin(tt * 1.3) * 0.05, player.z);
camera.lookAt(
player.x + Math.sin(player.yaw) * cp2 * 10,
player.y + Math.sin(player.pitch) * 10,
player.z - Math.cos(player.yaw) * cp2 * 10
);
// Animate environment
sandTex.offset.x += dt * 0.012;
sandTex.offset.y += dt * 0.008;
surfTex.offset.x += dt * 0.01;
surfTex.offset.y -= dt * 0.006;
for (const b of beams) b.mat.opacity = 0.05 + 0.04 * Math.sin(tt * 0.7 + b.ph);
for (const k of kelps) {
const N = k.segs.length;
for (let i = 0; i < N; i++) {
const a = (i + 1) / N;
const s = k.segs[i];
s.rotation.z = Math.sin(tt * 0.9 + k.ph + i * 0.5) * 0.12 * a + 0.04 * a * Math.sin(tt * 0.2 + k.ph);
s.rotation.x = Math.cos(tt * 0.7 + k.ph * 1.7 + i * 0.4) * 0.08 * a;
}
}
for (const m of mantas) {
const a = m.ph + tt * m.w;
const sgn = Math.sign(m.w);
m.m.position.set(m.cx + m.R * Math.cos(a), m.y0 + Math.sin(tt * 0.6 + m.ph) * 1.2, m.cz + m.R * Math.sin(a));
const dx = -Math.sin(a) * sgn, dz = Math.cos(a) * sgn;
m.m.rotation.set(0, Math.atan2(dx, dz), Math.sin(tt * 1.6 + m.ph) * 0.08);
}
updateFish(dt, tt);
for (const b of bubs) {
b.y += b.sp * dt;
b.x += Math.sin(tt + b.ph) * 0.3 * dt;
if (b.y > 36) {
b.x = rnd(-140, 140); b.z = rnd(-140, 140);
b.y = groundY(b.x, b.z) + 1;
}
}
for (let i = 0; i < BUB; i++) {
const b = bubs[i];
bdummy.position.set(b.x, b.y, b.z);
bdummy.scale.setScalar(b.s);
bdummy.updateMatrix();
bubMesh.setMatrixAt(i, bdummy.matrix);
}
bubMesh.instanceMatrix.needsUpdate = true;
renderer.render(scene, camera);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
})();
</script>
</body>
</html>
