Back to the app
The code
Swim the Kelp Garden by GPT-6.2 Astra
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,viewport-fit=cover"><title>Kelp Garden · Pelagic Field Atlas</title><style>
*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#084657;color:#f4eed5;font-family:Arial,sans-serif}canvas{display:block;touch-action:none}#hud{position:absolute;inset:0;pointer-events:none;background:linear-gradient(0deg,rgba(1,23,27,.77),transparent 27%,transparent 86%,rgba(1,34,38,.28))}header,footer{position:absolute;left:4%;right:4%;display:flex;align-items:center;justify-content:space-between}header{top:4.5%}.brand,.depth,.guide{display:flex;align-items:center;gap:12px}.brand svg{width:38px;height:38px}.micro{font-size:10px;font-weight:bold;letter-spacing:.21em;text-transform:uppercase}.depth{border:1px solid #d4ecd457;border-radius:30px;background:#062f3a68;padding:9px 15px;font:12px monospace}.dot{width:6px;height:6px;border-radius:50%;background:#b8d992}footer{bottom:5%;align-items:end}.kicker{color:#e8c68a;display:flex;align-items:center;gap:10px}.kicker:before{content:"";width:32px;height:1px;background:#deb876}h1{font:normal clamp(46px,6vw,92px)/1 Georgia,serif;letter-spacing:-.055em;margin:12px 0 0}.guide{font-size:12px;color:#e4ede4}.guide svg{width:22px;height:27px}.rule{height:1px;width:24px;background:#abbfba80}button{pointer-events:auto;cursor:pointer;border:1px solid #d4ecd459;border-radius:50%;background:#07343ac9;color:#fff5d7;width:46px;height:46px;font-size:18px}.actions{display:flex;align-items:center;gap:18px}.sound{display:flex;align-items:center;justify-content:center;gap:3px}.sound i{width:2px;height:7px;background:currentColor}.sound i:nth-child(2){height:16px}.sound i:nth-child(3){height:11px}.sound[aria-pressed=false]{color:#a8c3bb}@media(max-width:650px){header,footer{left:6%;right:6%}footer{align-items:start;flex-direction:column;gap:18px}.actions{width:100%;justify-content:space-between}.micro{font-size:9px}.brand{gap:7px}}
</style></head><body><div id="hud"><header><div class="brand"><svg viewBox="0 0 40 40" fill="none" stroke="currentColor" stroke-width="1.25"><circle cx="20" cy="20" r="18"/><path d="M10 28c7 0 4-10 9-16m-3 16c8-4 1-13 8-21m-2 22c6-4 1-9 8-15"/></svg><span class="micro">Pelagic Field Atlas</span></div><div class="depth"><i class="dot"></i><span id="depth">08.0 m</span></div></header><footer><div><div class="micro kicker">Habitat 01 / Shallow sea</div><h1>Kelp Garden</h1></div><div class="actions"><div class="guide"><svg viewBox="0 0 24 30" stroke="currentColor" fill="none"><rect x="5" y="2" width="15" height="25" rx="7.5"/><path d="M12.5 3v9"/></svg><span>Hold to swim</span><i class="rule"></i><span>Drag to turn</span></div><button class="sound" aria-label="Toggle underwater sound" aria-pressed="false"><i></i><i></i><i></i><i></i></button></div></footer></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script><script>
const T=THREE,S=new T.Scene(),C=new T.PerspectiveCamera(65,innerWidth/innerHeight,.08,130),R=new T.WebGLRenderer({antialias:true});R.setPixelRatio(Math.min(devicePixelRatio,1.65));R.setSize(innerWidth,innerHeight);document.body.prepend(R.domElement);S.background=new T.Color(0x267f91);S.fog=new T.FogExp2(0x267f91,.037);let seed=7632;function rand(){seed=(1664525*seed+1013904223)>>>0;return seed/4294967296}function range(a,b){return a+(b-a)*rand()}const V=(x,y,z)=>new T.Vector3(x,y,z),mat=(c)=>new T.MeshStandardMaterial({color:c,flatShading:true,roughness:.95,side:T.DoubleSide});function mesh(g,m,p=S){let o=new T.Mesh(g,m);p.add(o);return o}function at(o,x,y,z){o.position.set(x,y,z);return o}function tri(pos,cols){let g=new T.BufferGeometry();g.setAttribute('position',new T.Float32BufferAttribute(pos,3));g.setAttribute('color',new T.Float32BufferAttribute(cols,3));g.computeVertexNormals();return g}const stone=[0x586957,0x52665d,0x78816b,0x64715b,0x445e57].map(mat),obstacles=[];let sun=new T.DirectionalLight(0xffdfa0,2.65);at(sun,-12,22,4);S.add(sun,new T.HemisphereLight(0xc0ffdf,0x599798,1.8));
function floor(x,z){return .32*Math.sin(x*.27+z*.19)+.27*Math.cos(z*.4)+.15*Math.sin(x*.74-z*.16)}
let ground=new T.PlaneGeometry(160,160,160,160);ground.rotateX(-Math.PI/2);let gp=ground.attributes.position;for(let i=0;i<gp.count;i++)gp.setY(i,floor(gp.getX(i),gp.getZ(i)));ground.computeVertexNormals();let sand=mat(0xb9b582),time={value:0};sand.onBeforeCompile=s=>{s.uniforms.tm=time;s.vertexShader='varying vec3 wp;\n'+s.vertexShader.replace('#include <begin_vertex>','#include <begin_vertex>\nwp=position;');s.fragmentShader='varying vec3 wp;uniform float tm;\n'+s.fragmentShader.replace('#include <color_fragment>','#include <color_fragment>\n vec2 q=wp.xz; float f=sin(q.x*2.3+sin(q.y*2.+tm*.55)*1.9+tm*.4)+sin(q.y*2.5+sin(q.x*1.6-tm*.35)*1.7); float lines=pow(max(0.,1.-abs(f)*1.9),3.);diffuseColor.rgb*=.77+.16*sin(q.x*.6+q.y*.4)+lines*.44;')};mesh(ground,sand);
let rockGeo=new T.IcosahedronGeometry(1,0);function rock(x,y,z,a,b,c,solid=true){let o=at(mesh(rockGeo,stone[Math.floor(rand()*stone.length)]),x,y,z);o.scale.set(a,b,c);o.rotation.y=rand()*6;if(solid)obstacles.push([x,y,z,Math.max(a,c)*1.06,b,Math.max(a,c)*1.06]);return o}
function arch(x,z,s){let pos=[],cols=[],rings=[];for(let i=0;i<=16;i++){let t=i/16*Math.PI,ring=[];for(let j=0;j<9;j++){let a=j/9*6.283,r=(1.05+.24*Math.cos(t*2)+range(-.18,.18))*s;ring.push(V(x+Math.cos(t)*(3.5*s+r*Math.cos(a)),Math.sin(t)*(4.8*s+r*Math.cos(a))-.3,z+r*Math.sin(a)*1.55))}rings.push(ring);obstacles.push([x+Math.cos(t)*3.5*s,Math.sin(t)*4.8*s-.3,z,1.35*s,1.35*s,2.05*s])}for(let i=0;i<16;i++)for(let j=0;j<9;j++){let k=(j+1)%9;for(let face of [[rings[i][j],rings[i+1][j],rings[i][k]],[rings[i][k],rings[i+1][j],rings[i+1][k]]]){let co=new T.Color().setHSL(range(.15,.19),range(.1,.22),range(.27,.39));for(let p of face){pos.push(...p.toArray());cols.push(co.r,co.g,co.b)}}}mesh(tri(pos,cols),new T.MeshStandardMaterial({vertexColors:true,flatShading:true,side:T.DoubleSide}))}arch(-3,-5,1.25);arch(-14,-23,1.65);
for(let i=0;i<145;i++){let x=range(-35,35),z=range(-46,18),a=range(.3,2.4);if(Math.abs(x)<6&&z>0)a*=.27;rock(x,floor(x,z)-.35,z,a,a*range(.5,1.1),a*.87)}
// Open ribbed wooden hull, broken rails and mast.
let ship=new T.Group();S.add(ship);at(ship,7,.35,-10);ship.rotation.set(.06,-.66,-.13);let wood=[0x674832,0x825d3b,0x976a41,0x543e30].map(mat);function beam(p,a,b,w,m,w2=w){let d=b.clone().sub(a),o=mesh(new T.BoxGeometry(w,d.length(),w2),m,p);o.position.copy(a).lerp(b,.5);o.quaternion.setFromUnitVectors(V(0,1,0),d.normalize());return o}function hull(z,h,side){return V(side*(.55+.48*h)*(1-.84*Math.pow(Math.abs(z/5),2.8)),h+.55*Math.pow(z/5,2),z)}for(let side of [-1,1])for(let i=0;i<10;i++){let z=i-5;for(let j=0;j<7;j++){if(j>4&&i>2&&i<6&&side<0&&rand()<.65)continue;let h=j*.35;beam(ship,hull(z,h,side),hull(z+1,h,side),.17,wood[(i+j)%4],.34)}beam(ship,hull(z,0,side),hull(z,range(2.3,3.1),side),.18,wood[0])}beam(ship,V(0,0,-1),V(-.4,6.8,-1),.25,wood[0]);beam(ship,V(-.4,5.3,-3),V(-.4,5.3,1.5),.17,wood[2]);ship.updateMatrixWorld();for(let z=-5;z<=5;z+=.6){let p=ship.localToWorld(V(0,1.3,z));obstacles.push([p.x,p.y,p.z,2.3,2.2,2.3])}for(let y=3;y<7;y+=.4){let p=ship.localToWorld(V(-.4,y,-1));obstacles.push([p.x,p.y,p.z,.6,.6,.6])}
// Each blade has a folded midrib and tapered, curling leaves.
let kp=[],kc=[];function leaf(a,b,c,color){for(let v of [a,b,c]){kp.push(v.x,v.y,v.z);kc.push(color.r,color.g,color.b)}}function stalk(x,z,h){let cy=floor(x,z)-.2,ph=range(0,6),base=new T.Color().setHSL(range(.18,.29),range(.55,.8),range(.13,.31)),light=base.clone().multiplyScalar(1.5),last;for(let i=0;i<=14;i++){let u=i/14,y=h*u,mid=V(x+.32*Math.sin(u*7+ph)+u*u*.7,cy+y,z+.25*Math.sin(u*8+ph)),w=(.05+.10*Math.sin(u*Math.PI))*(1-u*.75),L=mid.clone().add(V(-w,0,0)),H=mid.clone().add(V(w,0,0));if(last){leaf(last[0],last[1],L,base);leaf(L,last[1],H,light)}last=[L,H];if(i<2||i===14)continue;let a=ph+i*2.61,d=V(Math.cos(a),0,Math.sin(a)),n=V(-d.z,0,d.x),len=(.48+.8*Math.sin(u*Math.PI))*Math.min(h/5,1.5),end=mid.clone().addScaledVector(d,len).add(V(.1,len*range(.65,1.45),0)),rib=mid.clone().lerp(end,.54).addScaledVector(d,len*.16),left=rib.clone().addScaledVector(n,len*.15),right=rib.clone().addScaledVector(n,-len*.15);rib.y+=len*.13;leaf(mid,left,rib,light);leaf(mid,rib,right,base);leaf(left,end,rib,light);leaf(rib,end,right,base)}}for(let i=0;i<440;i++){let x=range(-30,30),z=range(-43,13);if(z>-15&&x>-7&&x<9)continue;stalk(x,z,range(2,11))}for(let [x,z] of [[-7,5],[7,5],[-9,1],[9,0],[-7,-7],[10,-8]])for(let i=0;i<6;i++)stalk(x+range(-1,1),z+range(-1,1),range(4,10));let km=new T.MeshStandardMaterial({vertexColors:true,side:T.DoubleSide});km.onBeforeCompile=s=>{s.uniforms.tm=time;s.vertexShader='uniform float tm;\n'+s.vertexShader.replace('#include <begin_vertex>','#include <begin_vertex>\ntransformed.x+=.075*max(position.y,0.)*sin(tm*.73+position.y*.46+position.z*.38);')};mesh(tri(kp,kc),km);
let coral=[0xdd793d,0xec9954,0xb45c30,0xd5a044].map(mat),branches=[];function branch(p,dir,len,thick,level,m){let q=p.clone().addScaledVector(dir,len);branches.push([p,q,thick,m]);if(level)for(let k of [-1,1])branch(q,V(dir.x*.5+k*range(.25,.75),range(.45,.95),range(-.33,.33)).normalize(),len*.7,thick*.69,level-1,m)}for(let i=0;i<78;i++){let x=range(-18,19),z=range(-26,9);if(Math.abs(x)<3&&z>1)continue;branch(V(x,floor(x,z),z),V(range(-.2,.2),1,0),range(.28,.82),range(.07,.15),3,i%4)}for(let m=0;m<4;m++){let list=branches.filter(b=>b[3]===m),inst=new T.InstancedMesh(new T.CylinderGeometry(.73,1,1,6),coral[m],list.length);list.forEach(([a,b,r],i)=>{let o=new T.Object3D(),d=b.clone().sub(a);o.position.copy(a).lerp(b,.5);o.scale.set(r,d.length()+r*.5,r);o.quaternion.setFromUnitVectors(V(0,1,0),d.normalize());o.updateMatrix();inst.setMatrixAt(i,o.matrix)});S.add(inst)}
// Layered translucent shafts and moving surface shimmer.
let surface=mesh(new T.PlaneGeometry(165,165),new T.ShaderMaterial({uniforms:{tm:time},side:T.DoubleSide,vertexShader:'varying vec2 v;void main(){v=position.xy;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.);}',fragmentShader:'varying vec2 v;uniform float tm;void main(){float f=sin(v.y*3.+sin(v.x*.8+tm*.6)*2.+tm*.6)+sin(v.x*.95+v.y*1.2);gl_FragColor=vec4(mix(vec3(.15,.54,.59),vec3(.71,.91,.78),smoothstep(.25,2.,f)*.68),1.); }'}));surface.rotation.x=Math.PI/2;surface.position.y=14;
for(let i=0;i<32;i++){let x=range(-37,28),z=range(-48,9),w=range(.23,1.7),p=[x,14,z,x+w,14,z,x+8,-1,z,x+8,-1,z,x+w,14,z,x+8+w*2,-1,z];let g=new T.BufferGeometry();g.setAttribute('position',new T.Float32BufferAttribute(p,3));g.setAttribute('uv',new T.Float32BufferAttribute([0,1,1,1,0,0,0,0,1,1,1,0],2));mesh(g,new T.ShaderMaterial({side:T.DoubleSide,transparent:true,depthWrite:false,blending:T.AdditiveBlending,vertexShader:'varying vec2 v;void main(){v=uv;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.);}',fragmentShader:'varying vec2 v;void main(){gl_FragColor=vec4(.68,.91,.68,.075*sin(v.x*3.14159)*v.y); }'}))}
let fish=[],fg=new T.SphereGeometry(1,9,6),tail=new T.ConeGeometry(1,1,3),fm=[0xe6ab4d,0xdf8a3a,0xaacaa0].map(mat);for(let s=0;s<3;s++)for(let i=0;i<21;i++){let o=new T.Group();S.add(o);let size=range(.22,.41),body=mesh(fg,fm[s],o);body.scale.set(size,size*.36,size*.22);let fin=at(mesh(tail,fm[s],o),-size*1.03,0,0);fin.rotation.z=-Math.PI/2;fin.scale.set(size*.52,size*.61,size*.12);fish.push({o,s,x:range(-2.8,2.8),y:range(-1,1),z:range(-1.3,1.3)})}
let rays=[];for(let i=0;i<3;i++){let o=new T.Group();S.add(o);let p=[0,0,1.2,-.5,.07,-.35,-2.15,.16,-.8,0,0,1.2,-2.15,.16,-.8,-.56,-.12,.67,0,0,1.2,2.15,.16,-.8,.5,.07,-.35,0,0,1.2,.56,-.12,.67,2.15,.16,-.8,-.5,.07,-.35,0,0,1.2,.5,.07,-.35];let g=new T.BufferGeometry();g.setAttribute('position',new T.Float32BufferAttribute(p,3));g.computeVertexNormals();mesh(g,mat(0x245955),o);beam(o,V(0,0,0),V(.12,-.1,-2.2),.057,mat(0x345c58));rays.push({o,g})}
let bubbleGeo=new T.SphereGeometry(1,10,8),bm=new T.MeshPhongMaterial({color:0x9ae8d5,specular:0xffffff,shininess:90,opacity:.27,transparent:true,depthWrite:false}),bubbles=[];for(let i=0;i<95;i++){let k=i%5,x=[-4,5,-9,11,1][k]+range(-.65,.65),z=[3,-3,-9,-20,-15][k]+rand(),r=range(.027,.11),o=mesh(bubbleGeo,bm);o.scale.setScalar(r);bubbles.push({o,x,z,y:rand()*14,s:range(.42,.9)})}
let yaw=0,pitch=-.11,held=false,px,py,demo=location.hash.endsWith('demo'),t=0,last=performance.now();C.rotation.order='YXZ';at(C,0,4.4,12);let canvas=R.domElement;window.addEventListener('pointerdown',()=>demo=false,true);canvas.onpointerdown=e=>{canvas.setPointerCapture(e.pointerId);held=true;px=e.clientX;py=e.clientY};canvas.onpointermove=e=>{if(!held)return;yaw-=(e.clientX-px)*.004;pitch=Math.max(-1.26,Math.min(1.26,pitch-(e.clientY-py)*.004));px=e.clientX;py=e.clientY};canvas.onpointerup=canvas.onpointercancel=canvas.onlostpointercapture=()=>held=false;
function valid(p){return Math.abs(p.x)<42&&Math.abs(p.z)<48&&p.y>floor(p.x,p.z)+.55&&p.y<13.35&&!obstacles.some(([x,y,z,a,b,c])=>((p.x-x)/(a+.38))**2+((p.y-y)/(b+.38))**2+((p.z-z)/(c+.38))**2<1)}
let sound=document.querySelector('button'),ac,gain;sound.onclick=()=>{if(!ac){ac=new AudioContext();let buffer=ac.createBuffer(1,ac.sampleRate*4,ac.sampleRate),data=buffer.getChannelData(0);for(let i=0;i<data.length;i++)data[i]=Math.random()*2-1;let src=ac.createBufferSource(),lp=ac.createBiquadFilter();src.buffer=buffer;src.loop=true;lp.frequency.value=410;gain=ac.createGain();gain.gain.value=0;src.connect(lp).connect(gain).connect(ac.destination);src.start()}ac.resume();let on=sound.getAttribute('aria-pressed')!=='true';gain.gain.setTargetAtTime(on?.17:0,ac.currentTime,.45);sound.setAttribute('aria-pressed',on)};
function frame(now){let dt=Math.min(.06,(now-last)/1000);last=now;t+=dt;time.value=t;if(demo){let a=t*Math.PI/10;C.position.set(2.5*Math.sin(a),4.7+.9*Math.sin(a),11+1.9*Math.cos(a));yaw=.32*Math.sin(a);pitch=-.09+.14*Math.sin(a*2)}C.rotation.set(pitch,yaw,0,'YXZ');if(held){let d=C.getWorldDirection(V()).multiplyScalar(dt*2.8);for(let k of ['x','y','z']){let p=C.position.clone();p[k]+=d[k];if(valid(p))C.position.copy(p)}}for(let f of fish){let a=t*.17+f.s*2.25;f.o.position.set(Math.sin(a)*5+f.x+(f.s-1)*3,4.1+f.s*.72+f.y+.25*Math.sin(a*3+f.x),-3-f.s*4+Math.cos(a)*2+f.z);f.o.rotation.y=Math.atan2(2*Math.sin(a),5*Math.cos(a))+.08*Math.sin(t*4+f.x)}rays.forEach(({o,g},i)=>{let a=t*.095+i*1.85;o.position.set(10*Math.sin(a),8+i*.6+.3*Math.cos(a),-12-i*4+4*Math.cos(a));o.rotation.y=Math.atan2(10*Math.cos(a),-4*Math.sin(a));let p=g.attributes.position;for(let j=0;j<p.count;j++)if(Math.abs(p.getX(j))>2)p.setY(j,.18+.55*Math.sin(t*1.35+i));p.needsUpdate=true});for(let b of bubbles)b.o.position.set(b.x+.2*Math.sin(t+b.y),.3+(b.y+t*b.s)%13.5,b.z+.12*Math.cos(t*.55+b.y));document.getElementById('depth').textContent=(14-C.position.y).toFixed(1).padStart(4,'0')+' m';R.render(S,C);requestAnimationFrame(frame)}onresize=()=>{R.setSize(innerWidth,innerHeight);C.aspect=innerWidth/innerHeight;C.updateProjectionMatrix()};requestAnimationFrame(frame);
</script></body></html>
