Back to the app
The code
Build a Cell, Part by Part by GPT-6.2 Astra
Exactly as the AI wrote it. Shown as text, so nothing runs on this page.
index.html
partly 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"><meta name="theme-color" content="#080f1d"><title>Cellscope · Animal cell explorer</title>
<style>
*{box-sizing:border-box} :root{color-scheme:dark;--ink:#eef4fb;--dim:#a3b1c6;--mint:#66e3ca;--line:#283649}body{margin:0;background:#090f1b;color:var(--ink);font:15px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif}header{height:68px;border-bottom:1px solid #253043;background:#0d1522;display:flex;align-items:center;justify-content:space-between;padding:0 max(5vw,20px)}.brand{display:flex;align-items:center;gap:11px;font-size:23px;font-weight:720;letter-spacing:-1.3px}.logo{width:36px;height:36px;background:#183a40;border:1px solid #37635f;border-radius:11px;display:grid;place-items:center;color:var(--mint)}.headernote,.mono,.tag,.group,.counter,.status{font:600 10px/1.4 ui-monospace,Consolas,monospace;letter-spacing:1.45px;text-transform:uppercase}.headernote{display:flex;align-items:center;gap:10px;color:#adbbcc}.dot{display:inline-block;width:7px;height:7px;background:var(--mint);border-radius:50%;box-shadow:0 0 10px #62ebc959}main{max-width:1460px;margin:auto;padding:29px 5vw 20px}.intro{display:flex;justify-content:space-between;align-items:end;margin-bottom:22px}.tag{color:var(--mint);display:flex;align-items:center;gap:8px}.tag:before{content:"";width:23px;height:2px;background:var(--mint)}h1{font-size:clamp(34px,3.4vw,50px);letter-spacing:-2.2px;line-height:1.13;margin:7px 0 5px}.intro p{margin:0;color:var(--dim);font-size:14px}.workspace{display:grid;grid-template-columns:minmax(0,1fr) 295px;gap:16px}.stage,.panel,.transport{border:1px solid var(--line);border-radius:17px;overflow:hidden;background:#101a29}.stage{position:relative;min-height:490px;background:radial-gradient(ellipse at 49% 46%,#172e46 0,#101d30 45%,#0d1626 76%);isolation:isolate}.stage:before{content:"";position:absolute;inset:0;background-image:radial-gradient(#8eaac52d .8px,transparent .9px);background-size:21px 21px;pointer-events:none}.stage canvas{position:absolute;width:100%;height:100%;touch-action:none;cursor:grab}.stage canvas:active{cursor:grabbing}.stageTop,.stageBase{position:absolute;pointer-events:none;left:18px;right:18px;display:flex;align-items:center;justify-content:space-between;gap:7px}.stageTop{top:16px}.stageBase{bottom:15px;color:#a3b2c3;font-size:11px}.badge,.cut{background:#101c2bec;border:1px solid #304050;border-radius:8px;display:flex;align-items:center;gap:8px;padding:8px 10px}.badge{color:#bcd3df;font-size:9px;letter-spacing:1.3px}.cut{pointer-events:auto;font:550 12px system-ui;color:#e5edf6;cursor:pointer;min-height:42px}.toggle{width:27px;height:16px;background:#46556b;border-radius:12px;position:relative}.toggle:after{content:"";position:absolute;left:3px;top:3px;width:10px;height:10px;background:#e2eaf5;border-radius:50%;transition:.2s}.cut[aria-checked=true] .toggle{background:#268f80}.cut[aria-checked=true] .toggle:after{transform:translateX(11px)}.hint{display:flex;align-items:center;gap:6px}.panel{padding:19px 17px 12px}.panelTitle,.playhead,.controls,.action,.row,.rowname,.countwrap{display:flex;align-items:center}.panelTitle,.playhead{justify-content:space-between}.panelTitle h2{font-size:18px;letter-spacing:-.6px;margin:0}.counter{background:#1b293a;color:#a9bcd3;padding:4px 8px;border-radius:5px;letter-spacing:.7px}.group{margin:13px 0 6px;color:#8599b1;font-size:9px}.row{background:transparent;border:1px solid transparent;color:#c6d1df;width:100%;border-radius:8px;gap:11px;cursor:pointer;text-align:left;padding:5px 8px;min-height:32px;font:500 13px system-ui}.row:hover{background:#192638}.row.active{background:#1a303b;border-color:#31535a;color:#fff}.rowname{flex:1}.struc{width:23px;height:19px;flex:none}.mark{font-family:monospace;font-size:13px;color:#687a91}.row.active .mark{color:var(--mint)}.transport{margin-top:16px;padding:16px 20px;display:flex;align-items:center;gap:22px}.controls{gap:9px}.action{justify-content:center;gap:8px;border-radius:9px;min-height:43px;padding:0 14px;cursor:pointer;font:650 13px system-ui;border:1px solid #344257;background:#192537;color:#e3edf6}.primary{background:#73e5cb;color:#0c2926;border-color:#73e5cb;min-width:99px}.timeline{flex:1;border-left:1px solid var(--line);padding-left:22px}.playhead{font-size:12px}.playhead b{font-weight:600}.playhead span{font:11px ui-monospace,monospace;color:var(--mint)}input{width:100%;height:22px;margin:3px 0 0;cursor:pointer;accent-color:var(--mint)}.info{position:absolute;bottom:48px;left:18px;max-width:calc(100% - 36px);padding:10px 14px 11px 13px;border:1px solid #35495c;border-left:3px solid var(--accent,var(--mint));border-radius:9px;background:#0c1727ed;pointer-events:none}.info strong{display:block;font-size:14px}.info p{margin:2px 0 0;color:#c1ccdb;font-size:12px}.status{color:#89a9bb;font-size:9px}.footer{display:flex;justify-content:space-between;color:#798ca4;font-size:11px;margin-top:13px}.axis{color:#8295ad}svg{display:block}button:focus-visible,input:focus-visible{outline:2px solid #80f0d7;outline-offset:2px}
@media(min-width:1550px){.stage{min-height:555px}}@media(max-width:850px){main{padding:20px}.workspace{grid-template-columns:minmax(0,1fr) 235px;gap:10px}.panel{padding:14px 10px}.stageBase .axis{display:none}.stageTop{left:10px;right:10px}}
@media(max-width:660px){header{height:55px}.brand{font-size:21px}.headernote{font-size:8px}main{padding:18px 13px}.intro{margin-bottom:15px}.workspace{display:contents}.stage{min-height:0;height:clamp(400px,65svh,510px)}.panel{margin-top:12px;padding:15px}.layout{display:flex;flex-direction:column}.stage{order:0}.transport{order:1;margin-top:10px;gap:10px;flex-wrap:wrap;padding:12px}.panel{order:2}.controls{gap:6px}.action{padding:0 10px}.primary{min-width:81px}.timeline{padding-left:10px;min-width:111px}.row{min-height:43px}.group{margin-top:15px}.info{bottom:42px;left:12px}.footer{gap:10px}.footer span:last-child{display:none}.stageTop .badge{font-size:8px}}
</style></head><body><header><div class="brand"><span class="logo"><svg width="27" height="27" viewBox="0 0 30 30" fill="none" stroke="currentColor" stroke-width="1.6"><path d="M25 11c4 8-2 15-10 15S2 21 4 14 12 2 19 5q5 1 6 6Z"/><ellipse cx="15" cy="15" rx="5" ry="4" transform="rotate(-32 15 15)"/><circle cx="21" cy="10" r="1" fill="currentColor"/><path d="m7 19 3 2"/></svg></span>Cellscope</div><div class="headernote"><i class="dot"></i>Interactive biology</div></header>
<main><div class="intro"><div><div class="tag">Cell explorer</div><h1>Animal cell</h1><p>Watch a cell come to life, one part at a time.</p></div></div><div class="layout"><div class="workspace"><section class="stage" id="stage" aria-label="Interactive three-dimensional animal cell"><canvas id="view" aria-label="Drag to orbit, pinch or scroll to zoom, or select a part from the index"></canvas><div class="stageTop"><span class="badge mono"><i class="dot"></i>Live specimen</span><button class="cut" id="cut" role="switch" aria-checked="false">Cut open <span class="toggle"></span></button></div><div class="info" id="info" aria-live="polite"><strong id="part"></strong><p id="desc"></p></div><div class="stageBase"><span class="hint">⤧ Drag to orbit <span>·</span> Pinch to zoom</span><span class="axis mono">3D viewport</span></div></section><aside class="panel"><div class="panelTitle"><h2>Cell parts</h2><span class="counter" id="count"></span></div><div id="parts"></div></aside></div><section class="transport"><div class="controls"><button class="action primary" id="play"></button><button class="action" id="reset"><span style="font-size:19px">↻</span> Rebuild</button></div><div class="timeline"><div class="playhead"><b>Build progress</b><span id="progress"></span></div><input type="range" min="0" max="11" value="0" step="1" id="slider" aria-label="Build progress"></div></section></div><div class="footer"><span>Tap a cell part to explore its function.</span><span>Cellscope / Biology lab</span></div></main>
<script>
'use strict';
const $=id=>document.getElementById(id),C=$('view'),ctx=C.getContext('2d'),TAU=Math.PI*2;
const D=[
['Cell membrane','This thin, flexible skin controls what enters and leaves the cell.','#60e2df'],
['Nucleus','The nucleus holds DNA, the instructions your cell uses to grow and work.','#bf8ef9'],
['Nucleolus','The nucleolus makes the pieces that fit together to form ribosomes.','#ff98d7'],
['Rough ER','The rough endoplasmic reticulum helps fold proteins made by ribosomes on its surface.','#839ff6'],
['Smooth ER','The smooth endoplasmic reticulum makes fats and helps break down harmful substances.','#65c8e9'],
['Ribosomes','Ribosomes join tiny building blocks together to make proteins.','#ffe1a1'],
['Golgi apparatus','The Golgi apparatus sorts and packages proteins for delivery.','#efa2bd'],
['Mitochondria','Mitochondria turn energy from food into a form the cell can use.','#ffa369'],
['Lysosomes','Lysosomes break down worn-out cell parts so their materials can be used again.','#a3df78'],
['Vesicles','Vesicles are little sacs that carry materials around the cell.','#65dcd2'],
['Centrioles','Centrioles help organize the fibers that pull chromosomes apart when a cell divides.','#ffd378'],
['Cytoskeleton','This network of fibers gives the cell shape and helps things move inside it.','#70afbc']];
const icons=['','<ellipse cx="12" cy="10" rx="9" ry="7"/><circle cx="13" cy="9" r="3"/>','<ellipse cx="12" cy="10" rx="5" ry="4"/>','<path d="M2 7q5-8 12-2l6 1M3 11q5-8 12-2l5 1M5 15q5-7 12-2"/><path d="M3 3h1m5 6h1m6 7h1"/>','<path d="M2 7q3-7 7-1t7 1 5-1M3 13q3-7 7-1t7 1 4-1"/>','<path d="M4 6h1m7-3h1m4 7h1M8 13h1m5 4h1" stroke-width="3"/>','<path d="M3 4q8 7 17 1M3 8q8 7 17 1M4 12q8 6 14 2"/>','<ellipse cx="12" cy="10" rx="10" ry="5.5" transform="rotate(-18 12 10)"/><path d="m5 11 3-4 2 5 3-6 2 4 3-3"/>','<circle cx="12" cy="10" r="7"/><path d="M8 9h1m3 4h1m1-7h1"/>','<circle cx="9" cy="11" r="5"/><circle cx="17" cy="5" r="3"/>','<path d="m3 7 13-4 2 6-13 4zm2 3 12-4m-5 7 6 4 3-4-5-3"/>','<path d="m1 14 20-9M4 4l13 14M6 18l8-16m-9 7 16 4"/>'];
let rows=[];for(let i=1;i<D.length;i++){if([1,3,7,10].includes(i)){let el=document.createElement('div');el.className='group';el.textContent=({1:'Control center',3:'Production & packaging',7:'Energy & transport',10:'Structure & support'})[i];$('parts').append(el)}let el=document.createElement('button');el.className='row';el.innerHTML='<svg class="struc" viewBox="0 0 24 20" fill="none" stroke="'+D[i][2]+'" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">'+icons[i]+'</svg><span class="rowname">'+D[i][0]+'</span><span class="mark">·</span>';el.onclick=()=>select(i);$('parts').append(el);rows[i]=el}
let step=0,sel=0,playing=true,cut=false,demo=location.hash.endsWith('#demo'),clock=0,last=performance.now(),demoTime=0,focused=false;
let yaw=.04,pitch=-.12,zoom=1,aim=[0,0,0],Y=yaw,P=pitch,Z=1,A=[0,0,0], age=0;
function ui(){ $('part').textContent=D[sel][0];$('desc').textContent=D[sel][1];$('info').style.setProperty('--accent',D[sel][2]);$('count').textContent=step+' / 11';$('progress').textContent=Math.round(step/11*100)+'%';$('slider').value=step;$('play').innerHTML=playing?'Ⅱ Pause':step===11?'▶ Replay':'▶ Play';$('cut').setAttribute('aria-checked',cut);rows.forEach((r,i)=>{r.classList.toggle('active',i===sel);r.lastChild.textContent=i===sel?'›':i<=step?'✓':'·'});}
function wide(){focused=false;Z=1;A=[0,0,0]}
function build(n){step=sel=n;age=0;wide();if(n===11)playing=false;ui()}
function restart(){playing=true;cut=false;clock=0;Y=.04;P=-.12;build(0)}
function select(i){demo=false;playing=false;step=Math.max(i,step);sel=i;focused=i>0;A=i?centers[i].slice():[0,0,0];Z=i?1.53:1;ui()}
$('slider').oninput=e=>{demo=playing=false;clock=0;build(+e.target.value)};$('reset').onclick=()=>{demo=false;restart()};$('play').onclick=()=>{demo=false;if(step===11)restart();else{playing=!playing;clock=0;wide();ui()}};$('cut').onclick=()=>{demo=false;cut=!cut;ui()};document.addEventListener('pointerdown',()=>demo=false,true);
const centers=[[.82,.34,-.1],[-.23,-.05,.06],[-.19,-.08,.23],[-.24,-.35,.05],[-.55,.27,.05],[.03,-.45,.15],[.39,-.23,.12],[.44,.28,.17],[-.23,.46,.12],[.67,-.07,.15],[.09,.37,.13],[-.47,-.40,-.1]];
let seed=5321;function rand(){seed=(1664525*seed+1013904223)>>>0;return seed/4294967296}const spots=Array.from({length:1400},()=>{let z=rand()*2-1,a=rand()*TAU,r=Math.sqrt(1-z*z);return [r*Math.cos(a),r*Math.sin(a),z,rand()]});
let objects=[];function orb(id,pos,sz,color,style='',rot=0){objects.push({id,pos,sz,color,style,rot})}function line(id,points,w,color){objects.push({id,points,w,color})}
orb(1,centers[1],[.315,.274,.24],'#a677dc','nuc',-.18);orb(2,centers[2],[.101,.085,.08],'#e683c0','pearl');
for(let k=0;k<6;k++){let pts=[];for(let j=0;j<=48;j++){let a=2.9+j/48*2.78,r=.29+k*.035;pts.push([-.23+r*Math.cos(a),-.045+.77*r*Math.sin(a)+.022*Math.sin(a*8+k*.7),.02+.023*k+.028*Math.sin(a*3)])}line(3,pts,.026,'#809aea');for(let j=1;j<48;j+=4){let p=pts[j];orb(5,[p[0],p[1]-.009,p[2]+.012],[.009,.009,.008],'#ffe1ad')}}
for(let k=0;k<5;k++){let p=[];for(let j=0;j<=40;j++){let a=j/40;p.push([-.79+a*.53+.018*Math.sin(k+a*9),.13+.049*k+.055*Math.sin(a*8+k*.8),.04+.07*Math.sin(a*6+k)])}line(4,p,.023,'#69c7dc')}
for(let k=0;k<6;k++){let p=[];for(let j=0;j<=38;j++){let a=j/38;p.push([.18+.44*a+(k-3)*.012,-.39+k*.042+.084*Math.sin(a*Math.PI)+.029*Math.sin(a*5+k*.2),.05+.022*k+.055*Math.sin(a*3)])}line(6,p,.031,'#e89ab3')}
for(const [x,y,z,r,s] of [[.44,.28,.17,-.48,1],[-.43,.46,-.07,.2,.78],[.22,-.52,-.06,-.26,.72],[-.70,-.20,.12,-.8,.64]])orb(7,[x,y,z],[.174*s,.084*s,.073*s],'#f29b60','mito',r);
for(let i=0;i<7;i++){let p=i?[Math.cos(i*2.8)*(.54+rand()*.17),Math.sin(i*2.8)*.53,(rand()-.5)*.4]:centers[8];let r=.031+rand()*.029;orb(8,p,[r,r,r],'#9dce72','pearl')}
for(let i=0;i<16;i++){let a=rand()*TAU,r=rand()*.035+.016;orb(9,i?[Math.cos(a)*(.51+rand()*.28),Math.sin(a)*(.35+rand()*.22),rand()*.34-.17]:centers[9],[r,r,r],'#67cbc6','bubble')}
for(let i=0;i<72;i++){let a=rand()*TAU,r=.35+rand()*.45;orb(5,[r*Math.cos(a),.76*r*Math.sin(a),rand()*.48-.18],[.008,.008,.008],'#e5c89f')}
for(let k=0;k<2;k++)for(let j=0;j<9;j++){let a=j/9*TAU,x=.06+k*.09+.037*Math.cos(a),z=.13+.037*Math.sin(a);line(10,[[x,.30+k*.02,z],[x+(k?.082:-.051),.46+k*.012,z+.018]],.014,'#edc568')}
for(let k=0;k<24;k++){let a=rand()*TAU,b=a+1.0+rand()*1.85,p=[];for(let j=0;j<22;j++){let t=j/21;p.push([.9*((1-t)*Math.cos(a)+t*Math.cos(b)),.70*((1-t)*Math.sin(a)+t*Math.sin(b))+.05*Math.sin(t*Math.PI),-.23+.14*Math.sin(t*4+k)])}line(11,p,.006,'#559baa')}
let W,H,S,cx,cy,cs,sn,cp,sp,time=0,hits=[];function project(p){let x=p[0]-aim[0],y=p[1]-aim[1],z=p[2]-aim[2],u=x*cs+z*sn,v=z*cs-x*sn;return [cx+u*S,cy+(y*cp-v*sp)*S,v*cp+y*sp]}
function shape(u,v){let f=1+.033*Math.sin(u*3+.45)*Math.cos(v)+.032*Math.sin(u*2+v*3);return [1.02*Math.cos(v)*Math.cos(u)*f,.79*Math.sin(v)*f,.74*Math.cos(v)*Math.sin(u)*f]}
function path(ps,close=false){ctx.beginPath();ps.forEach((p,i)=>i?ctx.lineTo(p[0],p[1]):ctx.moveTo(p[0],p[1]));if(close)ctx.closePath()}
function hull(ps){let t=(a,b,c)=>(b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0]);ps.sort((a,b)=>a[0]-b[0]||a[1]-b[1]);let l=[],r=[];for(let p of ps){while(l.length>1&&t(l.at(-2),l.at(-1),p)<=0)l.pop();l.push(p)}for(let p of ps.reverse()){while(r.length>1&&t(r.at(-2),r.at(-1),p)<=0)r.pop();r.push(p)}return l.concat(r)}
function rgba(hex,a){let n=parseInt(hex.slice(1),16);return 'rgba('+[n>>16,(n>>8)&255,n&255,a].join(',')+')'}
function membrane(front){let ps=[],rim=[];for(let j=0;j<=24;j++)for(let k=0;k<64;k++){let p=shape(k*TAU/64,(j/24-.5)*Math.PI);if(!cut||p[2]<=.00001)ps.push(project(p))}let edge=hull(ps),o=project([0,0,0]);ctx.save();path(edge,true);if(!front){let g=ctx.createRadialGradient(o[0]-.22*S,o[1]-.25*S,.03*S,o[0],o[1],1.06*S);g.addColorStop(0,'#29536a');g.addColorStop(.54,'#254958');g.addColorStop(.84,'#30666d');g.addColorStop(1,'#68b4ae');ctx.fillStyle=g;ctx.shadowColor='#4ca8ab60';ctx.shadowBlur=23;ctx.fill();ctx.shadowBlur=0}else{ctx.strokeStyle='#9ce9dca8';ctx.lineWidth=2;ctx.stroke();ctx.clip();for(let q=1;q<5;q++){ctx.save();ctx.translate(o[0],o[1]);ctx.scale(1-q*.008,1-q*.008);ctx.translate(-o[0],-o[1]);path(edge,true);ctx.strokeStyle=rgba('#92efda',.26-q*.035);ctx.lineWidth=1.4;ctx.stroke();ctx.restore()}}
for(let a of spots){let p=shape(Math.atan2(a[2],a[0]),Math.asin(a[1]));if(cut&&p[2]>.001)continue;let v=project(p);if((v[2]>o[2])!==front)continue;ctx.fillStyle=rgba('#a5f6da',(front?.12:.17)+a[3]*.28);ctx.beginPath();ctx.arc(v[0],v[1],Math.max(.4,S*(.0016+.0034*a[3])),0,TAU);ctx.fill()}
if(cut&&front){for(let j=0;j<=100;j++){let a=j/100*TAU;rim.push(project(shape(Math.cos(a)>=0?0:Math.PI,Math.asin(Math.sin(a)))))}path(rim,true);ctx.lineWidth=3;ctx.strokeStyle='#8de6d2';ctx.stroke()}ctx.restore()}
function drawOrb(o,p){let rx=o.sz[0]*S,ry=o.sz[1]*S,r=o.rot;ctx.save();ctx.translate(p[0],p[1]);ctx.rotate(r);ctx.scale(rx,ry);let g=ctx.createRadialGradient(-.32,-.42,.02,.04,.05,1.1);g.addColorStop(0,rgba(o.color,.98));g.addColorStop(.58,o.color);g.addColorStop(1,o.style==='nuc'?'#4d3978':o.style==='mito'?'#995446':'#34545d');ctx.beginPath();ctx.arc(0,0,1,0,TAU);ctx.fillStyle=g;ctx.globalAlpha=o.style==='bubble'?.76:1;ctx.fill();ctx.strokeStyle=rgba(o.color,.85);ctx.lineWidth=.045;ctx.stroke();ctx.clip();if(o.style==='nuc'){for(let j=0;j<165;j++){let a=j*2.399,b=Math.sqrt((j+.5)/165),x=b*Math.cos(a),y=b*Math.sin(a);ctx.fillStyle=j%3?'#edd8ff4a':'#69468d88';ctx.beginPath();ctx.ellipse(x,y,.016+(j%4)*.006,.012+(j%3)*.008,a,0,TAU);ctx.fill()}ctx.beginPath();ctx.ellipse(0,.02,.95,.92,0,0,TAU);ctx.strokeStyle='#e3b5ff73';ctx.stroke()}if(o.style==='mito'){ctx.beginPath();for(let j=0;j<=90;j++){let t=j/90,x=-.83+1.66*t,y=Math.sin(t*TAU*4.5)*.49*Math.sin(Math.PI*t)**.5;j?ctx.lineTo(x,y):ctx.moveTo(x,y)}ctx.strokeStyle='#a5503e';ctx.lineWidth=.16;ctx.stroke();ctx.strokeStyle='#ffc58d';ctx.lineWidth=.054;ctx.stroke()}if(o.style==='pearl'||o.style==='bubble'){ctx.beginPath();ctx.arc(-.07,-.08,.70,3.5,4.7);ctx.strokeStyle='#ffffff80';ctx.lineWidth=.09;ctx.stroke()}ctx.restore()}
function render(dt){let w=C.clientWidth,h=C.clientHeight,dpr=Math.min(devicePixelRatio||1,2);if(C.width!==Math.round(w*dpr)||C.height!==Math.round(h*dpr)){C.width=Math.round(w*dpr);C.height=Math.round(h*dpr)}ctx.setTransform(dpr,0,0,dpr,0,0);W=w;H=h;ctx.clearRect(0,0,w,h);let s=1-Math.exp(-dt*6);yaw+=(Y-yaw)*s;pitch+=(P-pitch)*s;zoom+=(Z-zoom)*s;aim=aim.map((v,i)=>v+(A[i]-v)*s);S=Math.min(w*.405,(h-142)*.56)*zoom*(1+.006*Math.sin(time*1.5));cx=w*.5;cy=h*.46;cs=Math.cos(yaw);sn=Math.sin(yaw);cp=Math.cos(pitch);sp=Math.sin(pitch);hits=[];membrane(false);
let sorted=[];for(let o of objects){if(o.id>step)continue;let drift=.007*Math.sin(time*.7+o.id);if(o.points){let ps=o.points.map(p=>project([p[0],p[1]+drift,p[2]]));sorted.push({o,ps,z:ps[Math.floor(ps.length/2)][2]})}else{let p=project([o.pos[0],o.pos[1]+drift,o.pos[2]]);sorted.push({o,p,z:p[2]})}}sorted.sort((a,b)=>a.z-b.z);for(let {o,p,ps} of sorted){ctx.save();if(o.id===step&&playing)ctx.globalAlpha=Math.min(1,.3+age*2);if(p){drawOrb(o,p);hits.push([o.id,p[0],p[1],Math.max(6,o.sz[0]*S),Math.max(6,o.sz[1]*S)])}else{path(ps);ctx.lineCap=ctx.lineJoin='round';ctx.strokeStyle=rgba(o.color,o.id===11?.49:.96);ctx.lineWidth=Math.max(1,o.w*S*2);ctx.stroke();if(o.id!==11){ctx.translate(0,-o.w*S*.48);ctx.lineWidth=Math.max(1,o.w*S*.52);ctx.strokeStyle='#ffffff50';ctx.stroke()}for(let k=0;k<ps.length;k+=3)hits.push([o.id,ps[k][0],ps[k][1],Math.max(6,o.w*S),Math.max(6,o.w*S)])}ctx.restore()}membrane(true);
let pt=project(centers[sel]),right=pt[0]<w*.57,label=D[sel][0];ctx.font='600 12px system-ui';let lw=ctx.measureText(label).width+22,x=Math.max(8,Math.min(w-lw-8,pt[0]+(right?32:-lw-32))),y=Math.max(70,Math.min(h-136,pt[1]-43));ctx.strokeStyle=D[sel][2];ctx.lineWidth=1;path([pt,[pt[0]+(right?13:-13),y+14],[right?x:x+lw,y+14]]);ctx.stroke();ctx.fillStyle=D[sel][2];ctx.beginPath();ctx.arc(pt[0],pt[1],3,0,TAU);ctx.fill();ctx.beginPath();ctx.roundRect(x,y,lw,27,6);ctx.fillStyle='#101d2eee';ctx.fill();ctx.strokeStyle=rgba(D[sel][2],.66);ctx.stroke();ctx.fillStyle='#eef4fa';ctx.fillText(label,x+11,y+18)}
let pointers=new Map(),moved=false,dist=0,start=null;function gap(){let [a,b]=[...pointers.values()];return Math.hypot(a.x-b.x,a.y-b.y)}C.onpointerdown=e=>{demo=false;C.setPointerCapture(e.pointerId);pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});if(pointers.size===1){start=[e.clientX,e.clientY];moved=false}else{moved=true;dist=gap()}};C.onpointermove=e=>{let old=pointers.get(e.pointerId);if(!old)return;pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});if(pointers.size>=2){let n=gap();if(dist>1)Z=Math.max(.65,Math.min(2.7,Z*n/dist));dist=n}else{let dx=e.clientX-old.x,dy=e.clientY-old.y;if(Math.hypot(e.clientX-start[0],e.clientY-start[1])>3)moved=true;Y+=dx*.008;P=Math.max(-1.48,Math.min(1.48,P-dy*.008))}};C.onpointerup=e=>{if(!moved&&pointers.size===1){let r=C.getBoundingClientRect(),x=e.clientX-r.left,y=e.clientY-r.top,hit=hits.slice().reverse().find(a=>((x-a[1])/a[3])**2+((y-a[2])/a[4])**2<1);if(hit)select(hit[0]);else if(((x-cx)/S)**2+((y-cy)/(.8*S))**2<1)select(0)}pointers.delete(e.pointerId)};C.onpointercancel=e=>{pointers.delete(e.pointerId);moved=true};C.onwheel=e=>{e.preventDefault();demo=false;Z=Math.max(.65,Math.min(2.7,Z*Math.exp(-e.deltaY*.001)))};
function frame(now){let dt=Math.min(.08,(now-last)/1000);last=now;time+=dt;age+=dt;if(demo){demoTime+=dt;Y+=dt*.16;let n=Math.min(11,Math.floor(demoTime/.93));if(n!==step)build(n);if(demoTime>11.3&&demoTime<14.1&&sel!==7){sel=7;A=centers[7].slice();Z=1.5;ui()}if(demoTime>=14.1&&!cut){wide();cut=true;sel=6;ui()}if(demoTime>=20){demoTime=0;restart()}}else if(playing){clock+=dt;if(clock>(step===0?1.35:2.3)){clock=0;build(Math.min(11,step+1))}if(!pointers.size)Y+=dt*.038}render(dt);requestAnimationFrame(frame)}ui();requestAnimationFrame(frame);
</script></body></html>
