Skip to content
VibeCodeBench
Back to the app

The code

Swim the Kelp Garden by GPT-6.1 Sol

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.)18.6 KB · 81 lines · loads cdn.jsdelivr.net/npm/[email protected]/build/three.min.js
Download
<!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>Stillwater — an underwater garden</title>
<style>
@import url('data:text/css,');
*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#073c48;color:#e9ead4;font-family:Arial,sans-serif}canvas{display:block;touch-action:none}#veil{position:fixed;inset:0;pointer-events:none;background:radial-gradient(ellipse at 50% 43%,transparent 35%,#002b4255 100%)}header{position:fixed;left:38px;top:31px;pointer-events:none}.eyebrow{font-size:10px;letter-spacing:4px;color:#bdd7c5;text-transform:uppercase}.brand{font-family:Georgia,serif;font-size:34px;letter-spacing:1px;margin-top:9px;font-weight:normal}.brand i{font-size:14px;color:#b9d3b7;vertical-align:middle;margin-left:12px}#topright{position:fixed;right:35px;top:35px;display:flex;gap:12px}.pill{border:1px solid #badbc435;background:#073e4855;backdrop-filter:blur(12px);border-radius:30px;padding:12px 17px;color:#dbe5cf;font-size:10px;letter-spacing:2px;display:flex;align-items:center;gap:9px}.dot{height:5px;width:5px;background:#d2d991;border-radius:50%;box-shadow:0 0 9px #d2d991}#intro{position:fixed;bottom:110px;left:38px;pointer-events:none;transition:opacity 2s}h1{font-family:Georgia,serif;font-size:clamp(30px,4vw,54px);font-weight:normal;line-height:1.12;margin:13px 0;color:#f0eed5}#intro p{font-size:12px;line-height:1.9;color:#c4d8c5;max-width:290px;margin:0}.bottom{position:fixed;bottom:27px;left:38px;right:35px;display:flex;justify-content:space-between;align-items:center;gap:14px}.instructions{display:flex;align-items:center;gap:13px;font-size:11px;letter-spacing:.4px;color:#d1ddcd}.gesture{width:32px;height:43px;border:1px solid #cfdfba66;border-radius:17px;display:grid;place-items:center}.gesture:after{content:'';height:8px;width:3px;border-radius:4px;background:#d4dfbb}button{cursor:pointer;color:#e5e8d2;background:#0a414b99;border:1px solid #b5d1b74d;border-radius:50%;width:48px;height:48px;font-size:18px;backdrop-filter:blur(15px)}button:hover{background:#326460bb}button:focus-visible{outline:2px solid #dfce8d}.actions{display:flex;gap:10px}#compass{position:fixed;right:43px;bottom:110px;border:1px solid #d5dfbc40;border-radius:50%;width:64px;height:64px;display:grid;place-items:center;color:#c4d4b7;font-size:9px}#needle{position:absolute;font-size:28px;color:#d6c887}#compass span{position:absolute;top:6px}#reticle{position:fixed;top:50%;left:50%;width:5px;height:5px;border:1px solid #e4edc66b;border-radius:50%;pointer-events:none}#notice{position:fixed;top:110px;right:35px;font-size:10px;letter-spacing:2px;color:#c9dbbe}#loading{position:fixed;inset:0;display:grid;place-content:center;text-align:center;background:#073b46;z-index:10;transition:opacity 1.3s;font:25px Georgia}#loading small{font:10px Arial;letter-spacing:4px;margin-top:18px;color:#bdcba7}#error{max-width:320px;font:14px/1.7 Arial}@media(max-width:600px){header{left:23px;top:25px}.brand{font-size:27px}#topright{right:20px;top:27px}.pill{padding:11px;font-size:9px}.pill .wide{display:none}#intro{left:24px;bottom:125px}#intro p{max-width:235px}.bottom{left:24px;right:20px;bottom:25px}.instructions{max-width:190px;font-size:10px;line-height:1.6}.gesture{flex-shrink:0}#compass{right:25px;bottom:105px}#notice{right:23px;top:91px;font-size:8px}.actions{gap:7px}button{width:44px;height:44px}}
</style>
</head>
<body>
<div id="loading">A little further from everything.<small>ENTERING STILLWATER</small></div>
<div id="veil"></div><header><div class="eyebrow">An ocean garden</div><div class="brand">stillwater <i>✳</i></div></header>
<div id="topright"><div class="pill"><span class="dot"></span><span class="wide">EXPLORING · </span><span id="depth">8.0 M</span></div></div>
<div id="notice"></div><div id="reticle"></div>
<div id="intro"><div class="eyebrow">Breathe. Drift. Discover.</div><h1>Let the world<br>move a little slower.</h1><p>Follow the light through a living kelp forest.<br>There is nowhere you need to be.</p></div>
<div id="compass"><span>N</span><div id="needle">⌁</div></div>
<div class="bottom"><div class="instructions"><div class="gesture"></div><span>Hold to swim · drag to look around</span></div><div class="actions"><button id="sound" aria-label="Enable underwater sound" title="Underwater sound">♪</button><button id="home" aria-label="Return to starting viewpoint" title="Return to the garden">↺</button></div></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>
<script>
(function(){
'use strict';
const loading=document.getElementById('loading');
if(!window.THREE){loading.innerHTML='<div id="error">The garden could not load.<br>Please reconnect and reload this page.</div>';return;}
let renderer;try{renderer=new THREE.WebGLRenderer({antialias:true,powerPreference:'high-performance'});}catch(e){loading.innerHTML='<div id="error">This garden needs WebGL. Please open it in a browser with 3D graphics enabled.</div>';return;}
renderer.setSize(innerWidth,innerHeight);renderer.setPixelRatio(Math.min(devicePixelRatio,1.7));renderer.outputColorSpace=THREE.SRGBColorSpace;renderer.toneMapping=THREE.ACESFilmicToneMapping;renderer.toneMappingExposure=1.15;document.body.prepend(renderer.domElement);
const scene=new THREE.Scene();scene.background=new THREE.Color('#087680');scene.fog=new THREE.FogExp2('#087681',.026);
const camera=new THREE.PerspectiveCamera(62,innerWidth/innerHeight,.1,160);camera.position.set(0,5.3,23);camera.rotation.order='YXZ';let yaw=0,pitch=-.08;
scene.add(new THREE.HemisphereLight(0xb4f4d3,0x25494a,2.2));const sun=new THREE.DirectionalLight(0xffe9ab,3.1);sun.position.set(-15,35,6);scene.add(sun);
const mat=(color,extra={})=>new THREE.MeshStandardMaterial({color,roughness:.88,...extra});const sand=mat('#a99d62');const rockMats=['#45665b','#507367','#647b65','#3e625c'].map(c=>mat(c));const wood=mat('#755634');const woodLight=mat('#937142');const gold=mat('#bd984e');
let seed=5183;function rand(){seed=(seed*16807)%2147483647;return(seed-1)/2147483646}function between(a,b){return a+(b-a)*rand()}
function mesh(geo,material,x,y,z,parent=scene){const m=new THREE.Mesh(geo,material);m.position.set(x,y,z);parent.add(m);return m}
const groundGeo=new THREE.PlaneGeometry(230,230,110,110);groundGeo.rotateX(-Math.PI/2);let gp=groundGeo.attributes.position;for(let i=0;i<gp.count;i++){let x=gp.getX(i),z=gp.getZ(i);gp.setY(i,.22*Math.sin(x*.22)*Math.cos(z*.18)+.07*Math.sin(x*2+z*.6));}groundGeo.computeVertexNormals();mesh(groundGeo,sand,0,-.6,0);
// Animated sandy light, generated entirely in a shader.
const causticMat=new THREE.ShaderMaterial({transparent:true,depthWrite:false,uniforms:{time:{value:0}},vertexShader:'varying vec3 p;void main(){p=position;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.);}',fragmentShader:'varying vec3 p;uniform float time;void main(){vec2 v=p.xz;float a=sin(v.x*2.9+sin(v.y*2.1+time*.43)*1.5+time*.4);float b=sin(v.y*3.7+sin(v.x*1.6-time*.3)*1.7);float q=pow(max(0.,1.-abs(a+b)*1.7),12.);gl_FragColor=vec4(.93,.94,.59,q*.24);}' });mesh(new THREE.PlaneGeometry(200,200).rotateX(-Math.PI/2),causticMat,0,-.28,0);
const colliders=[];function stone(x,y,z,sx,sy,sz,solid=true){const m=mesh(new THREE.DodecahedronGeometry(1,1),rockMats[Math.floor(rand()*4)],x,y,z);m.scale.set(sx,sy,sz);m.rotation.set(rand(),rand()*3,rand());if(solid)colliders.push({type:'sphere',p:new THREE.Vector3(x,y,z),r:Math.max(sx,sy,sz)*.9});return m;}
// An open arch made from weathered blocks; the opening remains swimmable.
for(let side of [-1,1])for(let j=0;j<4;j++)stone(-10+side*(3.3-j*.23),j*1.6+.6,-9,1.45,1.25,1.65);
for(let i=0;i<7;i++){let a=i/6*Math.PI;stone(-10+Math.cos(a)*2.8,5.4+Math.sin(a)*2,-9,1.18,1.1,1.5);}
for(let i=0;i<65;i++){let x=between(-65,65),z=between(-80,35);if(Math.abs(x)<5&&z>10)continue;stone(x,between(-.2,.2),z,between(.4,2.3),between(.3,1.3),between(.4,2.2));}
// The little wreck: individually modeled ribs, split planks and a leaning mast.
const ship=new THREE.Group();ship.position.set(9,.2,-20);ship.rotation.y=-.38;scene.add(ship);
for(let i=0;i<17;i++){let z=-7+i*.85,w=2.5*Math.sin((i+1)/18*Math.PI);for(let side of [-1,1]){let p=mesh(new THREE.BoxGeometry(.22,1.8,.65),i%3?wood:woodLight,side*w,1.1,z,ship);p.rotation.z=-side*.24;for(let row=0;row<3;row++){if(i>6&&i<10&&side===-1&&row>0)continue;mesh(new THREE.BoxGeometry(.16,.37,.89),wood,side*(w+.12),.45+row*.48,z,ship);}}mesh(new THREE.BoxGeometry(w*2,.16,.66),woodLight,0,.28,z,ship);}
const mast=mesh(new THREE.CylinderGeometry(.13,.24,10,9),wood,0,5,-1.7,ship);mast.rotation.z=-.16;const spar=mesh(new THREE.CylinderGeometry(.09,.11,6.7,8),woodLight,.4,7,-1.7,ship);spar.rotation.z=Math.PI/2-.14;
const sailGeo=new THREE.PlaneGeometry(4.7,4,8,8);const sp=sailGeo.attributes.position;for(let i=0;i<sp.count;i++)sp.setZ(i,Math.sin(sp.getX(i)*.7)*.6);const sail=mesh(sailGeo,mat('#a69a67',{side:THREE.DoubleSide,transparent:true,opacity:.65}),.4,4.9,-1.6,ship);sail.rotation.z=-.14;
ship.updateMatrixWorld(true);const shipInv=ship.matrixWorld.clone().invert();colliders.push({type:'ship'});
// Kelp ribbons are tapered and gently curl with the water.
const kelps=[];const kelpMats=['#566d27','#71803b','#87964b','#376c42','#a19a43'].map(c=>mat(c,{side:THREE.DoubleSide}));
for(let i=0;i<155;i++){let x=between(-48,48),z=between(-65,28);if((Math.abs(x)<4.5&&z>0)||(x>-15&&x<-5&&z>-14&&z<-4)||(x>4&&x<14&&z>-29&&z<-11))continue;let height=between(4,15),phase=rand()*6.28;let g=new THREE.PlaneGeometry(between(.35,.9),height,2,20);g.translate(0,height/2,0);const pos=g.attributes.position;const base=pos.array.slice();let m=mesh(g,kelpMats[i%5],x,-.3,z);m.rotation.y=rand()*6.28;kelps.push({m,base,height,phase});for(let k=0;k<4;k++){let h=height*(.2+k*.17);let leaf=mesh(new THREE.SphereGeometry(1,6,5),kelpMats[(i+k)%5],x+(k%2?.6:-.6),h,z);leaf.scale.set(.12,1.15,.36);leaf.rotation.z=k%2?-.6:.6;}}
// Warm branching corals and soft gold anemones.
function branch(parent,a,b,r,material){let d=new THREE.Vector3().subVectors(b,a);let m=mesh(new THREE.CylinderGeometry(r*.6,r,d.length(),6),material,...a.toArray(),parent);m.position.addScaledVector(d,.5);m.quaternion.setFromUnitVectors(new THREE.Vector3(0,1,0),d.normalize());}
const coralMats=['#d18b46','#bf6d3b','#dfb254','#9b8c35'].map(c=>mat(c));for(let i=0;i<38;i++){let x=between(-33,33),z=between(-47,19);if(Math.abs(x)<4)continue;let group=new THREE.Group();group.position.set(x,0,z);scene.add(group);let material=coralMats[i%4],height=between(.5,1.7);branch(group,new THREE.Vector3(),new THREE.Vector3(0,height,0),.12,material);for(let j=0;j<7;j++){let a=rand()*6.28,h=between(.2,height);let p=new THREE.Vector3(0,h,0),q=new THREE.Vector3(Math.cos(a)*.65,h+.55,Math.sin(a)*.65);branch(group,p,q,.065,material);branch(group,q,q.clone().add(new THREE.Vector3(.12,.3,.05)),.035,material);}}
const fishGeometry=new THREE.SphereGeometry(1,8,6);const tailGeo=new THREE.ConeGeometry(.22,.4,3);tailGeo.rotateZ(-Math.PI/2);const fishMats=[mat('#d5b45e',{metalness:.25}),mat('#99bc95',{metalness:.4}),mat('#db8d43',{metalness:.2})];const schools=[];
for(let s=0;s<5;s++){let group=new THREE.Group();scene.add(group);let fishes=[];for(let i=0;i<24;i++){const f=new THREE.Group();let body=mesh(fishGeometry,fishMats[s%3],0,0,0,f);body.scale.set(.33,.13,.09);let tail=mesh(tailGeo,fishMats[s%3],-.4,0,0,f);tail.scale.z=.3;let eye=mesh(new THREE.SphereGeometry(.023,5,4),mat('#142f2e'),.21,.035,.078,f);f.position.set(between(-3,3),between(-1.1,1.1),between(-2,2));group.add(f);fishes.push({f,tail,offset:f.position.clone()});}schools.push({group,fishes,phase:rand()*6.28,r:between(7,16),y:between(3,9),z:between(-35,-8)});}
const rays=[];for(let k=0;k<3;k++){const g=new THREE.Group();const vertices=new Float32Array([0,.12,-.85,-.5,0,-.35,-2.5,.1,.35,-.65,0,.5,0,.1,.8,.65,0,.5,2.5,.1,.35,.5,0,-.35]);const geo=new THREE.BufferGeometry();geo.setAttribute('position',new THREE.BufferAttribute(vertices,3));geo.setIndex([0,1,3,1,2,3,0,3,4,0,4,5,0,5,7,7,5,6]);geo.computeVertexNormals();mesh(geo,mat('#496c60',{side:THREE.DoubleSide}),0,0,0,g);const tail=mesh(new THREE.ConeGeometry(.06,3,6),mat('#3b615a'),0,0,2.1,g);tail.rotation.x=Math.PI/2;g.scale.setScalar(.8+k*.15);scene.add(g);rays.push({g,geo,phase:k*2.1});}
// Fine suspended particles and slowly rising bubbles.
const particleGeo=new THREE.BufferGeometry(),particles=new Float32Array(1100*3);for(let i=0;i<particles.length;i+=3){particles[i]=between(-65,65);particles[i+1]=between(0,24);particles[i+2]=between(-85,40);}particleGeo.setAttribute('position',new THREE.BufferAttribute(particles,3));scene.add(new THREE.Points(particleGeo,new THREE.PointsMaterial({color:'#c5dfb1',size:.045,transparent:true,opacity:.48,depthWrite:false})));
const bubbles=[];const bubbleMat=new THREE.MeshPhongMaterial({color:'#addbc0',transparent:true,opacity:.22,shininess:100});for(let i=0;i<65;i++){let b=mesh(new THREE.SphereGeometry(between(.025,.11),7,6),bubbleMat,between(-30,30),between(0,22),between(-45,24));bubbles.push({b,speed:between(.35,.9),x:b.position.x});}
// Surface and long, soft shafts of sunlight.
const surface=mesh(new THREE.PlaneGeometry(240,240,30,30).rotateX(Math.PI/2),new THREE.MeshBasicMaterial({color:'#8ecdb1',transparent:true,opacity:.22,side:THREE.DoubleSide}),0,23,0);
const beamMat=new THREE.ShaderMaterial({transparent:true,depthWrite:false,side:THREE.DoubleSide,blending:THREE.AdditiveBlending,uniforms:{time:{value:0}},vertexShader:'varying vec2 v;void main(){v=uv;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.);}',fragmentShader:'varying vec2 v;uniform float time;void main(){float edge=pow(sin(v.x*3.14159),2.);float pulse=.8+.2*sin(time*.35+v.y*5.);gl_FragColor=vec4(.66,.77,.42,edge*(.02+.065*v.y)*pulse);}' });for(let i=0;i<15;i++){const b=mesh(new THREE.PlaneGeometry(between(1,3),30),beamMat,between(-35,30),12,between(-55,6));b.rotation.z=-.35;b.rotation.y=.3;}
let down=false,lastX=0,lastY=0,activePointer=null,demo=location.hash==='#demo',demoStart=performance.now(),introHidden=false;const notice=document.getElementById('notice');if(demo)notice.textContent='GUIDED DRIFT · TOUCH TO EXPLORE';
function hideIntro(){if(!introHidden){introHidden=true;document.getElementById('intro').style.opacity='0';}}
renderer.domElement.addEventListener('pointerdown',e=>{demo=false;notice.textContent='';down=true;activePointer=e.pointerId;lastX=e.clientX;lastY=e.clientY;renderer.domElement.setPointerCapture(e.pointerId);hideIntro();});
renderer.domElement.addEventListener('pointermove',e=>{if(!down||e.pointerId!==activePointer)return;yaw-=(e.clientX-lastX)*.004;pitch-= (e.clientY-lastY)*.003;pitch=THREE.MathUtils.clamp(pitch,-1.15,1.05);lastX=e.clientX;lastY=e.clientY;});
function release(){down=false;activePointer=null}renderer.domElement.addEventListener('pointerup',release);renderer.domElement.addEventListener('pointercancel',release);window.addEventListener('blur',release);
let audio=null;document.getElementById('sound').onclick=function(){if(!audio){const C=window.AudioContext||window.webkitAudioContext;if(!C)return;audio=new C();let buffer=audio.createBuffer(1,audio.sampleRate*4,audio.sampleRate),data=buffer.getChannelData(0);let brown=0;for(let i=0;i<data.length;i++){brown=(brown+Math.random()*.04-.02)/1.02;data[i]=brown*3;}let source=audio.createBufferSource();source.buffer=buffer;source.loop=true;let filter=audio.createBiquadFilter();filter.type='lowpass';filter.frequency.value=480;let gain=audio.createGain();gain.gain.value=.3;source.connect(filter).connect(gain).connect(audio.destination);source.start();}else if(audio.state==='running'){audio.suspend();}else audio.resume();this.style.color=audio.state==='running'?'#e5ce7e':'#e5e8d2';this.setAttribute('aria-label',audio.state==='running'?'Mute underwater sound':'Enable underwater sound');};
document.getElementById('home').onclick=()=>{demo=false;down=false;yaw=0;pitch=-.08;camera.position.set(0,5.3,23);notice.textContent='';};
const local=new THREE.Vector3();function allowed(p){if(p.y<.8||p.y>21||Math.abs(p.x)>80||p.z< -90||p.z>65)return false;for(const c of colliders){if(c.type==='sphere'){if(p.distanceToSquared(c.p)<(c.r+.5)**2)return false;}else{local.copy(p).applyMatrix4(shipInv);if(Math.abs(local.x)<3.25&&Math.abs(local.z)<8&&local.y<3.2)return false;if((local.x+.16*(local.y-5))**2+(local.z+1.7)**2<.75**2&&local.y<10.5)return false;if(Math.abs(local.x-.4)<3.7&&Math.abs(local.y-7)<.65&&Math.abs(local.z+1.7)<.7)return false;if(Math.abs(local.x-.4)<2.9&&local.y>2.5&&local.y<7.5&&Math.abs(local.z+1.6)<1.2)return false;}}return true;}
function move(delta){const p=camera.position.clone();for(const axis of ['x','y','z']){p.copy(camera.position);p[axis]+=delta[axis];if(allowed(p))camera.position.copy(p);}}
let prev=performance.now();const direction=new THREE.Vector3();function frame(now){requestAnimationFrame(frame);const dt=Math.min((now-prev)/1000,.05),t=now/1000;prev=now;
if(demo){const u=((now-demoStart)/1000%20)/20;camera.position.set(Math.sin(u*Math.PI*2)*3,5.3+Math.sin(u*Math.PI*2)*1.4,23-Math.sin(u*Math.PI)*13);yaw=Math.sin(u*Math.PI*2)*.53;pitch=-.04+Math.sin(u*Math.PI*2)*.12;if(u>.18)hideIntro();}
camera.rotation.set(pitch,yaw,0);if(down){camera.getWorldDirection(direction);move(direction.multiplyScalar(dt*3.2));}
for(const k of kelps){let pos=k.m.geometry.attributes.position;for(let i=0;i<pos.count;i++){const y=k.base[i*3+1],v=y/k.height;pos.setX(i,k.base[i*3]*(1-v*.7)+Math.sin(t*.6+k.phase+v*2.3)*v*v*1.6);pos.setZ(i,k.base[i*3+2]+Math.cos(t*.43+k.phase+v*2)*v*.6);}pos.needsUpdate=true;}
for(const s of schools){let a=t*.14+s.phase;s.group.position.set(Math.cos(a)*s.r,s.y+Math.sin(a*1.7)*.6,s.z+Math.sin(a)*s.r*.4);s.group.rotation.y=Math.atan2(-Math.cos(a)*.4,-Math.sin(a));for(let i=0;i<s.fishes.length;i++){let f=s.fishes[i];f.f.position.y=f.offset.y+Math.sin(t*2+i*.7)*.09;f.tail.rotation.y=Math.sin(t*9+i)*.35;}}
for(const r of rays){let a=t*.065+r.phase;r.g.position.set(Math.sin(a)*22,11+Math.sin(a*2),-20+Math.cos(a)*12);r.g.rotation.y=Math.atan2(-Math.cos(a),Math.sin(a)*.55);const p=r.geo.attributes.position;p.setY(2,Math.sin(t*1.4+r.phase)*.6);p.setY(6,Math.sin(t*1.4+r.phase)*.6);p.needsUpdate=true;}
for(const o of bubbles){o.b.position.y+=dt*o.speed;if(o.b.position.y>23)o.b.position.y=.1;o.b.position.x=o.x+Math.sin(t*.6+o.x)*.25;}causticMat.uniforms.time.value=t;beamMat.uniforms.time.value=t;surface.position.y=23+Math.sin(t*.5)*.12;document.getElementById('depth').textContent=(23-camera.position.y).toFixed(1)+' M';document.getElementById('needle').style.transform='rotate('+(-yaw*180/Math.PI)+'deg)';renderer.render(scene,camera);}
window.addEventListener('resize',()=>{camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();renderer.setSize(innerWidth,innerHeight);});
requestAnimationFrame(frame);loading.style.opacity='0';setTimeout(()=>loading.remove(),1400);
})();
</script></body></html>