import * as THREE from 'three'; const $ = (s, el = document) => el.querySelector(s); const $$ = (s, el = document) => [...el.querySelectorAll(s)]; // ------------------------------------------------------------------ // flavors — every post is a translucent iMac colour // ------------------------------------------------------------------ const FLAVOR = { 'css-grid-lanes': { name: 'BLUEBERRY', c: '#2f6df0', kind: 'code' }, 'spool': { name: 'TANGERINE', c: '#ff8a1c', kind: 'code' }, 'ferrotype': { name: 'GRAPHITE', c: '#5d6a7c', kind: 'code' }, 'building-ui-in-gpui': { name: 'BONDI', c: '#00a3c4', kind: 'code' }, 'the-black-magic-of-canvas-and-text-editing': { name: 'SAGE', c: '#7fae7a', kind: 'note' }, 'fig-gen-making-generative-art-in-figma': { name: 'GRAPE', c: '#8a43c9', kind: 'image' }, 'writing-with-adhd': { name: 'STRAWBERRY', c: '#ef3f7a', kind: 'prose' }, 'design-workshop': { name: 'LIME', c: '#73c63a', kind: 'image' }, }; function flavor(p) { if (FLAVOR[p.slug]) return FLAVOR[p.slug]; const imgs = (p.html.match(/ 3 ? 'image' : pres > 1 ? 'code' : p.html.length < 2500 ? 'note' : 'prose' }; } // ------------------------------------------------------------------ // liquid chrome // ------------------------------------------------------------------ const canvas = $('#gl'); const renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true }); renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75)); const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(32, 1, 0.1, 100); camera.position.set(0, 0, 9); const NOISE = ` vec3 mod289(vec3 x){return x-floor(x*(1./289.))*289.;} vec4 mod289(vec4 x){return x-floor(x*(1./289.))*289.;} vec4 permute(vec4 x){return mod289(((x*34.)+1.)*x);} vec4 taylorInvSqrt(vec4 r){return 1.79284291400159-.85373472095314*r;} float snoise(vec3 v){ const vec2 C=vec2(1./6.,1./3.); const vec4 D=vec4(0.,.5,1.,2.); vec3 i=floor(v+dot(v,C.yyy)); vec3 x0=v-i+dot(i,C.xxx); vec3 g=step(x0.yzx,x0.xyz); vec3 l=1.-g; vec3 i1=min(g.xyz,l.zxy); vec3 i2=max(g.xyz,l.zxy); vec3 x1=x0-i1+C.xxx; vec3 x2=x0-i2+C.yyy; vec3 x3=x0-D.yyy; i=mod289(i); vec4 p=permute(permute(permute(i.z+vec4(0.,i1.z,i2.z,1.))+i.y+vec4(0.,i1.y,i2.y,1.))+i.x+vec4(0.,i1.x,i2.x,1.)); float n_=.142857142857; vec3 ns=n_*D.wyz-D.xzx; vec4 j=p-49.*floor(p*ns.z*ns.z); vec4 x_=floor(j*ns.z); vec4 y_=floor(j-7.*x_); vec4 x=x_*ns.x+ns.yyyy; vec4 y=y_*ns.x+ns.yyyy; vec4 h=1.-abs(x)-abs(y); vec4 b0=vec4(x.xy,y.xy); vec4 b1=vec4(x.zw,y.zw); vec4 s0=floor(b0)*2.+1.; vec4 s1=floor(b1)*2.+1.; vec4 sh=-step(h,vec4(0.)); vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy; vec4 a1=b1.xzyw+s1.xzyw*sh.zzww; vec3 p0=vec3(a0.xy,h.x); vec3 p1=vec3(a0.zw,h.y); vec3 p2=vec3(a1.xy,h.z); vec3 p3=vec3(a1.zw,h.w); vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3))); p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w; vec4 m=max(.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.); m=m*m; return 42.*dot(m*m,vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3))); }`; const ENV = ` uniform vec3 uTint; uniform float uIri; uniform float uTime; vec3 env(vec3 r){ float y = r.y; vec3 sky = mix(vec3(.93,.97,1.), vec3(.32,.52,.9), smoothstep(.02,.85,y)); vec3 ground = mix(vec3(.3,.33,.42), vec3(.82,.84,.9), smoothstep(-1.,-.1,y)); vec3 c = y > 0. ? sky : ground; c *= 1. - .85*smoothstep(-.02,-.07,y)*smoothstep(-.22,-.08,y); // the dark chrome horizon c += vec3(1.)*smoothstep(.03,.0,abs(y-.015))*.8; // horizon glint float sb = smoothstep(.22,.17,abs(r.x-.42)) * smoothstep(.26,.2,abs(r.y-.5)); float sb2 = smoothstep(.07,.04,abs(r.x+.62)) * smoothstep(.55,.45,abs(r.y-.25)); float sb3 = smoothstep(.3,.0,length(r.xy-vec2(-.15,.85))); c += vec3(1.5)*(sb + sb2) + vec3(.6)*sb3; return c; } vec3 shade(vec3 n, vec3 wp){ vec3 v = normalize(wp - cameraPosition); vec3 r = reflect(v, n); vec3 c = env(r); float fres = pow(1. - max(dot(-v, n), 0.), 2.2); vec3 iri = .5 + .5*cos(6.2831*(fres*1.3 + vec3(0.,.33,.67) + uTime*.04 + n.y*.3)); c = mix(c, c*(.45 + uTint*1.1), .5); c += iri*fres*uIri; return c; }`; const uniforms = { uTime: { value: 0 }, uAmp: { value: 0.26 }, uTint: { value: new THREE.Color('#8fb4ff') }, uIri: { value: 0.55 }, uPoke: { value: new THREE.Vector3(0, 0, 3) }, uPokeAmt: { value: 0 }, }; const blobMat = new THREE.ShaderMaterial({ uniforms, vertexShader: ` uniform float uTime; uniform float uAmp; uniform vec3 uPoke; uniform float uPokeAmt; varying vec3 vN; varying vec3 vW; ${NOISE} vec3 disp(vec3 p){ vec3 d = normalize(p); float n = snoise(d*.95 + vec3(0., uTime*.2, uTime*.12)) + .22*snoise(d*2.1 - vec3(uTime*.15)); float poke = uPokeAmt * smoothstep(1.2, 0., distance(d, normalize(uPoke))); return d * (1. + n*uAmp + poke*.35); } void main(){ vec3 p = position; vec3 t = normalize(cross(normal, abs(normal.y) < .99 ? vec3(0.,1.,0.) : vec3(1.,0.,0.))); vec3 b = normalize(cross(normal, t)); float e = .012; vec3 d0 = disp(p), d1 = disp(p + t*e), d2 = disp(p + b*e); vec3 n = normalize(cross(d1 - d0, d2 - d0)); if (dot(n, normal) < 0.) n = -n; vec4 w = modelMatrix * vec4(d0, 1.); vW = w.xyz; vN = normalize(mat3(modelMatrix) * n); gl_Position = projectionMatrix * viewMatrix * w; }`, fragmentShader: ` varying vec3 vN; varying vec3 vW; ${ENV} void main(){ gl_FragColor = vec4(shade(normalize(vN), vW), 1.); }`, }); const solidMat = new THREE.ShaderMaterial({ uniforms, vertexShader: `varying vec3 vN; varying vec3 vW; void main(){ vec4 w = modelMatrix*vec4(position,1.); vW = w.xyz; vN = normalize(mat3(modelMatrix)*normal); gl_Position = projectionMatrix*viewMatrix*w; }`, fragmentShader: `varying vec3 vN; varying vec3 vW; ${ENV} void main(){ gl_FragColor = vec4(shade(normalize(vN), vW), 1.); }`, }); const rig = new THREE.Group(); scene.add(rig); const blob = new THREE.Mesh(new THREE.IcosahedronGeometry(1, 64), blobMat); rig.add(blob); const ring = new THREE.Mesh(new THREE.TorusGeometry(1.75, 0.045, 24, 160), solidMat); ring.rotation.set(1.2, 0.2, 0.3); rig.add(ring); const orbs = [0.16, 0.1, 0.22].map((r, i) => { const m = new THREE.Mesh(new THREE.SphereGeometry(r, 48, 32), solidMat); rig.add(m); return m; }); const star = (() => { // a chrome four-point star const s = new THREE.Shape(); const R = 0.5, r = 0.09; for (let i = 0; i < 8; i++) { const a = i * Math.PI / 4 + Math.PI / 2, rad = i % 2 ? r : R; i ? s.lineTo(Math.cos(a) * rad, Math.sin(a) * rad) : s.moveTo(Math.cos(a) * rad, Math.sin(a) * rad); } const g = new THREE.ExtrudeGeometry(s, { depth: 0.08, bevelEnabled: true, bevelSize: 0.05, bevelThickness: 0.06, bevelSegments: 4 }); g.center(); const m = new THREE.Mesh(g, solidMat); rig.add(m); return m; })(); // where the rig sits, per view const pose = { x: -2.2, y: 0.1, s: 1.25, tx: -2.2, ty: 0.1, ts: 1.25 }; const tint = new THREE.Color('#8fb4ff'), tintT = new THREE.Color('#8fb4ff'); const mouse = { x: 0, y: 0, sx: 0, sy: 0 }; addEventListener('pointermove', e => { mouse.x = e.clientX / innerWidth * 2 - 1; mouse.y = -(e.clientY / innerHeight * 2 - 1); }); function resize() { renderer.setSize(innerWidth, innerHeight, false); camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix(); } addEventListener('resize', resize); resize(); const clock = new THREE.Clock(); let scrollF = 0; function tick() { const dt = Math.min(clock.getDelta(), 0.05), t = clock.elapsedTime; const k = 1 - Math.pow(0.04, dt); mouse.sx += (mouse.x - mouse.sx) * k; mouse.sy += (mouse.y - mouse.sy) * k; pose.x += (pose.tx - pose.x) * k; pose.y += (pose.ty - pose.y) * k; pose.s += (pose.ts - pose.s) * k; tint.lerp(tintT, k); uniforms.uTint.value.copy(tint); uniforms.uTime.value = t; uniforms.uPoke.value.set(mouse.sx * 2, mouse.sy * 2, 1.5); uniforms.uPokeAmt.value += ((Math.abs(mouse.x) + Math.abs(mouse.y) > 0 ? 1 : 0) - uniforms.uPokeAmt.value) * k; const aspectShift = camera.aspect < 1 ? 0.45 : 1; rig.position.set(pose.x * aspectShift, pose.y - scrollF * 2.4, 0); rig.scale.setScalar(pose.s); blob.rotation.set(mouse.sy * 0.4 + t * 0.05, mouse.sx * 0.6 + t * 0.12, 0); ring.rotation.z = t * 0.25; ring.rotation.x = 1.2 + Math.sin(t * 0.4) * 0.15; orbs.forEach((o, i) => { const a = t * (0.5 + i * 0.17) + i * 2.1, r = 1.95 + i * 0.25; o.position.set(Math.cos(a) * r, Math.sin(a * 1.3) * 0.7, Math.sin(a) * r * 0.6); }); star.position.set(1.35, 1.25, 0.6); star.rotation.set(0, t * 1.4, Math.sin(t) * 0.2); renderer.render(scene, camera); requestAnimationFrame(tick); } requestAnimationFrame(tick); // ------------------------------------------------------------------ // sparkles // ------------------------------------------------------------------ const sp = $('#sparkles'); for (let i = 0; i < 26; i++) { const s = document.createElement('i'); const z = 6 + Math.random() * 22; s.style.cssText = `left:${Math.random() * 100}%;top:${Math.random() * 100}%;width:${z}px;height:${z}px;animation-delay:${-Math.random() * 4}s;animation-duration:${2.4 + Math.random() * 3}s`; sp.append(s); } let visitors = 4213; setInterval(() => { if (Math.random() < .3) $('#counter').textContent = String(++visitors).padStart(7, '0'); }, 2600); // ------------------------------------------------------------------ // content // ------------------------------------------------------------------ let posts = []; const app = $('#app'); const words = html => html.replace(//g, '').replace(/<[^>]+>/g, ' ').split(/\s+/).filter(Boolean).length; const dur = p => { const s = Math.round(words(p.html) / 230 * 60) + (p.html.match(/
 new Date(d + 'T12:00:00').toLocaleDateString('en-US', { month: '2-digit', day: '2-digit', year: 'numeric' }).replace(/\//g, '.');
const strip = (html, title) => html.replace(/^\s*]*>([\s\S]*?)<\/h1>\s*/, (m, i) => i.replace(/<[^>]+>/g, '').trim().toLowerCase() === title.toLowerCase() ? '' : m);
const esc = s => s.replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));

