// ─────────── data ─────────── const ART={ 'css-grid-lanes':'note','spool':'code','ferrotype':'code','building-ui-in-gpui':'code', 'the-black-magic-of-canvas-and-text-editing':'note','fig-gen-making-generative-art-in-figma':'image', 'writing-with-adhd':'prose','design-workshop':'image' }; const KL={code:'source',image:'gallery',prose:'longform',note:'kiosk'}; const FPAL={prose:'mint',code:'peri',image:'cream',intro:'lav'}; let POSTS=[]; const esc=s=>s.replace(/[&<>"]/g,c=>({'&':'&','<':'<','>':'>','"':'"'}[c])); const pad=n=>String(n).padStart(2,'0'); const dfmt=d=>new Date(d+'T12:00:00').toLocaleDateString('en-US',{month:'short',day:'numeric',year:'numeric'}); const words=t=>(t.match(/\S+/g)||[]).length; function analyse(p){ const d=document.createElement('div');d.innerHTML=p.html; const h1=d.querySelector('h1');if(h1&&h1.textContent.trim().toLowerCase()===p.title.toLowerCase())h1.remove(); const byImg=(ART[p.slug]||'')==='image'||d.querySelectorAll('img').length>=4; // split into sections (floors) by h2 — and, for galleries, by each picture const secs=[{title:'Opening',w:0,code:0,imgs:[],ai:0}]; let plate=0; [...d.children].forEach((el,ix)=>{ if(el.tagName==='H2'){secs.push({title:el.textContent,w:0,code:0,imgs:[],ai:ix});return;} if(byImg&&el.querySelector('img')){plate++;const im=el.querySelector('img');secs.push({title:im.alt||('Plate '+String(plate).padStart(2,'0')),w:0,code:0,imgs:[im.src],ai:ix});return;} const s=secs[secs.length-1]; if(el.tagName==='PRE'){s.code+=el.querySelectorAll('.line').length;return;} el.querySelectorAll('img').forEach(i=>s.imgs.push(i.src)); s.w+=words(el.textContent); }); if(secs[0].w===0&&secs[0].code===0&&!secs[0].imgs.length&&secs.length>1)secs.shift(); secs.forEach(s=>{s.type=s.imgs.length?'image':s.code>=4?'code':'prose';s.h=.4+s.w/240+s.code/26+(s.imgs.length?.9:0);}); const tw=secs.reduce((a,s)=>a+s.w,0), tc=secs.reduce((a,s)=>a+s.code,0), ti=secs.reduce((a,s)=>a+s.imgs.length,0); return{secs,words:tw,code:tc,imgs:ti,allImgs:secs.flatMap(s=>s.imgs)}; } // ─────────── background triangles ─────────── (function(){ const t=document.getElementById('tris'); for(let i=0;i<26;i++){const s=document.createElement('i');const z=10+Math.random()*34; s.style.cssText=`left:${Math.random()*100}%;top:${Math.random()*100}%;--z:${z}px;--r:${[0,60,120,180,240,300][i%6]}deg;--d:${14+Math.random()*20}s;--o:${.15+Math.random()*.35};animation-delay:${-Math.random()*20}s`;t.appendChild(s);} })(); // ─────────── building model ─────────── function buildingFor(p,scaleH){ const a=p.a; const total=a.secs.reduce((s,f)=>s+f.h,0); const target=scaleH(p,total); const k=target/total; return a.secs.map((f,i)=>({...f,hh:f.h*k,i})); } function drawBuilding(iso,p,bx,by,fw,fd,floors,t,st={}){ // st: lift (whole), built(i)->0..1, cur index, floatGap let z=st.lift||0; const ink='rgba(90,60,150,.55)'; const out=[]; floors.forEach((f,i)=>{ const pal=PAL[FPAL[f.type]]; const inset=(i%2)*.08; const built=st.built?st.built[i]:1; const extra=st.gap?st.gap[i]:0; const zz=z+extra; const x=bx+inset,y=by+inset,w=fw-inset*2,d=fd-inset*2; let deco=null; if(f.type==='prose')deco={left:DECO.windows('rgba(255,255,255,.75)',3,1.4),right:DECO.windows('rgba(120,150,200,.35)',2,1.4)}; if(f.type==='code')deco={left:DECO.racks('rgba(255,255,255,.55)',['#ff4fa3','#55e0c6','#8a7cff'],t),right:DECO.stripes('rgba(90,100,200,.25)',Math.max(3,Math.round(f.hh*4)))}; if(f.type==='image')deco={left:DECO.picture(iso,f.imgs[0],'#ffffff'),right:DECO.picture(iso,f.imgs[1]||f.imgs[0],'#ffffff')}; if(built<1){ iso.box(x,y,zz,w,d,f.hh*.999,pal,null,{ghost:true,stroke:ink}); if(built>0){ iso.ctx.globalAlpha=built; iso.box(x,y,zz,w,d,f.hh,pal,deco,{}); iso.ctx.globalAlpha=1; } } else iso.box(x,y,zz,w,d,f.hh,pal,deco,st.cur===i?{stroke:'#ff4fa3'}:{}); out.push({z0:zz,z1:zz+f.hh}); z=zz+f.hh+(st.gapBetween||0); }); // roof const k=p.k, cx=bx+fw/2, cy=by+fd/2; const roofBuilt=st.built?st.built[floors.length-1]>=1:true; if(roofBuilt){ if(k==='code'){iso.box(cx-.35,cy-.35,z,.7,.7,.25,PAL.lav);iso.box(cx-.05,cy-.05,z+.25,.1,.1,.9,PAL.cream);iso.box(cx-.12,cy-.12,z+1.15,.24,.24,.24,{top:'#ff8cc4',left:'#ff4fa3',right:'#e23d8c'});} else if(k==='prose'){iso.box(bx+.3,by+.3,z,fw-.6,fd-.6,.35,PAL.lav);iso.box(bx+.6,by+.6,z+.35,fw-1.2,fd-1.2,.35,PAL.rose);} else if(k==='image'){iso.box(bx+.2,by+.2,z,fw*.45,fd-.4,.3,PAL.lav,{top:DECO.stripes('rgba(255,255,255,.6)',4)});} else {iso.box(cx-.4,cy-.08,z,.8,.16,.55,PAL.rose,{left:DECO.sign(p.title.split(/\s/)[0].toUpperCase(),'#fff','#7a4fd0')});} } return {top:z+ (k==='code'?1.4:.7), floors:out}; } // ─────────── views ─────────── const app=document.getElementById('app'); let stop=()=>{}; function renderIndex(){ stop(); document.title='nate.rip — iso city'; app.innerHTML=`
nate butler · est. 2015

