@logomarks/generate 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,13 @@
4
4
  * by the gap). Three from core's letter skeletons (one geometric sans as centrelines): stencil (each stroke solid, split
5
5
  * at its sharp corners and cleared from the ones before by the gap, a closed bowl slit at its top), slabs (the stencil
6
6
  * parts sheared and parted wider, like Shear) and route (the skeleton walked in runs at 0°, 45° and 90°, mitred, like
7
- * Route). After lettermarks built as blocks, slabs and bands: a K of slanted slabs, an H of three bars.
7
+ * Route). And five more: wedge (strokes cut level at the cap and base lines: slanted-slab letters), cut (the route
8
+ * letter heavy, its outer corners rounded: the upright, diagonal band and quarter round of a cut block letter), rails
9
+ * (two nested strokes), hexfold (heavy, cut by a hexagon) and quarter (the Mosaic grid in quarter discs). After
10
+ * lettermarks built as blocks, slabs and bands: a K of slanted slabs, an H of three bars.
8
11
  */
9
- import { U, D, I, rect, rr, mapPts, stroke, SKEL, skelSolid, skStroke, skLine, robust } from '@logomarks/core/geometry';
12
+ import { U, D, I, rect, rr, mapPts, stroke, grow, regular, SKEL, skelSolid, skStroke, skLine, robust } from '@logomarks/core/geometry';
13
+ import { build as mosaic, CHARS as MOSAIC } from './mosaic.js';
10
14
  import { BOX, GAP, clear, tidy } from '../draw.js';
11
15
 
12
16
  robust();
