@logomarks/generate 0.3.1 → 0.4.0

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,43 @@
1
+ /**
2
+ * Mirror: a bold emblem symmetric both ways, in few heavy pieces cut by a body (a hexagon on its point or a rounded
3
+ * square): across the middle two thick bowed bands that meet at the centre and part towards the sides in a V; above and
4
+ * below, one thick band bowed in towards the middle, a gap between.
5
+ * After the arch emblems of the owner's references, made a family of its own rather than one of them: no end caps, the
6
+ * body and the bands vary. One band each side and always thick (thin arcs stacked are a Wi-Fi icon), no dots (a face).
7
+ */
8
+ import { U, I, arcBand, mapPts, rr, regular } from '@logomarks/core/geometry';
9
+ import { BOX, GAP, tidy } from '../draw.js';
10
+
11
+ /** @type {import('../index.js').Control[]} */
12
+ export const controls = [
13
+ { key: 'body', label: 'Body', type: 'choice', options: ['hexagon', 'square'], value: 'hexagon' },
14
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.22, max: 0.34, step: 0.005, value: 0.28 },
15
+ { key: 'bow', label: 'Middle curve', type: 'range', min: 1, max: 1.8, step: 0.05, value: 1.3 },
16
+ { key: 'bowl', label: 'Band curve', type: 'range', min: 0.7, max: 1.1, step: 0.01, value: 0.78 },
17
+ ];
18
+
19
+ /** The body, filling the box. */
20
+ function body(kind) {
21
+ const { cx, cy, x0, y0, size } = BOX;
22
+ // a hexagon standing on a point (on its side, points left and right, the silhouette is the reference's own) or a
23
+ // rounded square; never a disc (with these bands, the reference itself)
24
+ if (kind === 'hexagon') return regular(cx, cy, size / 2, 6, -90);
25
+ return rr(x0, y0, size, size, size * 0.2);
26
+ }
27
+
28
+ /** The mark for resolved params. */
29
+ export function build(p) {
30
+ const R = BOX.size / 2, T = p.weight * R, { cx, cy } = BOX;
31
+ // the middle: a band sagging from above and its mirror rising from below, meeting at the centre (never a straight bar:
32
+ // with a band either side, a divide sign; inside a lens, a theta or an eye)
33
+ const Rc = R * p.bow, middle = arcBand(cx, cy - Rc, Rc, T, 5, 175);
34
+ // the band above, a gap over the middle's top edge, bowed in (a bowl, its low point over the centre). Never bowed out:
35
+ // with the middle it closes into a lens with two slits, an eye
36
+ const edge = cy - T / 2 - GAP * 1.5, r2 = R * p.bowl * 1.4;
37
+ const band = arcBand(cx, edge - T / 2 - r2, r2, T, 5, 175);
38
+ const above = U(middle, band), below = mapPts(above, ([x, y]) => [x, 2 * cy - y]);
39
+ return tidy(I(U(above, below), body(p.body)));
40
+ }
41
+
42
+ /** Four to six heavy pieces. */
43
+ 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,61 @@
1
+ /**
2
+ * Ribbon: one thick band that folds back on itself, its turns round, a slot (a round-ended gap) along its longest run,
3
+ * one end square and the other cut by the box. After the folded S of the owner's references. Unlike a plain letter (the
4
+ * dropped Fold, mitred, read as blocky L, U, S): the round turns, the slot and the weight are always there.
5
+ */
6
+ import { D, I, rect, stroke, pill, grow } from '@logomarks/core/geometry';
7
+ import { BOX, GAP, tidy } from '../draw.js';
8
+
9
+ /** The paths, in a unit box (0–1 across and down). */
10
+ const PATHS = {
11
+ n: [[0, 1], [0, 0], [1, 1], [1, 0]],
12
+ z: [[0, 0], [1, 0], [0, 1], [1, 1]],
13
+ hook: [[1, 0], [0.3, 0], [1, 0.85], [0.1, 0.85]],
14
+ hairpin: [[0, 1], [0, 0], [1, 1], [1, 0.45]],
15
+ };
16
+
17
+ /** @type {import('../index.js').Control[]} */
18
+ export const controls = [
19
+ { key: 'path', label: 'Fold', type: 'choice', options: Object.keys(PATHS), value: 'n' },
20
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.2, max: 0.34, step: 0.005, value: 0.27 },
21
+ { key: 'bend', label: 'Turn radius', type: 'range', min: 0.6, max: 1.4, step: 0.05, value: 1 },
22
+ { key: 'slot', label: 'Slot length', type: 'range', min: 0.35, max: 0.75, step: 0.01, value: 0.55 },
23
+ { key: 'width', label: 'Width', type: 'range', min: 0.7, max: 1, step: 0.01, value: 0.86 },
24
+ ];
25
+
26
+ /** A polyline with each inner corner rounded: a circular-ish quadratic `r` back along both legs. */
27
+ function fillet(pts, r) {
28
+ const out = [pts[0]];
29
+ for (let k = 1; k < pts.length - 1; k++) {
30
+ const [a, v, b] = [pts[k - 1], pts[k], pts[k + 1]];
31
+ 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);
32
+ 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];
33
+ 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]]); }
34
+ }
35
+ out.push(pts.at(-1));
36
+ return out;
37
+ }
38
+
39
+ /** The mark for resolved params. */
40
+ export function build(p) {
41
+ const T = p.weight * BOX.size, W = BOX.size * p.width - T, H = BOX.size - T;
42
+ const x0 = BOX.cx - W / 2, y0 = BOX.y0 + T / 2;
43
+ const pts = PATHS[p.path].map(([u, v]) => [x0 + u * W, y0 + v * H]);
44
+ // the ends run a little past the box so the box's edge squares them off
45
+ const ext = (a, b) => { const l = Math.hypot(b[0] - a[0], b[1] - a[1]); return [b[0] + ((b[0] - a[0]) / l) * T, b[1] + ((b[1] - a[1]) / l) * T]; };
46
+ pts[0] = ext(pts[1], pts[0]);
47
+ pts[pts.length - 1] = ext(pts.at(-2), pts.at(-1));
48
+ let s = stroke(fillet(pts, T * p.bend), T, {});
49
+ // the slot: a round-ended gap along the middle of the longest run
50
+ let best = 1, bl = 0;
51
+ for (let k = 1; k < pts.length - 2; k++) { const l = Math.hypot(pts[k + 1][0] - pts[k][0], pts[k + 1][1] - pts[k][1]); if (l > bl) { bl = l; best = k; } }
52
+ if (pts.length === 4) best = 1; // the middle run of a three-run fold
53
+ const [a, b] = [pts[best], pts[best + 1]], m = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2], h = p.slot / 2;
54
+ const sa = [m[0] + (a[0] - m[0]) * h * 2 * 0.5, m[1] + (a[1] - m[1]) * h * 2 * 0.5], sb = [m[0] + (b[0] - m[0]) * h * 2 * 0.5, m[1] + (b[1] - m[1]) * h * 2 * 0.5];
55
+ s = D(s, pill(sa, sb, GAP));
56
+ return tidy(I(s, rect(BOX.x0, BOX.y0, BOX.size, BOX.size)));
57
+ }
58
+
59
+ /** One band with a slot: its turns are its only curves. */
60
+ export const guard = {};
61
+ void grow;
@@ -5,7 +5,9 @@
5
5
  * rings, halos and orbit marks. `shape` makes the rings frames (rounded, square, chamfered or hexagonal: broken polygon
6
6
  * frames), and `breakKind` step makes each gap a stepped break (on rings at least 3 gaps thick; thinner ones split into
7
7
  * hairlines, so they keep the straight cut). Square frames take three gaps at most (four is a
8
- * crosshair or a focus frame).
8
+ * crosshair or a focus frame). Two gaps sit 150° apart, never opposite (a slashed ring is the no-entry sign), and one
9
+ * gap turns at least 24° ring to ring (aligned, it is the power symbol). In a round body the innermost ring is never broken
10
+ * once (a C in a ring is the copyright sign): it takes two gaps.
9
11
  */
