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.)16.7 KB · 94 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, viewport-fit=cover">
<title>Little slice of sunshine</title>
<style>
:root{color-scheme:light;--ink:#4d3326;--muted:#987c69;--orange:#ea7825;--cream:#fff9ef}*{box-sizing:border-box}html,body{margin:0;width:100%;height:100%;overflow:hidden}body{font-family:ui-rounded,"Avenir Next",Avenir,system-ui,-apple-system,sans-serif;background:#f5eadb;color:var(--ink)}#stage{position:absolute;inset:0;touch-action:none;cursor:grab}#stage:active{cursor:grabbing}canvas{display:block;width:100%;height:100%}.top{position:absolute;top:0;left:0;right:0;display:flex;justify-content:space-between;align-items:flex-start;padding:clamp(20px,4vw,48px);pointer-events:none}.eyebrow{font-size:10px;letter-spacing:.23em;font-weight:800;color:#c67a3f;text-transform:uppercase;margin-bottom:9px}.top h1{font-family:Georgia,serif;font-size:clamp(28px,4.2vw,52px);font-weight:400;letter-spacing:-.045em;line-height:1;margin:0}.top p{font-size:13px;color:#a18573;margin:10px 0 0;letter-spacing:.01em}.badge{border:1px solid #e7d1bd;background:#fffaf1aa;border-radius:99px;padding:10px 15px;font-size:10px;font-weight:800;letter-spacing:.16em;color:#b97b4d;white-space:nowrap}.panel{position:absolute;left:50%;bottom:max(24px,env(safe-area-inset-bottom));transform:translateX(-50%);width:min(680px,calc(100% - 32px));background:#fffdf8ed;box-shadow:0 16px 50px #9a704226,0 2px 8px #9a70420d;border:1px solid #fff;border-radius:22px;padding:18px 20px;display:flex;align-items:center;gap:18px;backdrop-filter:blur(15px)}.hint{flex:1;min-width:140px}.hint strong{display:block;font-family:Georgia,serif;font-size:17px;font-weight:400}.hint span{display:block;font-size:11px;color:#a98e7b;margin-top:4px}.divider{height:42px;width:1px;background:#efe3d6}.control{width:130px}.control label{display:flex;justify-content:space-between;color:#806553;font-size:11px;font-weight:700;margin-bottom:7px}.control output{color:#d77c35}input[type=range]{width:100%;height:20px;margin:0;accent-color:#ed8d3d;cursor:pointer;touch-action:pan-x}.buttons{display:flex;gap:8px}button{font:inherit;cursor:pointer;border:0;min-height:46px;border-radius:14px;font-weight:700;font-size:12px;padding:0 17px;white-space:nowrap;transition:transform .15s,background .15s}button:active{transform:scale(.96)}#squeeze{color:#fff;background:#ed8a39;box-shadow:0 5px 12px #ed8a393b}#squeeze:hover{background:#db7628}#reset{color:#8a6b57;background:#f8eee2}#reset:hover{background:#f1e0ce}.caption{position:absolute;right:clamp(20px,4vw,48px);bottom:145px;text-align:right;color:#ba9d88;font-size:10px;letter-spacing:.15em;text-transform:uppercase;pointer-events:none}.error{display:none;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);text-align:center;padding:24px;background:#fffaf2;border-radius:18px;max-width:80%;line-height:1.5}.error.show{display:block}@media(max-width:600px){.top{padding:25px 22px}.top h1{font-size:33px}.top p{font-size:12px}.badge{font-size:9px;padding:9px 11px}.panel{bottom:max(14px,env(safe-area-inset-bottom));display:grid;grid-template-columns:1fr auto;gap:13px 10px;padding:15px;border-radius:19px}.hint strong{font-size:16px}.divider{display:none}.control{grid-column:1;grid-row:2;width:100%;max-width:210px}.buttons{grid-column:2;grid-row:1 / span 2;align-items:center;gap:6px}button{padding:0 12px;min-height:48px}.caption{display:none}}@media(max-width:370px){.badge{display:none}.buttons{flex-direction:column;align-items:stretch}button{min-height:38px}.panel{gap:8px}.top h1{font-size:29px}}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive orange jelly. Drag the slice to stretch it."></div>
<header class="top"><div><div class="eyebrow">A little moment of play</div><h1>Slice of sunshine<span style="color:#ed8a39">.</span></h1><p>A little squish for your day.</p></div><div class="badge">✳ &nbsp; FRESHLY MADE</div></header>
<div class="caption">Made to be squished &nbsp; ✳</div>
<section class="panel" aria-label="Jelly controls"><div class="hint"><strong>Go on, give it a poke.</strong><span>Drag the jelly, then let it wobble.</span></div><div class="divider"></div><div class="control"><label for="firmness">Firmness <output id="firmValue">Medium</output></label><input id="firmness" type="range" min="0" max="100" value="50" aria-label="Jelly firmness"></div><div class="buttons"><button id="squeeze" type="button">Squeeze <span aria-hidden="true">↘</span></button><button id="reset" type="button">Reset</button></div></section>
<div id="error" class="error">The jelly couldn't load. Please check your connection and try again.</div>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
<script>
(function(){
'use strict';
if(!window.THREE){document.getElementById('error').classList.add('show');return;}
const stage=document.getElementById('stage'), firmness=document.getElementById('firmness'), firmValue=document.getElementById('firmValue');
const scene=new THREE.Scene();scene.background=new THREE.Color(0xf5eadb);scene.fog=new THREE.Fog(0xf5eadb,12,24);
const camera=new THREE.PerspectiveCamera(35,1,.1,100);camera.position.set(3.1,2.65,7.3);camera.lookAt(0,.82,0);
const renderer=new THREE.WebGLRenderer({antialias:true,alpha:false});renderer.setPixelRatio(Math.min(devicePixelRatio,2));renderer.setSize(innerWidth,innerHeight);renderer.outputColorSpace=THREE.SRGBColorSpace;renderer.toneMapping=THREE.ACESFilmicToneMapping;renderer.toneMappingExposure=1.12;renderer.shadowMap.enabled=true;renderer.shadowMap.type=THREE.PCFSoftShadowMap;stage.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xfff7e9,0xd5a97e,2.1));
const key=new THREE.DirectionalLight(0xfff4d6,3.1);key.position.set(-3,6,5);key.castShadow=true;key.shadow.mapSize.set(1024,1024);key.shadow.camera.left=-5;key.shadow.camera.right=5;key.shadow.camera.top=5;key.shadow.camera.bottom=-5;key.shadow.normalBias=.025;key.shadow.bias=-.0002;scene.add(key);
const rim=new THREE.DirectionalLight(0xffc473,2.0);rim.position.set(1,3,-4);scene.add(rim);
const floor=new THREE.Mesh(new THREE.PlaneGeometry(200,200),new THREE.MeshStandardMaterial({color:0xf5eadb,roughness:1}));floor.rotation.x=-Math.PI/2;floor.position.y=-.055;floor.receiveShadow=true;scene.add(floor);
// A shallow, lathed porcelain plate, with a gently raised rim.
const profile=[new THREE.Vector2(0,0),new THREE.Vector2(1.25,0),new THREE.Vector2(1.52,.025),new THREE.Vector2(1.75,.09),new THREE.Vector2(1.94,.17),new THREE.Vector2(2.02,.19),new THREE.Vector2(2.05,.17),new THREE.Vector2(2.03,.13),new THREE.Vector2(1.9,.08),new THREE.Vector2(1.7,.015),new THREE.Vector2(1.45,-.025),new THREE.Vector2(.5,-.035),new THREE.Vector2(0,-.035)];
const plate=new THREE.Mesh(new THREE.LatheGeometry(profile,96),new THREE.MeshPhysicalMaterial({color:0xfffdf9,roughness:.2,clearcoat:.65,clearcoatRoughness:.18}));plate.position.y=.025;plate.receiveShadow=true;plate.castShadow=true;scene.add(plate);
const BASE=.145,R=1.48,DEPTH=.52;
// The soft body is a 3D lattice of particles connected by distance constraints.
// Face, shear and cross-layer links maintain volume while allowing elastic motion.
const nodes=[],links=[],index=new Map(),step=.24;
for(let z=-1;z<=1;z++)for(let y=0;y<=6;y++)for(let x=-6;x<=6;x++){
 const px=x*step,py=y*step;if(px*px+py*py>(R-.015)*(R-.015))continue;
 const p=new THREE.Vector3(px,BASE+py,z*.215);let id=nodes.length;nodes.push({p:p.clone(),old:p.clone(),rest:p.clone(),x,y,z});index.set(x+','+y+','+z,id);
}
for(let i=0;i<nodes.length;i++){const a=nodes[i];for(let dz=-1;dz<=1;dz++)for(let dy=-1;dy<=1;dy++)for(let dx=-1;dx<=1;dx++){
 if(!dx&&!dy&&!dz)continue;const j=index.get((a.x+dx)+','+(a.y+dy)+','+(a.z+dz));if(j===undefined||j<=i)continue;
 links.push({a:i,b:j,len:a.rest.distanceTo(nodes[j].rest),weight:(Math.abs(dx)+Math.abs(dy)+Math.abs(dz)===1)?1:.8});
}}
function makeShape(r1,r2,a1,a2){const s=new THREE.Shape();let n=36;s.moveTo(Math.cos(a1)*r1,BASE+Math.sin(a1)*r1);for(let i=0;i<=n;i++){let a=a1+(a2-a1)*i/n;s.lineTo(Math.cos(a)*r2,BASE+Math.sin(a)*r2)}for(let i=n;i>=0;i--){let a=a1+(a2-a1)*i/n;s.lineTo(Math.cos(a)*r1,BASE+Math.sin(a)*r1)}s.closePath();return s;}
function material(color,opacity){return new THREE.MeshPhysicalMaterial({color,transparent:true,opacity,roughness:.2,metalness:0,clearcoat:1,clearcoatRoughness:.12,side:THREE.DoubleSide,depthWrite:true});}
const peelMat=new THREE.MeshPhysicalMaterial({color:0xff8a08,roughness:.29,clearcoat:.9,clearcoatRoughness:.16});
const pithMat=new THREE.MeshPhysicalMaterial({color:0xffedc8,roughness:.5,clearcoat:.3});
const jellyMat=material(0xffa427,.82), segMats=[material(0xffa527,.83),material(0xffb238,.83),material(0xff9818,.84)];
const deformables=[];
function bind(geo){const pos=geo.attributes.position;const original=new Float32Array(pos.array);const ids=new Uint16Array(pos.count*4),weights=new Float32Array(pos.count*4);for(let i=0;i<pos.count;i++){
 const px=original[i*3],py=original[i*3+1],pz=original[i*3+2];let near=[];for(let j=0;j<nodes.length;j++){const q=nodes[j].rest,dist=(q.x-px)**2+(q.y-py)**2+(q.z-pz)**2;near.push([dist,j]);}near.sort((a,b)=>a[0]-b[0]);let sum=0;for(let k=0;k<4;k++){let w=1/(near[k][0]+.012);ids[i*4+k]=near[k][1];weights[i*4+k]=w;sum+=w;}for(let k=0;k<4;k++)weights[i*4+k]/=sum;
 }deformables.push({geo,original,ids,weights});}
function extruded(shape,depth,mat,bevel){const g=new THREE.ExtrudeGeometry(shape,{depth,bevelEnabled:true,bevelThickness:bevel,bevelSize:bevel,bevelSegments:2,curveSegments:24,steps:1});g.translate(0,0,-depth/2);g.computeVertexNormals();bind(g);const mesh=new THREE.Mesh(g,mat);mesh.castShadow=true;mesh.receiveShadow=true;scene.add(mesh);return mesh;}
// A translucent orange body, pith border, peel and individual radial segments.
const body=extruded(makeShape(0,R-.055,0,Math.PI),DEPTH-.04,jellyMat,.025);
extruded(makeShape(R-.13,R-.045,0,Math.PI),DEPTH+.008,pithMat,.012);
extruded(makeShape(R-.055,R,0,Math.PI),DEPTH+.02,peelMat,.018);
const count=9;
for(let i=0;i<count;i++){let gap=.022,a=i*Math.PI/count+gap,b=(i+1)*Math.PI/count-gap;extruded(makeShape(.075,R-.16,a,b),DEPTH+.032,segMats[i%3],.016);}
// Hundreds of small, individually placed translucent vesicles on both cut faces.
let seed=87331;function rand(){seed=(seed*1664525+1013904223)>>>0;return seed/4294967296;}
const cellGeo=new THREE.SphereGeometry(1,7,5),cellMat=new THREE.MeshPhysicalMaterial({color:0xffd36d,transparent:true,opacity:.63,roughness:.25,clearcoat:1,depthWrite:false});
const cellCount=640,cells=new THREE.InstancedMesh(cellGeo,cellMat,cellCount);cells.frustumCulled=false;scene.add(cells);const cellData=[];for(let i=0;i<cellCount;i++){
 let seg=Math.floor(rand()*count),angle=(seg+.12+rand()*.76)*Math.PI/count,rad=.17+Math.sqrt(rand())*(R-.37),x=Math.cos(angle)*rad,y=BASE+Math.sin(angle)*rad,z=(i%2?1:-1)*(DEPTH/2+.036+rand()*.008);let closest=0,dmin=Infinity;for(let j=0;j<nodes.length;j++){let p=nodes[j].rest,d=(p.x-x)**2+(p.y-y)**2+(p.z-z)**2;if(d<dmin){dmin=d;closest=j;}}cellData.push({x,y,z,angle,node:closest,size:.7+rand()*.7});}
const dummy=new THREE.Object3D();function updateCells(){for(let i=0;i<cellCount;i++){const c=cellData[i],n=nodes[c.node],d=n.p.clone().sub(n.rest);dummy.position.set(c.x+d.x,c.y+d.y,c.z+d.z);dummy.rotation.set(0,0,c.angle-Math.PI/2);dummy.scale.set(.012*c.size,.039*c.size,.008*c.size);dummy.updateMatrix();cells.setMatrixAt(i,dummy.matrix);}cells.instanceMatrix.needsUpdate=true;}
function updateSkin(){for(const item of deformables){const pos=item.geo.attributes.position,arr=pos.array;for(let i=0;i<pos.count;i++){let x=item.original[i*3],y=item.original[i*3+1],z=item.original[i*3+2];for(let k=0;k<4;k++){const n=nodes[item.ids[i*4+k]],w=item.weights[i*4+k];x+=(n.p.x-n.rest.x)*w;y+=(n.p.y-n.rest.y)*w;z+=(n.p.z-n.rest.z)*w;}arr[i*3]=x;arr[i*3+1]=y;arr[i*3+2]=z;}pos.needsUpdate=true;item.geo.computeVertexNormals();item.geo.computeBoundingSphere();}updateCells();}
const droplets=[];const dropMat=new THREE.MeshPhysicalMaterial({color:0xffaa2b,transparent:true,opacity:.82,roughness:.1,clearcoat:1});
function makeDrops(){for(let i=0;i<5;i++){let m=new THREE.Mesh(new THREE.SphereGeometry(.035+rand()*.018,12,8),dropMat);m.position.set((rand()-.5)*.8,BASE+.13,(rand()-.5)*.3);m.scale.set(.8,1.25,.8);scene.add(m);droplets.push({mesh:m,v:new THREE.Vector3((rand()-.5)*.8,.45+rand()*.45,.35+rand()*.5),life:0});}}
let squeezeTime=0,drag=null;function squeeze(){squeezeTime=1.05;makeDrops();}
function reset(){drag=null;squeezeTime=0;for(const n of nodes){n.p.copy(n.rest);n.old.copy(n.rest);}while(droplets.length)scene.remove(droplets.pop().mesh);updateSkin();}
const raycaster=new THREE.Raycaster(),pointer=new THREE.Vector2(),plane=new THREE.Plane(),intersection=new THREE.Vector3();
function coords(e){const rect=renderer.domElement.getBoundingClientRect();pointer.set((e.clientX-rect.left)/rect.width*2-1,-(e.clientY-rect.top)/rect.height*2+1);raycaster.setFromCamera(pointer,camera);}
function nearestNode(point){let best=0,d=Infinity;for(let i=0;i<nodes.length;i++){let v=nodes[i].p.distanceToSquared(point);if(v<d){d=v;best=i;}}return best;}
function poke(point){for(const n of nodes){let d=n.p.distanceTo(point);if(d<.7){const amount=(1-d/.7)*.095;n.old.z+=amount;n.old.y-=amount*.35;}}}
let demo=location.hash==='#demo',demoStart=performance.now(),demoPhase=-1;
stage.addEventListener('pointerdown',e=>{demo=false;coords(e);const hit=raycaster.intersectObject(body,false)[0];if(!hit)return;e.preventDefault();poke(hit.point);const normal=camera.getWorldDirection(new THREE.Vector3());plane.setFromNormalAndCoplanarPoint(normal,hit.point);drag={id:nearestNode(hit.point),start:hit.point.clone(),target:hit.point.clone(),pointer:e.pointerId};stage.setPointerCapture(e.pointerId);});
stage.addEventListener('pointermove',e=>{if(!drag||drag.pointer!==e.pointerId)return;coords(e);if(raycaster.ray.intersectPlane(plane,intersection)){let delta=intersection.clone().sub(drag.start);delta.clampLength(0,.8);drag.target.copy(drag.start).add(delta);drag.target.y=Math.max(BASE,drag.target.y);}});
function endDrag(e){if(drag&&drag.pointer===e.pointerId)drag=null;}stage.addEventListener('pointerup',endDrag);stage.addEventListener('pointercancel',endDrag);
function stopDemo(){demo=false;drag=null;}document.getElementById('squeeze').addEventListener('click',()=>{stopDemo();squeeze();});document.getElementById('reset').addEventListener('click',()=>{stopDemo();reset();});firmness.addEventListener('input',()=>{stopDemo();const v=+firmness.value;firmValue.textContent=v<34?'Soft':v<67?'Medium':'Firm';});
function simulate(dt){const stiff=.24+(+firmness.value/100)*.48;for(const n of nodes){let vx=(n.p.x-n.old.x)*.985,vy=(n.p.y-n.old.y)*.985,vz=(n.p.z-n.old.z)*.985;n.old.copy(n.p);n.p.x+=vx;n.p.y+=vy-3.2*dt*dt;n.p.z+=vz;if(squeezeTime>0){let f=Math.sin(Math.PI*(1-squeezeTime/1.05));n.p.x-=n.p.x*f*.005;n.p.y-=(n.p.y-BASE)*f*.0015;}}
 for(let it=0;it<5;it++){for(const l of links){let a=nodes[l.a].p,b=nodes[l.b].p,dx=b.x-a.x,dy=b.y-a.y,dz=b.z-a.z,dist=Math.sqrt(dx*dx+dy*dy+dz*dz)||.0001,correction=(dist-l.len)/dist*stiff*l.weight*.5;dx*=correction;dy*=correction;dz*=correction;a.x+=dx;a.y+=dy;a.z+=dz;b.x-=dx;b.y-=dy;b.z-=dz;}if(drag){let n=nodes[drag.id];n.p.lerp(drag.target,.38);}for(const n of nodes){n.p.y=Math.max(BASE,n.p.y);n.p.x=THREE.MathUtils.clamp(n.p.x,-2.05,2.05);n.p.z=THREE.MathUtils.clamp(n.p.z,-.85,.85);}}
 if(squeezeTime>0)squeezeTime=Math.max(0,squeezeTime-dt);for(let i=droplets.length-1;i>=0;i--){let d=droplets[i];d.life+=dt;d.v.y-=3.4*dt;d.mesh.position.addScaledVector(d.v,dt);if(d.mesh.position.y<.18){d.mesh.position.y=.18;d.v.y=Math.abs(d.v.y)*.18;d.v.x*=.9;d.v.z*=.9;d.mesh.scale.y=.55;}if(d.life>3.5){scene.remove(d.mesh);droplets.splice(i,1);}}}
function resize(){const w=innerWidth,h=innerHeight;camera.aspect=w/h;if(w<600){camera.position.set(3.35,2.9,8.8);camera.lookAt(0,.8,0);}else{camera.position.set(3.1,2.65,7.3);camera.lookAt(0,.82,0);}camera.updateProjectionMatrix();renderer.setSize(w,h);}
window.addEventListener('resize',resize);resize();updateSkin();let last=performance.now(),acc=0;
function animate(now){requestAnimationFrame(animate);let elapsed=Math.min((now-last)/1000,.05);last=now;
 if(demo){let t=((now-demoStart)/1000)%20,phase=Math.floor(t);if(phase!==demoPhase){demoPhase=phase;if(phase===1)poke(new THREE.Vector3(.3,1.1,.25));if(phase===7)squeeze();if(phase===14){firmness.value=15;firmValue.textContent='Soft';poke(new THREE.Vector3(-.45,.9,.25));}if(phase===18){firmness.value=50;firmValue.textContent='Medium';reset();}}
 if(t>=3&&t<5.5){if(!drag){let p=new THREE.Vector3(.72,1.17,.22);drag={id:nearestNode(p),start:p.clone(),target:p.clone(),pointer:-1};}drag.target.set(.72+.36*Math.sin((t-3)/2.5*Math.PI),1.17+.22*Math.sin((t-3)/2.5*Math.PI),.22);}else if(drag&&drag.pointer===-1)drag=null;}
 acc+=elapsed;let steps=0;while(acc>=1/120&&steps<6){simulate(1/120);acc-=1/120;steps++;}updateSkin();renderer.render(scene,camera);}
requestAnimationFrame(animate);
})();
</script>
</body>
</html>