Back to the app
The code
Swim the Kelp Garden by GPT-6.1 Terra
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"><meta name="theme-color" content="#063c4a">
<title>Kelp Garden</title>
<style>
*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#052e3b;font-family:Georgia,serif;color:#f5edcf}canvas{display:block;width:100%;height:100%;touch-action:none}#overlay{position:absolute;inset:0;pointer-events:none;background:linear-gradient(180deg,rgba(2,37,45,.34),transparent 25%,transparent 72%,rgba(1,30,39,.4))}.top{position:absolute;top:0;left:0;right:0;padding:clamp(22px,4vw,44px);display:flex;justify-content:space-between;align-items:flex-start;gap:20px}.brand{font-size:11px;letter-spacing:.25em;text-transform:uppercase;font-family:Arial,sans-serif;color:#d8e9c5}.brand strong{display:block;font:normal clamp(25px,4vw,40px) Georgia,serif;letter-spacing:-.03em;text-transform:none;color:#fff6d8;margin-top:8px}.badge{font:10px Arial,sans-serif;letter-spacing:.18em;text-transform:uppercase;border:1px solid #b9dfd477;border-radius:30px;padding:10px 14px;color:#daf0d6}.bottom{position:absolute;left:0;right:0;bottom:0;display:flex;align-items:end;justify-content:space-between;padding:clamp(22px,4vw,44px);gap:20px}.hint{max-width:320px}.hint .eyebrow{font:10px Arial,sans-serif;letter-spacing:.22em;text-transform:uppercase;color:#c5e3ca}.hint p{font-size:16px;line-height:1.5;margin:9px 0 0;color:#f6efd5}.controls{display:flex;gap:10px;pointer-events:auto}.controls button{appearance:none;border:1px solid #c7e7d677;background:rgba(3,57,65,.6);backdrop-filter:blur(8px);color:#f8f3d9;border-radius:50%;width:52px;height:52px;font-size:21px;cursor:pointer}.controls button:active{background:#b9dbb866;color:#fff}.cross{position:absolute;left:50%;top:50%;width:7px;height:7px;border:1px solid #e3f4d5aa;border-radius:50%;transform:translate(-50%,-50%)}#notice{position:absolute;left:50%;top:26%;transform:translateX(-50%);font:11px Arial,sans-serif;letter-spacing:.16em;text-transform:uppercase;background:#093f4bb8;padding:10px 17px;border-radius:20px;white-space:nowrap;opacity:0;transition:opacity .4s}.show{opacity:1!important}@media(max-width:600px){.top,.bottom{padding:22px}.badge{font-size:9px}.hint p{font-size:14px;max-width:220px}.controls button{width:48px;height:48px}}
</style>
</head>
<body><div id="scene"></div><div id="overlay"><div class="top"><div class="brand">An underwater escape<strong>Kelp Garden</strong></div><div class="badge">Take a breath ✳</div></div><div class="cross"></div><div id="notice"></div><div class="bottom"><div class="hint"><div class="eyebrow">Explore at your own pace</div><p id="instruction">Press and hold to swim. Drag to look around.</p></div><div class="controls"><button id="sound" aria-label="Toggle underwater sound" title="Toggle sound">♪</button><button id="reset" aria-label="Return to the beginning" title="Return to beginning">↺</button></div></div></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>
<script>
(()=>{'use strict';
const mount=document.getElementById('scene'), notice=document.getElementById('notice');
if(!window.THREE){notice.textContent='The underwater scene could not load.';notice.classList.add('show');return}
const scene=new THREE.Scene();scene.background=new THREE.Color(0x075569);scene.fog=new THREE.FogExp2(0x07586b,.026);
const renderer=new THREE.WebGLRenderer({antialias:true,powerPreference:'high-performance'});renderer.setPixelRatio(Math.min(devicePixelRatio,1.5));renderer.setSize(innerWidth,innerHeight);renderer.outputColorSpace=THREE.SRGBColorSpace;renderer.toneMapping=THREE.ACESFilmicToneMapping;renderer.toneMappingExposure=1.12;mount.appendChild(renderer.domElement);
const camera=new THREE.PerspectiveCamera(60,innerWidth/innerHeight,.1,125);camera.position.set(0,5,19);let yaw=0,pitch=-.06;
scene.add(new THREE.HemisphereLight(0xbceacb,0x124d50,2));const sun=new THREE.DirectionalLight(0xffe5a0,2.3);sun.position.set(-15,28,12);scene.add(sun);
const mat=(c,extra={})=>new THREE.MeshStandardMaterial({color:c,roughness:.9,...extra});const sand=mat(0xc5af70),rock=mat(0x3c6d67),wood=mat(0x705639),darkWood=mat(0x3d4939),kelpMat=mat(0x598351,{side:THREE.DoubleSide}),coralMat=mat(0xd88746),gold=mat(0xe4bc68);
const floor=new THREE.Mesh(new THREE.PlaneGeometry(220,220,100,100),sand);floor.rotation.x=-Math.PI/2;const fp=floor.geometry.attributes.position;for(let i=0;i<fp.count;i++){let x=fp.getX(i),y=fp.getY(i);fp.setZ(i,Math.sin(x*.3)*.2+Math.cos(y*.26)*.18+Math.sin(x*.8+y*.6)*.05)}floor.geometry.computeVertexNormals();floor.position.y=-.4;scene.add(floor);
// Thin golden markings give the sand a gently shifting caustic pattern.
const caustics=new THREE.Group();scene.add(caustics);const lineMat=new THREE.MeshBasicMaterial({color:0xffe5a0,transparent:true,opacity:.13,side:THREE.DoubleSide,depthWrite:false});for(let i=0;i<180;i++){let m=new THREE.Mesh(new THREE.RingGeometry(.18+Math.random()*.6,.21+Math.random()*.6,20,1,0,Math.PI*(.5+Math.random())),lineMat);m.rotation.x=-Math.PI/2;m.position.set((Math.random()-.5)*100,.04,(Math.random()-.5)*100);caustics.add(m)}
const surface=new THREE.Mesh(new THREE.PlaneGeometry(220,220,40,40),new THREE.MeshStandardMaterial({color:0x79c8b8,transparent:true,opacity:.32,side:THREE.DoubleSide,roughness:.28}));surface.rotation.x=Math.PI/2;surface.position.y=26;scene.add(surface);
const beamMat=new THREE.MeshBasicMaterial({color:0xe8e5a5,transparent:true,opacity:.045,side:THREE.DoubleSide,depthWrite:false});for(let i=0;i<12;i++){const b=new THREE.Mesh(new THREE.PlaneGeometry(3+Math.random()*4,34),beamMat);b.position.set(-26+i*5,12,-20-(i%3)*7);b.rotation.z=-.34;b.rotation.y=.2;scene.add(b)}
const colliders=[];function addRock(x,z,sx,sy,sz){const m=new THREE.Mesh(new THREE.DodecahedronGeometry(1,1),rock);m.position.set(x,sy*.47,z);m.scale.set(sx,sy,sz);m.rotation.y=Math.random()*3;scene.add(m);colliders.push({x,z,r:Math.max(sx,sz)*.8});return m}
// Rocks form two arches with clear swim-through openings.
function arch(x,z,scale,rotation){const group=new THREE.Group();group.position.set(x,0,z);group.rotation.y=rotation;scene.add(group);const pillar=(px)=>{const m=new THREE.Mesh(new THREE.DodecahedronGeometry(1,1),rock);m.scale.set(1.7*scale,4.1*scale,1.8*scale);m.position.set(px*scale,3*scale,0);group.add(m);const p=new THREE.Vector3(px*scale,0,0).applyAxisAngle(new THREE.Vector3(0,1,0),rotation);colliders.push({x:x+p.x,z:z+p.z,r:1.65*scale})};pillar(-3.2);pillar(3.2);const top=new THREE.Mesh(new THREE.TorusGeometry(3.2*scale,1.25*scale,8,18,Math.PI),rock);top.position.y=5*scale;group.add(top)}arch(-15,-18,1.25,.25);arch(20,-40,1,-.5);
for(let i=0;i<38;i++){let x=(Math.random()-.5)*90,z=(Math.random()-.5)*100;if(Math.abs(x)<6&&z>4)continue;let s=.5+Math.random()*2;addRock(x,z,s,s*(.7+Math.random()),s*.8)}
// A weathered shipwreck, with collision volumes spanning its hull.
const ship=new THREE.Group();ship.position.set(13,0,-12);ship.rotation.y=-.48;scene.add(ship);const hull=new THREE.Mesh(new THREE.CylinderGeometry(2.6,1.45,11,7,1,false,0,Math.PI*2),wood);hull.rotation.z=Math.PI/2;hull.position.y=2;hull.scale.z=1.15;ship.add(hull);const deck=new THREE.Mesh(new THREE.BoxGeometry(10,.35,4.6),darkWood);deck.position.y=3.35;ship.add(deck);for(let i=0;i<12;i++){const plank=new THREE.Mesh(new THREE.BoxGeometry(.1,.1,4.4),gold);plank.position.set(-4.8+i*.87,3.55,0);ship.add(plank)}for(const x of [-2.8,2]){const mast=new THREE.Mesh(new THREE.CylinderGeometry(.14,.22,7,8),darkWood);mast.position.set(x,6,0);mast.rotation.z=x<0?.13:-.18;ship.add(mast);const yard=new THREE.Mesh(new THREE.CylinderGeometry(.08,.1,4.5,6),wood);yard.rotation.z=Math.PI/2;yard.position.set(x,8,0);ship.add(yard)}for(let i=-2;i<=2;i++){const p=new THREE.Vector3(i*2,0,0).applyAxisAngle(new THREE.Vector3(0,1,0),ship.rotation.y).add(ship.position);colliders.push({x:p.x,z:p.z,r:2.4})}
const kelps=[];for(let i=0;i<150;i++){let x=(Math.random()-.5)*92,z=(Math.random()-.5)*95;if(Math.abs(x)<5&&z>3)continue;let h=4+Math.random()*11;const g=new THREE.Group();g.position.set(x,0,z);for(let j=0;j<3;j++){let blade=new THREE.Mesh(new THREE.PlaneGeometry(.55+Math.random()*.7,h,1,8),kelpMat);blade.position.set((j-1)*.28,h/2,0);blade.rotation.y=j*Math.PI/3;blade.rotation.z=(j-1)*.08;g.add(blade)}g.userData={phase:Math.random()*6,speed:.5+Math.random()*.5};scene.add(g);kelps.push(g)}
for(let i=0;i<65;i++){let x=(Math.random()-.5)*85,z=(Math.random()-.5)*90;const group=new THREE.Group();group.position.set(x,0,z);let count=3+Math.random()*4;for(let j=0;j<count;j++){const branch=new THREE.Mesh(new THREE.CylinderGeometry(.08,.2,1+Math.random()*2,6),coralMat);branch.position.set((j-2)*.25,.6,0);branch.rotation.z=(j-2)*.25;group.add(branch);const tip=new THREE.Mesh(new THREE.SphereGeometry(.18,6,5),gold);tip.position.set(branch.position.x+Math.sin(-branch.rotation.z)*.6,1.2,0);group.add(tip)}scene.add(group)}
const fishGeometry=new THREE.SphereGeometry(1,8,5),tailGeometry=new THREE.ConeGeometry(.33,.65,3);const fishMats=[mat(0xe0af59),mat(0xdf8b4d),mat(0x8abca3)];const schools=[];for(let s=0;s<5;s++){const group=new THREE.Group();for(let i=0;i<22;i++){const fish=new THREE.Group();const body=new THREE.Mesh(fishGeometry,fishMats[s%3]);body.scale.set(.48,.2,.16);fish.add(body);const tail=new THREE.Mesh(tailGeometry,fishMats[s%3]);tail.rotation.z=-Math.PI/2;tail.position.x=-.5;fish.add(tail);fish.position.set((Math.random()-.5)*6,(Math.random()-.5)*3,(Math.random()-.5)*4);fish.scale.setScalar(.65+Math.random()*.5);group.add(fish)}scene.add(group);schools.push({group,phase:s*1.8,r:8+s*3,cy:5+s*2,cx:(s-2)*8,cz:-20-s*8})}
const rays=[];for(let i=0;i<3;i++){const g=new THREE.Group();const shape=new THREE.Shape();shape.moveTo(0,1.4);shape.quadraticCurveTo(-2,.8,-3.4,-.5);shape.quadraticCurveTo(-1.2,-.2,0,-1);shape.quadraticCurveTo(1.2,-.2,3.4,-.5);shape.quadraticCurveTo(2,.8,0,1.4);const wing=new THREE.Mesh(new THREE.ShapeGeometry(shape),mat(0x326e70,{side:THREE.DoubleSide}));wing.rotation.x=-Math.PI/2;g.add(wing);const tail=new THREE.Mesh(new THREE.CylinderGeometry(.025,.07,2.7,5),darkWood);tail.rotation.x=Math.PI/2;tail.position.z=2;g.add(tail);scene.add(g);rays.push({g,phase:i*2.5})}
const bubbleGeo=new THREE.SphereGeometry(.12,8,6),bubbleMat=new THREE.MeshBasicMaterial({color:0xc7f3dc,transparent:true,opacity:.35,wireframe:true});const bubbles=[];for(let i=0;i<100;i++){const b=new THREE.Mesh(bubbleGeo,bubbleMat);b.position.set((Math.random()-.5)*75,Math.random()*26,(Math.random()-.5)*80);b.scale.setScalar(.4+Math.random()*1.2);scene.add(b);bubbles.push(b)}
let down=false,lastX=0,lastY=0,demo=location.hash==='#demo',start=performance.now(),audio=null,soundOn=false;function message(t){notice.textContent=t;notice.classList.add('show');setTimeout(()=>notice.classList.remove('show'),2200)}function reset(){camera.position.set(0,5,19);yaw=0;pitch=-.06;demo=false;message('Back to the beginning')}
renderer.domElement.addEventListener('pointerdown',e=>{if(e.button!==undefined&&e.button!==0)return;demo=false;down=true;lastX=e.clientX;lastY=e.clientY;renderer.domElement.setPointerCapture(e.pointerId)});renderer.domElement.addEventListener('pointermove',e=>{if(!down)return;yaw-=(e.clientX-lastX)*.004;pitch-=(e.clientY-lastY)*.003;pitch=Math.max(-1.15,Math.min(1.15,pitch));lastX=e.clientX;lastY=e.clientY});for(const ev of ['pointerup','pointercancel','lostpointercapture'])renderer.domElement.addEventListener(ev,()=>down=false);document.getElementById('reset').onclick=reset;
document.getElementById('sound').onclick=async function(){demo=false;try{if(!audio){const ctx=new (window.AudioContext||window.webkitAudioContext)();const buffer=ctx.createBuffer(1,ctx.sampleRate*3,ctx.sampleRate);const data=buffer.getChannelData(0);for(let i=0;i<data.length;i++)data[i]=Math.random()*2-1;const source=ctx.createBufferSource();source.buffer=buffer;source.loop=true;const filter=ctx.createBiquadFilter();filter.type='lowpass';filter.frequency.value=220;const gain=ctx.createGain();gain.gain.value=.12;source.connect(filter).connect(gain).connect(ctx.destination);source.start();audio={ctx,gain}}soundOn=!soundOn;if(soundOn)await audio.ctx.resume();audio.gain.gain.setTargetAtTime(soundOn?.12:0,audio.ctx.currentTime,.4);this.textContent=soundOn?'♫':'♪';this.setAttribute('aria-label',soundOn?'Mute underwater sound':'Turn on underwater sound');message(soundOn?'Sound on':'Sound off')}catch(e){message('Sound unavailable')}};
function move(dt){const speed=4.4*dt;const dx=-Math.sin(yaw)*Math.cos(pitch)*speed,dz=-Math.cos(yaw)*Math.cos(pitch)*speed,dy=Math.sin(pitch)*speed;let nx=camera.position.x+dx,nz=camera.position.z+dz;for(const c of colliders){let x=nx-c.x,z=nz-c.z,d=Math.hypot(x,z),r=c.r+.65;if(d<r){if(d<.001){x=1;z=0;d=1}nx=c.x+x/d*r;nz=c.z+z/d*r}}camera.position.x=THREE.MathUtils.clamp(nx,-53,53);camera.position.z=THREE.MathUtils.clamp(nz,-60,45);camera.position.y=THREE.MathUtils.clamp(camera.position.y+dy,1.1,23)}
let prev=performance.now();function animate(now){requestAnimationFrame(animate);let dt=Math.min((now-prev)/1000,.05),t=(now-start)/1000;prev=now;if(demo){let a=(t%20)/20*Math.PI*2;camera.position.set(Math.sin(a)*9,7+Math.sin(a*2)*1.5,2+Math.cos(a)*12);let target=new THREE.Vector3(1,5,-19);camera.lookAt(target)}else{if(down)move(dt);camera.rotation.order='YXZ';camera.rotation.y=yaw;camera.rotation.x=pitch}for(const k of kelps)k.rotation.z=Math.sin(t*k.userData.speed+k.userData.phase)*.1;caustics.position.x=Math.sin(t*.3)*.25;lineMat.opacity=.1+Math.sin(t*.8)*.025;for(const s of schools){let a=t*.16+s.phase;s.group.position.set(s.cx+Math.sin(a)*s.r,s.cy+Math.sin(a*2)*1.1,s.cz+Math.cos(a)*s.r);s.group.rotation.y=a+Math.PI/2;s.group.children.forEach((f,i)=>{f.rotation.y=Math.sin(t*8+i)*.12})}for(const r of rays){let a=t*.08+r.phase;r.g.position.set(Math.sin(a)*28,14+Math.sin(a*2)*2,-25+Math.cos(a)*23);r.g.rotation.y=-a;r.g.rotation.z=Math.sin(t*1.3+r.phase)*.12}for(const b of bubbles){b.position.y+=dt*(.5+b.scale.x*.5);b.position.x+=Math.sin(t+b.position.z)*dt*.06;if(b.position.y>26)b.position.y=0}renderer.render(scene,camera)}requestAnimationFrame(animate);addEventListener('resize',()=>{camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();renderer.setSize(innerWidth,innerHeight)});if(demo)document.getElementById('instruction').textContent='A little tour. Touch anywhere to take over.';
})();
</script></body></html>