10
12
  import { U, D, circle, annulus, rot, rect, rr, poly } from '@logomarks/core/geometry';
11
13
  import { BOX, GAP, tidy } from '../draw.js';
@@ -54,12 +56,44 @@ function gapCut(kind, cx, cy, R, w, a, t, rMid) {
54
56
  return rot(rect(cx - w / 2, cy - R - 10, w, R + 10), a, cx, cy);
55
57
  }
56
58
 
59
+ /**
60
+ * Where gap g of n sits on a ring, in degrees from the top. Two gaps are never opposite: two opposite gaps cut one straight
61
+ * channel through the middle, and round an open centre that is the empty-set or no-entry sign (a slashed ring). They sit
62
+ * 150° apart instead; three and four stay even (they always turn ring to ring, so they never line up into a channel).
63
+ */
64
+ export const gapAt = (n, g) => START + (n === 2 ? g * 150 : (360 * g) / n);
65
+
66
+ /**
67
+ * Where the first gap starts, clockwise from the top. A ring broken at twelve o'clock round a slotted middle is the power
68
+ * symbol, so the outer ring's first gap sits up and to the right instead.
69
+ */
70
+ export const START = 40;
71
+
72
+ /**
73
+ * How far each ring's gaps turn from the ring outside it. Gaps lined up through every ring read as a sign: one gap is
74
+ * the power symbol (a ring broken at the top round a bar), two or more a peace sign, a car badge or a crosshair. So with
75
+ * one gap the turn is at least 24°, with more at least 14°.
76
+ */
77
+ export function minTurn(p) {
78
+ const least = p.gaps === 1 ? 24 : p.gaps >= 2 ? 14 : 0;
79
+ return Math.abs(p.spin) < least ? (p.spin < 0 ? -least : least) : p.spin;
80
+ }
81
+
57
82
  /** The mark for resolved params. */
