Back to the app
The code
Build a Cell, Part by Part by Claude Opus 5.5
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">
<title>Build a Cell</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#0b1424;font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif;color:#eef;touch-action:none;user-select:none;-webkit-user-select:none}
canvas{display:block}
#top{position:fixed;top:0;left:0;right:0;padding:12px 16px;text-align:center;pointer-events:none}
#top h1{margin:0;font-size:20px;color:#9fe3ff}
#card{position:fixed;left:50%;transform:translateX(-50%);top:52px;max-width:min(92vw,520px);background:rgba(20,34,60,.88);border:2px solid #3d6aa8;border-radius:16px;padding:12px 16px;text-align:center;transition:opacity .4s}
#card b{display:block;font-size:20px;margin-bottom:4px}
#card span{font-size:16px;line-height:1.35}
#ui{position:fixed;left:0;right:0;bottom:0;padding:10px 16px 16px;background:linear-gradient(transparent,rgba(5,10,20,.9));display:flex;flex-direction:column;gap:10px;align-items:center}
#row{display:flex;gap:10px;flex-wrap:wrap;justify-content:center}
button{font-size:17px;padding:12px 18px;min-height:50px;border-radius:14px;border:2px solid #5ab0ff;background:#17325a;color:#fff;font-weight:600}
button.on{background:#e0693a;border-color:#ffb08a}
#slider{width:min(92vw,520px);height:40px;accent-color:#5ab0ff}
#step{font-size:14px;opacity:.8}
#lbl{position:fixed;pointer-events:none;font-size:13px;font-weight:700;background:rgba(0,0,0,.55);padding:3px 8px;border-radius:8px;transform:translate(-50%,-140%);white-space:nowrap;display:none}
</style>
</head>
<body>
<div id="top"><h1>Build an Animal Cell</h1></div>
<div id="card"><b id="ct">Cell membrane</b><span id="cs">A thin, bendy skin that holds the cell together and decides what gets in and out.</span></div>
<div id="lbl"></div>
<div id="ui">
<div id="step">Building...</div>
<input id="slider" type="range" min="0" max="11" step="0.01" value="0">
<div id="row">
<button id="cut">Cut open: OFF</button>
<button id="rebuild">Rebuild</button>
<button id="home">Whole cell</button>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
<script>
const R=5;
const scene=new THREE.Scene();
scene.fog=new THREE.Fog(0x0b1424,20,45);
const camera=new THREE.PerspectiveCamera(50,innerWidth/innerHeight,0.1,100);
camera.position.set(0,3,15);
const renderer=new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.setSize(innerWidth,innerHeight);
renderer.localClippingEnabled=true;
document.body.prepend(renderer.domElement);
const controls=new THREE.OrbitControls(camera,renderer.domElement);
controls.enableDamping=true;controls.enablePan=false;controls.minDistance=2;controls.maxDistance=28;
scene.add(new THREE.AmbientLight(0xffffff,0.55));
const dl=new THREE.DirectionalLight(0xffffff,0.9);dl.position.set(5,8,6);scene.add(dl);
const pl=new THREE.PointLight(0x88ccff,0.6,30);pl.position.set(-6,-3,4);scene.add(pl);
const clip=new THREE.Plane(new THREE.Vector3(0,0,-1),0);
let cutOn=false;
const allMats=[];
function mat(c,o){const m=new THREE.MeshStandardMaterial(Object.assign({color:c,roughness:.5,metalness:.05,transparent:true,opacity:1,side:THREE.DoubleSide},o||{}));m.userData.baseOp=m.opacity;allMats.push(m);return m}
function rnd(a,b){return a+Math.random()*(b-a)}
function inCell(r){let v;do{v=new THREE.Vector3(rnd(-1,1),rnd(-1,1),rnd(-1,1))}while(v.length()>1);return v.multiplyScalar(r)}
function outsideNuc(min,max){let v;do{v=inCell(max)}while(v.distanceTo(new THREE.Vector3(-0.6,0.3,0))<min);return v}
// membrane
const memMat=mat(0x6fd0ff,{opacity:.18,depthWrite:false,roughness:.2});
const membrane=new THREE.Mesh(new THREE.SphereGeometry(R,64,48),memMat);
const memGeo=membrane.geometry,memBase=memGeo.attributes.position.array.slice();
scene.add(membrane);
const memWire=new THREE.Mesh(new THREE.SphereGeometry(R*1.003,32,24),mat(0x9fe8ff,{wireframe:true,opacity:.08,depthWrite:false}));
membrane.add(memWire);
membrane.userData.part=-1;
const parts=[];
function addPart(name,text,group,focus,dist){
group.traverse(o=>{if(o.isMesh)o.userData.part=parts.length});
group.visible=false;scene.add(group);
parts.push({name,text,group,focus:focus||new THREE.Vector3(),dist:dist||5});
}
const nucC=new THREE.Vector3(-0.6,0.3,0);
// 1 nucleus
{const g=new THREE.Group();g.position.copy(nucC);
g.add(new THREE.Mesh(new THREE.SphereGeometry(1.6,48,32),mat(0x8a5cf0,{opacity:.55,depthWrite:false})));
const pores=new THREE.InstancedMesh(new THREE.SphereGeometry(.07,8,6),mat(0xd8c8ff),60);
const d=new THREE.Object3D();for(let i=0;i<60;i++){d.position.randomDirection?d.position.randomDirection():d.position.set(rnd(-1,1),rnd(-1,1),rnd(-1,1)).normalize();d.position.multiplyScalar(1.6);d.updateMatrix();pores.setMatrixAt(i,d.matrix)}
g.add(pores);
addPart("Nucleus","The control center: it keeps the cell's DNA, the instruction book for everything the cell does.",g,nucC,6);}
// 2 nucleolus
{const g=new THREE.Group();g.position.copy(nucC).add(new THREE.Vector3(.3,.2,0));
g.add(new THREE.Mesh(new THREE.SphereGeometry(.55,32,24),mat(0xff5fa8,{emissive:0x401028})));
addPart("Nucleolus","A dense spot inside the nucleus that builds the parts used to make ribosomes.",g,g.position.clone(),3);}
// 3 rough ER
const ribosomeSpots=[];
{const g=new THREE.Group();g.position.copy(nucC);const m=mat(0x4fb3d9,{opacity:.85});
for(let i=0;i<5;i++){const r=1.95+i*.32;
const t=new THREE.Mesh(new THREE.TorusGeometry(r,.07,8,64,Math.PI*1.3),m);
t.rotation.set(Math.PI/2+rnd(-.25,.25),rnd(-.2,.2),Math.PI*.35+i*.15);g.add(t);
for(let k=0;k<26;k++){const a=Math.random()*Math.PI*1.3;ribosomeSpots.push({t,v:new THREE.Vector3(Math.cos(a)*r,Math.sin(a)*r,rnd(-.08,.08))})}}
addPart("Rough endoplasmic reticulum","Folded tubes covered in ribosomes that make proteins and send them off to be packed.",g,nucC.clone().add(new THREE.Vector3(1.5,0,1)),5);}
// 4 smooth ER
{const g=new THREE.Group();const m=mat(0x5fe0b0,{opacity:.85});const c=new THREE.Vector3(2.4,-1.6,1);
for(let i=0;i<6;i++){const pts=[];let p=c.clone().add(new THREE.Vector3(rnd(-.6,.6),rnd(-.6,.6),rnd(-.6,.6)));
for(let k=0;k<6;k++){pts.push(p.clone());p.add(new THREE.Vector3(rnd(-.5,.5),rnd(-.5,.5),rnd(-.5,.5)))}
g.add(new THREE.Mesh(new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts),40,.1,8,false),m))}
addPart("Smooth endoplasmic reticulum","Smooth tubes with no ribosomes that make fats and help clean out harmful stuff.",g,c,4);}
// 5 ribosomes
{const g=new THREE.Group();const n=ribosomeSpots.length+140;
const im=new THREE.InstancedMesh(new THREE.SphereGeometry(.06,6,5),mat(0xffd24a,{emissive:0x332200}),n);
const d=new THREE.Object3D();let i=0;scene.updateMatrixWorld(true);
parts[2].group.updateMatrixWorld(true);
ribosomeSpots.forEach(s=>{s.t.updateMatrixWorld(true);d.position.copy(s.v).applyMatrix4(s.t.matrixWorld);d.updateMatrix();im.setMatrixAt(i++,d.matrix)});
for(;i<n;i++){d.position.copy(outsideNuc(2.2,4.6));d.updateMatrix();im.setMatrixAt(i,d.matrix)}
g.add(im);
addPart("Ribosomes","Tiny protein factories that read instructions and build proteins one piece at a time.",g,new THREE.Vector3(1.8,1.2,1.5),4);}
// 6 Golgi
{const g=new THREE.Group();const c=new THREE.Vector3(2.5,1.4,-0.8);g.position.copy(c);
const cols=[0xffa040,0xff8c30,0xff7a28,0xff6a20,0xff5a18];
for(let i=0;i<5;i++){const s=new THREE.Mesh(new THREE.TorusGeometry(.9-i*.06,.11,10,40,Math.PI*1.2),mat(cols[i]));
s.position.y=i*.25-.5;s.rotation.x=Math.PI/2;s.rotation.z=Math.PI*.9;s.scale.set(1,1,1.2);g.add(s)}
g.rotation.set(.3,-.6,.4);
addPart("Golgi apparatus","The cell's post office: it sorts, packs and labels proteins, then ships them out.",g,c,4);}
// 7 mitochondria
{const g=new THREE.Group();const outer=mat(0xff4f4f),inner=mat(0xffb0a0);
for(let i=0;i<7;i++){const m=new THREE.Group();
const body=new THREE.Mesh(new THREE.SphereGeometry(.35,24,16),outer);body.scale.set(2,1,1);m.add(body);
for(let k=-2;k<=2;k++){const f=new THREE.Mesh(new THREE.BoxGeometry(.04,.45,.5),inner);f.position.x=k*.22;m.add(f)}
m.position.copy(outsideNuc(2.6,4.1));m.rotation.set(rnd(0,3),rnd(0,3),rnd(0,3));g.add(m)}
addPart("Mitochondria","The powerhouses: they turn food and oxygen into energy the cell can use.",g,g.children[0].position,3.5);}
// 8 lysosomes
{const g=new THREE.Group();const m=mat(0x8cff5a,{emissive:0x113300});
for(let i=0;i<8;i++){const s=new THREE.Mesh(new THREE.SphereGeometry(rnd(.2,.3),16,12),m);s.position.copy(outsideNuc(2.4,4.3));g.add(s)}
addPart("Lysosomes","Little recycling bags full of chemicals that break down worn-out parts and waste.",g,g.children[0].position,2.5);}
// 9 vesicles
{const g=new THREE.Group();const m=mat(0xfff0a8,{opacity:.7});
for(let i=0;i<14;i++){const s=new THREE.Mesh(new THREE.SphereGeometry(rnd(.1,.17),12,10),m);
s.position.copy(i<8?new THREE.Vector3(2.5,1.4,-.8).add(new THREE.Vector3(rnd(-1.2,1.2),rnd(-1.2,1.2),rnd(-1.2,1.2))):outsideNuc(2.4,4.5));g.add(s)}
addPart("Vesicles","Tiny bubbles that carry materials around the cell and out through the membrane.",g,new THREE.Vector3(2.8,1.8,0),3);}
// 10 centrioles
{const g=new THREE.Group();const c=new THREE.Vector3(1.2,-0.6,-2.4);g.position.copy(c);const m=mat(0x3fe0ff);
for(let j=0;j<2;j++){const cg=new THREE.Group();
for(let k=0;k<9;k++){const a=k/9*Math.PI*2;const t=new THREE.Mesh(new THREE.CylinderGeometry(.04,.04,.6,6),m);t.position.set(Math.cos(a)*.17,0,Math.sin(a)*.17);cg.add(t)}
if(j)cg.rotation.z=Math.PI/2,cg.position.x=.4;g.add(cg)}
addPart("Centrioles","A pair of tiny tube bundles that help pull the cell apart neatly when it divides.",g,c,2.5);}
// 11 cytoskeleton
{const g=new THREE.Group();const m=new THREE.LineBasicMaterial({color:0xb0c8ff,transparent:true,opacity:.45});m.userData.baseOp=.45;allMats.push(m);
for(let i=0;i<40;i++){const a=new THREE.Vector3().setFromSpherical(new THREE.Spherical(R*.96,rnd(0,Math.PI),rnd(0,6.28)));
const b=new THREE.Vector3().setFromSpherical(new THREE.Spherical(R*.96,rnd(0,Math.PI),rnd(0,6.28)));
const mid=a.clone().add(b).multiplyScalar(.5).add(inCell(1));
const pts=new THREE.QuadraticBezierCurve3(a,mid,b).getPoints(24);
const l=new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts),m);g.add(l)}
// invisible pick shell
const pick=new THREE.Mesh(new THREE.SphereGeometry(R*.93,24,16),new THREE.MeshBasicMaterial({visible:false}));g.add(pick);
addPart("Cytoskeleton","A web of protein threads that gives the cell its shape and acts like roads for moving things.",g,new THREE.Vector3(0,-3,3),5);
parts[10].pickOnly=pick;}
allMats.forEach(m=>{m.clippingPlanes=[clip]});
const N=parts.length;
const slider=document.getElementById('slider');slider.max=N;
const ct=document.getElementById('ct'),cs=document.getElementById('cs'),step=document.getElementById('step'),lbl=document.getElementById('lbl');
const MEM={name:"Cell membrane",text:"A thin, bendy skin that holds the cell together and decides what gets in and out."};
let progress=0,building=true,complete=false,lastShown=-2,focusIdx=-1;
function setCard(p){ct.textContent=p.name;cs.textContent=p.text}
function applyProgress(){
parts.forEach((p,i)=>{const t=Math.min(1,Math.max(0,(progress-i)/0.8));
p.appear=t;p.group.visible=t>0;
const e=t<1?1-Math.pow(1-t,3):1;p.scaleK=0.2+0.8*e;
p.group.traverse(o=>{if(o.material){const ms=Array.isArray(o.material)?o.material:[o.material];}});
p.fade=e;});
const idx=Math.min(N-1,Math.floor(progress));
if(progress<0.05){if(lastShown!==-1&&focusIdx<0){setCard(MEM);lastShown=-1}}
else if(idx!==lastShown&&focusIdx<0){setCard(parts[idx]);lastShown=idx}
complete=progress>=N-0.001;
step.textContent=complete?"Complete! Drag to spin, pinch to zoom, tap a part.":"Adding part "+Math.min(N,Math.floor(progress)+1)+" of "+N+": "+parts[idx].name;
}
// per-part opacity via own material clones
parts.forEach(p=>{p.group.traverse(o=>{if(o.material){o.material=o.material.clone();o.material.userData.baseOp=o.material.userData.baseOp??o.material.opacity;o.material.clippingPlanes=[clip]}})});
slider.addEventListener('input',()=>{stopDemo();building=false;progress=+slider.value;focusIdx=-1;applyProgress()});
document.getElementById('rebuild').onclick=()=>{progress=0;building=true;focusIdx=-1;lastShown=-2;flyHome();applyProgress()};
const cutBtn=document.getElementById('cut');
function setCut(v){cutOn=v;cutBtn.classList.toggle('on',v);cutBtn.textContent="Cut open: "+(v?"ON":"OFF")}
cutBtn.onclick=()=>setCut(!cutOn);
document.getElementById('home').onclick=()=>{focusIdx=-1;lastShown=-2;flyHome();applyProgress()};
// fly
let fly=null;
function flyTo(target,dist){
const dir=camera.position.clone().sub(controls.target).normalize();
fly={t:0,fromP:camera.position.clone(),fromT:controls.target.clone(),toT:target.clone(),toP:target.clone().add(dir.multiplyScalar(dist))};
}
function flyHome(){flyTo(new THREE.Vector3(),15)}
function focusPart(i){focusIdx=i;const p=parts[i];setCard(p);
const wp=new THREE.Vector3();p.group.updateMatrixWorld(true);
wp.copy(p.focus);if(p.group.position.equals(p.focus)===false&&p.focus===p.group.position)wp.copy(p.group.position);
flyTo(wp,p.dist);}
// picking
const ray=new THREE.Raycaster(),ptr=new THREE.Vector2();let down=null,activeTouches=0;
renderer.domElement.addEventListener('pointerdown',e=>{stopDemo();down={x:e.clientX,y:e.clientY,t:performance.now()}});
renderer.domElement.addEventListener('pointerup',e=>{
if(!down)return;const moved=Math.hypot(e.clientX-down.x,e.clientY-down.y);const d=down;down=null;
if(moved>8||performance.now()-d.t>600||!complete)return;
ptr.set(e.clientX/innerWidth*2-1,-(e.clientY/innerHeight)*2+1);ray.setFromCamera(ptr,camera);
const objs=[];parts.forEach(p=>p.group.traverse(o=>{if(o.isMesh)objs.push(o)}));
let hits=ray.intersectObjects(objs,false);
if(cutOn)hits=hits.filter(h=>h.point.z<=0.01);
// prefer non-shell hits
const solid=hits.find(h=>h.object!==parts[10].pickOnly);
const h=solid||hits[0];
if(h){const i=h.object.userData.part;const p=parts[i];
const fp=h.object.isInstancedMesh||p.group.children.length>1?h.point.clone():p.focus;
focusIdx=i;setCard(p);flyTo(i===10?p.focus:fp,p.dist);}
else{focusIdx=-1;setCard(MEM);flyHome()}
});
window.addEventListener('touchstart',()=>stopDemo(),{passive:true});
// demo
let demo=location.hash==='#demo',demoT=0;
function stopDemo(){if(demo){demo=false}}
const demoTaps=[0,6,1,5,9];
function runDemo(dt){
demoT+=dt;const T=demoT%20;
if(T<8){building=false;progress=Math.min(N,T/8*N*1.02);focusIdx=-1;setCut(false);controls.autoRotate=true}
else if(T<10){progress=N;setCut(true)}
else if(T<18){progress=N;const k=Math.floor((T-10)/2);if(k!==demo.k){demo={k};demo.k=k;focusPart(demoTaps[k]||0)}}
else{if(demo.k!=='home'){demo={k:'home'};setCut(false);focusIdx=-1;flyHome()}}
if(!demo)demo=true;
}
if(demo){demo={k:-1}}
addEventListener('resize',()=>{camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();renderer.setSize(innerWidth,innerHeight)});
const clock=new THREE.Clock();
const v=new THREE.Vector3();
function loop(){
requestAnimationFrame(loop);
const dt=Math.min(clock.getDelta(),.05),t=clock.elapsedTime;
if(demo){runDemo(dt)}else{controls.autoRotate=false}
controls.autoRotateSpeed=1.2;
if(building&&progress<N){progress=Math.min(N,progress+dt/1.6)}
slider.value=progress;applyProgress();
// clip plane animate
const target=cutOn?0:-R*1.5;clip.constant+=(target-clip.constant)*0.1;
if(!cutOn&&clip.constant<-R*1.4)clip.constant=100;else if(cutOn&&clip.constant>50)clip.constant=R*1.5;
// membrane wobble
const pa=memGeo.attributes.position;
for(let i=0;i<pa.count;i++){const x=memBase[i*3],y=memBase[i*3+1],z=memBase[i*3+2];
const w=1+0.025*Math.sin(t*1.3+x*.9+y*.7)+0.015*Math.sin(t*2.1+z*1.1);pa.setXYZ(i,x*w,y*w,z*w)}
pa.needsUpdate=true;
memMat.opacity=cutOn?0.12:0.18;
// parts pulse & drift
parts.forEach((p,i)=>{
const s=p.scaleK*(1+0.02*Math.sin(t*1.5+i));
p.group.scale.setScalar(s);
if(!p.base)p.base=p.group.position.clone();
p.group.position.copy(p.base).multiplyScalar(s).add(v.set(Math.sin(t*.6+i)*.05,Math.cos(t*.5+i*2)*.05,Math.sin(t*.7+i*3)*.05));
p.group.traverse(o=>{if(o.material)o.material.opacity=o.material.userData.baseOp*p.fade});
if(i===6||i===7||i===8)p.group.children.forEach((c,k)=>{if(!c.base)c.base=c.position.clone();c.position.copy(c.base).add(v.set(Math.sin(t*.8+k)*.12,Math.cos(t*.7+k*1.3)*.12,Math.sin(t*.9+k*.7)*.12));if(i===6)c.rotation.y+=dt*.2});
});
// label
if(focusIdx>=0){const p=parts[focusIdx];v.copy(fly?fly.toT:controls.target).project(camera);
lbl.style.display='block';lbl.textContent=p.name;lbl.style.left=((v.x+1)/2*innerWidth)+'px';lbl.style.top=((1-v.y)/2*innerHeight)+'px'}
else if(progress>0.05&&!complete){const p=parts[Math.min(N-1,Math.floor(progress))];v.copy(p.focus).project(camera);
lbl.style.display='block';lbl.textContent=p.name;lbl.style.left=((v.x+1)/2*innerWidth)+'px';lbl.style.top=((1-v.y)/2*innerHeight)+'px'}
else lbl.style.display='none';
if(fly){fly.t=Math.min(1,fly.t+dt/1.2);const e=fly.t<.5?2*fly.t*fly.t:1-Math.pow(-2*fly.t+2,2)/2;
camera.position.lerpVectors(fly.fromP,fly.toP,e);controls.target.lerpVectors(fly.fromT,fly.toT,e);if(fly.t>=1)fly=null}
controls.update();
renderer.render(scene,camera);
}
applyProgress();loop();
</script>
</body>
</html>
