@logomarks/generate 0.0.0-stage → 0.1.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +41 -2
  4. package/package.json +29 -4
  5. package/src/controls.js +34 -0
  6. package/src/draw.js +60 -0
  7. package/src/finish.js +172 -0
  8. package/src/generate.js +194 -0
  9. package/src/guard.js +66 -0
  10. package/src/index.d.ts +96 -0
  11. package/src/index.js +9 -0
  12. package/src/presets.js +26 -0
  13. package/src/random.js +23 -0
  14. package/src/raster.js +52 -0
  15. package/src/recipes/arcs.js +83 -0
  16. package/src/recipes/bands.js +90 -0
  17. package/src/recipes/bars.js +106 -0
  18. package/src/recipes/blobs.js +74 -0
  19. package/src/recipes/bloom.js +53 -0
  20. package/src/recipes/burst.js +44 -0
  21. package/src/recipes/chevrons.js +45 -0
  22. package/src/recipes/cut.js +80 -0
  23. package/src/recipes/dashes.js +61 -0
  24. package/src/recipes/dots.js +47 -0
  25. package/src/recipes/fan.js +73 -0
  26. package/src/recipes/fold.js +66 -0
  27. package/src/recipes/hex.js +58 -0
  28. package/src/recipes/horizon.js +51 -0
  29. package/src/recipes/index.js +79 -0
  30. package/src/recipes/iso.js +35 -0
  31. package/src/recipes/letter.js +204 -0
  32. package/src/recipes/line.js +142 -0
  33. package/src/recipes/links.js +63 -0
  34. package/src/recipes/orbit.js +50 -0
  35. package/src/recipes/pixel.js +38 -0
  36. package/src/recipes/rings.js +82 -0
  37. package/src/recipes/route.js +107 -0
  38. package/src/recipes/shear.js +61 -0
  39. package/src/recipes/spiral.js +42 -0
  40. package/src/recipes/split.js +54 -0
  41. package/src/recipes/stack.js +71 -0
  42. package/src/recipes/steps.js +35 -0
  43. package/src/recipes/stripes.js +66 -0
  44. package/src/recipes/tiles.js +60 -0
  45. package/src/recipes/tri.js +126 -0
  46. package/src/recipes/turns.js +41 -0
  47. package/src/recipes/twin.js +64 -0
  48. package/src/recipes/venn.js +54 -0
  49. package/src/recipes/waves.js +40 -0
  50. package/src/shapes.js +54 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Rings: two to five concentric rings, each broken by one to four gaps, the gaps turning a little from ring to ring (a
3
+ * spiral or a fan; with two or more gaps they always turn, never line up into a sign or a crosshair), round a centre dot
4
+ * or an open eye, the centre pushed off to one side if asked. After inverted
5
+ * rings, halos and orbit marks. `shape` makes the rings frames (rounded, square, chamfered or hexagonal: broken polygon
6
+ * frames), and `breakKind` step makes each gap a stepped break (on rings at least 3 gaps thick; thinner ones split into
7
+ * hairlines, so they keep the straight cut). Square frames take three gaps at most (four is a
8
+ * crosshair or a focus frame).
9
+ */
10
+ import { U, D, circle, annulus, rot, rect, rr, poly } from '@logomarks/core/geometry';
11
+ import { BOX, GAP, tidy } from '../draw.js';
12
+
13
+ /** @type {import('../index.js').Control[]} */
14
+ export const controls = [
15
+ { key: 'count', label: 'Rings', type: 'range', min: 2, max: 5, step: 1, value: 3 },
16
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.85, step: 0.01, value: 0.62 },
17
+ { key: 'gaps', label: 'Gaps per ring', type: 'range', min: 0, max: 4, step: 1, value: 1 },
18
+ { key: 'gapSize', label: 'Gap size', type: 'range', min: 1, max: 4, step: 0.1, value: 1.6 },
19
+ { key: 'spin', label: 'Turn per ring', type: 'range', min: -90, max: 90, step: 1, value: 30 },
20
+ { key: 'centre', label: 'Centre', type: 'choice', options: ['dot', 'open', 'solid'], value: 'dot' },
21
+ { key: 'offset', label: 'Off centre', type: 'range', min: 0, max: 0.6, step: 0.01, value: 0 },
22
+ { key: 'shape', label: 'Shape', type: 'choice', options: ['circle', 'rounded', 'square', 'chamfer', 'hexagon'], value: 'circle' },
23
+ { key: 'breakKind', label: 'Break', type: 'choice', options: ['cut', 'step'], value: 'cut' },
24
+ ];
25
+
26
+ /** A solid outline of a shape, radius r round (cx, cy). */
27
+ function outline(shape, cx, cy, r) {
28
+ if (shape === 'rounded') return rr(cx - r, cy - r, 2 * r, 2 * r, r * 0.32);
29
+ if (shape === 'square') return rect(cx - r, cy - r, 2 * r, 2 * r);
30
+ if (shape === 'chamfer') { const k = r * 0.32; return poly([[cx - r + k, cy - r], [cx + r - k, cy - r], [cx + r, cy - r + k], [cx + r, cy + r - k], [cx + r - k, cy + r], [cx - r + k, cy + r], [cx - r, cy + r - k], [cx - r, cy - r + k]]); }
31
+ return poly(Array.from({ length: 6 }, (_, i) => { const a = (Math.PI / 3) * i - Math.PI / 2; return [cx + r * Math.cos(a), cy + r * Math.sin(a)]; }));
32
+ }
33
+
34
+ /** One ring of a shape: the outline at rOuter less its inner outline, drawn directly so the band is even. */
35
+ function ringOf(shape, cx, cy, rOuter, t) {
36
+ if (shape === 'circle') return annulus(cx, cy, rOuter - t / 2, t);
37
+ const ri = rOuter - t;
38
+ if (ri <= 2) return outline(shape, cx, cy, rOuter);
39
+ let inner;
40
+ if (shape === 'square') inner = rect(cx - ri, cy - ri, 2 * ri, 2 * ri);
41
+ else if (shape === 'rounded') inner = rr(cx - ri, cy - ri, 2 * ri, 2 * ri, Math.max(0.01, rOuter * 0.32 - t));
42
+ else if (shape === 'chamfer') { const k = Math.max(0, rOuter * 0.32 - t * 0.414); inner = poly([[cx - ri + k, cy - ri], [cx + ri - k, cy - ri], [cx + ri, cy - ri + k], [cx + ri, cy + ri - k], [cx + ri - k, cy + ri], [cx - ri + k, cy + ri], [cx - ri, cy + ri - k], [cx - ri, cy - ri + k]]); }
43
+ else inner = outline('hexagon', cx, cy, rOuter - t / Math.cos(Math.PI / 6));
44
+ return D(outline(shape, cx, cy, rOuter), inner);
45
+ }
46
+
47
+ /** A gap cut through a ring, pointing up from (cx, cy) then turned a degrees: straight, or stepped halfway out. */
48
+ function gapCut(kind, cx, cy, R, w, a, t, rMid) {
49
+ if (kind === 'step') {
50
+ const outer = rect(cx - w * 0.75, cy - R - 10, w * 0.75, R + 10 - rMid);
51
+ const inner = rect(cx, cy - rMid, w * 0.75, rMid);
52
+ return rot(U(outer, inner, rect(cx - w * 0.75, cy - rMid - Math.min(GAP, t) / 2, w * 1.5, Math.min(GAP, t))), a, cx, cy);
53
+ }
54
+ return rot(rect(cx - w / 2, cy - R - 10, w, R + 10), a, cx, cy);
55
+ }
56
+
57
+ /** The mark for resolved params. */
58
+ export function build(params) {
59
+ const p = { ...params };
60
+ 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 = [];
63
+ for (let k = 0; k < p.count; k++) {
64
+ const rOuter = R - k * (t + gap), rMid = rOuter - t / 2;
65
+ // an off-centre stack: the rings share their top edge's tangent, slid toward it by the offset
66
+ const cy = BOX.cy - p.offset * (R - rOuter);
67
+ let ring = p.shape && p.shape !== 'circle' ? ringOf(p.shape, BOX.cx, cy, rOuter, t) : annulus(BOX.cx, cy, rMid, t);
68
+ // gaps lined up through every ring read as a sign (three: a peace sign or a car badge; four: a crosshair), so with
69
+ // 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;
73
+ 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
+ }
75
+ parts.push(ring);
76
+ }
77
+ const inner = R - p.count * (t + gap);
78
+ const poly2 = (r) => (p.shape && p.shape !== 'circle' ? outline(p.shape, BOX.cx, BOX.cy - p.offset * (R - inner), r) : circle(BOX.cx, BOX.cy - p.offset * (R - inner), r, 64));
79
+ if (p.centre === 'dot' && inner > t * 0.6) parts.push(poly2(Math.min(inner, t)));
80
+ if (p.centre === 'solid' && inner > 4) parts.push(poly2(inner));
81
+ return tidy(U(...parts));
82
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Route: heavy bands that run only level, upright or at 45°, turning on a lattice and forking, joined by nodes (a
3
+ * square, a diamond or a disc) where they turn, laid out by a numbered layout. After the owner's favourite, Tech · Route.
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
6
+ * (four hooks round a centre) is passed over for the next layout.
7
+ */
8
+ import { U, rect, poly, circle, stroke, rot } from '@logomarks/core/geometry';
9
+ import { BOX } from '../draw.js';
10
+ import { rng } from '../random.js';
11
+ import { fill } from '../raster.js';
12
+
13
+ /** @type {import('../index.js').Control[]} */
14
+ export const controls = [
15
+ { key: 'tracks', label: 'Tracks', type: 'range', min: 1, max: 3, step: 1, value: 2 },
16
+ { key: 'steps', label: 'Turns', type: 'range', min: 1, max: 4, step: 1, value: 2 },
17
+ { key: 'layout', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 12 },
18
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.08, max: 0.2, step: 0.005, value: 0.13 },
19
+ { key: 'node', label: 'Nodes', type: 'choice', options: ['none', 'square', 'diamond', 'disc'], value: 'diamond' },
20
+ { key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'node', 'round'], value: 'node' },
21
+ { key: 'diagonals', label: 'Diagonals', type: 'toggle', value: true },
22
+ { key: 'frame', label: 'Frame', type: 'choice', options: ['none', 'full', 'open', 'corners'], value: 'none' },
23
+ { key: 'turns', label: 'Turns', type: 'choice', options: ['mitre', 'round'], value: 'mitre' },
24
+ ];
25
+
26
+ /** A polyline with every inner corner filleted: each turn becomes a quadratic curve `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 / 2, lb / 2);
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 <= 10; i++) { const t = i / 10, 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 frame's strokes, as polylines on the lattice's outer points. */
40
+ function framePaths(kind) {
41
+ const c = [at(0, 0), at(4, 0), at(4, 4), at(0, 4)];
42
+ if (kind === 'full') return [[...c, c[0]]];
43
+ if (kind === 'open') return [[c[3], c[2], c[1], c[0]]];
44
+ return [[at(0, 2), c[0], at(2, 0)], [at(4, 2), c[2], at(2, 4)]];
45
+ }
46
+
47
+ /** A lattice of 5 × 5 points across the box. */
48
+ const at = (i, j) => [BOX.x0 + (i * BOX.size) / 4, BOX.y0 + (j * BOX.size) / 4];
49
+ const DIRS = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [-1, 1], [1, -1], [-1, -1]];
50
+
51
+ /** One track's lattice points: from a start on the left edge, `steps` runs, each turning, staying in the lattice. */
52
+ function track(rand, steps, diagonals, row) {
53
+ let i = 0, j = row, pts = [[i, j]], dir = [1, 0];
54
+ for (let s = 0; s <= steps; s++) {
55
+ const len = 1 + Math.floor(rand() * 2);
56
+ for (let k = 0; k < len; k++) { const ni = i + dir[0], nj = j + dir[1]; if (ni < 0 || nj < 0 || ni > 4 || nj > 4) break; i = ni; j = nj; }
57
+ pts.push([i, j]);
58
+ const options = DIRS.slice(0, diagonals ? 8 : 4).filter(([a, b]) => !(a === -dir[0] && b === -dir[1]) && !(a === dir[0] && b === dir[1]) && a >= 0);
59
+ dir = options[Math.floor(rand() * options.length)];
60
+ }
61
+ return pts.filter((p, k, a) => k === 0 || p[0] !== a[k - 1][0] || p[1] !== a[k - 1][1]);
62
+ }
63
+
64
+ /** A node at a lattice point. */
65
+ function node(kind, [x, y], w) {
66
+ const r = w * 0.95;
67
+ if (kind === 'square') return rect(x - r, y - r, 2 * r, 2 * r);
68
+ if (kind === 'disc') return circle(x, y, r * 1.1, 48);
69
+ return poly([[x, y - r * 1.35], [x + r * 1.35, y], [x, y + r * 1.35], [x - r * 1.35, y]]);
70
+ }
71
+
72
+ /** The mark for resolved params. */
73
+ export function build(p) {
74
+ const framed = p.frame && p.frame !== 'none';
75
+ for (let tries = 0; tries < 6; tries++) {
76
+ const s = draw(p, p.layout + tries * 1000, framed);
77
+ if (!framed || !quarterSame(s)) return s;
78
+ }
79
+ return draw(p, p.layout, framed);
80
+ }
81
+
82
+ /** Whether a mark looks the same a quarter turn round (bitmaps 90% the same): four hooks round a centre. */
83
+ function quarterSame(s) {
84
+ const a = fill(s, 64), b = fill(rot(s, 90, BOX.cx, BOX.cy), 64);
85
+ let both = 0, either = 0;
86
+ for (let i = 0; i < a.length; i++) { both += a[i] & b[i]; either += a[i] | b[i]; }
87
+ return either > 0 && both / either > 0.9;
88
+ }
89
+
90
+ /** The route for a layout number. */
91
+ function draw(p, layout, framed) {
92
+ const rand = rng(`route:${layout}`), w = p.weight * BOX.size, parts = [];
93
+ const rows = [[2], [1, 3], [0, 2, 4]][p.tracks - 1];
94
+ const line = (pts) => stroke(p.turns === 'round' ? fillet(pts, w * 0.9) : pts, w, { roundCaps: p.ends === 'round' });
95
+ if (framed) for (const f of framePaths(p.frame)) parts.push(line(f));
96
+ for (const row of rows) {
97
+ const pts = track(rand, p.steps, framed ? false : p.diagonals, row).map(([i, j]) => at(i, j));
98
+ if (pts.length < 2) continue;
99
+ parts.push(line(pts));
100
+ if (p.node !== 'none') for (const q of pts.slice(1, -1)) parts.push(node(p.node, q, w));
101
+ if (p.ends === 'node' && p.node !== 'none') parts.push(node(p.node, pts[0], w), node(p.node, pts.at(-1), w));
102
+ }
103
+ return U(...parts);
104
+ }
105
+
106
+ /** Routes are drawn over one another: a route crossing itself is allowed many pieces. */
107
+ export const guard = { maxPieces: 30 };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Shear: a grid of heavy slanted tiles (one to three rows of two to four), each a parallelogram leaning one way or the
3
+ * other, the house gap between them, some dropped to make a figure. `lengths` varies the tiles (long and short, a stair,
4
+ * or the first row as one long slab) and `slide` moves every other row along its lean, so the grid breaks into a
5
+ * letter-like figure (the slab marks). After marks of sheared blocks and split slants.
6
+ */
7
+ import { U, poly } from '@logomarks/core/geometry';
8
+ import { BOX, GAP } from '../draw.js';
9
+
10
+ /** @type {import('../index.js').Control[]} */
11
+ export const controls = [
12
+ { key: 'rows', label: 'Rows', type: 'range', min: 1, max: 3, step: 1, value: 2 },
13
+ { key: 'cols', label: 'Columns', type: 'range', min: 2, max: 4, step: 1, value: 3 },
14
+ { key: 'lean', label: 'Lean', type: 'choice', options: ['same', 'rows', 'columns', 'chevron'], value: 'rows' },
15
+ { key: 'angle', label: 'Angle', type: 'range', min: 10, max: 40, step: 1, value: 26 },
16
+ { key: 'drop', label: 'Drop', type: 'choice', options: ['none', 'checker', 'corner', 'diagonal', 'middle'], value: 'none' },
17
+ { key: 'spacing', label: 'Spacing', type: 'range', min: 1, max: 3, step: 0.1, value: 1 },
18
+ { key: 'taper', label: 'Taper', type: 'range', min: 0, max: 0.4, step: 0.01, value: 0 },
19
+ { key: 'lengths', label: 'Lengths', type: 'choice', options: ['equal', 'alternate', 'stair', 'one long'], value: 'equal' },
20
+ { key: 'slide', label: 'Slide', type: 'range', min: 0, max: 0.5, step: 0.01, value: 0 },
21
+ ];
22
+
23
+ /** Whether tile (r, c) of an R × C grid is dropped. */
24
+ function dropped(drop, r, c, R, C) {
25
+ if (drop === 'checker') return (r + c) % 2 === 1;
26
+ if (drop === 'corner') return r === 0 && c === C - 1;
27
+ if (drop === 'diagonal') return R > 1 && c === Math.round((r * (C - 1)) / (R - 1)) && C > 2;
28
+ if (drop === 'middle') return C > 2 && r === Math.floor(R / 2) && c === Math.floor(C / 2);
29
+ return false;
30
+ }
31
+
32
+ /** Which way tile (r, c) leans: 1 right, −1 left. */
33
+ function leanOf(lean, r, c, C) {
34
+ if (lean === 'rows') return r % 2 ? -1 : 1;
35
+ if (lean === 'columns') return c % 2 ? -1 : 1;
36
+ if (lean === 'chevron') return c < C / 2 ? 1 : -1;
37
+ return 1;
38
+ }
39
+
40
+ /** The mark for resolved params. */
41
+ export function build(p) {
42
+ const R = p.rows, C = p.cols, g = GAP * p.spacing;
43
+ const cw = (BOX.size - (C - 1) * g) / C, ch = (BOX.size - (R - 1) * g) / R;
44
+ const d = Math.min(cw * 0.55, ch * Math.tan((p.angle * Math.PI) / 180)); // past about half the tile, its tips go needle-thin
45
+ const parts = [];
46
+ /** A tile from x, `len` wide, on the row from y0 to y1, leaning s. */
47
+ const tile = (x, len, y0, y1, s, t) => (s > 0 ? poly([[x, y1], [x + len - d - t, y1], [x + len - t, y0], [x + d, y0]]) : poly([[x + d, y1], [x + len - t, y1], [x + len - d - t, y0], [x, y0]]));
48
+ for (let r = 0; r < R; r++) {
49
+ const y0 = BOX.y0 + r * (ch + g), y1 = y0 + ch, dx = r % 2 ? p.slide * cw : 0;
50
+ if (p.lengths === 'one long' && r === 0 && R > 1) { parts.push(tile(BOX.x0 + dx, BOX.size, y0, y1, leanOf(p.lean, r, 0, C), 0)); continue; }
51
+ for (let c = 0; c < C; c++) {
52
+ if (dropped(p.drop, r, c, R, C)) continue;
53
+ const s = leanOf(p.lean, r, c, C), t = p.taper * (cw - d) * 0.5 * (c / Math.max(1, C - 1));
54
+ // the tile's own length: long and short in turn, or shortening down the rows (a stair); never under d + a gap
55
+ const k = p.lengths === 'alternate' ? ((r + c) % 2 ? 0.62 : 1) : p.lengths === 'stair' ? 1 - (0.32 * r) / Math.max(1, R - 1) : 1;
56
+ const len = Math.max(d + GAP * 3, cw * k);
57
+ parts.push(tile(BOX.x0 + c * (cw + g) + dx, len, y0, y1, s, t));
58
+ }
59
+ }
60
+ return U(...parts);
61
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Spiral: ONE round band coiled one to three turns (an Archimedean spiral, so the gap between coils is even, the house gap
3
+ * or more), its inner end a dot or a square cut and its outer end running out as a straight tail if asked. Always round:
4
+ * a square spiral reads as a maze.
5
+ */
6
+ import { U, circle, stroke, rot } from '@logomarks/core/geometry';
7
+ import { BOX, GAP } from '../draw.js';
8
+
9
+ /** @type {import('../index.js').Control[]} */
10
+ export const controls = [
11
+ { key: 'turns', label: 'Turns', type: 'range', min: 1, max: 3, step: 0.25, value: 1.75 },
12
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.75, step: 0.01, value: 0.58 },
13
+ { key: 'start', label: 'Inner end', type: 'choice', options: ['dot', 'round', 'square'], value: 'round' },
14
+ { key: 'tail', label: 'Tail', type: 'range', min: 0, max: 0.6, step: 0.01, value: 0 },
15
+ { key: 'squash', label: 'Squash', type: 'range', min: 0.7, max: 1, step: 0.01, value: 1 },
16
+ { key: 'spin', label: 'Spin', type: 'range', min: 0, max: 345, step: 15, value: 0 },
17
+ { key: 'flip', label: 'Clockwise', type: 'toggle', value: true },
18
+ ];
19
+
20
+ /** The mark for resolved params. */
21
+ export function build(p) {
22
+ const R = BOX.size / 2, T = p.turns;
23
+ // coils `pitch` apart, the band `w` of it; the outermost coil's outer edge at R (a tail adds to the length, not the reach)
24
+ const pitch = Math.max((R * 0.92) / (T + 0.6), 0), w = Math.max(GAP * 1.2, Math.min(pitch - GAP, pitch * p.weight));
25
+ const r0 = pitch * (p.start === 'dot' ? 1.05 : 0.6), steps = Math.ceil(T * 96), dir = p.flip ? 1 : -1, pts = [];
26
+ for (let i = 0; i <= steps; i++) {
27
+ const t = (i / steps) * T * Math.PI * 2, r = r0 + (pitch * t) / (Math.PI * 2);
28
+ pts.push([BOX.cx + r * Math.cos(dir * t), BOX.cy + r * Math.sin(dir * t) * p.squash]);
29
+ }
30
+ if (p.tail > 0) {
31
+ // run straight on from the outer end along its tangent
32
+ const [ax, ay] = pts.at(-2), [bx, by] = pts.at(-1), L = Math.hypot(bx - ax, by - ay);
33
+ pts.push([bx + ((bx - ax) / L) * p.tail * R * 1.6, by + ((by - ay) / L) * p.tail * R * 1.6]);
34
+ }
35
+ let s = stroke(pts, w, { roundCaps: p.start !== 'square' });
36
+ if (p.start === 'dot') {
37
+ // a dot at the coil's centre, parted from the inner end by the gap (the coil starts further out to make room)
38
+ const dr = r0 - w / 2 - GAP;
39
+ if (dr > GAP * 0.8) s = U(s, circle(BOX.cx, BOX.cy, dr, 64));
40
+ }
41
+ return p.spin ? rot(s, p.spin, BOX.cx, BOX.cy) : s;
42
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Split: a shape (a circle, a square, a hexagon or a diamond) cut by one to three straight lines at an angle into parts
3
+ * parted by the gap, each part slid along its cut and turned a little if asked, so the shape reads whole but broken.
4
+ * After split discs, sliced squares and offset halves.
5
+ */
6
+ import { U, D, I, rect, poly, circle, rot, mapPts, grown } from '@logomarks/core/geometry';
7
+ import { BOX, GAP, tidy } from '../draw.js';
8
+
9
+ /** @type {import('../index.js').Control[]} */
10
+ export const controls = [
11
+ { key: 'shape', label: 'Shape', type: 'choice', options: ['circle', 'square', 'hexagon', 'diamond'], value: 'circle' },
12
+ { key: 'cuts', label: 'Cuts', type: 'range', min: 1, max: 3, step: 1, value: 2 },
13
+ { key: 'angle', label: 'Angle', type: 'range', min: -75, max: 75, step: 1, value: -30 },
14
+ { key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 3, step: 0.1, value: 1.3 },
15
+ { key: 'slide', label: 'Slide', type: 'range', min: 0, max: 0.3, step: 0.01, value: 0.12 },
16
+ { key: 'twist', label: 'Twist', type: 'range', min: 0, max: 8, step: 0.5, value: 0 },
17
+ { key: 'spread', label: 'Cut spread', type: 'range', min: 0.3, max: 0.9, step: 0.01, value: 0.55 },
18
+ ];
19
+
20
+ /** The whole shape, filling the box (a little inset so slid parts stay inside). */
21
+ function whole(kind) {
22
+ const { cx, cy, size } = BOX, r = size * 0.42;
23
+ if (kind === 'square') return rect(cx - r, cy - r, 2 * r, 2 * r);
24
+ if (kind === 'hexagon') return poly(Array.from({ length: 6 }, (_, k) => { const a = (Math.PI / 3) * k - Math.PI / 2; return [cx + r * 1.1 * Math.cos(a), cy + r * 1.1 * Math.sin(a)]; }));
25
+ if (kind === 'diamond') return poly([[cx, cy - r * 1.2], [cx + r * 1.2, cy], [cx, cy + r * 1.2], [cx - r * 1.2, cy]]);
26
+ return circle(cx, cy, r, 128);
27
+ }
28
+
29
+ /** The mark for resolved params. */
30
+ export function build(p) {
31
+ const { cx, cy, size } = BOX, n = p.cuts, g = GAP * p.spacing, s = whole(p.shape), parts = [];
32
+ // the cuts run level in a frame turned `angle`: cut k at offset (k − (n−1)/2) × pitch across the middle
33
+ const pitch = (size * 0.84 * p.spread) / Math.max(1, n), cuts = Array.from({ length: n }, (_, k) => (k - (n - 1) / 2) * pitch);
34
+ const edges = [-size, ...cuts, size];
35
+ const a = (p.angle * Math.PI) / 180, ux = Math.cos(a), uy = Math.sin(a);
36
+ for (let k = 0; k < edges.length - 1; k++) {
37
+ const top = edges[k] + (k ? g / 2 : 0), bottom = edges[k + 1] - (k < edges.length - 2 ? g / 2 : 0);
38
+ const band = rot(rect(cx - size, cy + top, 2 * size, bottom - top), p.angle, cx, cy);
39
+ let part = I(s, band);
40
+ const i = k - (edges.length - 2) / 2; // −…+ from the middle part
41
+ if (p.slide) part = mapPts(part, ([x, y]) => [x + ux * i * p.slide * size * 0.4, y + uy * i * p.slide * size * 0.4]);
42
+ if (p.twist) part = rot(part, i * p.twist, cx, cy);
43
+ parts.push(part);
44
+ }
45
+ // a twisted part can graze its neighbour: then keep the gap by clearing each from the ones before
46
+ return tidy(p.twist ? clearAll(parts, g) : U(...parts));
47
+ }
48
+
49
+ /** Parts cleared from one another by the gap, in order. */
50
+ function clearAll(parts, g) {
51
+ let acc = parts[0];
52
+ for (const q of parts.slice(1)) acc = U(acc, D(q, grown(acc, g)));
53
+ return acc;
54
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Stack: two to four primitive shapes laid out as a stack, a row, a grid, overlapping, nested or staggered, combined by
3
+ * ONE rule: kept apart by the house gap, laid over the one before with a gap round them, cut out of it, merged, or
4
+ * exclusive-or. Two shapes (A and B) and an order spread them over the slots; each can be turned. After marks that
5
+ * stack and tweak simple shapes together.
6
+ */
7
+ import { U, D, X, rot } from '@logomarks/core/geometry';
8
+ import { over } from '@logomarks/core/geometry';
9
+ import { BOX, GAP, clear } from '../draw.js';
10
+ import { primitive, PRIMITIVES } from '../shapes.js';
11
+
12
+ const TURNS = ['0', '90', '180', '270'];
13
+
14
+ /** @type {import('../index.js').Control[]} */
15
+ export const controls = [
16
+ { key: 'layout', label: 'Layout', type: 'choice', options: ['stack', 'row', 'grid', 'overlap', 'nest', 'stagger'], value: 'stack' },
17
+ { key: 'count', label: 'Shapes', type: 'range', min: 2, max: 4, step: 1, value: 3 },
18
+ { key: 'shapeA', label: 'Shape A', type: 'choice', options: PRIMITIVES, value: 'half' },
19
+ { key: 'turnA', label: 'Turn A', type: 'choice', options: TURNS, value: '0' },
20
+ { key: 'shapeB', label: 'Shape B', type: 'choice', options: PRIMITIVES, value: 'square' },
21
+ { key: 'turnB', label: 'Turn B', type: 'choice', options: TURNS, value: '180' },
22
+ { key: 'order', label: 'Order', type: 'choice', options: ['AB', 'AAB', 'ABB', 'ABA', 'A'], value: 'AB' },
23
+ { key: 'step', label: 'Turn each', type: 'choice', options: ['none', 'quarter', 'half'], value: 'none' },
24
+ { key: 'combine', label: 'Combine', type: 'choice', options: ['gap', 'over', 'cut', 'merge', 'xor'], value: 'gap' },
25
+ { key: 'size', label: 'Shape size', type: 'range', min: 0.5, max: 1, step: 0.01, value: 1 },
26
+ { key: 'overlap', label: 'Overlap', type: 'range', min: 0, max: 0.6, step: 0.01, value: 0.3 },
27
+ ];
28
+
29
+ /** The slots (boxes) of a layout for `n` shapes, in drawing order. */
30
+ function slots(layout, n, overlap) {
31
+ const { x0, y0, size } = BOX, g = GAP;
32
+ if (layout === 'row') { const w = (size - (n - 1) * g) / n; return Array.from({ length: n }, (_, i) => [x0 + i * (w + g), y0, w, size]); }
33
+ if (layout === 'grid') {
34
+ const c = (size - g) / 2, cells = [[x0, y0], [x0 + c + g, y0], [x0, y0 + c + g], [x0 + c + g, y0 + c + g]];
35
+ const pick = n === 2 ? [0, 3] : n === 3 ? [0, 1, 2] : [0, 1, 2, 3];
36
+ return pick.map((k) => [cells[k][0], cells[k][1], c, c]);
37
+ }
38
+ if (layout === 'nest') return Array.from({ length: n }, (_, i) => { const s = size * (1 - (i * 0.62) / n); return [BOX.cx - s / 2, BOX.cy - s / 2, s, s]; });
39
+ if (layout === 'overlap') {
40
+ const s = size / (1 + (n - 1) * (1 - overlap) * 0.5), step = (size - s) / Math.max(1, n - 1);
41
+ return Array.from({ length: n }, (_, i) => [x0 + i * step, y0 + i * step, s, s]);
42
+ }
43
+ const h = (size - (n - 1) * g) / n;
44
+ if (layout === 'stagger') { const w = size * (1 - overlap * 0.6); return Array.from({ length: n }, (_, i) => [i % 2 ? x0 + size - w : x0, y0 + i * (h + g), w, h]); }
45
+ return Array.from({ length: n }, (_, i) => [x0, y0 + i * (h + g), size, h]); // stack
46
+ }
47
+
48
+ /** Which of A and B fills slot i, by the order. */
49
+ function which(order, i) {
50
+ return order === 'A' ? 'A' : order[i % order.length] || 'A';
51
+ }
52
+
53
+ /** The mark for resolved params. */
54
+ export function build(p) {
55
+ const boxes = slots(p.layout, p.count, p.overlap);
56
+ const parts = boxes.map(([x, y, w, h], i) => {
57
+ const k = which(p.order, i), shrink = p.layout === 'nest' ? 1 : p.size;
58
+ const bw = w * shrink, bh = h * shrink, bx = x + (w - bw) / 2, by = y + (h - bh) / 2;
59
+ const extra = p.step === 'quarter' ? i : p.step === 'half' ? 2 * i : 0;
60
+ return primitive(k === 'A' ? p.shapeA : p.shapeB, bx, by, bw, bh, Number(k === 'A' ? p.turnA : p.turnB) / 90 + extra);
61
+ });
62
+ let acc = parts[0];
63
+ for (const s of parts.slice(1)) {
64
+ if (p.combine === 'merge') acc = U(acc, s);
65
+ else if (p.combine === 'xor') acc = X(acc, s);
66
+ else if (p.combine === 'cut') acc = D(acc, s);
67
+ else if (p.combine === 'over') acc = over(acc, s, GAP);
68
+ else acc = U(acc, clear(s, acc));
69
+ }
70
+ return acc;
71
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Steps: a staircase of two to six blocks: rising one way, both ways (a ziggurat), or hanging down (inverted), each
3
+ * tread a set depth and each riser a set height, the blocks parted by the house gap or fused into one solid, their
4
+ * treads rounded if asked. After stair marks, ziggurats and stepped blocks.
5
+ */
6
+ import { U, rect, rr } from '@logomarks/core/geometry';
7
+ import { BOX, GAP } from '../draw.js';
8
+
9
+ /** @type {import('../index.js').Control[]} */
10
+ export const controls = [
11
+ { key: 'count', label: 'Steps', type: 'range', min: 2, max: 6, step: 1, value: 4 },
12
+ { key: 'shape', label: 'Shape', type: 'choice', options: ['stair', 'ziggurat', 'inverted', 'zigzag'], value: 'ziggurat' },
13
+ { key: 'tread', label: 'Tread', type: 'range', min: 0.3, max: 1, step: 0.01, value: 0.6 },
14
+ { key: 'parted', label: 'Parted', type: 'toggle', value: true },
15
+ { key: 'roundTreads', label: 'Round treads', type: 'range', min: 0, max: 0.5, step: 0.01, value: 0 },
16
+ { key: 'gap', label: 'Gap', type: 'range', min: 1, max: 2.5, step: 0.1, value: 1 },
17
+ ];
18
+
19
+ /** The mark for resolved params. */
20
+ export function build(p) {
21
+ const n = p.count, { x0, y0, size, cx } = BOX, g = p.parted ? GAP * p.gap : 0;
22
+ const h = (size - (n - 1) * g) / n, parts = [];
23
+ for (let i = 0; i < n; i++) {
24
+ // block i from the top: its width grows with i for a stair or ziggurat, shrinks for inverted
25
+ const k = p.shape === 'inverted' ? n - 1 - i : i;
26
+ const share = (1 - p.tread) + p.tread * ((k + 1) / n);
27
+ const w = size * share, y = y0 + i * (h + g);
28
+ let x = x0;
29
+ if (p.shape === 'ziggurat' || p.shape === 'inverted') x = cx - w / 2;
30
+ if (p.shape === 'zigzag') x = i % 2 ? x0 + size - w : x0;
31
+ const r = Math.min(h / 2, p.roundTreads * h);
32
+ parts.push(r > 0.5 ? rr(x, y, w, h + (g ? 0 : 0.02), p.shape === 'stair' ? [0, r, 0, 0] : [r, r, 0, 0]) : rect(x, y, w, h + (g ? 0 : 0.02)));
33
+ }
34
+ return U(...parts);
35
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Stripes: a silhouette (a disc, a square, a hexagon, an arch, a triangle, a half disc or a diamond) drawn in five to
3
+ * twelve parallel stripes at any angle, with ONE move: the stripes shifted in turn, bent into a wave, tapered, or cut by
4
+ * a slot, or broken into dashes. `cover` stripes only part of the shape and leaves the rest solid, and `ends` rounds
5
+ * every stripe's ends. After striped suns, Strange Trails and the Bold · Stripes family.
6
+ */
7
+ import { U, D, I, rect, poly, mapPts, rot, grow } from '@logomarks/core/geometry';
8
+ import { BOX, GAP, tidy } from '../draw.js';
9
+ import { primitive } from '../shapes.js';
10
+
11
+ /** @type {import('../index.js').Control[]} */
12
+ export const controls = [
13
+ { key: 'shape', label: 'Shape', type: 'choice', options: ['circle', 'square', 'hexagon', 'arch', 'triangle', 'half', 'diamond'], value: 'circle' },
14
+ { key: 'stripes', label: 'Stripes', type: 'range', min: 4, max: 12, step: 1, value: 7 },
15
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.8, step: 0.01, value: 0.6 },
16
+ { key: 'angle', label: 'Angle', type: 'range', min: -90, max: 90, step: 5, value: 0 },
17
+ { key: 'move', label: 'Move', type: 'choice', options: ['none', 'shift', 'wave', 'taper', 'slot', 'dash'], value: 'none' },
18
+ { key: 'amount', label: 'Amount', type: 'range', min: 0, max: 1, step: 0.01, value: 0.5 },
19
+ { key: 'cover', label: 'Striped part', type: 'range', min: 0.3, max: 1, step: 0.01, value: 1 },
20
+ { key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round'], value: 'square' },
21
+ ];
22
+
23
+ /** The silhouette, filling the box. */
24
+ function silhouette(shape) {
25
+ const { x0, y0, size, cx, cy } = BOX;
26
+ if (shape === 'hexagon') return poly(Array.from({ length: 6 }, (_, k) => { const a = (Math.PI / 3) * k - Math.PI / 2; return [cx + (size / 2) * Math.cos(a), cy + (size / 2) * Math.sin(a)]; }));
27
+ return primitive(shape === 'arch' ? 'arch' : shape, x0, y0, size, size);
28
+ }
29
+
30
+ /** The mark for resolved params. */
31
+ export function build(p) {
32
+ const n = p.stripes, span = BOX.size * 1.5, pitch = span / n, gap = Math.max(GAP, pitch * (1 - p.weight)), w = pitch - gap;
33
+ const bands = [];
34
+ // cover: the stripes stop part way down the shape (in the stripes' own frame) and the rest is one solid
35
+ const yCut = BOX.y0 + (p.cover ?? 1) * BOX.size;
36
+ let solidFrom = null;
37
+ for (let k = 0; k < n; k++) {
38
+ const y = BOX.cy - span / 2 + k * pitch + gap / 2;
39
+ let width = w;
40
+ if (p.move === 'taper') width = Math.max(GAP * 0.8, w * (1 - p.amount * 0.75 * (k / (n - 1))));
41
+ if ((p.cover ?? 1) < 1 && y >= yCut) { solidFrom ??= y; continue; }
42
+ let band = rect(BOX.cx - span, y, 2 * span, width);
43
+ if (p.move === 'dash') {
44
+ // two breaks in each stripe, wandering from stripe to stripe by the amount
45
+ const wander = (k2) => Math.sin(k2 * 2.399 + 1.3) * p.amount * BOX.size * 0.22;
46
+ for (const at of [BOX.cx - BOX.size * 0.18 + wander(k), BOX.cx + BOX.size * 0.2 + wander(k + 7)]) band = D(band, rect(at - GAP * 0.7, y - 1, GAP * 1.4, width + 2));
47
+ }
48
+ bands.push(band);
49
+ }
50
+ if (solidFrom !== null) bands.push(rect(BOX.cx - span, solidFrom, 2 * span, span));
51
+ let stripes = U(...bands);
52
+ if (p.move === 'wave') stripes = mapPts(stripes, ([x, y]) => [x, y + Math.sin(((x - BOX.x0) / BOX.size) * Math.PI * 2) * pitch * 0.45 * p.amount]);
53
+ stripes = rot(stripes, p.angle, BOX.cx, BOX.cy);
54
+ let s = I(stripes, silhouette(p.shape));
55
+ if (p.move === 'shift') {
56
+ // every other stripe slid along its length: the silhouette breaks into a step
57
+ const d = p.amount * BOX.size * 0.12, a = (p.angle * Math.PI) / 180;
58
+ s = U(...[...s].map((q, k) => (k % 2 ? mapPts([q], ([x, y]) => [x + d * Math.cos(a), y + d * Math.sin(a)]) : [q])));
59
+ }
60
+ if (p.move === 'slot') s = D(s, rot(rect(BOX.cx - GAP * (1 + p.amount), BOX.y0 - 20, GAP * 2 * (1 + p.amount), BOX.size + 40), p.angle + 90, BOX.cx, BOX.cy));
61
+ if (p.ends === 'round') { const r = Math.max(4, w * 0.45); s = grow(grow(s, -r), r); } // every stripe's ends round (pills)
62
+ return tidy(s); // the stripes clipped at the silhouette's edge leave crumbs
63
+ }
64
+
65
+ /** Stripes are many pieces by design. */
66
+ export const guard = { maxPieces: 30 };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Tiles: a two-by-two to four-by-four grid of cells, each a square, a quarter disc, a half disc, a disc, a triangle or
3
+ * nothing, laid out by a numbered layout (the same number, the same layout) and made symmetric if asked, the cells
4
+ * touching (merged into one figure) or parted by the house gap. After modular marks of squares and quarter rounds.
5
+ */
6
+ import { U } from '@logomarks/core/geometry';
7
+ import { BOX, GAP } from '../draw.js';
8
+ import { primitive } from '../shapes.js';
9
+ import { rng } from '../random.js';
10
+
11
+ const SETS = { soft: ['square', 'quarter', 'quarter', 'half', 'circle'], sharp: ['square', 'triangle', 'parallelogram', 'diamond'], mixed: ['square', 'quarter', 'half', 'triangle', 'circle', 'leaf'] };
12
+
13
+ /** @type {import('../index.js').Control[]} */
14
+ export const controls = [
15
+ { key: 'grid', label: 'Grid', type: 'range', min: 2, max: 4, step: 1, value: 3 },
16
+ { key: 'layout', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 7 },
17
+ { key: 'set', label: 'Shapes', type: 'choice', options: ['soft', 'sharp', 'mixed'], value: 'soft' },
18
+ { key: 'density', label: 'Density', type: 'range', min: 0.4, max: 1, step: 0.01, value: 0.8 },
19
+ { key: 'symmetry', label: 'Symmetry', type: 'choice', options: ['none', 'mirror', 'both', 'turn'], value: 'mirror' },
20
+ { key: 'gap', label: 'Parted', type: 'toggle', value: true },
21
+ ];
22
+
23
+ /** The cell drawn at (r, c), from the layout's own random. */
24
+ function cellOf(p, r, c, rand) {
25
+ if (rand() > p.density) return null;
26
+ const set = SETS[p.set];
27
+ return { type: set[Math.floor(rand() * set.length)], turns: Math.floor(rand() * 4) };
28
+ }
29
+
30
+ /** The mark for resolved params. */
31
+ export function build(p) {
32
+ const n = p.grid, g = p.gap ? GAP : 0, c = (BOX.size - (n - 1) * g) / n, rand = rng(`tiles:${p.layout}:${n}:${p.set}`);
33
+ const cells = Array.from({ length: n }, () => Array(n).fill(null));
34
+ for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) cells[r][k] = cellOf(p, r, k, rand);
35
+ // symmetry: copy the source half (or quarter) over, turning each cell to match
36
+ for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) {
37
+ const src = cells[r][n - 1 - k];
38
+ if ((p.symmetry === 'mirror' || p.symmetry === 'both') && k >= Math.ceil(n / 2)) cells[r][k] = src && { type: src.type, turns: src.turns, flip: 'x' };
39
+ }
40
+ for (let r = Math.ceil(n / 2); r < n && p.symmetry === 'both'; r++) for (let k = 0; k < n; k++) { const s = cells[n - 1 - r][k]; cells[r][k] = s && { ...s, flip: s.flip === 'x' ? 'xy' : 'y' }; }
41
+ for (let r = 0; r < n && p.symmetry === 'turn'; r++) for (let k = 0; k < n; k++) if (r * n + k >= Math.ceil((n * n) / 2)) { const s = cells[n - 1 - r][n - 1 - k]; cells[r][k] = s && { type: s.type, turns: s.turns + 2 }; }
42
+ const parts = [];
43
+ for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) {
44
+ const cell = cells[r][k]; if (!cell) continue;
45
+ const x = BOX.x0 + k * (c + g), y = BOX.y0 + r * (c + g);
46
+ parts.push(flipCell(cell, x, y, c));
47
+ }
48
+ return parts.length ? U(...parts) : []; // an empty layout: the guard calls it nothing drawn
49
+ }
50
+
51
+ /** A cell's shape, mirrored across its box as the symmetry asks. */
52
+ function flipCell(cell, x, y, c) {
53
+ // mirroring a cell is the same as turning its primitive: x-flip maps turn t to (4 − t) of a quarter, near enough for
54
+ // the primitives' own symmetry; apply by turns so every result is still one of the primitives
55
+ let t = cell.turns;
56
+ if (cell.flip === 'x') t = (5 - t) % 4;
57
+ if (cell.flip === 'y') t = (3 - t) % 4;
58
+ if (cell.flip === 'xy') t = t + 2;
59
+ return primitive(cell.type, x, y, c, c, t);
60
+ }