58
83
  export function build(params) {
59
84
  const p = { ...params };
85
+ // a dot inside a rounded square frame broken once is an @: there the middle stays open
86
+ if (p.centre === 'dot' && p.shape === 'rounded') p.centre = 'open';
60
87
  if ((p.shape === 'square' || p.shape === 'rounded' || p.shape === 'chamfer') && p.gaps > 3) p.gaps = 3;
61
- const R = BOX.size / 2, n = p.count + (p.centre === 'open' ? 0 : 1);
62
- const gap = Math.max(GAP, ((1 - p.weight) * R) / n), t = (R - (n - 1) * gap) / n, parts = [];
88
+ // an open centre is a real hole, a gap wide at least: filled to the middle, the innermost band was a solid disc, and a disc
89
+ // with one slot inside a ring is a power button, a volume knob or a dial
90
+ const R = BOX.size / 2, open = p.centre === 'open', n = p.count + (open ? 0 : 1);
91
+ const gap = Math.max(GAP, ((1 - p.weight) * R) / (n + (open ? 1 : 0)));
92
+ // the open hole's radius is this plus a gap: smaller, the innermost ring's gap opens it into a keyhole (a lock) or an @;
93
+ // kept whole instead, the rings close round it into a target
94
+ // (with many rings it shrinks so each ring keeps a gap's width at least)
95
+ const hole = open ? Math.max(0, Math.min(gap * 1.6, R - n * gap - n * GAP)) : 0;
96
+ const t = (R - hole - (n - (open ? 0 : 1)) * gap) / n, parts = [];
63
97
  for (let k = 0; k < p.count; k++) {
64
98
  const rOuter = R - k * (t + gap), rMid = rOuter - t / 2;
65
99
  // an off-centre stack: the rings share their top edge's tangent, slid toward it by the offset
@@ -67,9 +101,18 @@ export function build(params) {
67
101
  let ring = p.shape && p.shape !== 'circle' ? ringOf(p.shape, BOX.cx, cy, rOuter, t) : annulus(BOX.cx, cy, rMid, t);
68
102
  // gaps lined up through every ring read as a sign (three: a peace sign or a car badge; four: a crosshair), so with
69
103
  // two or more gaps a ring always turns at least 14° from the one outside it
70
- const step = p.gaps >= 2 && Math.abs(p.spin) < 14 ? (p.spin < 0 ? -14 : 14) : p.spin;
71
- for (let g = 0; g < p.gaps; g++) {
72
- const a = step * k + (360 * g) / p.gaps;
104
+ const step = minTurn(p);
105
+ // round an open centre the innermost band is a solid disc: two gaps cut it into two sectors meeting in a point (or, opposite,
106
+ // into the halves of a slashed circle), so a disc takes one gap, a slot to its middle
107
+ const solid = rOuter - t < GAP; // (a dot centre's own disc is never cut; this only guards a very heavy setting)
108
+ // in a round body the innermost ring broken once is a C in a ring, the copyright sign (or, mirrored, copyleft): it takes
109
+ // two gaps instead, 150° apart (never opposite, so never a slash)
110
+ const round = !p.shape || p.shape === 'circle';
111
+ // (too small for two pieces that both read, the short one a crumb, it closes into a plain ring)
112
+ const two = rMid * ((150 * Math.PI) / 180) - GAP * p.gapSize >= GAP * 4;
113
+ const cuts = solid ? Math.min(1, p.gaps) : round && k === p.count - 1 && p.gaps === 1 ? (two ? 2 : 0) : p.gaps;
114
+ for (let g = 0; g < cuts; g++) {
115
+ const a = step * k + gapAt(cuts, g);
73
116
  ring = D(ring, p.breakKind === 'step' && t >= GAP * 3 ? gapCut('step', BOX.cx, cy, R, GAP * p.gapSize, a, t, rMid) : rot(rect(BOX.cx - (GAP * p.gapSize) / 2, cy - R - 10, GAP * p.gapSize, R + 10), a, BOX.cx, cy));
74
117
  }
75
118
  parts.push(ring);
@@ -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 };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Weave: two or three curves (waves of one to three swells) crossing each other, over and under by turns, the under
3
+ * strand broken by the gap at every crossing, inside a ring that holds their ends; or bare, with three strands. After the
4
+ * woven lenses in a ring of the owner's references. Never one swell (two curves crossing twice round one lens, in a ring:
5
+ * an eye), never a dot, and never three strands turned in threes (a trefoil).
6
+ */
7
+ import { sdPath, sdCircle, sdRing, shapeOf } from '@logomarks/core/sdf';
8
+ import { BOX, GAP, tidy } from '../draw.js';
9
+
10
+ /** @type {import('../index.js').Control[]} */
11
+ export const controls = [
12
+ { key: 'strands', label: 'Strands', type: 'range', min: 2, max: 3, step: 1, value: 2 },
13
+ { key: 'swells', label: 'Swells', type: 'range', min: 2, max: 3, step: 1, value: 2 },
14
+ { key: 'height', label: 'Height', type: 'range', min: 0.3, max: 0.7, step: 0.01, value: 0.5 },
15
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.06, max: 0.1, step: 0.005, value: 0.075 },
16
+ { key: 'ring', label: 'Ring', type: 'choice', options: ['ring', 'none'], value: 'ring' },
17
+ { key: 'tilt', label: 'Tilt', type: 'range', min: -30, max: 30, step: 1, value: 0 },
18
+ ];
19
+
20
+ /** The mark for resolved params. */
21
+ export function build(p) {
22
+ const R = BOX.size / 2, T = p.weight * BOX.size, n = p.ring === 'none' ? 3 : p.strands;
23
+ const inner = p.ring === 'ring' ? R - T : R, A = inner * p.height, steps = 64;
24
+ const tilt = (p.tilt * Math.PI) / 180, ct = Math.cos(tilt), st = Math.sin(tilt);
25
+ const curve = (phase) => Array.from({ length: steps + 1 }, (_, i) => {
26
+ const u = -1.15 + (2.3 * i) / steps, x = u * inner, y = A * Math.sin((u * p.swells * Math.PI) / 2 + phase) * Math.cos((u * Math.PI) / 2.3);
27
+ return [BOX.cx + x * ct - y * st, BOX.cy + x * st + y * ct];
28
+ });
29
+ const phases = Array.from({ length: n }, (_, k) => (2 * Math.PI * k) / n + (n === 2 ? 0 : 0.4));
30
+ const lines = phases.map(curve), fields = lines.map((pts) => sdPath(pts, T));
31
+ // the crossings, in order across: at each, one strand goes over and the other is broken by the gap, by turns
32
+ const crossings = [];
33
+ for (let a = 0; a < n; a++) for (let b = a + 1; b < n; b++) {
34
+ const P = lines[a], Q = lines[b];
35
+ for (let i = 1; i < P.length; i++) {
36
+ const d0 = P[i - 1][1] - Q[i - 1][1], d1 = P[i][1] - Q[i][1];
37
+ if (Math.sign(d0) !== Math.sign(d1)) crossings.push({ a, b, at: P[i] });
38
+ }
39
+ }
40
+ crossings.sort((u, v) => u.at[0] - v.at[0]);
41
+ const zone = T * 2.4;
42
+ const woven = (x, y) => {
43
+ const d = fields.map((f) => f(x, y));
44
+ for (const [k, c] of crossings.entries()) {
45
+ if (Math.hypot(x - c.at[0], y - c.at[1]) > zone) continue;
46
+ const [over, under] = k % 2 ? [c.a, c.b] : [c.b, c.a];
47
+ d[under] = Math.max(d[under], GAP - d[over]);
48
+ }
49
+ return Math.min(...d);
50
+ };
51
+ const ring = p.ring === 'ring';
52
+ const clip = sdCircle(BOX.cx, BOX.cy, ring ? inner + T * 0.2 : R), band = sdRing(BOX.cx, BOX.cy, R - T / 2, T);
53
+ const f = (x, y) => { const w = Math.max(woven(x, y), clip(x, y)); return ring ? Math.min(w, band(x, y)) : w; };
54
+ return tidy(shapeOf(f, { h: 2.5, x0: BOX.x0 - 6, y0: BOX.y0 - 6, x1: BOX.x1 + 6, y1: BOX.y1 + 6 }));
55
+ }
56
+
57
+ /** Strands are lines: they run near the thin limit by design. */
58
+ export const guard = { maxThinShare: 0.06, minInkShare: 0.1 };