function setTint(hex, iri = 0.55) { tintT.set(hex); uniforms.uIri.value = iri; document.documentElement.style.setProperty('--flavor', hex); }

function chromeTitle(text, cls = '') {
  return `

${esc(text)}

`; } // ---------- index: a chrome player ---------- let sel = 0; function renderIndex() { document.body.dataset.view = 'index'; Object.assign(pose, { tx: -2.35, ty: 0.15, ts: 1.3 }); setTint('#8fb4ff'); app.innerHTML = `

NEW! 8 transmissions from nate butler

${chromeTitle('NATE', 'xl')} ${chromeTitle('.RIP', 'xl two')}

design · type systems · canvases · rust · ui
a liquid homepage for the new millennium

NR-2000 DIGITAL BLOG PLAYER
TRK 01BLUEBERRY0:00
${Array.from({ length: 28 }, (_, i) => ``).join('')}
    ${posts.map((p, i) => { const f = flavor(p); return `
  1. ${String(i + 1).padStart(2, '0')} ${esc(p.title)} ${f.kind} ${dur(p)}
  2. `; }).join('')}
`; const tracks = $$('.tracks a'); const select = i => { sel = (i + posts.length) % posts.length; const p = posts[sel], f = flavor(p); tracks.forEach((a, j) => a.classList.toggle('on', j === sel)); $('#lcd-n').textContent = `TRK ${String(sel + 1).padStart(2, '0')}`; $('#lcd-f').textContent = f.name; $('#lcd-t').textContent = dur(p); const tl = $('#lcd-title'); tl.textContent = `${p.title.toUpperCase()} ★ ${fmt(p.date)} ★ ${f.kind.toUpperCase()} ★ `; tl.style.animation = 'none'; void tl.offsetWidth; tl.style.animation = ''; setTint(f.c, 0.75); }; tracks.forEach(a => a.addEventListener('pointerenter', () => select(+a.dataset.i))); $('#player').addEventListener('click', e => { const b = e.target.closest('[data-act]'); if (!b) return; if (b.dataset.act === 'prev') select(sel - 1); if (b.dataset.act === 'next') select(sel + 1); if (b.dataset.act === 'play') location.hash = posts[sel].slug; }); select(sel); } // ---------- post: an aqua window ---------- function windowChrome(title, cls, inner, extra = '') { return `
${title}${extra}
${inner}
`; } function renderPost(p) { const f = flavor(p); document.body.dataset.view = 'post'; document.body.dataset.kind = f.kind; setTint(f.c, 0.7); const idx = posts.indexOf(p), next = posts[(idx + 1) % posts.length], prev = posts[(idx - 1 + posts.length) % posts.length]; const html = strip(p.html, p.title); const wc = words(p.html); if (f.kind === 'note') return renderNote(p, f, html); Object.assign(pose, { tx: 2.6, ty: 1.35, ts: 0.82 }); const shortTitle = p.title.replace(/:.*$/, ''); const sub = p.title.includes(':') ? p.title.split(':').slice(1).join(':').trim() : ''; app.innerHTML = `
◀ BACK

