Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Figures: the graph tiles are slabs drawn whole, and the hub's tour visits all eight tiles

Lucas Marques6535ea354525
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c0cdf0..9a16258 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,7 @@ Every release of `@lucasmarkes/hairline`. The format follows
- `hub` and `Hub`: a hub and eight tiles on a grid. The tile under the pointer
rises and its link turns solid; its neighbours rise less. A stronger
- `intensity` raises the tiles higher.
+ `intensity` raises the tiles higher. Its tour visits all eight tiles in turn.
- `relay` and `Relay`: a hub and four branches of tiles. The path to the leaf
under the pointer lights hop by hop, each tile rising in turn. A stronger
`intensity` makes each hop wait longer.
@@ -26,6 +26,9 @@ Every release of `@lucasmarkes/hairline`. The format follows
- `stack` and `Stack`: a call stack of five frames. The pointer's height picks
one, and the frames above lift away to open it. A stronger `intensity` lifts
them further.
+- The tiles, plates and frames of these six figures are slabs drawn whole: a
+ thin body with small rounded corners, the full top edge and a closed inner
+ lip.
- Site: the Connectivity and Coding shelves hold six figures each, and each new
figure walks its own `tour` under `play`.
diff --git a/packages/hairline/package.json b/packages/hairline/package.json
index c0c3fdf..043139f 100644
--- a/packages/hairline/package.json
+++ b/packages/hairline/package.json
@@ -94,7 +94,7 @@
{
"name": "react, every component",
"path": "dist/react.js",
- "limit": "42.3 kB",
+ "limit": "42.4 kB",
"ignore": [
"react",
"react/jsx-runtime"
diff --git a/packages/hairline/src/figures/format.ts b/packages/hairline/src/figures/format.ts
index be73f9d..32efb37 100644
--- a/packages/hairline/src/figures/format.ts
+++ b/packages/hairline/src/figures/format.ts
@@ -1,6 +1,7 @@
-import { Cam, clamp, facing, fit, prism, proj, rad, rings, rrect, unproj, type Ring, type Vec2 } from "../core/iso";
+import { Cam, clamp, facing, fit, proj, rad, rrect, unproj, type Ring, type Vec2 } from "../core/iso";
import { reducedMotion, spring, stepS, type Spring } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { lid, slab } from "../slab";
/**
* Format: a file as a stack of ten thin slabs on a rounded board, one to a
@@ -38,7 +39,7 @@ const N = LINES.length;
type Row = {
r: number; yaw: number; dx: number; dy: number; dz: number; px: number; py: number; drawn: number;
- ring: Ring; inner: Ring; sp: Spring; tgt: number; due: number; el: Solid;
+ ring: Ring; sp: Spring; tgt: number; due: number; el: Solid;
lit: boolean; wantLit: boolean; litDue: number;
};
@@ -61,8 +62,8 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
const P = proj(C), front = facing(C);
const g = mk("g", {}, svg);
- const [br, bi] = rings(BX0, BY0, BX1, BY1, 9, 2.2);
- put(solid(g), prism(P, front, br, bi, -PB, 0));
+ const [br, bi] = lid(BX0, BY0, BX1, BY1, 8, 2.2);
+ put(solid(g), slab(P, front, br, bi, -PB, 0));
// the gutter: a dashed guide on the board, before any line lies on it
mk("path", { d: `M${P(X0 - 4, BY0 + 5, 0).join(" ")}L${P(X0 - 4, BY1 - 5, 0).join(" ")}`, class: "dash" }, g);
@@ -71,7 +72,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
const e = solid(g);
return {
r, yaw, dx, dy, dz, px: x0, py: y0 + WD / 2, drawn: NaN,
- ring: rrect(x0, y0, x0 + len, y0 + WD, 2.2, 4), inner: rrect(x0 + 0.9, y0 + 0.9, x0 + len - 0.9, y0 + WD - 0.9, 1.3, 4),
+ ring: rrect(x0, y0, x0 + len, y0 + WD, 2.2, 6),
sp: spring(1, { k: 100, c: 14, eps: 0.003 }), tgt: 1, due: -1, el: e,
// the bright edge: the kernel's stroke transition fades it in and out; this only says when
lit: false, wantLit: false, litDue: -1,
@@ -83,9 +84,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
if (m !== w.drawn) {
w.drawn = m;
const k = m * mess, th = w.yaw * MAXV * k, z = Math.max(0, m) * w.dz * mess;
- const ring = turn(w.ring, w.px, w.py, th, w.dx * k, w.dy * k), inner = turn(w.inner, w.px, w.py, th, w.dx * k, w.dy * k);
- const p = prism(P, front, ring, inner, z, z + T);
- put(w.el, p);
+ put(w.el, slab(P, front, turn(w.ring, w.px, w.py, th, w.dx * k, w.dy * k), null, z, z + T));
}
}
diff --git a/packages/hairline/src/figures/hub.ts b/packages/hairline/src/figures/hub.ts
index 5bb46e9..96e206b 100644
--- a/packages/hairline/src/figures/hub.ts
+++ b/packages/hairline/src/figures/hub.ts
@@ -1,6 +1,7 @@
-import { Cam, clamp, facing, fit, hull, open, poly, prism, proj, ringAt, rings, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { Cam, clamp, facing, fit, hull, open, poly, proj, ringAt, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";
import { reducedMotion, spring, stepS, tdone, tset, tval, tween, type Spring, type Tween } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { lid, slab } from "../slab";
/**
* Hub: a thick plate in the middle of a faint floor grid, eight thin tiles
@@ -14,7 +15,7 @@ import { disposer, mk, pointer, put, register, solid, type FigureMount, type Sol
* positions, a falloff by angle, a stagger by hops round the ring.
*/
-const D = 52, HS = 10, T = 4, HUB = 18, HT = 8, FALL = [1, 0.5, 0.2, 0.06, 0], STEP = 70, HIT = 40;
+const D = 52, HS = 10, T = 3, HUB = 18, HT = 8, FALL = [1, 0.5, 0.2, 0.06, 0], STEP = 70, HIT = 40;
// The rise arrives on a lightly underdamped spring; the return is slower and near-critical.
const UP = { k: 70, c: 14 }, DOWN = { k: 40, c: 12.4 }, DRAW = { k: 120, c: 21, eps: 0.002 }, RETRACT = { k: 36, c: 11.6, eps: 0.002 };
// Each tile's cell, and how far it sits off it.
@@ -78,14 +79,14 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
const order: (Tile | null)[] = [...tiles, null].sort((a, b) => (a ? a.x + a.y : 0) - (b ? b.x + b.y : 0));
for (const t of order) {
if (!t) {
- const [r, ri] = rings(-HUB, -HUB, HUB, HUB, 6, 1.4);
- put(solid(g), prism(P, front, r, ri, 0, HT));
+ const [r, ri] = lid(-HUB, -HUB, HUB, HUB, 5, 1.8);
+ put(solid(g), slab(P, front, r, ri, 0, HT));
mk("path", { d: open(ringAt(P, rrect(-13, -13, 13, 13, 3.5, 4).concat(rrect(-13, -13, 13, 13, 3.5, 4).slice(0, 1)), HT)), class: "nf lo" }, g);
const md = open(ringAt(P, rrect(-7, -7, 7, 7, 2, 4).concat(rrect(-7, -7, 7, 7, 2, 4).slice(0, 1)), HT));
mark = mk("path", { d: md, class: "nf hi" }, g);
continue;
}
- [t.ring, t.inner] = rings(t.x - HS, t.y - HS, t.x + HS, t.y + HS, 3.5, 1);
+ [t.ring, t.inner] = lid(t.x - HS, t.y - HS, t.x + HS, t.y + HS, 2.8, 1.8);
t.el = solid(g);
}
@@ -94,7 +95,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
function draw(t: Tile, now: number) {
const z = Math.max(0, t.sp.x), l = clamp(t.lk.x, 0, 1), w = tval(t.hw, now);
if (z !== t.drawn) {
- t.drawn = z; put(t.el, prism(P, front, t.ring, t.inner, z, z + T));
+ t.drawn = z; put(t.el, slab(P, front, t.ring, t.inner, z, z + T));
t.slot.setAttribute("d", z > 0.4 ? poly(ringAt(P, t.ring, 0)) : "");
}
// the bright mark is the stroke's own colour transition, switched when its weight crosses half
diff --git a/packages/hairline/src/figures/rebuild.ts b/packages/hairline/src/figures/rebuild.ts
index f3b1229..7859cc5 100644
--- a/packages/hairline/src/figures/rebuild.ts
+++ b/packages/hairline/src/figures/rebuild.ts
@@ -1,6 +1,7 @@
-import { Cam, facing, fit, hull, lerp, poly, prism, proj, ringAt, rings, seg, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { Cam, facing, fit, hull, lerp, poly, proj, ringAt, rings, seg, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
import { EASE_LIFT, reducedMotion, tdone, tset, tval, tween, type Tween } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { lid, slab } from "../slab";
/**
* Rebuild: a monorepo as a tree of package tiles on a rounded plinth, a thick
@@ -83,7 +84,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
// Back to front by x + y of the centre.
const order = NODES.slice().sort((a, b) => a.x + a.y - (b.x + b.y));
for (const n of order) {
- const [r, ri] = rings(n.x - n.h, n.y - n.h, n.x + n.h, n.y + n.h, n.l ? 3 : 4, n.l ? 1 : 1.6);
+ const [r, ri] = lid(n.x - n.h, n.y - n.h, n.x + n.h, n.y + n.h, n.l ? 2.8 : 3.6, n.l ? 1.8 : 2);
n.ring = r; n.inner = ri; n.el = solid(g);
// the root carries a recessed square in its lid
if (!n.l) {
@@ -92,7 +93,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
}
}
const draw = (n: Node, h: number) => {
- put(n.el, prism(P, front, n.ring, n.inner, h, h + thick(n)));
+ put(n.el, slab(P, front, n.ring, n.inner, h, h + thick(n)));
if (n.rec) n.recEl!.setAttribute("d", poly(ringAt(P, n.rec, h + thick(n))));
};
diff --git a/packages/hairline/src/figures/relay.ts b/packages/hairline/src/figures/relay.ts
index bb1b593..958e5ff 100644
--- a/packages/hairline/src/figures/relay.ts
+++ b/packages/hairline/src/figures/relay.ts
@@ -1,6 +1,7 @@
-import { Cam, facing, fit, lerp, poly, prism, proj, ringAt, rings, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { Cam, facing, fit, lerp, poly, proj, ringAt, rrect, seg, type Ring, type Vec2, type Vec3 } from "../core/iso";
import { tdone, tset, tval, tween, type Tween } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { lid, slab } from "../slab";
/**
* Relay: a hub plate and four branches of thin tiles on a floor, joined by
@@ -74,15 +75,15 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
// The hub: a thick plate with a recessed square set in its top.
const hub = solid(g);
- const [hr, hi] = rings(-HS, -HS, HS, HS, 6, 2);
- put(hub, prism(P, front, hr, hi, 0, HT));
+ const [hr, hi] = lid(-HS, -HS, HS, HS, 5, 2);
+ put(hub, slab(P, front, hr, hi, 0, HT));
const rim = mk("path", { d: poly(ringAt(P, rrect(-HS + 6, -HS + 6, HS - 6, HS - 6, 2.5, 4), HT)), class: "nf hi" }, g);
const rimW = tween(1); let rimD = true;
mk("path", { d: poly(ringAt(P, rrect(-HS + 9, -HS + 9, HS - 9, HS - 9, 1.2, 4), HT)), class: "nf lo" }, g);
// The tiles, back to front by x + y.
for (const n of nodes.slice().sort((p, q) => p.c[0] + p.c[1] - q.c[0] - q.c[1])) {
- [n.ring, n.inner] = rings(n.c[0] - TS, n.c[1] - TS, n.c[0] + TS, n.c[1] + TS, 3.4, 1.1);
+ [n.ring, n.inner] = lid(n.c[0] - TS, n.c[1] - TS, n.c[0] + TS, n.c[1] + TS, 2.5, 1.6);
n.el = solid(g);
}
@@ -96,7 +97,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
}
if (z !== n.zd) {
n.zd = z;
- put(n.el, prism(P, front, n.ring, n.inner, z * RISE, z * RISE + T));
+ put(n.el, slab(P, front, n.ring, n.inner, z * RISE, z * RISE + T));
}
// The bright edge is a class on the silhouette; the kernel eases the stroke between the two (260ms),
// so the hand-off is a cross-fade. Its weight tween only says when to flip.
diff --git a/packages/hairline/src/figures/settle.ts b/packages/hairline/src/figures/settle.ts
index 8589799..d0a8189 100644
--- a/packages/hairline/src/figures/settle.ts
+++ b/packages/hairline/src/figures/settle.ts
@@ -1,6 +1,7 @@
-import { Cam, clamp, facing, fit, lerp, poly, prism, proj, rad, ringAt, rings, rrect, seg, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
+import { Cam, clamp, facing, fit, lerp, poly, proj, rad, ringAt, rrect, seg, unproj, type Ring, type Vec2, type Vec3 } from "../core/iso";
import { reducedMotion, spring, stepS, tdone, tset, tval, tween, type Spring, type Tween } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { lid, slab } from "../slab";
/**
* Settle: a hub plate on a faint floor grid and twelve thin tiles lying
@@ -34,7 +35,7 @@ type Tile = {
/** A rounded square of half-side h about (cx, cy), turned by a degrees: a ring whose samples carry their normals round with it. */
function turned(cx: number, cy: number, h: number, r: number, a: number): Ring {
const c = Math.cos(rad(a)), s = Math.sin(rad(a));
- return rrect(-h, -h, h, h, r, 4).map((q) => ({
+ return rrect(-h, -h, h, h, r, 8).map((q) => ({
u: cx + q.u * c - q.v * s, v: cy + q.u * s + q.v * c, nu: q.nu * c - q.nv * s, nv: q.nu * s + q.nv * c,
}));
}
@@ -69,9 +70,9 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
// the hub: a thick slab with a recessed square set into its lid
const hub = mk("g", {}, g);
- const [hr, hi] = rings(-HUB, -HUB, HUB, HUB, 5, 1.6);
+ const [hr, hi] = lid(-HUB, -HUB, HUB, HUB, 4.5, 1.8);
const hs = solid(hub);
- put(hs, prism(P, front, hr, hi, 0, HUBT));
+ put(hs, slab(P, front, hr, hi, 0, HUBT));
hs.sil.classList.add("hi");
mk("path", { d: poly(ringAt(P, rrect(-9.5, -9.5, 9.5, 9.5, 2.5, 4), HUBT)), class: "nf lo" }, hub);
@@ -100,7 +101,7 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
tl.k = p.x + p.y + 6 * p.z;
if (key === tl.key) return;
tl.key = key;
- put(tl.el, prism(P, front, turned(p.x, p.y, HALF, 2.6, p.a), turned(p.x, p.y, HALF - 1.1, 1.6, p.a), p.z, p.z + TH));
+ put(tl.el, slab(P, front, turned(p.x, p.y, HALF, 2.3, p.a), turned(p.x, p.y, HALF - 1.6, 1, p.a), p.z, p.z + TH));
}
let order = "";
diff --git a/packages/hairline/src/figures/stack.ts b/packages/hairline/src/figures/stack.ts
index a6e75f9..2d73b2f 100644
--- a/packages/hairline/src/figures/stack.ts
+++ b/packages/hairline/src/figures/stack.ts
@@ -1,6 +1,7 @@
-import { Cam, facing, fit, poly, prism, proj, ringAt, rings, type Ring } from "../core/iso";
+import { Cam, facing, fit, poly, proj, ringAt, rings, type Ring } from "../core/iso";
import { spring, stepS, tdone, tset, tval, tween, type Spring, type Tween } from "../core/motion";
import { disposer, mk, pointer, put, register, solid, type FigureMount, type Solid } from "../core/stage";
+import { lid, slab } from "../slab";
/**
* Stack: a call stack, five frames laid one over another on a base plate, each
@@ -23,7 +24,7 @@ const OPEN = 700, CLOSE = 1250, CSTEP = 45, KICK = 0.42, SETTLE = 230;
const HYS = 5;
const OFF = [[-1.5, 1], [1.5, -1.2], [-0.5, -1.8], [2, 1.2], [0, 0]];
-type Frame = { j: number; ring: Ring; inner: Ring; el: Solid; rim: Ring; lid: SVGPathElement; tw: Tween; sp: Spring & { v0?: number }; kick: number; drawn: number };
+type Frame = { j: number; ring: Ring; el: Solid; rim: Ring; tw: Tween; sp: Spring & { v0?: number }; kick: number; drawn: number };
export const mount: FigureMount = ({ stage, svg, read }, value) => {
const bag = disposer();
@@ -37,8 +38,8 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
const P = proj(C), front = facing(C);
const g = mk("g", {}, svg);
- const [br, bi] = rings(BASE[0], BASE[1], BASE[2], BASE[3], 8, 1.6);
- put(solid(g), prism(P, front, br, bi, 0, BT));
+ const [br, bi] = lid(BASE[0], BASE[1], BASE[2], BASE[3], 7, 2);
+ put(solid(g), slab(P, front, br, bi, 0, BT));
// a recessed square in the base, under the stack
const [rr] = rings(4, 4, 52, 52, 4, 1);
mk("path", { d: poly(ringAt(P, rr, BT)), class: "nf lo" }, g);
@@ -46,17 +47,16 @@ export const mount: FigureMount = ({ stage, svg, read }, value) => {
const fr: Frame[] = [];
for (let j = 0; j < N; j++) {
const x0 = 0 + OFF[j][0], y0 = 0 + OFF[j][1];
- const [ring, inner] = rings(x0, y0, x0 + FW, y0 + FW, 5, 1.1);
+ const [ring] = lid(x0, y0, x0 + FW, y0 + FW, 5, 1.1);
const el = solid(g);
- // the same quiet inset rim on every lid
- const [rim] = rings(x0 + 5, y0 + 5, x0 + FW - 5, y0 + FW - 5, 2.5, 0.6);
- fr.push({ j, ring, inner, el, rim, lid: mk("path", { class: "nf lo" }, el.g), tw: tween(0), sp: spring(0, { k: 90, c: 10, eps: 0.005 }), kick: Infinity, drawn: NaN });
+ // the same quiet inset rim on every lid: the slab's lip
+ const [rim] = lid(x0 + 4, y0 + 4, x0 + FW - 4, y0 + FW - 4, 2.5, 0.6);
+ fr.push({ j, ring, el, rim, tw: tween(0), sp: spring(0, { k: 90, c: 10, eps: 0.005 }), kick: Infinity, drawn: NaN });
}
function draw(f: Frame, e: number) {
const z = Z0 + f.j * PITCH + e;
- put(f.el, prism(P, front, f.ring, f.inner, z, z + T));
- f.lid.setAttribute("d", poly(ringAt(P, f.rim, z + T)));
+ put(f.el, slab(P, front, f.ring, f.rim, z, z + T));
}
const B = register(stage, (_dt, now) => {
diff --git a/packages/hairline/src/index.ts b/packages/hairline/src/index.ts
index 8dee8f3..f34826b 100644
--- a/packages/hairline/src/index.ts
+++ b/packages/hairline/src/index.ts
@@ -321,7 +321,7 @@ export function hub(el: HTMLElement, options?: HairlineOptions): Figure {
label: "A hub and eight tiles on a grid: the tile under the pointer rises and its link turns solid; its neighbours rise less.",
rest: "rest",
engine: hubEngine,
- tour: [[205, 112], [260, 144], [329, 179], [263, 207], [201, 243], null],
+ tour: [[205, 112], [260, 144], [328, 179], [263, 207], [201, 243], [131, 209], [76, 177], [136, 141], null],
}, el, options);
}
diff --git a/packages/hairline/src/slab.ts b/packages/hairline/src/slab.ts
new file mode 100644
index 0000000..f5ca109
--- /dev/null
+++ b/packages/hairline/src/slab.ts
@@ -0,0 +1,31 @@
+import { hull, open, poly, ringAt, rrect, run, type PrismPaths, type Projector, type Ring, type Sample } from "./core/iso";
+
+/**
+ * Slabs: the tiles, plates and frames of the graph figures, drawn whole. Not
+ * in src/core, so the skill's kernel and the pages it wrote stay as they are.
+ */
+
+/**
+ * A prism whose lid is drawn whole. The silhouette carries the lid's front
+ * edge, so the lid reads as a face on its band, and the crease is the inset
+ * ring all round, a lip.
+ */
+export function slab(
+ P: Projector,
+ front: (q: Sample) => boolean,
+ ring: readonly Sample[],
+ inner: readonly Sample[] | null | undefined,
+ z0: number,
+ z1: number,
+): PrismPaths {
+ return {
+ sil: poly(hull(ringAt(P, ring, z1).concat(ringAt(P, ring, z0)))) + open(ringAt(P, run(ring, front), z1)),
+ crease: inner ? poly(ringAt(P, inner, z1)) : "",
+ };
+}
+
+/** A rounded footprint and its lip, inset by b, sampled finely enough for a large tile: eight samples per corner. */
+export const lid = (x0: number, y0: number, x1: number, y1: number, r: number, b: number): [Ring, Ring] => [
+ rrect(x0, y0, x1, y1, r, 8),
+ rrect(x0 + b, y0 + b, x1 - b, y1 - b, Math.max(0.3, r - b), 8),
+];