nate.rip

A small city of writing. Every building is a post; every floor is a section. Taller means wordier; antennas mean code; galleries hang the pictures.

${['prose','code','image'].map(k=>`${k==='prose'?'words':k==='code'?'code':'images'} floor`).join('')}
`; const cv=document.getElementById('cv'), iso=new Iso(cv); // lots: back row newest, front row older const lots=POSTS.map((p,i)=>{ const row=i<4?0:1, col=i%4; const fw=p.k==='image'?3:p.k==='note'?1.6:2.2, fd=p.k==='image'?2.3:p.k==='note'?1.6:2.2; const x=col*4.3+(3-fw)/2+(row?1.4:0), y=row*5.6+(2.6-fd)/2; const floors=buildingFor(p,(p,tot)=>Math.min(7.2,Math.max(1.3,.7+p.a.words/280+p.a.code/45+p.a.imgs*.08))); return{p,i,x,y,fw,fd,floors,lift:0,liftT:0,grow:0,delay:i*90}; }); let hover=-1, zoom=null; const tag=document.getElementById('tag'); function layout(){iso.resize();const W=iso.w,H=iso.h; // fit scene: x∈[-1,18] y∈[-1,9] const s=Math.min(W/((18+9)*C30)*.82,H/((18+9)*S30+7.5)*.9);iso.scale=s; const narrow=W<900; iso.ox=W*(narrow?.5:.6)-((18-9)/2)*C30*s+ (narrow?0:0); iso.oy=H*(narrow?.42:.5)-((18+9)/2)*S30*s+3.2*s;} layout(); const onR=()=>layout();addEventListener('resize',onR); const mouse=[-1,-1]; const onM=e=>{const r=cv.getBoundingClientRect();mouse[0]=e.clientX-r.left;mouse[1]=e.clientY-r.top;}; cv.addEventListener('pointermove',onM); cv.addEventListener('pointerleave',()=>{mouse[0]=-1;}); cv.addEventListener('click',()=>{if(hover>=0)go(hover);}); const dir=document.getElementById('dir'); let dirHover=-1; dir.querySelectorAll('a').forEach(a=>{a.addEventListener('pointerenter',()=>dirHover=+a.dataset.i);a.addEventListener('pointerleave',()=>dirHover=-1); a.addEventListener('click',e=>{e.preventDefault();go(+a.dataset.i);});}); function go(i){ if(zoom)return; const L=lots[i]; zoom={i,t0:performance.now(),s0:iso.scale,ox0:iso.ox,oy0:iso.oy,c:iso.P(L.x+L.fw/2,L.y+L.fd/2,2)}; } const t0=performance.now(); let raf; function frame(now){ const t=(now-t0)/1000, c=iso.ctx; c.setTransform(iso.dpr,0,0,iso.dpr,0,0);c.clearRect(0,0,iso.w,iso.h); if(zoom){const k=Math.min(1,(now-zoom.t0)/650),e=k*k*(3-2*k),z=1+e*2.4; c.translate(zoom.c[0],zoom.c[1]);c.scale(z,z);c.translate(-zoom.c[0],-zoom.c[1]);cv.style.opacity=1-e*.9; if(k>=1){location.hash=lots[zoom.i].p.slug;return;}} // ground plate iso.box(-1.2,-1.2,-.5,19.4,11.6,.5,PAL.rose,{top:(cc,w,d)=>{cc.strokeStyle='rgba(255,255,255,.55)';cc.lineWidth=.6/(w*iso.scale);for(let i=1;i{cc.fillStyle='rgba(255,255,255,.9)';for(let i=0;i<24;i++)cc.fillRect(i/24+.01,.47,.022,.06);}}); // hover pick (front to back) let pick=-1; if(mouse[0]>=0&&!zoom){for(let j=lots.length-1;j>=0;j--){const L=lots[j];const h=L.floors.reduce((a,f)=>a+f.hh,0)+1.2;if(c.isPointInPath(iso.outline(L.x,L.y,L.lift,L.fw,L.fd,h),mouse[0]*iso.dpr,mouse[1]*iso.dpr)){pick=j;break;}}} if(dirHover>=0)pick=dirHover; if(pick!==hover){hover=pick;cv.style.cursor=pick>=0?'pointer':'default';dir.querySelectorAll('a').forEach((a,j)=>a.classList.toggle('on',j===pick));} // draw in painter's order: back (small x+y) first const order=[...lots].sort((a,b)=>(a.x+a.y)-(b.x+b.y)); for(const L of order){ L.grow=Math.min(1,Math.max(0,(now-t0-L.delay)/900));const g=1-Math.pow(1-L.grow,3); L.liftT=L.i===hover?.6:0;L.lift+=(L.liftT-L.lift)*.15; // shadow const sh=[iso.P(L.x+.3,L.y+L.fd+.3,0),iso.P(L.x+L.fw+.3,L.y+L.fd+.3,0),iso.P(L.x+L.fw+.3,L.y+.3,0),iso.P(L.x+L.fw,L.y,0),iso.P(L.x,L.y+L.fd,0)]; iso.poly(sh,'rgba(150,80,160,'+(.14+L.lift*.1)+')'); const floors=L.floors.map(f=>({...f,hh:f.hh*g})); if(hover>=0&&L.i!==hover)c.globalAlpha=.55; const res=drawBuilding(iso,L.p,L.x,L.y,L.fw,L.fd,floors,t,{lift:L.lift}); c.globalAlpha=1; L.topZ=res.top; } // tag if(hover>=0){const L=lots[hover];const p=L.p;const pt=iso.P(L.x+L.fw/2,L.y+L.fd/2,L.topZ+L.lift+.4); tag.style.transform=`translate(${pt[0]+cv.offsetLeft}px,${pt[1]+cv.offsetTop}px)`;tag.classList.add('on'); document.getElementById('tagk').textContent=`${pad(hover+1)} · ${KL[p.k]}`; document.getElementById('tagt').textContent=p.title; document.getElementById('tagm').textContent=`${dfmt(p.date)} · ${p.a.secs.length} floors · ${p.a.words} words`; } else tag.classList.remove('on'); raf=requestAnimationFrame(frame); } raf=requestAnimationFrame(frame); stop=()=>{cancelAnimationFrame(raf);removeEventListener('resize',onR);}; } function renderPost(p){ stop(); const i=POSTS.indexOf(p), prev=POSTS[i+1], next=POSTS[i-1]; document.title=p.title+' — nate.rip'; app.innerHTML=`
`; const body=document.getElementById('body'); enhance(body,p); // section anchors (match analyse(): optional opening + one per h2) const kids=[...body.children]; const anchors=p.a.secs.map(s=>kids[s.ai]||body.firstElementChild); const cv=document.getElementById('cv'), iso=new Iso(cv); const floors=buildingFor(p,()=>1); let fw=p.k==='image'?3.2:p.k==='note'?2.2:2.6, fd=p.k==='image'?2.4:p.k==='note'?2.2:2.6; const N=floors.length; const built=floors.map(()=>0), gap=floors.map(()=>0); let cur=0; function layout(){iso.resize();const W=iso.w,H=iso.h; const totalH=floors.reduce((a,f)=>a+f.h,0); // fit: building height in units ~ choose scale so total + explode fits const s=Math.min(W/((fw+fd)*C30)*.5,(H*.62)/(totalH*1+fd*S30*2+N*.15+1.6)); iso.scale=Math.min(s,90); const k=Math.min(1,(H*.62/iso.scale)/totalH);floors.forEach(f=>f.hh=f.h*Math.max(.3,k*.98)); const bh=floors.reduce((a,f)=>a+f.hh,0); iso.ox=W/2-((fw-fd)/2)*C30*iso.scale; iso.oy=H/2+((bh)/2)*iso.scale-((fw+fd)/2)*S30*iso.scale+20;} layout(); const onR=()=>layout();addEventListener('resize',onR); const fl=document.getElementById('fl'); function progress(){ const vh=innerHeight;let c=0; anchors.forEach((a,j)=>{if(a.getBoundingClientRect().top{const tb=j<=cur?1:0;built[j]+=(tb-built[j])*.12;const tg=j>cur?.35+(j-cur)*.12:0;gap[j]+=(tg-gap[j])*.1;}); // plot const pw=fw+2.4,pd=fd+2.4; iso.box(-1.2,-1.2,-.3,pw,pd,.3,PAL.rose,{top:(cc,w,d)=>{cc.strokeStyle='rgba(255,255,255,.6)';cc.lineWidth=.8/(w*iso.scale);for(let q=1;q{const v=Math.max(0,gv-acc);acc=Math.max(acc,gv);return v;}); const res=drawBuilding(iso,p,0,0,fw,fd,floors,t,{built,gap:gap,cur}); // floor label const f=floors[cur],z=res.floors[cur]; if(f&&z){const pt=iso.P(fw,fd*.5,(z.z0+z.z1)/2); fl.style.transform=`translate(${pt[0]+14}px,${pt[1]}px)`; document.getElementById('flk').textContent=`floor ${pad(cur+1)}/${pad(N)} · ${f.type==='prose'?'words':f.type}`; document.getElementById('flt').textContent=f.title; document.getElementById('flm').textContent=`${f.w} words${f.code?` · ${f.code} ln`:''}${f.imgs.length?` · ${f.imgs.length} img`:''}`;} raf=requestAnimationFrame(frame); } raf=requestAnimationFrame(frame); stop=()=>{cancelAnimationFrame(raf);removeEventListener('resize',onR);removeEventListener('scroll',progress);}; } function enhance(body,p){ const h1=body.querySelector('h1');if(h1&&h1.textContent.trim().toLowerCase()===p.title.toLowerCase())h1.remove(); body.querySelectorAll('a[href^="http"]').forEach(a=>{a.target='_blank';a.rel='noopener'}); const kids=[...body.children]; p.a.secs.forEach((s,n)=>{const h=kids[s.ai];if(h&&h.tagName==='H2')h.innerHTML=`${pad(n+1)}${h.innerHTML}`;}); let c=0; body.querySelectorAll('pre').forEach(pre=>{c++;const w=document.createElement('figure');w.className='slab'; const txt=pre.textContent;const lang=/#\[|fn |let |impl |struct |::|pub /.test(txt)?'rust':/^\s*(cargo|spool|npm|git)\b/m.test(txt)?'shell':/display\s*:|grid-/.test(txt)?'css':/type |interface /.test(txt)?'typescript':'text'; w.innerHTML=`
block ${pad(c)}${lang} · ${pre.querySelectorAll('.line').length} ln
`;pre.replaceWith(w);w.appendChild(pre);}); body.querySelectorAll('img').forEach((img,j)=>{const host=img.closest('p')||img;const f=document.createElement('figure');f.className='tile '+(j%2?'r':'l');img.loading='lazy'; f.innerHTML='
';f.firstChild.appendChild(img);if(img.alt){const cap=document.createElement('figcaption');cap.className='px';cap.textContent=img.alt;f.appendChild(cap);}host.replaceWith(f);}); const io=new IntersectionObserver(es=>es.forEach(e=>{if(e.isIntersecting){e.target.classList.add('in');io.unobserve(e.target);}}),{rootMargin:'0px 0px -15% 0px'}); body.querySelectorAll('.tile,.slab').forEach(el=>io.observe(el)); } function route(){ const slug=decodeURIComponent(location.hash.slice(1)); const p=POSTS.find(x=>x.slug===slug); scrollTo(0,0); document.body.classList.toggle('is-post',!!p); p?renderPost(p):renderIndex(); } Promise.all([fetch('../content/posts.json').then(r=>r.json()),document.fonts.load('10px Silkscreen').catch(()=>{})]).then(([list])=>{ POSTS=list.map(p=>{p.a=analyse(p);p.k=ART[p.slug]||(p.a.imgs>=4?'image':p.a.code>=30?'code':p.a.words<320?'note':'prose');return p;}); addEventListener('hashchange',route); route(); });