${f.name} ${fmt(p.date)} · ${f.kind} · ${wc} words · ${dur(p)}

${chromeTitle(shortTitle, shortTitle.length > 16 ? 'long' : '')} ${sub ? `

${esc(sub)}

` : ''}
${f.kind === 'image' ? `
` : ''} ${f.kind === 'prose' ? `
0%
` : ''} ${windowChrome(`${esc(p.title)} — ${p.slug}.html`, 'main', `
${html}
`, `${wc} words`)}
`; const body = $('.body', app); $$('a[href^="http"]', body).forEach(a => { a.target = '_blank'; a.rel = 'noopener'; }); // code → little terminals with brushed metal $$('pre', body).forEach((pre, i) => { const lang = guessLang(pre.textContent); const w = document.createElement('div'); w.className = 'term'; w.innerHTML = `
${lang} — ${pre.querySelectorAll('.line').length} lines
`; pre.replaceWith(w); w.append(pre); }); // images → glossy, reflected $$('p', body).forEach(par => { const imgs = $$('img', par); if (imgs.length && !par.textContent.trim()) { const g = document.createElement('div'); g.className = imgs.length > 1 ? 'gloss-grid' : 'gloss'; imgs.forEach(img => { const fr = document.createElement('figure'); fr.append(img); if (img.alt) fr.insertAdjacentHTML('beforeend', `
${esc(img.alt)}
`); g.append(fr); }); par.replaceWith(g); } }); $$('img', body).forEach(i => { i.loading = 'lazy'; }); $$('h2', body).forEach(h => h.classList.add('gelh')); if (f.kind === 'image') coverFlow($('#flow'), [...p.html.matchAll(/]*src="([^"]+)"[^>]*?(?:alt="([^"]*)")?[^>]*>/g)].map(m => ({ src: m[1], alt: m[2] || '' }))); if (f.kind === 'prose') { $$('blockquote, ul', body).forEach(el => el.classList.add('bubble')); } } function guessLang(t) { if (/fn |let |impl |#\[|::/.test(t)) return 'rust'; if (/^\s*(cargo|npm|spool|git) /m.test(t)) return 'shell'; if (/\{"v":/.test(t)) return 'jsonl'; if (/display:|grid-/.test(t)) return 'css'; if (/type |interface |=>/.test(t)) return 'typescript'; return 'text'; } // ---------- cover flow ---------- function coverFlow(root, imgs) { let cur = Math.min(2, imgs.length - 1); root.innerHTML = `
${imgs.map((m, i) => `
${esc(m.alt)}
`).join('')}
`; const figs = $$('figure', root); const layout = () => { figs.forEach((fg, i) => { const d = i - cur, s = Math.sign(d), a = Math.abs(d); fg.style.transform = d === 0 ? 'translateX(-50%) translateZ(140px)' : `translateX(calc(-50% + ${s * (170 + (a - 1) * 70)}px)) translateZ(${-a * 30}px) rotateY(${-s * 62}deg)`; fg.style.zIndex = 100 - a; fg.classList.toggle('on', d === 0); }); $('#flowcap', root).textContent = `${cur + 1} of ${imgs.length}${imgs[cur].alt ? ' — ' + imgs[cur].alt : ''}`; $('#flowthumb', root).style.left = `${imgs.length > 1 ? cur / (imgs.length - 1) * 100 : 0}%`; }; root.addEventListener('click', e => { const fg = e.target.closest('figure'); const b = e.target.closest('[data-d]'); if (fg) cur = +fg.dataset.i; else if (b) cur = Math.max(0, Math.min(imgs.length - 1, cur + +b.dataset.d)); else return; layout(); }); addEventListener('keydown', function k(e) { if (!document.body.contains(root)) return removeEventListener('keydown', k); if (e.key === 'ArrowLeft') { cur = Math.max(0, cur - 1); layout(); } if (e.key === 'ArrowRight') { cur = Math.min(imgs.length - 1, cur + 1); layout(); } }); let auto = setInterval(() => { if (!document.body.contains(root)) return clearInterval(auto); if (root.matches(':hover')) return; cur = (cur + 1) % imgs.length; layout(); }, 3200); layout(); } // ---------- note: a PDA ---------- function renderNote(p, f, html) { Object.assign(pose, { tx: 0, ty: 0.2, ts: 1.9 }); const tmp = document.createElement('div'); tmp.innerHTML = html; // turn "**link** - author" paragraphs into menu items const items = []; let intro = '', outro = ''; [...tmp.children].forEach(el => { const first = el.firstElementChild; if (el.tagName === 'P' && first?.tagName === 'A' && first.querySelector('strong')) { items.push({ type: 'link', html: el.innerHTML }); } else if (/^H[23]$/.test(el.tagName)) items.push({ type: 'head', html: el.textContent }); else if (el.tagName === 'UL') items.push({ type: 'ul', html: el.innerHTML }); else if (el.tagName === 'HR') items.push({ type: 'hr' }); else if (!intro && el.tagName === 'P') intro = el.innerHTML; else items.push({ type: 'p', html: el.innerHTML }); }); const idx = posts.indexOf(p), next = posts[(idx + 1) % posts.length]; app.innerHTML = `
natePILOT
♪ ${fmt(p.date)}▮▮▮▯ 12:${String(new Date().getMinutes()).padStart(2, '0')}

