/* iso.js — a tiny CSS-3D box kit. World: rotateX(60) rotateZ(45). x runs down-right, y down-left, z up. Visible faces are top, south (+y) and east (+x). No perspective: true axonometric. */ const PAL = { mint: { t: '#d9f7f2', s: '#bde5ec', e: '#a3c6e6' }, peri: { t: '#e9e6fd', s: '#c6c8f4', e: '#a9afe9' }, pink: { t: '#fff0f7', s: '#f5cde6', e: '#e0b3dc' }, peach: { t: '#fff3ea', s: '#fad5d6', e: '#e7bad2' }, lilac: { t: '#f3e5fa', s: '#dbc5f1', e: '#c1ade8' }, sky: { t: '#e4f3ff', s: '#bfdcf6', e: '#a2bdec' }, butter: { t: '#fffbe4', s: '#f4e8c8', e: '#dfcdcc' }, ink: { t: '#5b5fa8', s: '#3f4386', e: '#2f3270' }, ground: { t: '#fbe6f3', s: '#efc4e0', e: '#dcacd7' }, white: { t: '#ffffff', s: '#f1eaf8', e: '#ddd6f1' }, }; const Iso = { PAL, full: false, // a box. returns the element; faces get classes so CSS can decorate them. box(u, { x = 0, y = 0, z = 0, w = 1, d = 1, h = 1, p = PAL.peri, cls = '', top = '', south = '', east = '', tag = 'div' }) { const b = document.createElement(tag); b.className = 'bx ' + cls; b.style.cssText = `left:${x * u}px;top:${y * u}px;width:${w * u}px;height:${d * u}px;transform:translateZ(${z * u}px)`; const W = w * u, D = d * u, H = h * u; b.innerHTML = `` + `` + `` + (Iso.full ? `` + `` : ''); return b; }, group(cls = '', x = 0, y = 0, z = 0, u = 1) { const g = document.createElement('div'); g.className = 'grp ' + cls; g.style.transform = `translate3d(${x * u}px,${y * u}px,${z * u}px)`; return g; }, // a billboard: something that faces the screen, standing at (x,y,z) board(u, x, y, z, html, cls = '') { const b = document.createElement('div'); b.className = 'board ' + cls; b.style.cssText = `left:${x * u}px;top:${y * u}px;transform:translateZ(${z * u}px) rotateZ(-45deg) rotateX(-60deg)`; b.innerHTML = html; return b; }, }; // --------------------------------------------------------------- // buildings — each kind of post becomes a different structure. // every builder returns { el, floors[], top } where floors can be revealed one at a time. // --------------------------------------------------------------- const Build = { // stacked server slabs with blinking diodes code(u, { w = 3, d = 3, n = 6, p = PAL.peri, img = [] }) { const g = Iso.group('b-code'); const floors = []; const base = Iso.box(u, { w: w + .4, d: d + .4, x: -.2, y: -.2, h: .35, p: PAL.white }); g.append(base); floors.push(base); let z = .35; for (let i = 0; i < n; i++) { const fh = .78; const f = Iso.box(u, { w, d, z, h: fh, p: i % 3 === 2 ? PAL.ink : p, south: 'leds', east: 'vents', cls: 'floor' }); f.style.setProperty('--blink', `${(i * .37) % 1.6}s`); g.append(f); floors.push(f); z += fh; const gap = Iso.box(u, { x: .25, y: .25, w: w - .5, d: d - .5, z, h: .12, p: PAL.white, cls: 'floor' }); g.append(gap); floors.push(gap); z += .12; } const cap = Iso.box(u, { x: w * .55, y: d * .55, w: w * .3, d: d * .3, z, h: .9, p: PAL.mint, cls: 'floor antenna' }); g.append(cap); floors.push(cap); z += .9; return { el: g, floors, top: z, cx: w / 2, cy: d / 2 }; }, // a gallery hall whose walls are the post's own images image(u, { w = 4, d = 3, n = 3, p = PAL.mint, img = [] }) { const g = Iso.group('b-image'); const floors = []; const plinth = Iso.box(u, { x: -.3, y: -.3, w: w + .6, d: d + .6, h: .3, p: PAL.white }); g.append(plinth); floors.push(plinth); let z = .3; for (let i = 0; i < n; i++) { const fh = 1.15, inset = i * .25; const f = Iso.box(u, { x: inset, y: inset, w: w - inset * 2, d: d - inset * 2, z, h: fh, p: i % 2 ? PAL.lilac : p, south: 'pic', east: 'pic', cls: 'floor' }); const src = img[i % Math.max(1, img.length)]; if (src) { f.querySelector('.fs').style.backgroundImage = `url("${src}")`; const src2 = img[(i + 1) % img.length]; f.querySelector('.fe').style.backgroundImage = `url("${src2}")`; } g.append(f); floors.push(f); z += fh; const ledge = Iso.box(u, { x: inset - .1, y: inset - .1, w: w - inset * 2 + .2, d: d - inset * 2 + .2, z, h: .14, p: PAL.white, cls: 'floor' }); g.append(ledge); floors.push(ledge); z += .14; } return { el: g, floors, top: z, cx: w / 2, cy: d / 2 }; }, // a ziggurat with a stair climbing its face prose(u, { w = 4, d = 4, n = 6, p = PAL.peach }) { const g = Iso.group('b-prose'); const floors = []; let z = 0; for (let i = 0; i < n; i++) { const inset = i * (Math.min(w, d) / (n * 2.6)); const fh = 1.2; const f = Iso.box(u, { x: inset, y: inset, w: w - inset * 2, d: d - inset * 2, z, h: fh, p: [p, PAL.pink, PAL.lilac][i % 3], south: 'lines', cls: 'floor' }); g.append(f); floors.push(f); // a step on the south face, leading up const st = Iso.box(u, { x: inset + (w - inset * 2) * .5 - .4, y: d - inset, w: .8, d: .45, z: z, h: fh * .5, p: PAL.white, cls: 'floor step' }); g.append(st); floors.push(st); z += fh; } const orb = Iso.box(u, { x: w / 2 - .35, y: d / 2 - .35, w: .7, d: .7, z: z + .5, h: .7, p: PAL.butter, cls: 'floor float' }); g.append(orb); floors.push(orb); return { el: g, floors, top: z + 1.2, cx: w / 2, cy: d / 2 }; }, // a tiny kiosk with a cube that won't stay put note(u, { w = 2, d = 2, p = PAL.sky }) { const g = Iso.group('b-note'); const floors = []; const a = Iso.box(u, { w, d, h: .25, p: PAL.white }); g.append(a); floors.push(a); const b = Iso.box(u, { x: .3, y: .3, w: w - .6, d: d - .6, z: .25, h: 1, p, south: 'door', cls: 'floor' }); g.append(b); floors.push(b); const c = Iso.box(u, { x: .15, y: .15, w: w - .3, d: d - .3, z: 1.25, h: .18, p: PAL.ink, cls: 'floor' }); g.append(c); floors.push(c); const spin = Iso.group('spinner floor', w / 2, d / 2, 2.4, u); spin.append(Iso.box(u, { x: -.35, y: -.35, w: .7, d: .7, h: .7, p: PAL.butter })); g.append(spin); floors.push(spin); return { el: g, floors, top: 3.3, cx: w / 2, cy: d / 2 }; }, // masonry: columns of different heights, packed like grid-lanes lanes(u, { w = 3, d = 3, p = PAL.mint }) { const g = Iso.group('b-lanes'); const floors = []; const base = Iso.box(u, { x: -.2, y: -.2, w: w + .4, d: d + .4, h: .25, p: PAL.white }); g.append(base); floors.push(base); const hs = [3.2, 1.6, 4.4, 2.4, 3.8, 1.2, 2.8, 4.9, 2.0]; const pals = [PAL.mint, PAL.peri, PAL.sky, PAL.lilac, PAL.mint, PAL.peach, PAL.peri, PAL.sky, PAL.pink]; let max = 0; for (let i = 0; i < 9; i++) { const cx = i % 3, cy = Math.floor(i / 3); const c = Iso.box(u, { x: cx * (w / 3) + .08, y: cy * (d / 3) + .08, w: w / 3 - .16, d: d / 3 - .16, z: .25, h: hs[i], p: pals[i], cls: 'floor lane' }); c.style.setProperty('--li', i); g.append(c); floors.push(c); max = Math.max(max, hs[i]); } return { el: g, floors, top: max + .4, cx: w / 2, cy: d / 2 }; }, // a spool: flange, wound thread, flange spool(u, { w = 2.4, d = 2.4, p = PAL.peach }) { const g = Iso.group('b-spool'); const floors = []; const f1 = Iso.box(u, { w, d, h: .35, p: PAL.butter }); g.append(f1); floors.push(f1); let z = .35; for (let i = 0; i < 6; i++) { const t = Iso.box(u, { x: .45, y: .45, w: w - .9, d: d - .9, z, h: .5, p: i % 2 ? PAL.pink : p, south: 'thread', east: 'thread', cls: 'floor' }); g.append(t); floors.push(t); z += .5; } const f2 = Iso.box(u, { w, d, z, h: .35, p: PAL.butter, cls: 'floor' }); g.append(f2); floors.push(f2); const pin = Iso.box(u, { x: w / 2 - .18, y: d / 2 - .18, w: .36, d: .36, z: z + .35, h: .8, p: PAL.ink, cls: 'floor' }); g.append(pin); floors.push(pin); return { el: g, floors, top: z + 1.4, cx: w / 2, cy: d / 2 }; }, }; window.Iso = Iso; window.Build = Build; window.PAL = PAL;