Skip to content
6 changes: 4 additions & 2 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ if (!/^[1-9]\d*x[1-9]\d*$/.test(frame)) fail(`--size is width x height, like 192
const [w, h] = frame.split('x').map(Number);
const maxMB = +num('--max-mb', flag('--max-mb', 9.5)); // GitHub README uploads cap at 10 MB
const headed = bool('--headed');
const style = oneOf('--style', flag('--style', 'pixel'), ['pixel', 'maquette', 'plan', 'nocturne', 'neon']);
// (neon and chip aren't in --help: neon is the first prototype, chip the easter egg a plain visit rolls now and then)
const styleAsked = args.includes('--style'); // if not, the live view leaves the page to pick (and maybe roll chip)
const style = oneOf('--style', flag('--style', 'pixel'), ['pixel', 'maquette', 'plan', 'nocturne', 'neon', 'chip']);
const pxOpt = num('--pixel', flag('--pixel')); // pixel style: size of one art pixel (default 1; 2 for chunkier art)
const zoomOpt = num('--zoom', flag('--zoom')); // close-up factor (pixel style)
const cityOpt = oneOf('--city', flag('--city', 'auto'), ['auto', 'classic', 'farm', 'desert', 'capital', 'mountain', 'university', 'port', 'industrial', 'science', 'themepark', 'resort',
Expand Down Expand Up @@ -246,7 +248,7 @@ server.listen(port, '127.0.0.1');
server.on('listening', () => {
const link = `http://localhost:${port}`;
if (!rec) {
const view = `${link}/?style=${style}&city=${cityOpt}${pxOpt ? `&px=${pxOpt}` : ''}${zoomOpt ? `&zoom=${zoomOpt}` : ''}`;
const view = `${link}/?${styleAsked ? `style=${style}&` : ''}city=${cityOpt}${pxOpt ? `&px=${pxOpt}` : ''}${zoomOpt ? `&zoom=${zoomOpt}` : ''}`;
console.log(` city open at ${cyan(view)}`);
if (!noOpen) openBrowser(view);
return;
Expand Down
2 changes: 1 addition & 1 deletion test/layout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for (const name of readdirSync(path.join(HERE, 'snapshots')).filter(f => f.endsW
const data = city(JSON.parse(readFileSync(path.join(HERE, 'snapshots', name), 'utf8')));
const gone = data.gone.slice(Math.max(0, data.gone.length - Math.ceil(data.files.length / 4)));
if (!gone.length) continue;
for (const kind of CITY_KINDS) {
for (const kind of [...CITY_KINDS, 'board']) { // (board: the chip style's one plan)
runs++;
const was = plan(data, kind, []), now = plan(data, kind, gone);
const say = msg => problems.push(`${name.replace('.json', '')} as ${kind}: ${msg}`);
Expand Down
425 changes: 425 additions & 0 deletions web/chip.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
body.style-pixel #links a, body.style-pixel #links button { color: #14121c; }
body.style-pixel #links a:hover, body.style-pixel #links button:hover { color: #c0413b; }
body.waiting #links { visibility: hidden; }
/* chip: silkscreen type on a dark board */
body.style-chip, body.style-chip #hud h1, body.style-chip #date .d, body.style-chip .label { font-family: var(--ui-font); }
body.style-chip #hud h1 { font-size: 30px; font-weight: 600; letter-spacing: .02em; }
body.style-chip .label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; }
body.style-chip .label.on { color: #d6a648 !important; }
body.style-chip #track { --on: #c8803f; --off: rgba(236,235,226,.16); --head: var(--ink); }
/* pixel names are little signs on posts, in the same paper-and-ink as the rest of the page */
body.style-pixel .label { font-size: 12px; color: #14121c !important; text-shadow: none; background: #f2efe9; border: 2px solid #14121c;
box-shadow: 2px 2px 0 #14121c; padding: 0 5px; line-height: 16px; letter-spacing: .02em; text-transform: none; }
Expand Down
39 changes: 39 additions & 0 deletions web/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,45 @@ const PLANNERS = {
height: (i, rel) => i === ctx.hub ? 2.4 : Math.min(0.35 + 0.25 * Math.pow(rel, 0.4), 0.9),
};
},

// not a city: the one plan of the chip style (?style=chip), whatever the repo. A square board, each
// directory a rectangular block of it, cut into an even grid of cells with channels between them
// for the traces, the parts packed into the cells in order
board(ds) {
// each block's share counts the channel round it, so a small directory stays a small square
// instead of being squeezed to a sliver by the channels
const PAD = 1.1, share = d => (Math.sqrt(d.area / 0.6) + PAD) ** 2;
const W = Math.sqrt(sum(ds.map(share))) + 1.2;
const root = hierarchy({ children: ds.map(d => ({ d, v: share(d) })) }).sum(x => x.v || 0).sort((a, b) => b.value - a.value);
treemap().tile(treemapSquarify.ratio(1)).size([W, W]).paddingInner(PAD).paddingOuter(0.6)(root);
const lots = [], blocks = [], labels = [], CELL = 6, GAP = 0.45;
for (const leaf of root.leaves()) {
const d = leaf.data.d, w = leaf.x1 - leaf.x0, h = leaf.y1 - leaf.y0;
const cols = Math.max(1, Math.round(w / Math.sqrt(CELL))), rows = Math.max(1, Math.round(h / Math.sqrt(CELL)));
const cw = (w - GAP * (cols - 1)) / cols, ch = (h - GAP * (rows - 1)) / rows;
// each cell takes an even share of what's left of the block's parts, by area, and a part goes in
// if at least half of it fits: a share fixed up front would leave every cell a little short and
// the last one crammed with the rest
const cells = cols * rows;
let k = 0, left = d.area;
for (let n = 0; n < cells && k < d.items.length; n++) {
const take = [], each = left / (cells - n);
let used = 0;
while (k < d.items.length && (n === cells - 1 || !take.length || used + d.items[k].a / 2 <= each)) { used += d.items[k].a; take.push(d.items[k++]); }
left -= used;
const c = n % cols, r = Math.floor(n / cols), x0 = leaf.x0 + c * (cw + GAP), z0 = leaf.y0 + r * (ch + GAP);
blocks.push({ poly: rectPoly(x0, z0, x0 + cw, z0 + ch), type: 'block' });
lots.push(...packRect(take, x0, z0, x0 + cw, z0 + ch, 0.12));
}
if (d.name !== '·') labels.push({ text: d.name, x: (leaf.x0 + leaf.x1) / 2, z: leaf.y1 + 0.45 });
}
// the board itself, on a dark bench
return {
lots, blocks, labels, ground: 'water', land: [rectPoly(-0.5, -0.5, W + 0.5, W + 0.5)],
camera: { az: 90, el: 89, dist: 1.05 }, // from straight above, the board square to the frame
height: (i, rel) => Math.min(0.32 + 0.95 * Math.sqrt(rel), 5),
};
},
};

// ---------------------------------------------------------------- entry point
Expand Down
37 changes: 27 additions & 10 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ const fail = msg => {
};
addEventListener('error', e => fail(e.message || e.error));
addEventListener('unhandledrejection', e => fail(e.reason?.stack || e.reason));
// pixel | maquette | plan | nocturne | neon (the original prototype)
const STYLE = params.get('style') || 'pixel';
// pixel | maquette | plan | nocturne | neon (the original prototype) | chip (the easter egg)
// a visit that names no style is pixel, except one in 100,000 that rolls chip and keeps ?style=chip, so it can be shared
// (never a share card or a recording: those are made, not visited; an empty ?style= names none either)
const STYLE = params.get('style') || (!params.has('card') && !params.has('record') && Math.random() < 1e-5 ? 'chip' : 'pixel');
if (!params.get('style') && STYLE === 'chip') { params.set('style', STYLE); history.replaceState(null, '', `${location.pathname}?${params}${location.hash}`); }
const NEON = STYLE === 'neon';
const PIXEL = STYLE === 'pixel';
// art-pixel size in screen pixels, and how far to zoom in (close-ups frame the city's landmark)
Expand Down Expand Up @@ -154,10 +157,11 @@ for (const l of leaves) {
// when each comes down (2: never), at the end of the timeline at the latest (a deletion can be the last commit)
B.forEach((b, i) => { b.died = files[i].gone ? Math.min(1, t01(files[i].died)) : 2; });

// city planners (lit styles only): ?city=auto picks the repo's own archetype, ?city=classic keeps the treemap
// city planners (lit styles only): ?city=auto picks the repo's own archetype, ?city=classic keeps the treemap;
// a circuit board (?style=chip) has the one plan, whatever the city
const CITY = params.get('city') || 'auto';
const cityKind = NEON || CITY === 'classic' ? null : CITY === 'auto' ? data.identity?.city : CITY;
const layout = cityKind && CITY_KINDS.includes(cityKind) ? timed('layout', () => buildLayout(cityKind, { files, inDeg, hub, SIZE, frontAz: PIXEL ? 45 : undefined })) : null;
const cityKind = NEON ? null : STYLE === 'chip' ? 'board' : CITY === 'classic' ? null : CITY === 'auto' ? data.identity?.city : CITY;
const layout = cityKind && (CITY_KINDS.includes(cityKind) || cityKind === 'board') ? timed('layout', () => buildLayout(cityKind, { files, inDeg, hub, SIZE, frontAz: PIXEL ? 45 : undefined })) : null;
if (layout) {
unit = layout.unit;
plateStep = unit * 0.06;
Expand Down Expand Up @@ -232,7 +236,7 @@ controls.dampingFactor = 0.06;
controls.maxPolarAngle = Math.PI * 0.48;
controls.minDistance = unit * 2;
controls.maxDistance = SIZE * 2.5;
controls.autoRotate = true;
controls.autoRotate = STYLE !== 'chip'; // a board is read from above, not spun
controls.autoRotateSpeed = 0.35;
let userMoved = false; // once you've panned or zoomed, a window resize doesn't snap the view back
controls.addEventListener('start', () => { controls.autoRotate = false; userMoved = true; });
Expand Down Expand Up @@ -426,8 +430,10 @@ if (NEON) {
const heat = new Float32Array(N);
const focusAttr = new Float32Array(N).fill(1);
const glowAttr = new Float32Array(N); // 1 for the buildings of the district under the pointer
// the circuit board's parts are fetched only for it
const chip = STYLE === 'chip' ? await import('./chip.js') : null;
const studio = NEON ? null : timed('studio (all)', () => buildStudio({ name: STYLE, scene, renderer, B, files, districts, unit, SIZE, plateStep, cx, cz,
shared, heat, focusAttr, glowAttr, inDeg, hub, t01, layout }));
shared, heat, focusAttr, glowAttr, inDeg, hub, t01, layout, chip }));
if (studio) {
document.body.classList.add('studio', `style-${STYLE}`);
if (studio.style.uiFont) document.body.style.setProperty('--ui-font', studio.style.uiFont);
Expand Down Expand Up @@ -839,7 +845,7 @@ if (route) {
$('#hud h1').replaceChildren(a);
$('#gh-repo').href = gh; $('#gh-repo').hidden = false; $('#another').hidden = false;
}
const CITY_PHRASE = { farm: 'a farm village', desert: 'a desert boomtown', industrial: 'a factory town', science: 'a science park', themepark: 'a theme park', resort: 'a seaside resort', capital: 'a planned capital', mountain: 'a mountain city', university: 'a university town', port: 'a port city', smalltown: 'a small town', manhattan: 'Manhattan', hongkong: 'Hong Kong', tokyo: 'Tokyo', la: 'Los Angeles', paris: 'Paris', venice: 'Venice', barcelona: 'Barcelona' };
const CITY_PHRASE = { board: 'a circuit board', farm: 'a farm village', desert: 'a desert boomtown', industrial: 'a factory town', science: 'a science park', themepark: 'a theme park', resort: 'a seaside resort', capital: 'a planned capital', mountain: 'a mountain city', university: 'a university town', port: 'a port city', smalltown: 'a small town', manhattan: 'Manhattan', hongkong: 'Hong Kong', tokyo: 'Tokyo', la: 'Los Angeles', paris: 'Paris', venice: 'Venice', barcelona: 'Barcelona' };
const shareLink = route ? `https://gitropolis.dev/${route[1]}/${route[2]}` : 'https://gitropolis.dev';
$('#share').onclick = async () => {
if (!pix || !layout) { // share cards are drawn in the pixel style; elsewhere, the link
Expand Down Expand Up @@ -1049,8 +1055,8 @@ function updateLabels() {
el.style.left = `${boxes[k].x}px`;
el.style.top = `${boxes[k].y}px`;
el.classList.toggle('on', k === hoverLabel);
// perspective views fade far names; the isometric pixel view has no near and far
el.style.opacity = camera.isOrthographicCamera ? 1 : Math.max(0.15, Math.min(1, 1.6 - camera.position.distanceTo(p) / SIZE));
// perspective views fade far names; the isometric pixel view has no near and far, nor a board seen from above
el.style.opacity = camera.isOrthographicCamera || STYLE === 'chip' ? 1 : Math.max(0.15, Math.min(1, 1.6 - camera.position.distanceTo(p) / SIZE));
});
}

Expand Down Expand Up @@ -1291,8 +1297,19 @@ async function record() {
aimPixel(FIT.center.clone().lerp(hubPos, push), FIT.zoom * (1 + 2.0 * push * push));
}

// a circuit board is filmed as it's seen, from straight above: a slow push-in on the hub, never turning
function shotBoard(u) {
planCamera(layout.camera);
const k = REC.fixed ? 0 : smooth(0.35, 1, u);
const from = controls.target.clone(), off = camera.position.clone().sub(from);
pivot.copy(from).lerp(hubPos, k);
camera.position.copy(pivot).addScaledVector(off, 1 - 0.6 * k * k);
camera.lookAt(pivot);
}

function shot(u) {
if (PIXEL) return shotPixel(u);
if (layout?.kind === 'board') return shotBoard(u);
const e = ease(u);
pivot.set(0, 0, 0).lerp(hubPos, smooth(0.5, 1, u));
const theta = theta0 + 1.7 * e;
Expand Down
Loading
Loading