Skip to content
VibeCodeBench
Back to the app

The code

Jelly Orange Slice 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.)14.3 KB · 39 lines · loads cdn.jsdelivr.net/npm/three@0.160.0/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,viewport-fit=cover">
<title>Orange Jelly Lab</title>
<style>
:root{color-scheme:light;--ink:#46362e;--orange:#e87325}*{box-sizing:border-box}body{margin:0;background:#f7f1e8;color:var(--ink);font-family:ui-rounded,"Trebuchet MS",system-ui,sans-serif;overflow:hidden}#scene{position:absolute;inset:0;touch-action:none}canvas{display:block;width:100%;height:100%}.top{position:absolute;top:max(22px,env(safe-area-inset-top));left:clamp(20px,5vw,70px);pointer-events:none}.eyebrow{font-size:11px;letter-spacing:.22em;font-weight:800;color:#df812f}.top h1{font-family:Georgia,serif;font-weight:normal;font-size:clamp(30px,5vw,54px);line-height:1;margin:9px 0;color:#51392c}.top p{font-size:14px;color:#90796c;margin:0}.tag{position:absolute;right:clamp(20px,5vw,65px);top:max(28px,env(safe-area-inset-top));font-size:11px;letter-spacing:.15em;font-weight:bold;color:#a88e7d;pointer-events:none}.panel{position:absolute;bottom:max(22px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);width:min(620px,calc(100% - 32px));padding:16px 18px;background:rgba(255,255,255,.83);backdrop-filter:blur(18px);border:1px solid rgba(255,255,255,.95);box-shadow:0 12px 44px #967b5d24;border-radius:22px;display:flex;align-items:center;gap:14px}.slider{flex:1;min-width:100px}.label{display:flex;justify-content:space-between;font-size:11px;letter-spacing:.13em;text-transform:uppercase;font-weight:800;margin-bottom:8px;color:#806e62}.label span:last-child{color:#db792c}input{display:block;width:100%;accent-color:#ec8a30;cursor:pointer}button{border:0;border-radius:14px;min-height:48px;padding:0 22px;font:700 14px inherit;cursor:pointer;touch-action:manipulation}#squeeze{background:#ed852d;color:white;box-shadow:0 5px 14px #e9813555}#reset{background:#f3ede6;color:#745e51}.hint{position:absolute;bottom:118px;left:50%;transform:translateX(-50%);background:#fffaf2cc;border:1px solid #fff;color:#987e6a;border-radius:30px;padding:9px 16px;font-size:12px;white-space:nowrap;pointer-events:none}.dot{display:inline-block;width:7px;height:7px;border-radius:50%;background:#f39a42;margin-right:7px}@media(max-width:520px){.tag{display:none}.panel{gap:8px;padding:13px}.slider{min-width:75px}button{padding:0 13px}.top p{max-width:230px;line-height:1.4}.hint{bottom:108px}}
</style>
</head>
<body>
<div id="scene"></div><div class="top"><div class="eyebrow">A LITTLE MOMENT OF PLAY</div><h1>Orange jelly</h1><p>A little slice of sunshine, made to wobble.</p></div><div class="tag">THE JELLY LAB &nbsp; / &nbsp; 01</div><div class="hint"><span class="dot"></span>poke or drag the jelly</div><div class="panel"><div class="slider"><div class="label"><span>Firmness</span><span id="level">medium</span></div><input id="firm" type="range" min="0" max="100" value="50" aria-label="Firmness"></div><button id="squeeze">Squeeze</button><button id="reset">Reset</button></div>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
<script>
(()=>{'use strict';
const host=document.getElementById('scene'), renderer=new THREE.WebGLRenderer({antialias:true,alpha:true});renderer.setPixelRatio(Math.min(devicePixelRatio,2));renderer.shadowMap.enabled=true;renderer.shadowMap.type=THREE.PCFSoftShadowMap;renderer.outputColorSpace=THREE.SRGBColorSpace;renderer.toneMapping=THREE.ACESFilmicToneMapping;renderer.toneMappingExposure=1.12;host.appendChild(renderer.domElement);
const scene=new THREE.Scene();scene.background=new THREE.Color(0xf8f3eb);scene.fog=new THREE.Fog(0xf8f3eb,12,25);const camera=new THREE.PerspectiveCamera(35,1,.1,100);camera.position.set(5,5.8,8.4);camera.lookAt(0,.45,0);
scene.add(new THREE.HemisphereLight(0xfff4df,0xbfa58a,2.2));const light=new THREE.DirectionalLight(0xfff2dc,3.2);light.position.set(-4,8,5);light.castShadow=true;light.shadow.mapSize.set(1024,1024);light.shadow.camera.left=-6;light.shadow.camera.right=6;light.shadow.camera.top=6;light.shadow.camera.bottom=-6;light.shadow.bias=-.0004;scene.add(light);const back=new THREE.DirectionalLight(0xffb84f,1.6);back.position.set(3,3,-5);scene.add(back);
const floor=new THREE.Mesh(new THREE.PlaneGeometry(200,200),new THREE.MeshStandardMaterial({color:0xf6f0e7,roughness:1}));floor.rotation.x=-Math.PI/2;floor.position.y=-.12;floor.receiveShadow=true;scene.add(floor);
const plateMat=new THREE.MeshPhysicalMaterial({color:0xffffff,roughness:.2,metalness:0,clearcoat:.55,clearcoatRoughness:.18});const profile=[new THREE.Vector2(0,0),new THREE.Vector2(1.45,0),new THREE.Vector2(1.72,.025),new THREE.Vector2(1.95,.1),new THREE.Vector2(2.18,.19),new THREE.Vector2(2.3,.22),new THREE.Vector2(2.34,.19),new THREE.Vector2(2.28,.13),new THREE.Vector2(2.1,.045),new THREE.Vector2(1.8,-.035),new THREE.Vector2(1.45,-.08),new THREE.Vector2(0,-.08)];const plate=new THREE.Mesh(new THREE.LatheGeometry(profile,96),plateMat);plate.position.y=.01;plate.receiveShadow=true;plate.castShadow=true;scene.add(plate);
// A spring lattice fills the half-disc. Surface and inclusions follow its simulated nodes.
const N=24,L=5,R=1.48,thick=.42,base=.24;let nodes=[],springs=[],faces=[],outer=[],front=[],backfaces=[];const idx=(i,j,k)=>k*(N+1)*(L+1)+i*(L+1)+j;
for(let k=0;k<2;k++)for(let i=0;i<=N;i++){let a=Math.PI*i/N;for(let j=0;j<=L;j++){let rad=R*j/L;nodes.push({p:new THREE.Vector3(Math.cos(a)*rad,base+Math.sin(a)*rad,k?thick/2:-thick/2),v:new THREE.Vector3(),rest:new THREE.Vector3(Math.cos(a)*rad,base+Math.sin(a)*rad,k?thick/2:-thick/2)});}}
function spring(a,b,w=1){let d=nodes[a].rest.distanceTo(nodes[b].rest);if(d>1e-5)springs.push({a,b,d,w})}for(let k=0;k<2;k++)for(let i=0;i<=N;i++)for(let j=0;j<=L;j++){let a=idx(i,j,k);if(j<L)spring(a,idx(i,j+1,k));if(i<N){spring(a,idx(i+1,j,k));if(j<L){spring(a,idx(i+1,j+1,k),.7);spring(idx(i,j+1,k),idx(i+1,j,k),.7)}}if(!k){spring(a,idx(i,j,1));if(i<N)spring(a,idx(i+1,j,1),.7);if(j<L)spring(a,idx(i,j+1,1),.7)}if(i+2<=N)spring(a,idx(i+2,j,k),.35);if(j+2<=L)spring(a,idx(i,j+2,k),.35)}
function quad(list,a,b,c,d){list.push(a,b,d,b,c,d)}for(let i=0;i<N;i++)for(let j=0;j<L;j++){quad(front,idx(i,j,0),idx(i+1,j,0),idx(i+1,j+1,0),idx(i,j+1,0));quad(backfaces,idx(i,j,1),idx(i,j+1,1),idx(i+1,j+1,1),idx(i+1,j,1))}for(let i=0;i<N;i++)quad(outer,idx(i,L,0),idx(i+1,L,0),idx(i+1,L,1),idx(i,L,1));for(let j=0;j<L;j++){quad(outer,idx(0,j,0),idx(0,j,1),idx(0,j+1,1),idx(0,j+1,0));quad(outer,idx(N,j,0),idx(N,j+1,0),idx(N,j+1,1),idx(N,j,1))}
function meshFor(indices,material){let g=new THREE.BufferGeometry(),pos=new Float32Array(nodes.length*3);g.setAttribute('position',new THREE.BufferAttribute(pos,3));g.setIndex(indices);g.computeVertexNormals();let m=new THREE.Mesh(g,material);m.castShadow=true;m.receiveShadow=true;scene.add(m);return m}
const fleshMat=new THREE.MeshPhysicalMaterial({color:0xff9b18,roughness:.17,metalness:0,transparent:true,opacity:.77,side:THREE.DoubleSide,clearcoat:1,clearcoatRoughness:.12,emissive:0xc44700,emissiveIntensity:.12,depthWrite:false});let flesh=meshFor(front.concat(backfaces),fleshMat);const peelMat=new THREE.MeshPhysicalMaterial({color:0xf47b08,roughness:.27,clearcoat:.8,side:THREE.DoubleSide});let peel=meshFor(outer,peelMat);
// Fine citrus membranes and a pale pith line are attached to corresponding lattice nodes.
const membraneMat=new THREE.LineBasicMaterial({color:0xffe3a0,transparent:true,opacity:.8});let lines=[],lineIndices=[];for(let k=0;k<2;k++){for(let i=0;i<=N;i+=3)for(let j=1;j<L;j++)lineIndices.push(idx(i,j,k),idx(i,j+1,k));for(let i=0;i<N;i++)lineIndices.push(idx(i,L-1,k),idx(i+1,L-1,k))}let lineGeo=new THREE.BufferGeometry();lineGeo.setAttribute('position',new THREE.BufferAttribute(new Float32Array(lineIndices.length*3),3));let membrane=new THREE.LineSegments(lineGeo,membraneMat);scene.add(membrane);
// Juice vesicles: thousands of little translucent, directional glints, embedded in the deforming mesh.
let seed=2048;function rand(){seed=(seed*1664525+1013904223)>>>0;return seed/4294967296}let cells=[];const cellGeo=new THREE.SphereGeometry(1,5,4),cellMat=new THREE.MeshPhysicalMaterial({color:0xffd060,transparent:true,opacity:.65,roughness:.24,emissive:0xf06a00,emissiveIntensity:.12,depthWrite:false});const cellCount=1100,inst=new THREE.InstancedMesh(cellGeo,cellMat,cellCount);scene.add(inst);let dummy=new THREE.Object3D();for(let n=0;n<cellCount;n++){let i=Math.min(N-1,Math.floor(rand()*N)),j=1+Math.min(L-2,Math.floor(rand()*(L-1))),u=rand(),v=rand(),z=rand(),size=.007+rand()*.009;cells.push({i,j,u,v,z,size,angle:Math.PI*(i+u)/N})}
function interp(i,j,u,v,z){let a=nodes[idx(i,j,0)].p,b=nodes[idx(i+1,j,0)].p,c=nodes[idx(i,j+1,0)].p,d=nodes[idx(i+1,j+1,0)].p;let e=nodes[idx(i,j,1)].p,f=nodes[idx(i+1,j,1)].p,g=nodes[idx(i,j+1,1)].p,h=nodes[idx(i+1,j+1,1)].p;return new THREE.Vector3().copy(a).multiplyScalar((1-u)*(1-v)*(1-z)).addScaledVector(b,u*(1-v)*(1-z)).addScaledVector(c,(1-u)*v*(1-z)).addScaledVector(d,u*v*(1-z)).addScaledVector(e,(1-u)*(1-v)*z).addScaledVector(f,u*(1-v)*z).addScaledVector(g,(1-u)*v*z).addScaledVector(h,u*v*z)}
function updateMesh(){for(const m of [flesh,peel]){let p=m.geometry.attributes.position;for(let i=0;i<nodes.length;i++)p.setXYZ(i,nodes[i].p.x,nodes[i].p.y,nodes[i].p.z);p.needsUpdate=true;m.geometry.computeVertexNormals()}let p=lineGeo.attributes.position;lineIndices.forEach((id,n)=>{let q=nodes[id].p;p.setXYZ(n,q.x,q.y,q.z+(id<(N+1)*(L+1)?-.009:.009))});p.needsUpdate=true;cells.forEach((c,n)=>{dummy.position.copy(interp(c.i,c.j,c.u,c.v,c.z));dummy.rotation.set(0,0,c.angle);dummy.scale.set(c.size*2.5,c.size,c.size);dummy.updateMatrix();inst.setMatrixAt(n,dummy.matrix)});inst.instanceMatrix.needsUpdate=true}
const drops=[];const dropMat=new THREE.MeshPhysicalMaterial({color:0xffa418,roughness:.12,transparent:true,opacity:.8,clearcoat:1});function drop(){let m=new THREE.Mesh(new THREE.SphereGeometry(.055,12,8),dropMat);m.position.set((rand()-.5)*1.5,.32,(rand()-.5)*.3);m.scale.set(.8,1.3,.8);scene.add(m);drops.push({m,v:new THREE.Vector3((rand()-.5)*.025,.01,(rand()-.5)*.03),life:3})}
let firmness=50,drag=null,squeeze=0,last=performance.now(),acc=0,demo=location.hash==='#demo',demoTime=0,demoStage=-1;const ray=new THREE.Raycaster(),pointer=new THREE.Vector2(),plane=new THREE.Plane(new THREE.Vector3(0,0,1),0),hit=new THREE.Vector3();function coords(e){let r=renderer.domElement.getBoundingClientRect();pointer.set((e.clientX-r.left)/r.width*2-1,-(e.clientY-r.top)/r.height*2+1);ray.setFromCamera(pointer,camera)}function start(e){demo=false;coords(e);let hits=ray.intersectObject(flesh);if(!hits.length)return;let point=hits[0].point,ids=[];nodes.forEach((n,i)=>{let d=n.p.distanceTo(point);if(d<.55)ids.push({i,w:Math.max(0,1-d/.55),offset:n.p.clone().sub(point)})});if(!ids.length)return;plane.setFromNormalAndCoplanarPoint(camera.getWorldDirection(new THREE.Vector3()).negate(),point);drag={ids,point:point.clone(),target:point.clone()};renderer.domElement.setPointerCapture(e.pointerId);e.preventDefault()}function move(e){if(!drag)return;coords(e);if(ray.ray.intersectPlane(plane,hit)){drag.target.copy(hit);let delta=drag.target.clone().sub(drag.point);delta.clampLength(0,.8);drag.target.copy(drag.point).add(delta)}e.preventDefault()}function end(){drag=null}renderer.domElement.addEventListener('pointerdown',start);renderer.domElement.addEventListener('pointermove',move);renderer.domElement.addEventListener('pointerup',end);renderer.domElement.addEventListener('pointercancel',end);
document.getElementById('firm').addEventListener('input',e=>{demo=false;firmness=+e.target.value;document.getElementById('level').textContent=firmness<34?'soft':firmness<67?'medium':'firm'});document.getElementById('squeeze').addEventListener('click',()=>{demo=false;squeeze=1;for(let i=0;i<5;i++)drop()});document.getElementById('reset').addEventListener('click',()=>{demo=false;reset()});function reset(){nodes.forEach(n=>{n.p.copy(n.rest);n.v.set(0,0,0)});drops.forEach(d=>scene.remove(d.m));drops.length=0;squeeze=0;drag=null}
function step(dt){const stiffness=95+firmness*2.2;nodes.forEach(n=>{n.v.y-=1.9*dt;n.v.addScaledVector(n.rest.clone().sub(n.p),4*dt)});for(let s of springs){let a=nodes[s.a],b=nodes[s.b],d=new THREE.Vector3().subVectors(b.p,a.p),len=d.length();if(len<1e-6)continue;d.multiplyScalar(1/len);let rel=new THREE.Vector3().subVectors(b.v,a.v).dot(d);let f=((len-s.d)*stiffness*s.w+rel*2.5)*dt;a.v.addScaledVector(d,f);b.v.addScaledVector(d,-f)}if(drag)for(let x of drag.ids){let n=nodes[x.i],target=drag.target.clone().add(x.offset);n.v.addScaledVector(target.sub(n.p),40*x.w*dt)}if(squeeze>0){squeeze=Math.max(0,squeeze-dt*.45);let strength=Math.sin((1-squeeze)*Math.PI)*10;for(let n of nodes){n.v.x-=n.p.x*strength*dt;n.v.y-=(n.p.y-base)*strength*.23*dt}}for(let n of nodes){n.v.multiplyScalar(Math.exp(-2.8*dt));n.v.clampLength(0,4);n.p.addScaledVector(n.v,dt);if(n.p.y<base){n.p.y=base;if(n.v.y<0)n.v.y*=-.12}let delta=n.p.clone().sub(n.rest);if(delta.length()>.9){delta.setLength(.9);n.p.copy(n.rest).add(delta);n.v.multiplyScalar(.4)}}for(let i=drops.length-1;i>=0;i--){let d=drops[i];d.life-=dt;d.v.y-=.0006;d.m.position.add(d.v);if(d.m.position.y<.13){d.m.position.y=.13;d.v.y=0;d.v.x*=.96;d.v.z*=.96;d.m.scale.set(1.2,.3,1.2)}d.m.material.opacity=Math.min(.8,d.life);if(d.life<=0){scene.remove(d.m);drops.splice(i,1)}}}
function resize(){let w=innerWidth,h=innerHeight;renderer.setSize(w,h);camera.aspect=w/h;camera.position.set(w/h<.8?6.4:5, w/h<.8?6.8:5.8,w/h<.8?10.4:8.4);camera.lookAt(0,.5,0);camera.updateProjectionMatrix()}addEventListener('resize',resize);resize();function frame(now){requestAnimationFrame(frame);let dt=Math.min((now-last)/1000,.05);last=now;acc+=dt;while(acc>1/120){step(1/120);acc-=1/120}if(demo){demoTime+=dt;let stage=Math.floor(demoTime/20);if(stage!==demoStage){demoStage=stage;reset()}let t=demoTime%20;if(t>2&&t<4){let id=idx(12,4,1);if(!drag){let p=nodes[id].p.clone();drag={ids:[{i:id,w:1,offset:new THREE.Vector3()}],point:p.clone(),target:p.clone()}}drag.target.copy(drag.point).add(new THREE.Vector3(.5*Math.sin((t-2)*Math.PI/2),.3*Math.sin((t-2)*Math.PI/2),.2))}else if(t>=4&&t<5)drag=null;if(t>7&&t<7.1&&!squeeze){squeeze=1;for(let i=0;i<5;i++)drop()}if(t>12&&t<15){firmness=15;document.getElementById('firm').value=15;document.getElementById('level').textContent='soft'}if(t>=17){firmness=50;document.getElementById('firm').value=50;document.getElementById('level').textContent='medium'}}updateMesh();renderer.render(scene,camera)}updateMesh();requestAnimationFrame(frame);
})();
</script></body></html>