@@ -57,7 +61,7 @@ const NUMERAL = { 0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five
57
61
  /** @type {import('../index.js').Control[]} */
58
62
  export const controls = [
59
63
  { key: 'char', label: 'Letter', type: 'choice', options: CHARS, value: 'K' },
60
- { key: 'build', label: 'Build', type: 'choice', options: ['slabs', 'stencil', 'route', 'tiles', 'blocks', 'pixel'], value: 'slabs' },
64
+ { key: 'build', label: 'Build', type: 'choice', options: ['slabs', 'stencil', 'route', 'tiles', 'blocks', 'pixel', 'wedge', 'cut', 'rails', 'hexfold', 'quarter'], value: 'slabs' },
61
65
  { key: 'weight', label: 'Weight', type: 'range', min: 0.12, max: 0.26, step: 0.005, value: 0.2 },
62
66
  { key: 'slant', label: 'Slant', type: 'range', min: -20, max: 20, step: 1, value: 0 },
63
67
  { key: 'spacing', label: 'Gaps', type: 'range', min: 1, max: 2.5, step: 0.1, value: 1.2 },
@@ -188,11 +192,53 @@ function routeLetter(ch, H, T) {
188
192
  return I(U(...parts), rect(-600, -T / 2, 1800, H + T));
189
193
  }
190
194
 
195
+ /**
196
+ * Wedge: the stencil letter with every stroke that ends on the cap or base line run on past it and cut level there, so
197
+ * an upright ends square and a diagonal becomes a parallelogram with a flat top and foot (the slanted-slab M).
198
+ */
199
+ function wedgeLetter(ch, H, T, gap) {
200
+ const run = (a, b) => { const l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1; return [b[0] + ((b[0] - a[0]) / l) * T, b[1] + ((b[1] - a[1]) / l) * T]; };
201
+ const edge = (q) => q[1] < 1 || q[1] > H - 1;
202
+ const strokes = splitAtCorners(skeleton(ch, H)).map((st) => {
203
+ if (st.closed || st.p.length < 2) return st;
204
+ const pts = st.p.slice();
205
+ if (edge(pts[0])) pts[0] = run(pts[1], pts[0]);
206
+ if (edge(pts.at(-1))) pts[pts.length - 1] = run(pts.at(-2), pts.at(-1));
207
+ return skStroke(pts, st.e);
208
+ }).sort((a, b) => lengthOf(b) - lengthOf(a));
209
+ const parts = [];
210
+ for (const st of strokes) { const solid = skelSolid(null, H, T, [st]); parts.push(parts.length ? clear(solid, U(...parts), gap) : solid); }
211
+ return I(U(...parts), rect(-600, 0, 1800, H));
212
+ }
213
+
214
+ /**
215
+ * Rails: the letter drawn heavy, then as two nested strokes: its outer rim and an inner core, the gap between (the
216
+ * offset-line F).
217
+ */
218
+ function railsLetter(ch, H, T) {
219
+ const heavy = skelSolid(null, H, T * 1.55, skeleton(ch, H)), W = T * 1.55, a = (W - 2 * GAP) / 3;
220
+ return U(D(heavy, grow(heavy, -a)), grow(heavy, -a - GAP));
221
+ }
222
+
223
+ /** Hexfold: the stencil letter drawn heavy and cut by a hexagon standing on a point round it (its corners chamfered). */
224
+ function hexfoldLetter(ch, H, T, gap) {
225
+ const s = stencilLetter(ch, H, T * 1.3, gap);
226
+ let x0 = Infinity, x1 = -Infinity;
227
+ for (const poly of s) for (const [x] of poly[0]) { x0 = Math.min(x0, x); x1 = Math.max(x1, x); }
228
+ const cx = (x0 + x1) / 2, r = Math.max(H * 0.58, (x1 - x0) * 0.6);
229
+ return I(s, regular(cx, H / 2, r, 6, -90));
230
+ }
231
+
191
232
  /** The mark for resolved params. */
192
233
  export function build(p) {
193
234
  const ch = String(p.char), H = 400, T = p.weight * BOX.size;
194
235
  let s;
236
+ if (p.build === 'quarter') return MOSAIC.includes(ch) ? mosaic({ char: ch, tiles: 'round', parted: false, corners: 'outer' }) : tidy(bitmapLetter(ch, 'tiles', p), { share: 0.004, width: 10 });
195
237
  if (p.build === 'tiles' || p.build === 'blocks' || p.build === 'pixel') s = bitmapLetter(ch, p.build, p);
238
+ else if (p.build === 'wedge') s = wedgeLetter(ch, H, T * 1.25, GAP * p.spacing);
239
+ else if (p.build === 'cut') { const r = routeLetter(ch, H, T * 1.15), k = T * 0.45; s = grow(grow(r, -k), k); }
240
+ else if (p.build === 'rails') s = railsLetter(ch, H, T);
241
+ else if (p.build === 'hexfold') s = hexfoldLetter(ch, H, T, GAP * p.spacing);
196
242
  else if (p.build === 'route') s = routeLetter(ch, H, T * 0.9);
197
243
  else s = stencilLetter(ch, H, T, GAP * p.spacing * (p.build === 'slabs' ? 1.5 : 1));
198
244
  const slant = p.slant + (p.build === 'slabs' ? 12 : 0);
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Mirror: a family of bold symmetric emblems in few heavy pieces, cut by a body. Symmetric two ways (bands pressing in
3
+ * from above and below) or four ways (from all four sides); one to three bands each side at stepping radii, bowed in;
4
+ * across the middle two bowed bands meeting at the centre, or (four ways) a centre piece (a diamond or a square);
5
+ * the bands as ink, or cut out of a solid body; the body a hexagon on its point, a rounded square, an octagon, or (four
6
+ * ways only) a disc. Cut, the bands are slots in a solid body with a rim.
7
+ * After the arch emblems of the owner's references and kept clear of the one it came from (R19, someone else's logo:
8
+ * under 0.65 by the house outline measure, a test holds it): no end caps, no two-way disc. Always thick bands (thin arcs
9
+ * stacked are a Wi-Fi icon), never a dot (a face), never a bar across the middle (a divide sign; in a lens, a theta or an
10
+ * eye), never bands bowed out round a lens (an eye).
11
+ */
12
+ import { U, D, I, arcBand, mapPts, rr, regular, rot, grow, poly } from '@logomarks/core/geometry';
13
+ import { BOX, GAP, tidy } from '../draw.js';
14
+
15
+ /** @type {import('../index.js').Control[]} */
16
+ export const controls = [
17
+ { key: 'body', label: 'Body', type: 'choice', options: ['hexagon', 'square', 'octagon', 'disc'], value: 'hexagon' },
18
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.22, max: 0.34, step: 0.005, value: 0.28 },
19
+ { key: 'bow', label: 'Middle curve', type: 'range', min: 1, max: 1.8, step: 0.05, value: 1.3 },
20
+ { key: 'bowl', label: 'Band curve', type: 'range', min: 0.7, max: 1.1, step: 0.01, value: 0.78 },
21
+ { key: 'symmetry', label: 'Symmetry', type: 'choice', options: ['two', 'four'], value: 'two' },
22
+ { key: 'bands', label: 'Bands each side', type: 'range', min: 1, max: 3, step: 1, value: 1 },
23
+ { key: 'centre', label: 'Centre', type: 'choice', options: ['bands', 'diamond', 'square', 'none'], value: 'bands' },
24
+ { key: 'ground', label: 'Ground', type: 'choice', options: ['ink', 'cut'], value: 'ink' },
25
+ ];
26
+
27
+ /** The body, filling the box. */
28
+ function body(kind, four) {
29
+ const { cx, cy, x0, y0, size } = BOX;
30
+ // a hexagon standing on a point, a rounded square or an octagon; a disc only four ways (two ways, with these bands, the
31
+ // reference itself)
32
+ if (kind === 'hexagon') return regular(cx, cy, size / 2, 6, -90);
33
+ if (kind === 'octagon') return regular(cx, cy, size / 2 / Math.cos(Math.PI / 8), 8, 22.5);
34
+ if (kind === 'disc' && four) return regular(cx, cy, size / 2, 96, 0);
35
+ return rr(x0, y0, size, size, size * 0.2);
36
+ }
37
+
38
+ /**
39
+ * The centre piece, `r` the room it has (a half width): a diamond, or a rounded square on its side. Never a lens: between
40
+ * bands above and below it is an eye.
41
+ */
42
+ function centrePiece(kind, r) {
43
+ const { cx, cy } = BOX;
44
+ if (kind === 'square') return rr(cx - r * 0.7, cy - r * 0.7, r * 1.4, r * 1.4, r * 0.22);
45
+ return regular(cx, cy, r, 4, 0);
46
+ }
47
+
48
+ /** The bands pressing in from above: `n` of them, the innermost `edge` above the centre, each bowed in. */
49
+ function bandsAbove(n, edge, T, bowl, R) {
50
+ const { cx } = BOX, out = [];
51
+ for (let i = 0; i < n; i++) {
52
+ const e = edge - i * (T + GAP), r2 = R * bowl * (1.4 + i * 0.35);
53
+ out.push(arcBand(cx, e - T / 2 - r2, r2, T, 5, 175));
54
+ }
55
+ return out.length > 1 ? U(...out) : out[0];
56
+ }
57
+
58
+ /** The mark for resolved params. */
59
+ export function build(p) {
60
+ const R = BOX.size / 2, { cx, cy } = BOX, four = p.symmetry === 'four';
61
+ // two ways a centre piece between bands above and below is a face (brows, a nose, a mouth), so it takes the bands; the
62
+ // meeting bands take one a side (more stack into lips or a Wi-Fi fan); with nothing between, two or three slots cut in a
63
+ // solid hexagon or octagon (one is a bare smile and frown; in a rounded square they make a screen)
64
+ const centre = four ? p.centre : p.centre === 'none' ? 'none' : 'bands';
65
+ const n = !four && centre === 'bands' ? 1 : !four ? Math.max(2, Math.round(p.bands)) : Math.round(p.bands);
66
+ // more bands each side are thinner, so the gaps keep the house width and nothing crowds
67
+ const T = p.weight * R * (n === 1 ? 1 : n === 2 ? 0.78 : 0.62);
68
+ let middle = [], edge;
69
+ // two ways, slots with nothing between are always cut out of a body (bare arcs are lips)
70
+ const cut = four ? p.ground === 'cut' : centre === 'none' || p.ground === 'cut';
71
+ // two ways the reference's own round silhouette is out: no disc, and no octagon unless the bands are cut out of it
72
+ const kind = four ? p.body : cut ? (p.body === 'square' || p.body === 'disc' ? 'octagon' : p.body) : p.body === 'octagon' || p.body === 'disc' ? 'hexagon' : p.body;
73
+ const b = body(kind, four);
74
+ if (centre === 'bands' && !four) {
75
+ // a band sagging from above and its mirror rising from below, meeting at the centre
76
+ const Rc = R * p.bow;
77
+ middle = arcBand(cx, cy - Rc, Rc, T, 5, 175);
78
+ edge = cy - T / 2 - GAP * 1.5;
79
+ } else {
80
+ // a centre piece (or none): the bands start a gap clear of it
81
+ const room = R * (four ? 0.26 : 0.3) * (centre === 'none' ? 0.6 : 1);
82
+ edge = cy - room - GAP;
83
+ if (centre !== 'none' && centre !== 'bands') middle = centrePiece(centre, room);
84
+ }
85
+ let above = bandsAbove(n, edge, T, p.bowl, R);
86
+ if (!four && centre === 'bands' && n === 1 && p.ground === 'ink') {
87
+ // the 0.4.0 emblem, built in its own order so settings saved then draw the same bytes
88
+ const top = U(middle, above), bottom = mapPts(top, ([x, y]) => [x, 2 * cy - y]);
89
+ return tidy(I(U(top, bottom), b));
90
+ }
91
+ let sides;
92
+ if (four) {
93
+ // the same bands from all four sides, each kept to its quarter (a wedge from the centre), a gap along the diagonals
94
+ const wedge = grow(poly([[cx, cy], [cx - R * 3, cy - R * 3], [cx + R * 3, cy - R * 3]]), -GAP / 2);
95
+ above = I(above, wedge);
96
+ sides = U(above, rot(above, 90, cx, cy), rot(above, 180, cx, cy), rot(above, 270, cx, cy));
97
+ } else {
98
+ const below = mapPts(above, ([x, y]) => [x, 2 * cy - y]);
99
+ sides = U(above, below);
100
+ }
101
+ const art = middle.length ? U(sides, middle) : sides;
102
+ // cut: the bands (and the centre) taken out of a solid body, a rim of the body kept round them
103
+ if (cut) return tidy(D(b, I(art, grow(b, -GAP * 1.6))));
104
+ return tidy(I(art, b));
105
+ }
106
+
107
+ /** Four to fifteen heavy pieces. */
108
+ export const guard = {};
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Mosaic: a capital on a coarse grid of cells (three wide, five tall, four wide for M and W), each filled cell one tile:
3
+ * a square, a half-square triangle or a quarter disc. Where a cell's two outer sides are open the tile turns its corner,
4
+ * round or angled; a diagonal stroke (the legs of K, M, N, V, W, X, Y, Z) is drawn by triangle cells. `tiles` sets the
5
+ * rule: all round, all angled, mixed (the stem square, the bowls of a B or a D round) or alternate (round and angled
6
+ * by the cell's parity). `parted` sets the cells apart by the gap instead of edge to edge. After Biskon's B and the tile-built
7
+ * capitals of Letters · Half Square.
8
+ */
9
+ import { U, rect, poly, circle, I, mapPts } from '@logomarks/core/geometry';
10
+ import { BOX, GAP, tidy } from '../draw.js';
11
+
12
+ /**
13
+ * The grids: '#' a square, '.' empty, a triangle named by the corner its right angle fills ('1' top left, '2' top
14
+ * right, '3' bottom right, '4' bottom left: a diagonal stroke runs along its long side), and a joint ('a' to 'd', the
15
+ * same corners): the tile that joins two squares meeting only at a corner, a triangle or a quarter disc by the tile rule.
16
+ */
17
+ const GRID = {
18
+ A: ['###', '#.#', '###', '#.#', '#.#'],
19
+ B: ['##d', '#.#', '###', '#.#', '##a'],
20
+ C: ['###', '#..', '#..', '#..', '###'],
21
+ D: ['##d', '#.#', '#.#', '#.#', '##a'],
22
+ E: ['###', '#..', '##.', '#..', '###'],
23
+ F: ['###', '#..', '##.', '#..', '#..'],
24
+ G: ['###', '#..', '#.#', '#.#', '###'],
25
+ H: ['#.#', '#.#', '###', '#.#', '#.#'],
26
+ J: ['..#', '..#', '..#', '#.#', '###'],
27
+ K: ['#.#', '#3#', '##.', '#2#', '#.#'],
28
+ L: ['#..', '#..', '#..', '#..', '###'],
29
+ M: ['#43#', '#..#', '#..#', '#..#', '#..#'],
30
+ N: ['#..#', '##.#', '#2##', '#..#', '#..#'],
31
+ P: ['##d', '#.#', '##a', '#..', '#..'],
32
+ R: ['##d', '#.#', '##a', '#b#', '#.#'],
33
+ S: ['###', '#..', '###', '..#', '###'],
34
+ T: ['###', '.#.', '.#.', '.#.', '.#.'],
35
+ U: ['#.#', '#.#', '#.#', '#.#', '###'],
36
+ V: ['#.#', '#.#', '#.#', '2.1', '.#.'],
37
+ W: ['#..#', '#..#', '#..#', '#..#', '#12#'],
38
+ X: ['#.#', '2.1', '.#.', '3.4', '#.#'],
39
+ Y: ['#.#', '#.#', '2#1', '.#.', '.#.'],
40
+ Z: ['###', '.3#', '.#.', '#1.', '###'],
41
+ };
42
+ export const CHARS = Object.keys(GRID);
43
+
44
+ /** @type {import('../index.js').Control[]} */
45
+ export const controls = [
46
+ { key: 'char', label: 'Letter', type: 'choice', options: CHARS, value: 'B' },
47
+ { key: 'tiles', label: 'Corners', type: 'choice', options: ['mixed', 'round', 'angled', 'alternate'], value: 'mixed' },
48
+ { key: 'parted', label: 'Cells apart', type: 'toggle', value: false },
49
+ { key: 'corners', label: 'Turned corners', type: 'choice', options: ['outer', 'all', 'ends'], value: 'outer' },
50
+ { key: 'width', label: 'Cell width', type: 'range', min: 0.8, max: 1.3, step: 0.01, value: 1 },
51
+ ];
52
+
53
+ /** A quarter disc filling a cell, its round corner at `corner` (0 top left, 1 top right, 2 bottom right, 3 bottom left). */
54
+ function quarter(x, y, s, corner) {
55
+ const c = [[x + s, y + s], [x, y + s], [x, y], [x + s, y]][corner];
56
+ return I(circle(c[0], c[1], s, 96), rect(x, y, s, s));
57
+ }
58
+
59
+ /** A half-square triangle filling the corner `corner` of a cell (the same numbering as `quarter`). */
60
+ function triangle(x, y, s, corner) {
61
+ const P = [[x, y], [x + s, y], [x + s, y + s], [x, y + s]];
62
+ return poly([P[corner], P[(corner + 1) % 4], P[(corner + 3) % 4]]);
63
+ }
64
+
65
+ /** The mark for resolved params. */
66
+ export function build(p) {
67
+ const rows = GRID[p.char] || GRID.B, cols = rows[0].length, n = rows.length;
68
+ const g = p.parted ? GAP : 0, sh = (BOX.size - (n - 1) * g) / n, sw = sh * (p.width ?? 1), s = sh, w = cols * sw + (cols - 1) * g;
69
+ const at = (c, r) => rows[r]?.[c] ?? '.', full = (c, r) => at(c, r) === '#';
70
+ const filled = (c, r) => at(c, r) !== '.';
71
+ const parts = [];
72
+ for (let r = 0; r < n; r++) for (let c = 0; c < cols; c++) {
73
+ const ch = at(c, r), x = BOX.cx - (cols * s + (cols - 1) * g) / 2 + c * (s + g), y = BOX.y0 + r * (s + g);
74
+ if (ch === '.') continue;
75
+ if ('1234'.includes(ch)) { parts.push(triangle(x, y, s, Number(ch) - 1)); continue; }
76
+ if ('abcd'.includes(ch)) {
77
+ const k = 'abcd'.indexOf(ch), round = p.tiles === 'round' || (p.tiles === 'mixed' && c > 0) || (p.tiles === 'alternate' && (c + r) % 2 === 0);
78
+ parts.push(round ? quarter(x, y, s, (k + 2) % 4) : triangle(x, y, s, k));
79
+ continue;
80
+ }
81
+ // which corner turns: the one whose two sides are open (outer); with `all`, also a corner with one open side at a
82
+ // stroke's end; `ends`, only the cell at the end of a stroke (open on three sides)
83
+ const open = [[-1, 0], [0, -1], [1, 0], [0, 1]].map(([dc, dr]) => !filled(c + dc, r + dr));
84
+ const corners = [[open[0] && open[1]], [open[1] && open[2]], [open[2] && open[3]], [open[3] && open[0]]].map(([v]) => v);
85
+ const ends = open.filter(Boolean).length >= 3;
86
+ let corner = -1;
87
+ if (p.corners !== 'ends' || ends) corner = corners.findIndex(Boolean);
88
+ if (corner < 0 || (!full(c, r))) { parts.push(rect(x - (g ? 0 : 0.02), y - (g ? 0 : 0.02), s + (g ? 0 : 0.04), s + (g ? 0 : 0.04))); continue; }
89
+ // mixed: the stem (the left column) keeps its square corners, the rest round (Biskon's B)
90
+ if (p.tiles === 'mixed' && c === 0) { parts.push(rect(x - (g ? 0 : 0.02), y - (g ? 0 : 0.02), s + (g ? 0 : 0.04), s + (g ? 0 : 0.04))); continue; }
91
+ const round = p.tiles === 'round' || p.tiles === 'mixed' || (p.tiles === 'alternate' && (c + r) % 2 === 0);
92
+ const keep = (corner + 2) % 4; // the tile keeps the corner opposite the one that turns
93
+ parts.push(round ? quarter(x, y, s, corner) : triangle(x, y, s, keep));
94
+ // a second open corner on the same cell (a cell open on three sides) turns too: the cell becomes a half
95
+ if (p.corners === 'all') {
96
+ const second = corners.findIndex((v, k) => v && k !== corner);
97
+ if (second >= 0) parts[parts.length - 1] = I(parts.at(-1), round ? quarter(x, y, s, second) : triangle(x, y, s, (second + 2) % 4));
98
+ }
99
+ }
100
+ // cells drawn square, then the whole letter stretched across by the cell width
101
+ const k = sw / sh, out = U(...parts);
102
+ return tidy(k === 1 ? out : mapPts(out, ([x, y]) => [BOX.cx + (x - BOX.cx) * k, y]), { share: 0.004, width: 10 });
103
+ }
104
+
105
+ /** A mosaic letter is up to fifteen cells; parted, each its own piece. */
106
+ export const guard = { maxPieces: 22, minInkShare: 0.2 };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Nodes: four or five round nodes at even turns round a ring (a round or rounded-square hole through the middle), each
3
+ * joined to the ring by a soft neck, every join a concave fillet, so the whole reads as one soft solid with a hole.
4
+ * After Orbience's soft X and the live Soft · Nodes. Never a centre disc (with the nodes round it, a face or a figure),
5
+ * never three nodes (a fidget spinner, near the biohazard sign) or six (a cog), and no orbits (an atom).
6
+ */
7
+ import { sdCircle, sdBox, shell, smin, shapeOf } from '@logomarks/core/sdf';
8
+ import { BOX, tidy } from '../draw.js';
9
+
10
+ /** @type {import('../index.js').Control[]} */
11
+ export const controls = [
12
+ { key: 'nodes', label: 'Nodes', type: 'range', min: 4, max: 5, step: 1, value: 4 },
13
+ { key: 'size', label: 'Node size', type: 'range', min: 0.13, max: 0.24, step: 0.01, value: 0.19 },
14
+ { key: 'ring', label: 'Ring width', type: 'range', min: 0.1, max: 0.24, step: 0.01, value: 0.16 },
15
+ { key: 'hole', label: 'Hole', type: 'range', min: 0.2, max: 0.42, step: 0.01, value: 0.3 },
16
+ { key: 'neck', label: 'Neck', type: 'range', min: 0.3, max: 1, step: 0.05, value: 0.6 },
17
+ { key: 'shape', label: 'Hole shape', type: 'choice', options: ['round', 'square'], value: 'round' },
18
+ { key: 'sizes', label: 'Node sizes', type: 'choice', options: ['even', 'big-small'], value: 'even' },
19
+ { key: 'spin', label: 'Spin', type: 'range', min: 0, max: 90, step: 1, value: 45 },
20
+ ];
21
+
22
+ /** The mark for resolved params. */
23
+ export function build(p) {
24
+ const n = p.nodes, R = BOX.size / 2, { cx, cy } = BOX;
25
+ const hole = p.hole * R, w = p.ring * R, mid = hole + w / 2;
26
+ const fields = [p.shape === 'square' ? shell(sdBox(cx, cy, 2 * mid, 2 * mid, mid * 0.28), w) : shell(sdCircle(cx, cy, mid), w)];
27
+ for (let k = 0; k < n; k++) {
28
+ // big and small take turns (four only: with five the odd one is out)
29
+ const rn = p.size * R * (p.sizes === 'big-small' && n === 4 ? (k % 2 ? 0.78 : 1.15) : 1);
30
+ // each node sits just off the ring's outer edge and the smooth union draws the neck across (wide enough that it
31
+ // always joins: a node left apart is a dot round a ring, a loading spinner); the fit scales the whole to the box
32
+ const a = ((p.spin - 90 + (360 * k) / n) * Math.PI) / 180, d = mid + w / 2 + rn * 1.05;
33
+ fields.push(sdCircle(cx + d * Math.cos(a), cy + d * Math.sin(a), rn));
34
+ }
35
+ // a smooth union: the neck between each node and the ring a concave fillet, its width by `neck`
36
+ const k = p.size * R * (0.35 + p.neck * 0.55);
37
+ return tidy(shapeOf(smin(k, ...fields), { h: 2, x0: BOX.x0 - 8, y0: BOX.y0 - 8, x1: BOX.x1 + 8, y1: BOX.y1 + 8 }));
38
+ }
39
+
40
+ /** One soft solid with one hole. */
41
+ export const guard = {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Notch: a block (square, chamfered or rounded) with a chevron notch cut into one side and a diamond seated in the
3
+ * notch, the gap all round it, poking out past the side; the block parted from the notch's point to the
4
+ * far side by the gap if asked. After Dinpak's D. The notch is always on a side (on the top it is an envelope), the seat
5
+ * is never a triangle (a play button), and nothing runs behind the point (an arrow).
6
+ */
7
+ import { U, D, rect, poly, rr, grow } from '@logomarks/core/geometry';
8
+ import { BOX, GAP, tidy } from '../draw.js';
9
+
10
+ /** @type {import('../index.js').Control[]} */
11
+ export const controls = [
12
+ { key: 'body', label: 'Block', type: 'choice', options: ['chamfer', 'square', 'rounded'], value: 'chamfer' },
13
+ { key: 'depth', label: 'Notch depth', type: 'range', min: 0.22, max: 0.5, step: 0.01, value: 0.34 },
14
+ { key: 'mouth', label: 'Notch mouth', type: 'range', min: 0.45, max: 0.85, step: 0.01, value: 0.62 },
15
+ { key: 'seat', label: 'Seat', type: 'choice', options: ['diamond', 'none'], value: 'diamond' },
16
+ { key: 'split', label: 'Parted', type: 'toggle', value: true },
17
+ { key: 'width', label: 'Width', type: 'range', min: 0.7, max: 1, step: 0.01, value: 0.86 },
18
+ { key: 'height', label: 'Height', type: 'range', min: 0.5, max: 1, step: 0.01, value: 0.72 },
19
+ ];
20
+
21
+ /** The mark for resolved params. */
22
+ export function build(p) {
23
+ const H = BOX.size * p.height, W = BOX.size * p.width, x0 = BOX.cx - W / 2 + (p.seat === 'diamond' ? W * 0.08 : 0), y0 = BOX.cy - H / 2;
24
+ const x1 = x0 + W, cy = BOX.cy, c = H * 0.22;
25
+ let body;
26
+ if (p.body === 'chamfer') body = poly([[x0, y0], [x1 - c, y0], [x1, y0 + c], [x1, y0 + H - c], [x1 - c, y0 + H], [x0, y0 + H]]);
27
+ else if (p.body === 'rounded') body = rr(x0, y0, W, H, [0, c, c, 0]);
28
+ else body = rect(x0, y0, W, H);
29
+ // the notch: a V from the left side, its mouth `mouth` of the height, its point `depth` of the width in
30
+ const m = (H * p.mouth) / 2, d = W * p.depth;
31
+ const notch = poly([[x0 - 2, cy - m - 2], [x0 + d, cy], [x0 - 2, cy + m + 2]]);
32
+ let s = D(body, notch);
33
+ if (p.split) s = D(s, rect(x0 + d - 1, cy - GAP / 2, W, GAP));
34
+ if (p.seat !== 'none') {
35
+ // the seat: the notch shrunk by the gap, mirrored out past the side into a diamond (or left as the notch's own shape, sunk)
36
+ const k = (d - GAP * 1.5) / d;
37
+ if (k > 0.3) {
38
+ const dx = d * k, dy = m * k, ax = x0 + d - GAP * 1.5 / Math.sin(Math.atan2(m, d));
39
+ const seat = poly([[ax, cy], [ax - dx, cy - dy], [ax - 2 * dx, cy], [ax - dx, cy + dy]]);
40
+ s = U(s, D(seat, grow(s, GAP)));
41
+ }
42
+ }
43
+ return tidy(s);
44
+ }
45
+
46
+ /** A block, its parts and its seat. */
47
+ export const guard = {};
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Ribbon: one thick band that folds back on itself, its turns round, slots (round-ended gaps) along its runs, its ends
3
+ * cut by the box, rounded or angled. After the folded S of the owner's references, widened into a family: one, two or
4
+ * three steps, a wave of one swing, the turns round or creased (paper folded flat: a mitre opened by the gap), one or
5
+ * two slots or none, the whole slanted. Unlike a plain letter (the dropped Fold, mitred, read as
6
+ * blocky L, U, S): the round turns and the weight are always there, and the figures that read as a letter (N, Z) are by
7
+ * hand only; a shuffle never draws them.
8
+ */
9
+ import { D, I, rect, stroke, pill, regular } from '@logomarks/core/geometry';
10
+ import { BOX, GAP, tidy, shear } from '../draw.js';
11
+
12
+ /**
13
+ * The figures, in a unit box (0–1 across and down): the path's corners, the band's weight as a share of the plain one
14
+ * (a figure with more runs side by side needs a thinner band to keep the gaps), and `over`: the run that passes over
15
+ * another ([over, under] run indices), the under run cut by a gap either side of it.
16
+ */
17
+ const FIGURES = {
18
+ n: { pts: [[0, 1], [0, 0], [1, 1], [1, 0]] },
19
+ z: { pts: [[0, 0], [1, 0], [0, 1], [1, 1]] },
20
+ hook: { pts: [[1, 0], [0.3, 0], [1, 0.85], [0.1, 0.85]] },
21
+ hairpin: { pts: [[0, 1], [0, 0], [1, 1], [1, 0.45]] },
22
+ // a stair of two folds, the runs level and upright, the middle run at `reach`
23
+ step: { pts: [[0, 1], [0, (r) => r], [1, (r) => r], [1, 0]], k: 1 },
24
+ // two steps: down and across twice
25
+ stairs: { pts: [[0, 1], [0, 0.55], [0.5, 0.55], [0.5, 0], [1, 0]], k: 0.8 },
26
+ // a wave: the band swinging across and back, its turns wide and round (`reach` sets how deep)
27
+ wave: { pts: [[0, 0.5], [0.25, (r) => 0.5 - r * 0.5], [0.75, (r) => 0.5 + r * 0.5], [1, 0.5]], k: 0.92, wave: true },
28
+ // three steps, a flight
29
+ flight: { pts: [[0, 1], [0, 0.68], [0.34, 0.68], [0.34, 0.34], [0.68, 0.34], [0.68, 0], [1, 0]], k: 0.62 },
30
+ };
31
+ /**
32
+ * The figures a shuffle draws: never one whose main read is a letter. Drawn and dropped (2026-11-27, from sheets): a
33
+ * loop over itself (a P), a square spiral (an a), a frame round a square (a Q), one round a triangle (a muddle), a
34
+ * serpent of upright runs (n, N, M), a pleat of level runs (the numerals 2 and 3), a wave of two swings (an M) and a hairpin that steps out (ru).
35
+ */
36
+ export const SHUFFLE_FIGURES = ['step', 'stairs', 'flight', 'wave'];
37
+
38
+ /** @type {import('../index.js').Control[]} */
39
+ export const controls = [
40
+ { key: 'path', label: 'Fold', type: 'choice', options: Object.keys(FIGURES), value: 'step' },
41
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.2, max: 0.34, step: 0.005, value: 0.27 },
42
+ { key: 'bend', label: 'Turn radius', type: 'range', min: 0.6, max: 1.4, step: 0.05, value: 1 },
43
+ { key: 'slot', label: 'Slot length', type: 'range', min: 0.35, max: 0.75, step: 0.01, value: 0.55 },
44
+ { key: 'width', label: 'Width', type: 'range', min: 0.7, max: 1, step: 0.01, value: 0.86 },
45
+ { key: 'reach', label: 'Reach', type: 'range', min: 0.3, max: 0.7, step: 0.01, value: 0.5 },
46
+ { key: 'slots', label: 'Slots', type: 'choice', options: ['one', 'two', 'none'], value: 'one' },
47
+ { key: 'ends', label: 'Ends', type: 'choice', options: ['box', 'round', 'angled'], value: 'box' },
48
+ { key: 'turns', label: 'Turns', type: 'choice', options: ['round', 'crease'], value: 'round' },
49
+ { key: 'slant', label: 'Slant', type: 'range', min: -25, max: 25, step: 1, value: 0 },
50
+ ];
51
+
52
+ /** A polyline with each inner corner rounded: a circular-ish quadratic `r` back along both legs. */
53
+ function fillet(pts, r) {
54
+ const out = [pts[0]];
55
+ for (let k = 1; k < pts.length - 1; k++) {
56
+ const [a, v, b] = [pts[k - 1], pts[k], pts[k + 1]];
57
+ const la = Math.hypot(a[0] - v[0], a[1] - v[1]), lb = Math.hypot(b[0] - v[0], b[1] - v[1]), d = Math.min(r, la * 0.48, lb * 0.48);
58
+ const p1 = [v[0] + ((a[0] - v[0]) * d) / la, v[1] + ((a[1] - v[1]) * d) / la], p2 = [v[0] + ((b[0] - v[0]) * d) / lb, v[1] + ((b[1] - v[1]) * d) / lb];
59
+ for (let i = 0; i <= 16; i++) { const t = i / 16, u = 1 - t; out.push([u * u * p1[0] + 2 * u * t * v[0] + t * t * p2[0], u * u * p1[1] + 2 * u * t * v[1] + t * t * p2[1]]); }
60
+ }
61
+ out.push(pts.at(-1));
62
+ return out;
63
+ }
64
+
65
+ const len = (a, b) => Math.hypot(b[0] - a[0], b[1] - a[1]);
66
+ /** A point `d` along from `a` towards `b`. */
67
+ const along = (a, b, d) => { const l = len(a, b) || 1; return [a[0] + ((b[0] - a[0]) * d) / l, a[1] + ((b[1] - a[1]) * d) / l]; };
68
+
69
+ /** The mark for resolved params. */
70
+ export function build(p) {
71
+ const fig = FIGURES[p.path] || FIGURES.step;
72
+ const kW = fig.k ?? 1;
73
+ const T = p.weight * BOX.size * kW, W = BOX.size * p.width - T, H = BOX.size - T;
74
+ const x0 = BOX.cx - W / 2, y0 = BOX.y0 + T / 2;
75
+ const at = (v) => (typeof v === 'function' ? v(p.reach) : v);
76
+ const unit = fig.pts;
77
+ const pts = unit.map(([u, v]) => [x0 + at(u) * W, y0 + at(v) * H]);
78
+ // creased turns need runs long enough to hold a mitre and its gap; a flight's short runs keep round turns
79
+ const crease = p.turns === 'crease' && !fig.wave && pts.slice(2, -1).every((q, k) => len(pts[k + 1], q) > T * 1.5);
80
+ // the ends: run past the box and cut square by it, or stop short and round, or stop short and cut on the slant
81
+ const ext = (a, b, d) => [b[0] + ((b[0] - a[0]) / len(a, b)) * d, b[1] + ((b[1] - a[1]) / len(a, b)) * d];
82
+ if (p.ends === 'box') { pts[0] = ext(pts[1], pts[0], T); pts[pts.length - 1] = ext(pts.at(-2), pts.at(-1), T); }
83
+ else if (p.ends === 'angled') { pts[0] = ext(pts[1], pts[0], T * 0.5); pts[pts.length - 1] = ext(pts.at(-2), pts.at(-1), T * 0.5); }
84
+ let s = stroke(crease ? pts : fillet(pts, T * p.bend * (fig.wave ? 3 : 1)), T, { roundCaps: p.ends === 'round' });
85
+ if (crease) {
86
+ // each corner a crease: the mitre line from the inner corner to the outer one, opened by the gap
87
+ for (let k = 1; k < pts.length - 1; k++) {
88
+ const a = pts[k - 1], v = pts[k], b = pts[k + 1];
89
+ const ua = [(a[0] - v[0]) / len(a, v), (a[1] - v[1]) / len(a, v)], ub = [(b[0] - v[0]) / len(b, v), (b[1] - v[1]) / len(b, v)];
90
+ const bis = [ua[0] + ub[0], ua[1] + ub[1]], bl = Math.hypot(bis[0], bis[1]) || 1, d = (T / 2) * Math.SQRT2 * 1.2;
91
+ const inner = [v[0] + (bis[0] / bl) * d, v[1] + (bis[1] / bl) * d], outer = [v[0] - (bis[0] / bl) * d, v[1] - (bis[1] / bl) * d];
92
+ s = D(s, pill(inner, outer, GAP));
93
+ }
94
+ }
95
+ if (p.ends === 'angled') {
96
+ // each end sliced at 45° across the band: everything past the line through the tip's middle at 45° goes
97
+ for (const [a, b] of [[pts[1], pts[0]], [pts.at(-2), pts.at(-1)]]) {
98
+ const u = [(b[0] - a[0]) / len(a, b), (b[1] - a[1]) / len(a, b)], n = [-u[1], u[0]], F = T * 2;
99
+ const c = [b[0] - u[0] * T * 0.25, b[1] - u[1] * T * 0.25], l = [u[0] - n[0], u[1] - n[1]], o = [u[0] + n[0], u[1] + n[1]];
100
+ // only near the tip: a fold that comes back close by must not lose a corner to it
101
+ const near = regular(b[0], b[1], T * 0.95, 32, 0);
102
+ s = D(s, I([[[c[0] + l[0] * F, c[1] + l[1] * F], [c[0] - l[0] * F, c[1] - l[1] * F], [c[0] - l[0] * F + o[0] * F, c[1] - l[1] * F + o[1] * F], [c[0] + l[0] * F + o[0] * F, c[1] + l[1] * F + o[1] * F]]], near));
103
+ }
104
+ }
105
+ // the slots: round-ended gaps along the longest runs (none, one, or two), each kept to the run's straight middle: an end
106
+ // run counts only up to the box (its extension is cut away), a turn's curve takes `bend` × the weight off each end
107
+ const inBox = ([x, y]) => [Math.min(BOX.x1, Math.max(BOX.x0, x)), Math.min(BOX.y1, Math.max(BOX.y0, y))];
108
+ const runs = [];
109
+ for (let k = 0; k < pts.length - 1; k++) {
110
+ const a = k === 0 ? inBox(pts[0]) : pts[k], b = k === pts.length - 2 ? inBox(pts[k + 1]) : pts[k + 1];
111
+ // a wave is all curve but for the swing's middle, where it crosses straight: there a short slot fits
112
+ const curve = (k === 0 ? 0 : 1) + (k === pts.length - 2 ? 0 : 1), straight = fig.wave ? (k === 1 ? len(a, b) * 0.3 : 0) : len(a, b) - curve * T * p.bend * 0.9 - T * 0.3;
113
+ runs.push([straight, a, b]);
114
+ }
115
+ runs.sort((x, y) => y[0] - x[0]);
116
+ const want = p.slots === 'none' ? 0 : p.slots === 'two' ? 2 : 1;
117
+ for (const [straight, a, b] of runs.slice(0, want)) {
118
+ const h = (straight * p.slot) / 2;
119
+ if (h < GAP * 0.6) continue;
120
+ const m = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
121
+ s = D(s, pill(along(m, a, h), along(m, b, h), GAP));
122
+ }
123
+ s = I(s, rect(BOX.x0, BOX.y0, BOX.size, BOX.size));
124
+ return tidy(p.slant ? shear(s, p.slant) : s);
125
+ }
126
+
127
+ /** One band: its turns are its only curves. */
128
+ export const guard = {};
@@ -2,11 +2,12 @@
2
2
  * Route: heavy bands that run only level, upright or at 45°, turning on a lattice and forking, joined by nodes (a
3
3
  * square, a diamond or a disc) where they turn, laid out by a numbered layout. After the owner's favourite, Tech · Route.
4
4
  * `frame` joins the bands to a square frame (full, open on one side, or two corner Ls: the square-glyph meanders), which
5
- * turns the diagonals off; `turns` round fillets every turn. A framed layout that looks the same a quarter turn round
5
+ * turns the diagonals off; `turns` round fillets every turn. `body: 'cube'` draws an iso cube instead, its three faces
6
+ * a gap apart, each engraved with one or two short round-ended tracks ending in a node (circuit tracks on a cube). A framed layout that looks the same a quarter turn round
6
7
  * (four hooks round a centre) is passed over for the next layout.
7
8
  */
8
- import { U, rect, poly, circle, stroke, rot } from '@logomarks/core/geometry';
9
- import { BOX } from '../draw.js';
9
+ import { U, D, rect, poly, circle, stroke, rot } from '@logomarks/core/geometry';
10
+ import { BOX, GAP, tidy } from '../draw.js';
10
11
  import { rng } from '../random.js';
11
12
  import { fill } from '../raster.js';
12
13
 
@@ -21,6 +22,7 @@ export const controls = [
21
22
  { key: 'diagonals', label: 'Diagonals', type: 'toggle', value: true },
22
23
  { key: 'frame', label: 'Frame', type: 'choice', options: ['none', 'full', 'open', 'corners'], value: 'none' },
23
24
  { key: 'turns', label: 'Turns', type: 'choice', options: ['mitre', 'round'], value: 'mitre' },
25
+ { key: 'body', label: 'Body', type: 'choice', options: ['square', 'cube'], value: 'square' },
24
26
  ];
25
27
 
26
28
  /** A polyline with every inner corner filleted: each turn becomes a quadratic curve `r` back along both legs. */
@@ -71,6 +73,7 @@ function node(kind, [x, y], w) {
71
73
 
72
74
  /** The mark for resolved params. */
73
75
  export function build(p) {
76
+ if (p.body === 'cube') return cube(p, p.layout);
74
77
  const framed = p.frame && p.frame !== 'none';
75
78
  for (let tries = 0; tries < 6; tries++) {
76
79
  const s = draw(p, p.layout + tries * 1000, framed);
@@ -103,5 +106,46 @@ function draw(p, layout, framed) {
103
106
  return U(...parts);
104
107
  }
105
108
 
109
+ /** The short track shapes a cube face takes, in its own unit square (an L, a Z, a U, a hook, a straight run). */
110
+ const FACE_TRACKS = [
111
+ [[0.22, 0.2], [0.22, 0.78], [0.78, 0.78]],
112
+ [[0.2, 0.25], [0.5, 0.25], [0.5, 0.75], [0.8, 0.75]],
113
+ [[0.25, 0.2], [0.25, 0.75], [0.75, 0.75], [0.75, 0.35]],
114
+ [[0.2, 0.5], [0.62, 0.5], [0.62, 0.2]],
115
+ [[0.2, 0.3], [0.8, 0.3]],
116
+ [[0.3, 0.8], [0.3, 0.45], [0.75, 0.45]],
117
+ ];
118
+
119
+ /**
120
+ * Circuit tracks on an iso cube: the cube's three faces (parallelograms of a hexagon standing on a point), the gap
121
+ * between them, and on each face one or two short tracks (drawn in the face's own square and mapped onto it, so they
122
+ * lie in the face's plane), round-ended, with a node at their end.
123
+ */
124
+ function cube(p, layout) {
125
+ const rand = rng(`route-cube:${layout}`), R = BOX.size / 2, { cx, cy } = BOX;
126
+ const V = (deg) => [cx + R * Math.cos((deg * Math.PI) / 180), cy + R * Math.sin((deg * Math.PI) / 180)], C = [cx, cy];
127
+ const sub = (a, b) => [a[0] - b[0], a[1] - b[1]];
128
+ const faces = [[V(210), sub(V(270), V(210)), sub(C, V(210))], [V(210), sub(C, V(210)), sub(V(150), V(210))], [C, sub(V(330), C), sub(V(90), C)]];
129
+ const parts = [], m = GAP / R / 2.2, w = Math.min(0.16, p.weight * 1.1);
130
+ for (const [O, a, b] of faces) {
131
+ const map = ([u, v]) => [O[0] + u * a[0] + v * b[0], O[1] + u * a[1] + v * b[1]];
132
+ const face = poly([[m, m], [1 - m, m], [1 - m, 1 - m], [m, 1 - m]].map(map));
133
+ const n = p.tracks > 1 && rand() < 0.5 ? 2 : 1;
134
+ let ink = [];
135
+ for (let k = 0; k < n; k++) {
136
+ let t = FACE_TRACKS[Math.floor(rand() * FACE_TRACKS.length)];
137
+ if (rand() < 0.5) t = t.map(([u, v]) => [1 - u, v]);
138
+ t = t.map(([u, v]) => [0.12 + u * 0.76, 0.12 + v * 0.76]); // kept off the face's edges, or the strip left there is a sliver
139
+ if (n === 2) t = t.map(([u, v]) => [u, k ? 0.5 + v * 0.45 : v * 0.45]);
140
+ const line = stroke(t, w, { roundCaps: true }), nodes = p.node !== 'none' ? [circle(t.at(-1)[0], t.at(-1)[1], w * 1.05, 32)] : [];
141
+ ink.push(U(line, ...nodes));
142
+ }
143
+ // the face is solid, the tracks cut out of it (a gap round each): circuit tracks engraved on the cube
144
+ const tracks = U(...ink.map((q) => q.map((poly2) => poly2.map((ring) => ring.map(map)))));
145
+ parts.push(D(face, tracks));
146
+ }
147
+ return tidy(U(...parts));
148
+ }
149
+
106
150
  /** Routes are drawn over one another: a route crossing itself is allowed many pieces. */
107
151
  export const guard = { maxPieces: 30 };