${esc(p.title)}

${intro}

    ${items.map(it => it.type === 'link' ? `
  • ${it.html}
  • ` : it.type === 'head' ? `
  • ${esc(it.html)}
  • ` : it.type === 'ul' ? `
    • ${it.html}
  • ` : it.type === 'hr' ? `
  • ` : `
  • ${it.html}
  • `).join('')}

${f.name} · NOTE

${chromeTitle('BLACK', 'md')}${chromeTitle('MAGIC', 'md two')}

a pocket reading list on canvas & text — scroll the screen, tap a link.

◀ back to playlist
`; $$('.pda-screen a[href^="http"]').forEach(a => { a.target = '_blank'; a.rel = 'noopener'; }); } // ------------------------------------------------------------------ addEventListener('scroll', () => { const max = Math.max(1, document.documentElement.scrollHeight - innerHeight); scrollF = document.body.dataset.view === 'post' ? Math.min(1, scrollY / innerHeight) : 0; const pr = $('#prog'); if (pr) { const f = scrollY / max; pr.style.width = `${f * 100}%`; $('#progt').textContent = `${Math.round(f * 100)}%`; } }, { passive: true }); function route() { const slug = decodeURIComponent(location.hash.slice(1)); const p = posts.find(x => x.slug === slug); app.classList.remove('enter'); void app.offsetWidth; scrollTo(0, 0); scrollF = 0; if (p) renderPost(p); else renderIndex(); app.classList.add('enter'); } addEventListener('hashchange', route); (async () => { posts = await fetch('../content/posts.json').then(r => r.json()); $('#ticker').innerHTML = Array(3).fill(posts.map(p => `★ NEW: ${esc(p.title)}`).join('') + '★ sign my guestbook★ under construction forever').join(''); route(); })();