@logomarks/generate 0.2.1 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2026-11-27)
4
+
5
+ Recipes that combine UNLIKE shapes (the owner: "there isn't enough variation… most shapes are combined different shapes
6
+ together"). 45 recipes: seven added, two removed (a breaking change, hence the minor version).
7
+
8
+ - `src/primitives.js` (exported: `PRIMS`, `prim`, `alike`, `banned`, `unlike`, `unlikePair`, `unlikeTriple`, `BANNED`):
9
+ fourteen basic shapes drawn in a box, pickers that never pair two that read alike, and per recipe the pairings banned
10
+ because the combination is an object (a person, a play button, an eye, a house, an arrow, a pin, a camera, a nut).
11
+ - Seven recipes on it: `merge`, `overlap`, `counter`, `pair` (Split pair), `corners`, `offset`, `quarters`. Each steers
12
+ its independent shape controls with `unlike()` and exports `shapesOf(params)` (corners: `cornersOf`), the shapes as
13
+ drawn. Seven presets (36).
14
+ - `stack` rebuilt as a totem: a third shape (`shapeC`, `turnC`, the `ABC` order), neighbours steered off the banned
15
+ pairs, and its shuffles keep to a stack, a row or a stagger with the gap between (the nests and overlaps that threw a
16
+ bare outline, an eye and a bust in the bulk run are by hand only). Old settings still draw.
17
+ - Removed: `pixelarc` (the weakest style, blocky and repetitive) and `venn` (two distinct marks in a bulk run of 130;
18
+ `overlap` draws what it did, with unlike shapes). Settings saved for either no longer draw.
19
+ - Tried and left out: Fold (a band with gaps at its creases reads as blocky letters), Interlock (what `links` draws, with
20
+ arrow-like nicks and half its draws failing), Satellite (a small shape set in a big one reads as an icon in a tile),
21
+ and a notch recipe (`cut` and `bite` already take one shape out of another's edge).
22
+ - How distinct the new recipes are, by the bulk pipeline's measure (130 shuffles each, mutually under 0.72 by outline,
23
+ then clear of the 6,072 live marks): stack 45 then 35, overlap 37 then 17, quarters 25 then 17, pair 18 then 12, offset
24
+ 26 then 10; merge 10, counter 5 and corners 6 distinct, none clear of the live set (heavy solids all score close to
25
+ the live blocks, though they look unlike them).
26
+
3
27
  ## 0.2.1 (2026-11-26)
4
28
 
5
29
  Five recipes reworked from sheets of their shuffles (ids and count unchanged, 40; settings saved from 0.2.0 still draw):
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @logomarks/generate
2
2
 
3
- Abstract logomarks from rules and controls, no AI. Each recipe is one construction (40 of them: bars, bands, twin,
4
- stack, shear, turns, burst, tiles, route, arcs, rings, stripes, chevrons, waves, cut, split, venn, spiral, bloom, links,
5
- horizon, steps, hex, iso and letter, then fifteen after live house families: arcstep, halfsq, invert, leaves, lobes, loops, trine, strips, bite, blades, wavecut, capsules, flare, pixelarc, seam) that lists its controls
3
+ Abstract logomarks from rules and controls, no AI. Each recipe is one construction (45 of them: bars, bands, twin,
4
+ stack, shear, turns, burst, tiles, route, arcs, rings, stripes, chevrons, waves, cut, split, spiral, bloom, links,
5
+ horizon, steps, hex, iso and letter; fourteen after live house families: arcstep, halfsq, invert, leaves, lobes, loops,
6
+ trine, strips, bite, blades, wavecut, capsules, flare, seam; and seven that combine unlike shapes: merge, overlap,
7
+ counter, pair, corners, offset, quarters) that lists its controls
6
8
  and draws a mark from them, fitted to the Logomarks standard: a 512 canvas, the longest side 448, centred,
7
9
  `currentColor`, the house gap. Every recipe also takes the finish controls (turn, mirror, round corners, outline, an
8
10
  accent dot, a container: badge or clip). Each mark comes with its `pieces`, and `svgOf()` draws them in two colours. A
@@ -45,3 +47,27 @@ const twoTone = svgOf(mark.pieces, { colors: ['#0b0b0b', '#c8ff00'], pattern: 'r
45
47
  ## Licence
46
48
 
47
49
  MIT © ArrayPress Limited. What you generate is yours to use.
50
+
51
+ ## Combining unlike shapes
52
+
53
+ Seven recipes (and `stack`, a totem) build a mark from DIFFERENT basic shapes, drawn by `src/primitives.js`:
54
+
55
+ - `PRIMS`: disc, square, rsquare, triangle, wedge, half, quarter, arch, leaf, pill, diamond, hexagon, ring, bar.
56
+ `prim(type, [x, y, w, h], turn, mirror)` draws one in a box, turned by quarter turns.
57
+ - `alike(a, b)`: two shapes that read the same (a disc and a ring, a square and a rounded square) are never paired.
58
+ - `BANNED[recipe]`: the pairings a recipe never draws, each with the read it avoids (a disc over a block is a person, a
59
+ triangle in a tile a play button, a disc in a leaf an eye). `banned(recipe, a, b)` gives the reason, or ''.
60
+ - `unlike(recipe, a, b, pool)`: `b` if it may go with `a`, else the next shape of the pool that may. A recipe draws its
61
+ shapes from independent controls and steers them with this, so a banned pair is never drawn (each recipe's
62
+ `shapesOf(params)` gives the shapes as drawn). `unlikePair(rand, pool, recipe)` and `unlikeTriple` pick from a random
63
+ source.
64
+
65
+ | Recipe | What it draws |
66
+ |---|---|
67
+ | `merge` | two unlike shapes fused flat side to flat side into one solid, the second narrower and set to one side |
68
+ | `overlap` | two unlike shapes crossing: one over the other, the overlap knocked out, or the overlap kept as a piece |
69
+ | `counter` | a solid whose hole is a different shape |
70
+ | `pair` | a block split in two, each half a different shape, flat sides to the split |
71
+ | `corners` | one block, each corner square, rounded, cut, scooped or notched (never a cross, a star or an arrow) |
72
+ | `offset` | a shape and its copy slid aside: a hard shadow, the overlap knocked out or kept |
73
+ | `quarters` | four big cells, each a different shape, turned by one rule; never a plus-shaped gap |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logomarks/generate",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Abstract logomarks from rules and controls, no AI: 34 recipes (bars, bands, twin, stack, shear, turns, burst, tiles, route, arcs, rings, stripes, dots, pixel, chevrons, waves, cut, split, venn, blobs, dashes, fan, fold, spiral, orbit, bloom, links, horizon, steps, hex, tri, iso, line, letter) that each list their controls and draw a mark from them and a seed, fitted to the Logomarks standard (512 canvas, 448 fit, the house gap), a shared finish (rounding, outline, an accent dot, a container), two-colour pieces, seeded variations and presets. Runs in the browser and in Node.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/generate.js CHANGED
@@ -249,7 +249,7 @@ export function similar(id, params, { count = 12, seed = 1, amount = 0.15, locke
249
249
  * How often each recipe comes up in `mix()`, relative to 1: the ones whose shuffles most often give a mark worth
250
250
  * keeping lead; the textured ones (iso, hex, tiles) come up less.
251
251
  */
252
- export const MIX_WEIGHT = { twin: 1.6, cut: 1.6, split: 1.4, chevrons: 1.3, spiral: 1.2, links: 1.2, arcs: 1.2, bands: 1.2, stripes: 1.2, rings: 0.8, turns: 1.1, bloom: 1, burst: 1, bars: 1, waves: 0.9, stack: 0.8, steps: 0.8, letter: 0.8, shear: 0.6, venn: 0.5, route: 0.5, horizon: 0.5, tiles: 0.6, hex: 0.5, iso: 0.5, arcstep: 1.4, leaves: 1.3, seam: 1.3, trine: 1.1, blades: 1.1, invert: 1, wavecut: 1, capsules: 1, bite: 0.9, loops: 0.8, strips: 0.7, flare: 0.8, lobes: 0.9, halfsq: 0.8, pixelarc: 0.4 };
252
+ export const MIX_WEIGHT = { twin: 1.6, cut: 1.6, split: 1.4, chevrons: 1.3, spiral: 1.2, links: 1.2, arcs: 1.2, bands: 1.2, stripes: 1.2, rings: 0.8, turns: 1.1, bloom: 1, burst: 1, bars: 1, waves: 0.9, stack: 0.8, steps: 0.8, letter: 0.8, shear: 0.6, route: 0.5, horizon: 0.5, tiles: 0.6, hex: 0.5, iso: 0.5, arcstep: 1.4, leaves: 1.3, seam: 1.3, trine: 1.1, blades: 1.1, invert: 1, wavecut: 1, capsules: 1, bite: 0.9, loops: 0.8, strips: 0.7, flare: 0.8, lobes: 0.9, halfsq: 0.8, pixelarc: 0.4 , merge: 1.3, overlap: 1.3, counter: 1.2, pair: 1.3, corners: 1.2, offset: 1.1, quarters: 1.1 };
253
253
 
254
254
  /**
255
255
  * `count` marks from ANY recipe: each slot picks a recipe by its seed (from `ids`, every recipe by default, weighted by
package/src/index.d.ts CHANGED
@@ -109,3 +109,20 @@ export function piecesOf(shape: unknown): string[];
109
109
  export function svgOf(pieces: string[], o?: { colors?: [string, string]; pattern?: 'alternate' | 'first' | 'last' | 'rows' | 'size' | 'smallest' | 'inner' | 'outer' | 'left' | 'top' | 'gradient' }): string;
110
110
  /** The colour patterns `svgOf` knows, in a picker's order. */
111
111
  export const PATTERNS: readonly string[];
112
+
113
+ /** The primitives the composition recipes combine, in a picker's order. */
114
+ export const PRIMS: string[];
115
+ /** Primitive `type` in a box ([x, y, w, h]), turned `turn` quarter turns and, with `mirror`, flipped left to right. */
116
+ export function prim(type: string, box: [number, number, number, number], turn?: number, mirror?: boolean): unknown;
117
+ /** Whether two primitives are the same or read alike. */
118
+ export function alike(a: string, b: string): boolean;
119
+ /** Why `recipe` never draws `a` with `b` (the read it avoids), or '' when it may. */
120
+ export function banned(recipe: string, a: string, b: string): string;
121
+ /** `b` if it may go with `a` in `recipe` (and with `also`), else the next shape of `pool` that may. */
122
+ export function unlike(recipe: string, a: string, b: string, pool?: string[], also?: string[]): string;
123
+ /** Two primitives of `pool`, neither alike nor banned together in `recipe`. */
124
+ export function unlikePair(rand: () => number, pool?: string[], recipe?: string): [string, string];
125
+ /** Three primitives of `pool`, no two alike or banned together. */
126
+ export function unlikeTriple(rand: () => number, pool?: string[], recipe?: string): [string, string, string];
127
+ /** Per recipe, the pairings it never draws: [a, b, the read avoided]. */
128
+ export const BANNED: Record<string, [string, string, string][]>;
package/src/index.js CHANGED
@@ -8,3 +8,4 @@ export { rng, seedOf } from './random.js';
8
8
  export { GUARD, problems } from './guard.js';
9
9
  export { TUNING, MAIN } from './tuning.js';
10
10
  export { PRESETS } from './presets.js';
11
+ export { PRIMS, prim, alike, banned, unlike, unlikePair, unlikeTriple, BANNED } from './primitives.js';
package/src/presets.js CHANGED
@@ -34,4 +34,11 @@ export const PRESETS = [
34
34
  { id: 'tenon-block', name: 'Tenon block', recipe: 'seam', params: { joint: 'tenon', body: 'square' }, note: 'A block in two halves, joined by a tenon.' },
35
35
  { id: 'shutter', name: 'Rotor', recipe: 'trine', params: { body: 'disc', offset: 0.3, depth: 0.8 }, note: 'A disc with three slits of unlike depth that pass the centre and stop short.' },
36
36
  { id: 'blade-sweep', name: 'Blade sweep', recipe: 'blades', params: { count: 3, grow: 0.5, width: 1.6 }, note: 'Three blades, each taller than the last.' },
37
+ { id: 'dome-wedge', name: 'Dome and wedge', recipe: 'merge', params: { a: 'half', b: 'wedge', width: 0.62 }, note: 'A dome fused to a wedge set to one side: one solid.' },
38
+ { id: 'four-corners', name: 'Four corners', recipe: 'corners', params: { nw: 'round', ne: 'square', se: 'scoop', sw: 'cut', reach: 0.4 }, note: 'One block, each corner treated a different way.' },
39
+ { id: 'leaf-window', name: 'Leaf window', recipe: 'counter', params: { body: 'square', hole: 'leaf', size: 0.44 }, note: 'A square with a leaf-shaped hole.' },
40
+ { id: 'facing-halves', name: 'Facing halves', recipe: 'pair', params: { a: 'half', b: 'quarter' }, note: 'A half disc and a quarter disc, flat sides to the split.' },
41
+ { id: 'disc-on-square', name: 'Disc over square', recipe: 'overlap', params: { a: 'disc', b: 'square', way: 'over' }, note: 'A square laid over a disc, cut free by the gap.' },
42
+ { id: 'dome-shadow', name: 'Dome shadow', recipe: 'offset', params: { shape: 'half', way: 'shadow', dir: 'se', shift: 0.28 }, note: 'A dome and its copy slid behind it.' },
43
+ { id: 'four-shapes', name: 'Four shapes', recipe: 'quarters', params: { a: 'quarter', b: 'wedge', c: 'disc', d: 'leaf', rule: 'rotate' }, note: 'Four unlike shapes, each a quarter turn on from the last.' },
37
44
  ];
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The primitives the composition recipes combine: fourteen basic shapes, each drawn in a box and placed by a turn and a
3
+ * mirror, with pickers that never pair two shapes that read alike, and the pairings each recipe bans because the
4
+ * combination reads as an object (a disc over a block is a person, a triangle in a disc a play button). A recipe draws
5
+ * its shapes from independent controls, then steers them with `unlike()`, so no banned pair is ever drawn.
6
+ */
7
+ import { U, D, I, rect, poly, circle, ellipse, rr, rot, mapPts } from '@logomarks/core/geometry';
8
+
9
+ /** Every primitive, in the order a picker lists them. */
10
+ export const PRIMS = ['disc', 'square', 'rsquare', 'triangle', 'wedge', 'half', 'quarter', 'arch', 'leaf', 'pill', 'diamond', 'hexagon', 'ring', 'bar'];
11
+
12
+ /** Points of an arc round (cx, cy), radii (rx, ry), from a0 to a1 degrees. */
13
+ const arc = (cx, cy, rx, ry, a0, a1, n = 40) => Array.from({ length: n + 1 }, (_, i) => { const a = ((a0 + ((a1 - a0) * i) / n) * Math.PI) / 180; return [cx + rx * Math.cos(a), cy + ry * Math.sin(a)]; });
14
+ const oval = (x, y, w, h) => (Math.abs(w - h) < 0.5 ? circle(x + w / 2, y + h / 2, w / 2, 96) : ellipse(x + w / 2, y + h / 2, w / 2, h / 2, 0, 96));
15
+
16
+ /** The primitive unturned: flat sides down (a half's dome and a triangle's point are up, a quarter's corner bottom left). */
17
+ function draw(type, x, y, w, h) {
18
+ const x1 = x + w, y1 = y + h, cx = x + w / 2, cy = y + h / 2, m = Math.min(w, h);
19
+ switch (type) {
20
+ case 'disc': return oval(x, y, w, h);
21
+ case 'rsquare': return rr(x, y, w, h, m * 0.26);
22
+ case 'triangle': return poly([[x, y1], [cx, y], [x1, y1]]);
23
+ case 'wedge': return poly([[x, y], [x1, y1], [x, y1]]);
24
+ case 'half': return poly([...arc(cx, y1, w / 2, h, 180, 360)]);
25
+ case 'quarter': return poly([[x, y1], ...arc(x, y1, w, h, 270, 360)]);
26
+ case 'arch': { const t = m * 0.36; return poly([...arc(cx, y1, w / 2, h, 180, 360), ...arc(cx, y1, w / 2 - t, h - t, 360, 180)]); }
27
+ case 'leaf': return I(circle(x1, y1, Math.max(w, h), 128), circle(x, y, Math.max(w, h), 128), rect(x, y, w, h));
28
+ // in a square box a pill would be a disc: it lies level across the middle instead
29
+ case 'pill': return Math.abs(w - h) < m * 0.2 ? rr(x, cy - h * 0.29, w, h * 0.58, h * 0.29 - 0.01) : rr(x, y, w, h, m / 2 - 0.01);
30
+ case 'diamond': return poly([[cx, y], [x1, cy], [cx, y1], [x, cy]]);
31
+ case 'hexagon': return poly([[x + w * 0.25, y], [x + w * 0.75, y], [x1, cy], [x + w * 0.75, y1], [x + w * 0.25, y1], [x, cy]]);
32
+ case 'ring': { const t = m * 0.3; return D(oval(x, y, w, h), oval(x + t, y + t, w - 2 * t, h - 2 * t)); }
33
+ case 'bar': return rect(x, cy - h * 0.22, w, h * 0.44);
34
+ default: return rect(x, y, w, h);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Primitive `type` in `box` ([x, y, w, h]), turned `turn` quarter turns clockwise about the box's centre (squashed back
40
+ * into a box that isn't square) and, with `mirror`, flipped left to right first.
41
+ */
42
+ export function prim(type, [x, y, w, h], turn = 0, mirror = false) {
43
+ const cx = x + w / 2, cy = y + h / 2, t = ((turn % 4) + 4) % 4, side = t % 2 === 1 && Math.abs(w - h) > 0.5;
44
+ // drawn in the box it will fill once turned, so a turned half is a true half of that box
45
+ let s = side ? draw(type, cx - h / 2, cy - w / 2, h, w) : draw(type, x, y, w, h);
46
+ if (mirror) s = mapPts(s, ([px, py]) => [2 * cx - px, py]);
47
+ return t ? rot(s, 90 * t, cx, cy) : s;
48
+ }
49
+
50
+ /** Shapes that read alike: never paired. */
51
+ const ALIKE = [['disc', 'ring'], ['square', 'rsquare'], ['square', 'bar'], ['pill', 'bar'], ['pill', 'rsquare'], ['half', 'arch'], ['triangle', 'wedge']];
52
+ /** Whether two primitives are the same or read alike. */
53
+ export const alike = (a, b) => a === b || ALIKE.some(([p, q]) => (p === a && q === b) || (p === b && q === a));
54
+
55
+ /**
56
+ * The pairings each recipe never draws, with the read each avoids. A pair is banned either way round.
57
+ */
58
+ export const BANNED = {
59
+ merge: [['disc', 'square', 'a person'], ['disc', 'rsquare', 'a person'], ['disc', 'pill', 'a person'], ['disc', 'half', 'a person'], ['disc', 'bar', 'a person'], ['disc', 'triangle', 'a pin'], ['disc', 'wedge', 'a pin'], ['disc', 'diamond', 'a pin'], ['triangle', 'square', 'a house'], ['triangle', 'rsquare', 'a house'], ['triangle', 'pill', 'an arrow'], ['triangle', 'bar', 'an arrow'], ['triangle', 'half', 'a cone'], ['diamond', 'half', 'a cone'], ['leaf', 'disc', 'a flame'], ['hexagon', 'triangle', 'a pencil'], ['square', 'half', 'a tombstone'], ['rsquare', 'half', 'a tombstone'], ['pill', 'half', 'a mushroom']],
60
+ overlap: [['disc', 'triangle', 'a play button'], ['ring', 'bar', 'a no-entry sign'], ['ring', 'pill', 'a no-entry sign'], ['disc', 'bar', 'a no-entry sign'], ['ring', 'triangle', 'a play button'], ['ring', 'square', 'a magnifier'], ['ring', 'rsquare', 'a magnifier'], ['ring', 'diamond', 'a key'], ['disc', 'half', 'a person'], ['triangle', 'square', 'a house'], ['triangle', 'rsquare', 'a house']],
61
+ counter: [['disc', 'triangle', 'a play button'], ['rsquare', 'triangle', 'a play button'], ['square', 'triangle', 'a play button'], ['hexagon', 'triangle', 'a play button'], ['disc', 'wedge', 'a play button'], ['rsquare', 'wedge', 'a play button'], ['hexagon', 'disc', 'a nut'], ['triangle', 'disc', 'an eye in a triangle'], ['leaf', 'disc', 'an eye'], ['disc', 'leaf', 'an eye'], ['disc', 'square', 'a stop button'], ['disc', 'rsquare', 'a stop button'], ['rsquare', 'disc', 'a camera'], ['square', 'disc', 'a camera'], ['half', 'disc', 'an eye'], ['diamond', 'disc', 'an eye'], ['disc', 'pill', 'a no-entry sign'], ['disc', 'bar', 'a no-entry sign'], ['rsquare', 'pill', 'a battery'], ['hexagon', 'pill', 'a screw head'], ['disc', 'half', 'a face'], ['rsquare', 'half', 'a face'], ['square', 'half', 'a door'], ['square', 'arch', 'a door'], ['rsquare', 'arch', 'a door']],
62
+ pair: [['triangle', 'square', 'an arrow'], ['triangle', 'rsquare', 'an arrow'], ['triangle', 'pill', 'an arrow'], ['wedge', 'square', 'an arrow'], ['triangle', 'bar', 'an arrow'], ['half', 'triangle', 'a play button']],
63
+ stack: [['half', 'square', 'a burger'], ['half', 'pill', 'a burger'], ['circle', 'square', 'a person'], ['circle', 'pill', 'a person'], ['circle', 'half', 'a person'], ['circle', 'arch', 'a person'], ['circle', 'triangle', 'a pin'], ['circle', 'chevron', 'a person'], ['circle', 'ring', 'an eye'], ['ring', 'half', 'an eye'], ['ring', 'pill', 'an eye'], ['ring', 'square', 'a person'], ['ring', 'triangle', 'a pin'], ['triangle', 'square', 'a house'], ['triangle', 'pill', 'an arrow'], ['chevron', 'square', 'a house'], ['triangle', 'half', 'a cone'], ['diamond', 'half', 'a cone']],
64
+ offset: [],
65
+ quarters: [],
66
+ };
67
+
68
+ /** Why a recipe never draws `a` with `b`, or '' when it may. */
69
+ export function banned(recipe, a, b) {
70
+ if (alike(a, b)) return 'two alike';
71
+ const hit = (BANNED[recipe] || []).find(([p, q]) => (p === a && q === b) || (p === b && q === a));
72
+ return hit ? hit[2] : '';
73
+ }
74
+
75
+ /**
76
+ * `b` if it may go with `a` in `recipe` (and with `also`, shapes already chosen), else the next shape of `pool` after
77
+ * it that may: how a recipe steers independent controls away from a banned pair.
78
+ */
79
+ export function unlike(recipe, a, b, pool = PRIMS, also = []) {
80
+ const ok = (c) => !banned(recipe, a, c) && also.every((d) => !banned(recipe, d, c));
81
+ if (ok(b)) return b;
82
+ const i = Math.max(0, pool.indexOf(b));
83
+ for (let k = 1; k <= pool.length; k++) { const c = pool[(i + k) % pool.length]; if (ok(c)) return c; }
84
+ return b;
85
+ }
86
+
87
+ /** Two primitives of `pool` that neither read alike nor are banned in `recipe`, from a random source (0–1). */
88
+ export function unlikePair(rand, pool = PRIMS, recipe = '') {
89
+ const a = pool[Math.floor(rand() * pool.length)];
90
+ return [a, unlike(recipe, a, pool[Math.floor(rand() * pool.length)], pool)];
91
+ }
92
+
93
+ /** Three primitives of `pool`, no two alike or banned together in `recipe`. */
94
+ export function unlikeTriple(rand, pool = PRIMS, recipe = '') {
95
+ const [a, b] = unlikePair(rand, pool, recipe);
96
+ return [a, b, unlike(recipe, b, pool[Math.floor(rand() * pool.length)], pool, [a])];
97
+ }
98
+
99
+ /** The union of shapes, skipping empty ones. */
100
+ export const join = (...shapes) => { const s = shapes.filter((x) => x && x.length); return s.length > 1 ? U(...s) : s[0] || []; };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Corners: one block whose four corners are each treated a different way: left square, rounded, cut at 45°, scooped
3
+ * (a quarter circle taken out) or notched (a square taken out). Never four notches (a cross), four scoops (a
4
+ * four-point star) or four cuts (an octagon): the fourth of a kind is rounded instead.
5
+ */
6
+ import { D, U, I, rect, poly, circle } from '@logomarks/core/geometry';
7
+ import { BOX, tidy } from '../draw.js';
8
+
9
+ const KINDS = ['square', 'round', 'cut', 'scoop', 'notch'];
10
+
11
+ /** @type {import('../index.js').Control[]} */
12
+ export const controls = [
13
+ { key: 'nw', label: 'Top left', type: 'choice', options: KINDS, value: 'round' },
14
+ { key: 'ne', label: 'Top right', type: 'choice', options: KINDS, value: 'square' },
15
+ { key: 'se', label: 'Bottom right', type: 'choice', options: KINDS, value: 'scoop' },
16
+ { key: 'sw', label: 'Bottom left', type: 'choice', options: KINDS, value: 'cut' },
17
+ { key: 'reach', label: 'Corner size', type: 'range', min: 0.2, max: 0.5, step: 0.01, value: 0.4 },
18
+ { key: 'second', label: 'Second size', type: 'range', min: 0.5, max: 1, step: 0.01, value: 1 },
19
+ { key: 'shape', label: 'Block', type: 'choice', options: ['square', 'wide', 'tall'], value: 'square' },
20
+ ];
21
+
22
+ /**
23
+ * The four treatments as drawn, clockwise from the top left. A corner past these limits is rounded instead: one notch
24
+ * at most (two are a T or an arrow's tail), two corners taken out in all (a notch or a scoop: more is a cross), two
25
+ * cuts, and never side by side (a house, an arrow's head), three left square.
26
+ */
27
+ export function cornersOf(p) {
28
+ const out = [];
29
+ for (const k of [p.nw, p.ne, p.se, p.sw]) {
30
+ const n = (x) => out.filter((o) => o === x).length, taken = n('notch') + n('scoop'), i = out.length;
31
+ const beside = (x) => out[i - 1] === x || (i === 3 && out[0] === x);
32
+ let v = k;
33
+ if (k === 'notch' && (n('notch') >= 1 || taken >= 2)) v = 'round';
34
+ else if (k === 'scoop' && taken >= 2) v = 'round';
35
+ else if (k === 'cut' && (n('cut') >= 2 || beside('cut'))) v = 'round';
36
+ else if (k === 'square' && n('square') >= 3) v = 'round';
37
+ out.push(v);
38
+ }
39
+ return out;
40
+ }
41
+
42
+ /** The mark for resolved params. */
43
+ export function build(p) {
44
+ const { x0, y0, size, cx, cy } = BOX, w = p.shape === 'tall' ? size * 0.74 : size, h = p.shape === 'wide' ? size * 0.74 : size;
45
+ const bx = cx - w / 2, by = cy - h / 2, m = Math.min(w, h), kinds = cornersOf(p);
46
+ let s = rect(bx, by, w, h);
47
+ // corner i: its point, and the directions along its two edges into the block
48
+ const C = [[bx, by, 1, 1], [bx + w, by, -1, 1], [bx + w, by + h, -1, -1], [bx, by + h, 1, -1]];
49
+ C.forEach(([px, py, sx, sy], i) => {
50
+ const r = m * p.reach * (i % 2 ? p.second : 1), k = kinds[i], sq = rect(Math.min(px, px + sx * r), Math.min(py, py + sy * r), r, r);
51
+ if (k === 'round') s = U(D(s, sq), I(circle(px + sx * r, py + sy * r, r, 96), sq));
52
+ else if (k === 'cut') s = D(s, poly([[px, py], [px + sx * r, py], [px, py + sy * r]]));
53
+ else if (k === 'scoop') s = D(s, circle(px, py, r, 96));
54
+ else if (k === 'notch') s = D(s, rect(Math.min(px, px + sx * r * 0.8), Math.min(py, py + sy * r * 0.8), r * 0.8, r * 0.8));
55
+ });
56
+ return tidy(s);
57
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Counter: one solid whose hole is a DIFFERENT shape (a square with a leaf-shaped hole, a disc with a diamond one), the
3
+ * hole set in the middle or off towards a corner or a side. Never a round hole in a round body (a target), a triangle
4
+ * in a disc or a tile (a play button), or a disc in a leaf (an eye).
5
+ */
6
+ import { D, rot } from '@logomarks/core/geometry';
7
+ import { BOX, tidy } from '../draw.js';
8
+ import { prim, unlike } from '../primitives.js';
9
+
10
+ // the bodies with room for a hole that reads: a diamond, a leaf or a triangle leaves only a speck of one
11
+ // (and a disc takes almost no hole that isn't a sign: a pie chart, a stop button, an eye)
12
+ export const BODIES = ['square', 'rsquare', 'hexagon', 'half', 'quarter'];
13
+ export const HOLES = ['leaf', 'diamond', 'quarter', 'square', 'half', 'hexagon', 'pill', 'wedge', 'triangle', 'disc'];
14
+ /** Each body: where a hole sits (the body's middle, as shares of the box), how far it may move, and how big it may be. */
15
+ const ROOM = {
16
+ square: [0.5, 0.5, 0.17, 0.5], rsquare: [0.5, 0.5, 0.14, 0.48], hexagon: [0.5, 0.5, 0.08, 0.44],
17
+ half: [0.5, 0.6, 0.05, 0.38], quarter: [0.38, 0.62, 0.05, 0.4],
18
+ };
19
+ const MOVE = { centre: [0, 0], corner: [1, 1], side: [1, 0], low: [0, 1], high: [-1, -1] };
20
+
21
+ /** @type {import('../index.js').Control[]} */
22
+ export const controls = [
23
+ { key: 'body', label: 'Body', type: 'choice', options: BODIES, value: 'square' },
24
+ { key: 'hole', label: 'Hole', type: 'choice', options: HOLES, value: 'leaf' },
25
+ { key: 'size', label: 'Hole size', type: 'range', min: 0.24, max: 0.5, step: 0.01, value: 0.44 },
26
+ { key: 'place', label: 'Hole position', type: 'choice', options: ['centre', 'corner', 'side', 'low', 'high'], value: 'centre' },
27
+ { key: 'holeTurn', label: 'Turn hole', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
28
+ { key: 'spin', label: 'Turn body', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
29
+ ];
30
+
31
+ export const shapesOf = (p) => [p.body, unlike('counter', p.body, p.hole, HOLES)];
32
+
33
+ /** The mark for resolved params. */
34
+ export function build(p) {
35
+ const { x0, y0, size, cx, cy } = BOX, [body, hole] = shapesOf(p), [mx, my, reach, most] = ROOM[body] || ROOM.square;
36
+ const s = size * Math.min(p.size, most), [dx, dy] = MOVE[p.place] || MOVE.centre;
37
+ const hx = x0 + size * (mx + dx * reach) - s / 2, hy = y0 + size * (my + dy * reach) - s / 2;
38
+ const cut = D(prim(body, [x0, y0, size, size]), prim(hole, [hx, hy, s, s], Number(p.holeTurn) / 90));
39
+ return tidy(rot(cut, Number(p.spin), cx, cy));
40
+ }
@@ -17,7 +17,6 @@ import * as chevrons from './chevrons.js';
17
17
  import * as waves from './waves.js';
18
18
  import * as cut from './cut.js';
19
19
  import * as split from './split.js';
20
- import * as venn from './venn.js';
21
20
  import * as spiral from './spiral.js';
22
21
  import * as bloom from './bloom.js';
23
22
  import * as links from './links.js';
@@ -40,7 +39,13 @@ import * as wavecut from './wavecut.js';
40
39
  import * as capsules from './capsules.js';
41
40
  import * as flare from './flare.js';
42
41
  import * as seam from './seam.js';
43
- import * as pixelarc from './pixelarc.js';
42
+ import * as merge from './merge.js';
43
+ import * as overlap from './overlap.js';
44
+ import * as counter from './counter.js';
45
+ import * as pair from './pair.js';
46
+ import * as corners from './corners.js';
47
+ import * as offset from './offset.js';
48
+ import * as quarters from './quarters.js';
44
49
  import { FINISH, finish } from '../finish.js';
45
50
  import { TUNING } from '../tuning.js';
46
51
 
@@ -68,7 +73,6 @@ export const RECIPES = {
68
73
  waves: R('waves', 'Waves', 'Wavy bands, in step or turning.', waves),
69
74
  cut: R('cut', 'Cut', 'One solid with one cut: a bite, notch, slot or step.', cut),
70
75
  split: R('split', 'Split', 'A shape cut into slid parts by straight lines.', split),
71
- venn: R('venn', 'Venn', 'Overlapping circles or squares, xor, over or knocked out.', venn),
72
76
  spiral: R('spiral', 'Spiral', 'One round band coiled, with a dot or a tail.', spiral),
73
77
  bloom: R('bloom', 'Bloom', 'Petals round an open or dotted centre.', bloom),
74
78
  links: R('links', 'Links', 'Two or three loops woven like a chain.', links),
@@ -90,6 +94,12 @@ export const RECIPES = {
90
94
  wavecut: R('wavecut', 'Squiggle', 'A solid cut or worn by one wavy line.', wavecut),
91
95
  capsules: R('capsules', 'Capsule', 'Slanted capsules stacked, their lengths set by one rule.', capsules),
92
96
  flare: R('flare', 'Flare', 'Rays that widen as they run out, from a corner, a foot or a centre.', flare),
93
- pixelarc: R('pixelarc', 'Pixel', 'One bold figure drawn in square pixels.', pixelarc),
97
+ merge: R('merge', 'Merge', 'Two unlike shapes fused along one edge into a single solid.', merge),
98
+ overlap: R('overlap', 'Overlap', 'Two unlike shapes crossing, one over the other or the overlap knocked out.', overlap),
99
+ counter: R('counter', 'Counter', 'A solid whose hole is a different shape.', counter),
100
+ pair: R('pair', 'Split pair', 'A block split in two, each half a different shape.', pair),
101
+ corners: R('corners', 'Corners', 'One block, each corner treated a different way.', corners),
102
+ offset: R('offset', 'Offset', 'A shape and its copy slid aside, kept apart by the gap.', offset),
103
+ quarters: R('quarters', 'Quarters', 'Four big cells, each a different shape, turned by one rule.', quarters),
94
104
  seam: R('seam', 'Seam', 'A block parted in two by one seam with a joint in it.', seam),
95
105
  };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Merge: two unlike shapes fused along a shared edge into ONE solid. One sits over the other, flat side to flat side;
3
+ * the lower one is narrower and set to one side, so the join steps (a centred join reads as an object: a mushroom, a
4
+ * lamp, a house). Which two, where they meet, how wide the second is and which side it keeps are the controls.
5
+ */
6
+ import { rot } from '@logomarks/core/geometry';
7
+ import { BOX, tidy } from '../draw.js';
8
+ import { prim, unlike, join } from '../primitives.js';
9
+
10
+ // no triangle or diamond (fused to a block off centre, a point is an arrow), no disc or hexagon (they fuse into lumps
11
+ // with nicks where the outlines cross)
12
+ export const POOL = ['square', 'half', 'quarter', 'wedge', 'leaf', 'rsquare'];
13
+ /** Shapes with a flat lower edge the full width of their box: the others lap further into the join. */
14
+ const FLAT = ['square', 'half', 'quarter', 'wedge'];
15
+
16
+ /** @type {import('../index.js').Control[]} */
17
+ export const controls = [
18
+ { key: 'a', label: 'First shape', type: 'choice', options: POOL, value: 'half' },
19
+ { key: 'b', label: 'Second shape', type: 'choice', options: POOL, value: 'wedge' },
20
+ { key: 'at', label: 'Join', type: 'range', min: 0.36, max: 0.64, step: 0.01, value: 0.5 },
21
+ { key: 'width', label: 'Second width', type: 'range', min: 0.4, max: 1, step: 0.01, value: 0.62 },
22
+ { key: 'side', label: 'Side', type: 'choice', options: ['start', 'end'], value: 'start' },
23
+ { key: 'flip', label: 'Flip second', type: 'choice', options: ['no', 'yes'], value: 'no' },
24
+ { key: 'spin', label: 'Spin', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
25
+ ];
26
+
27
+ /** The two shapes as drawn (the second steered off a banned pair). */
28
+ export const shapesOf = (p) => [p.a, unlike('merge', p.a, p.b, POOL)];
29
+
30
+ /** The mark for resolved params. */
31
+ export function build(p) {
32
+ const { x0, y0, size, cx, cy } = BOX, [a, b] = shapesOf(p), ya = size * p.at;
33
+ const lapA = FLAT.includes(a) ? 1 : ya * 0.34, lapB = FLAT.includes(b) ? 1 : (size - ya) * 0.34;
34
+ const bw = size * p.width, bx = p.side === 'end' ? x0 + size - bw : x0;
35
+ const A = prim(a, [x0, y0, size, ya + lapA]);
36
+ const B = prim(b, [bx, y0 + ya - lapB, bw, size - ya + lapB], 2, p.flip === 'yes');
37
+ return tidy(rot(join(A, B), Number(p.spin), cx, cy));
38
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Offset: a shape and a copy of itself slid along one direction, the two kept apart by the house gap: the copy behind
3
+ * as a hard shadow, the overlap knocked out, or the overlap kept as its own piece. One or two copies.
4
+ */
5
+ import { U, D, I, move, grown, grow } from '@logomarks/core/geometry';
6
+ import { BOX, GAP, tidy } from '../draw.js';
7
+ import { prim } from '../primitives.js';
8
+
9
+ // no disc (two discs are a Venn pair, which `venn` draws), no arch (two arches are a known logo), no square (a copy icon)
10
+ export const POOL = ['triangle', 'half', 'quarter', 'leaf', 'diamond', 'hexagon', 'wedge', 'pill'];
11
+ const DIRS = { e: [1, 0], se: [1, 1], s: [0, 1], sw: [-1, 1], ne: [1, -1] };
12
+
13
+ /** @type {import('../index.js').Control[]} */
14
+ export const controls = [
15
+ { key: 'shape', label: 'Shape', type: 'choice', options: POOL, value: 'half' },
16
+ { key: 'way', label: 'Copy', type: 'choice', options: ['shadow', 'knock', 'keep'], value: 'shadow' },
17
+ { key: 'dir', label: 'Direction', type: 'choice', options: Object.keys(DIRS), value: 'se' },
18
+ { key: 'shift', label: 'Shift', type: 'range', min: 0.16, max: 0.4, step: 0.01, value: 0.28 },
19
+ { key: 'copies', label: 'Copies', type: 'range', min: 1, max: 2, step: 1, value: 1 },
20
+ { key: 'facing', label: 'Turn', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
21
+ { key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 1.6, step: 0.1, value: 1 },
22
+ ];
23
+
24
+ /** The mark for resolved params. */
25
+ export function build(p) {
26
+ const { x0, y0, size } = BOX, g = GAP * p.spacing, [dx, dy] = DIRS[p.dir] || DIRS.se, n = Math.round(p.copies);
27
+ const d = size * p.shift, s = size - d * n * 0.6, way = p.way;
28
+ const A = prim(p.shape, [x0, y0, s, s], Number(p.facing) / 90);
29
+ let acc = A, front = A;
30
+ for (let k = 1; k <= n; k++) {
31
+ const C = move(A, dx * d * k, dy * d * k);
32
+ if (way === 'shadow') acc = U(acc, D(C, grown(front, g)));
33
+ else { const both = I(front, C); const out = D(U(acc, C), grown(both, g / 2)); acc = way === 'keep' && both.length ? U(out, grow(both, -g / 2)) : out; }
34
+ front = way === 'shadow' ? U(front, C) : C;
35
+ }
36
+ return tidy(acc);
37
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Overlap: two unlike shapes crossing, with the house gap deciding how: one laid over the other and cut free by the
3
+ * gap, or the overlap itself knocked out (and, as a third way, kept as its own piece between them). The shapes sit on
4
+ * a diagonal, side by side or one above the other.
5
+ */
6
+ import { U, D, I, grown, grow } from '@logomarks/core/geometry';
7
+ import { BOX, GAP, tidy } from '../draw.js';
8
+ import { prim, unlike } from '../primitives.js';
9
+
10
+ // no ring or arch: a ring under another shape is an eye or a key, an arch under a disc a person
11
+ export const POOL = ['disc', 'square', 'triangle', 'half', 'quarter', 'leaf', 'diamond', 'hexagon', 'rsquare', 'pill', 'wedge'];
12
+
13
+ /** @type {import('../index.js').Control[]} */
14
+ export const controls = [
15
+ { key: 'a', label: 'First shape', type: 'choice', options: POOL, value: 'disc' },
16
+ { key: 'b', label: 'Second shape', type: 'choice', options: POOL, value: 'square' },
17
+ { key: 'way', label: 'Overlap', type: 'choice', options: ['over', 'knock', 'keep'], value: 'over' },
18
+ { key: 'layout', label: 'Arrangement', type: 'choice', options: ['diagonal', 'counter', 'row', 'column'], value: 'diagonal' },
19
+ { key: 'size', label: 'Shape size', type: 'range', min: 0.56, max: 0.78, step: 0.01, value: 0.66 },
20
+ { key: 'turnA', label: 'Turn first', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
21
+ { key: 'turnB', label: 'Turn second', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
22
+ { key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 1.6, step: 0.1, value: 1 },
23
+ ];
24
+
25
+ export const shapesOf = (p) => [p.a, unlike('overlap', p.a, p.b, POOL)];
26
+
27
+ /** The mark for resolved params. */
28
+ export function build(p) {
29
+ const { x0, y0, x1, y1, size, cx, cy } = BOX, [a, b] = shapesOf(p), s = size * p.size, g = GAP * p.spacing;
30
+ const boxes = p.layout === 'row' ? [[x0, cy - s / 2], [x1 - s, cy - s / 2]] : p.layout === 'column' ? [[cx - s / 2, y0], [cx - s / 2, y1 - s]] : p.layout === 'counter' ? [[x1 - s, y0], [x0, y1 - s]] : [[x0, y0], [x1 - s, y1 - s]];
31
+ const A = prim(a, [...boxes[0], s, s], Number(p.turnA) / 90), B = prim(b, [...boxes[1], s, s], Number(p.turnB) / 90);
32
+ if (p.way === 'over') return tidy(U(D(A, grown(B, g)), B));
33
+ const both = I(A, B);
34
+ if (!both.length) return tidy(U(A, B));
35
+ const out = D(U(A, B), grown(both, g / 2));
36
+ return tidy(p.way === 'keep' ? U(out, grow(both, -g / 2)) : out);
37
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Split pair: a block split down the middle, each half a DIFFERENT shape, the two facing each other across the house
3
+ * gap with their flat sides to the split. One half can slide along the split.
4
+ */
5
+ import { U, rot, move } from '@logomarks/core/geometry';
6
+ import { BOX, GAP, tidy } from '../draw.js';
7
+ import { prim, unlike } from '../primitives.js';
8
+
9
+ export const POOL = ['half', 'quarter', 'wedge', 'square', 'triangle', 'rsquare', 'leaf', 'hexagon'];
10
+ /** The turn that puts each shape's flat side to the right (a mirror puts it to the left). */
11
+ const FACE = { half: 1, triangle: 1, quarter: 0, wedge: 3, arch: 1, square: 0, rsquare: 0, leaf: 0, hexagon: 0 };
12
+
13
+ /** @type {import('../index.js').Control[]} */
14
+ export const controls = [
15
+ { key: 'a', label: 'First half', type: 'choice', options: POOL, value: 'half' },
16
+ { key: 'b', label: 'Second half', type: 'choice', options: POOL, value: 'quarter' },
17
+ { key: 'at', label: 'Split', type: 'range', min: 0.36, max: 0.64, step: 0.01, value: 0.5 },
18
+ { key: 'flipA', label: 'Flip first', type: 'choice', options: ['no', 'yes'], value: 'no' },
19
+ { key: 'flipB', label: 'Flip second', type: 'choice', options: ['no', 'yes'], value: 'no' },
20
+ { key: 'slide', label: 'Slide', type: 'range', min: 0, max: 0.3, step: 0.01, value: 0 },
21
+ { key: 'spin', label: 'Spin', type: 'choice', options: ['0', '45', '90', '135', '180', '270'], value: '0' },
22
+ { key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 2, step: 0.1, value: 1 },
23
+ ];
24
+
25
+ export const shapesOf = (p) => [p.a, unlike('pair', p.a, p.b, POOL)];
26
+
27
+ /** A half-shape in `box`, flat side to the right, flipped top to bottom with `flip`. */
28
+ function facing(type, box, flip) {
29
+ let s = prim(type, box, FACE[type] ?? 0);
30
+ if (flip) s = mapY(s, box[1] + box[3] / 2);
31
+ return s;
32
+ }
33
+ const mapY = (s, cy) => (typeof s[0][0][0] === 'number' ? [s] : s).map((pg) => pg.map((r) => r.map(([x, y]) => [x, 2 * cy - y])));
34
+
35
+ /** The mark for resolved params. */
36
+ export function build(p) {
37
+ const { x0, y0, size, cx, cy } = BOX, [a, b] = shapesOf(p), g = GAP * p.spacing, wa = (size - g) * p.at, wb = size - g - wa;
38
+ const A = facing(a, [x0, y0, wa, size], p.flipA === 'yes');
39
+ // the second half is the first's mirror image in the split: drawn facing right, then flipped left to right
40
+ const Bbox = [x0 + wa + g, y0, wb, size], bcx = Bbox[0] + wb / 2;
41
+ let B = facing(b, Bbox, p.flipB === 'yes');
42
+ B = (typeof B[0][0][0] === 'number' ? [B] : B).map((pg) => pg.map((r) => r.map(([x, y]) => [2 * bcx - x, y])));
43
+ const d = size * p.slide;
44
+ return tidy(rot(U(move(A, 0, -d / 2), move(B, 0, d / 2)), Number(p.spin), cx, cy));
45
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Quarters: a two by two grid of big cells, each a primitive, the four turned by ONE rule (all the same way, a quarter
3
+ * turn on from cell to cell, mirrored across the middle, or all facing in or out). Two to four different shapes fill
4
+ * it by a pattern. No more than two cells fill their inner corner, so the gap between them is never a plus.
5
+ */
6
+ import { U, I, rect } from '@logomarks/core/geometry';
7
+ import { BOX, GAP, tidy } from '../draw.js';
8
+ import { prim, alike } from '../primitives.js';
9
+
10
+ export const POOL = ['quarter', 'wedge', 'half', 'leaf', 'triangle', 'disc', 'square', 'diamond', 'rsquare'];
11
+ /** Which of the four chosen shapes each cell takes (top left, top right, bottom right, bottom left). */
12
+ const PATTERNS = { four: [0, 1, 2, 3], diagonal: [0, 1, 0, 1], rows: [0, 0, 1, 1], three: [0, 1, 2, 1] };
13
+
14
+ /** @type {import('../index.js').Control[]} */
15
+ export const controls = [
16
+ { key: 'a', label: 'Shape 1', type: 'choice', options: POOL, value: 'quarter' },
17
+ { key: 'b', label: 'Shape 2', type: 'choice', options: POOL, value: 'wedge' },
18
+ { key: 'c', label: 'Shape 3', type: 'choice', options: POOL, value: 'disc' },
19
+ { key: 'd', label: 'Shape 4', type: 'choice', options: POOL, value: 'leaf' },
20
+ { key: 'pattern', label: 'Pattern', type: 'choice', options: Object.keys(PATTERNS), value: 'four' },
21
+ { key: 'rule', label: 'Turn rule', type: 'choice', options: ['same', 'rotate', 'mirror', 'in', 'out'], value: 'rotate' },
22
+ { key: 'start', label: 'First turn', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
23
+ { key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 1.8, step: 0.1, value: 1 },
24
+ ];
25
+
26
+ /** The four shapes as drawn: each steered off any before it that it reads like. */
27
+ export function shapesOf(p) {
28
+ const out = [];
29
+ for (const s of [p.a, p.b, p.c, p.d]) {
30
+ let c = s;
31
+ for (let k = 0; k < POOL.length && out.some((o) => alike(o, c)); k++) c = POOL[(POOL.indexOf(c) + 1) % POOL.length];
32
+ out.push(c);
33
+ }
34
+ return out;
35
+ }
36
+
37
+ /** The mark for resolved params. */
38
+ export function build(p) {
39
+ const { x0, y0, size } = BOX, g = GAP * p.spacing, c = (size - g) / 2, shapes = shapesOf(p), t0 = Number(p.start) / 90;
40
+ const at = [[x0, y0], [x0 + c + g, y0], [x0 + c + g, y0 + c + g], [x0, y0 + c + g]];
41
+ // the turn that brings a shape's bottom-left corner to the grid's middle, for each cell
42
+ const inward = [1, 2, 3, 0];
43
+ const pick = PATTERNS[p.pattern] || PATTERNS.four;
44
+ let filled = 0;
45
+ const cells = at.map(([x, y], i) => {
46
+ // two discs never share a row (a pair of eyes): in the rows pattern a disc gives way to a leaf
47
+ const type = p.pattern === 'rows' && shapes[pick[i]] === 'disc' ? 'leaf' : shapes[pick[i]];
48
+ let turn = p.rule === 'rotate' ? t0 + i : p.rule === 'in' ? inward[i] + t0 * 0 : p.rule === 'out' ? inward[i] + 2 : p.rule === 'mirror' ? t0 : t0;
49
+ const mirror = p.rule === 'mirror' && (i === 1 || i === 2), flip = p.rule === 'mirror' && i >= 2;
50
+ const drawn = (tn) => prim(type, [x, y, c, c], tn + (flip ? (tn % 2 ? 0 : 0) : 0), mirror);
51
+ // the cell's inner corner: a small probe there says whether the shape fills it
52
+ const px = i === 0 || i === 3 ? x + c - 14 : x, py = i < 2 ? y + c - 14 : y, probe = rect(px, py, 14, 14);
53
+ const fills = (s) => I(s, probe).reduce((t, pg) => t + Math.abs(area(pg[0])), 0) > 14 * 14 * 0.6;
54
+ let s = drawn(turn);
55
+ if (flip) s = flipY(s, y + c / 2);
56
+ if (fills(s)) {
57
+ if (filled >= 2) { for (let k = 1; k < 4 && fills(s); k++) { s = drawn(turn + k); if (flip) s = flipY(s, y + c / 2); } if (fills(s)) s = prim('disc', [x, y, c, c]); }
58
+ if (fills(s)) filled++;
59
+ }
60
+ return s;
61
+ });
62
+ return tidy(U(...cells));
63
+ }
64
+
65
+ const area = (r) => { let t = 0; for (let i = 0; i < r.length; i++) { const [x1, y1] = r[i], [x2, y2] = r[(i + 1) % r.length]; t += x1 * y2 - x2 * y1; } return t / 2; };
66
+ const flipY = (s, cy) => (typeof s[0][0][0] === 'number' ? [s] : s).map((pg) => pg.map((r) => r.map(([x, y]) => [x, 2 * cy - y])));
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Stack: two to four primitive shapes laid out as a stack, a row, a grid, overlapping, nested or staggered, combined by
2
+ * Stack: a totem. Two to four primitive shapes laid out as a stack, a row, a grid, overlapping, nested or staggered, combined by
3
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
4
  * exclusive-or. Two shapes (A and B) and an order spread them over the slots; each can be turned. After marks that
5
5
  * stack and tweak simple shapes together.
@@ -8,6 +8,7 @@ import { U, D, X, rot } from '@logomarks/core/geometry';
8
8
  import { over } from '@logomarks/core/geometry';
9
9
  import { BOX, GAP, clear } from '../draw.js';
10
10
  import { primitive, PRIMITIVES } from '../shapes.js';
11
+ import { BANNED } from '../primitives.js';
11
12
 
12
13
  const TURNS = ['0', '90', '180', '270'];
13
14
 
@@ -15,11 +16,13 @@ const TURNS = ['0', '90', '180', '270'];
15
16
  export const controls = [
16
17
  { key: 'layout', label: 'Layout', type: 'choice', options: ['stack', 'row', 'grid', 'overlap', 'nest', 'stagger'], value: 'stack' },
17
18
  { 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: 'shapeA', label: 'Shape A', type: 'choice', options: PRIMITIVES, value: 'quarter' },
19
20
  { 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: 'shapeB', label: 'Shape B', type: 'choice', options: PRIMITIVES, value: 'parallelogram' },
21
22
  { 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: 'shapeC', label: 'Shape C', type: 'choice', options: PRIMITIVES, value: 'half' },
24
+ { key: 'turnC', label: 'Turn C', type: 'choice', options: TURNS, value: '0' },
25
+ { key: 'order', label: 'Order', type: 'choice', options: ['AB', 'AAB', 'ABB', 'ABA', 'A', 'ABC'], value: 'AB' },
23
26
  { key: 'step', label: 'Turn each', type: 'choice', options: ['none', 'quarter', 'half'], value: 'none' },
24
27
  { key: 'combine', label: 'Combine', type: 'choice', options: ['gap', 'over', 'cut', 'merge', 'xor'], value: 'gap' },
25
28
  { key: 'size', label: 'Shape size', type: 'range', min: 0.5, max: 1, step: 0.01, value: 1 },
@@ -50,14 +53,32 @@ function which(order, i) {
50
53
  return order === 'A' ? 'A' : order[i % order.length] || 'A';
51
54
  }
52
55
 
56
+ /** Why two shapes never sit next to each other in a stack or a row ('' when they may): a disc over a block is a person. */
57
+ const clash = (a, b) => (BANNED.stack.find(([p, q]) => (p === a && q === b) || (p === b && q === a)) || [])[2] || '';
58
+
59
+ /**
60
+ * The shape in each slot, in order: A, B and C by the order, then steered: in the ABC order no two the same, and in a
61
+ * stack, a row or a stagger no shape beside one it reads as an object with (the next shape of the list takes its place).
62
+ */
63
+ export function shapesOf(p) {
64
+ const n = Math.round(p.count), named = { A: p.shapeA, B: p.shapeB, C: p.shapeC || p.shapeA };
65
+ const out = Array.from({ length: n }, (_, i) => named[which(p.order, i)]);
66
+ if (!['stack', 'row', 'stagger', 'grid'].includes(p.layout)) return out;
67
+ for (let i = 1; i < n; i++) {
68
+ const bad = (c) => clash(out[i - 1], c) || (p.order === 'ABC' && out.slice(0, i).includes(c));
69
+ for (let k = 0; k < PRIMITIVES.length && bad(out[i]); k++) out[i] = PRIMITIVES[(PRIMITIVES.indexOf(out[i]) + 1) % PRIMITIVES.length];
70
+ }
71
+ return out;
72
+ }
73
+
53
74
  /** The mark for resolved params. */
54
75
  export function build(p) {
55
- const boxes = slots(p.layout, p.count, p.overlap);
76
+ const boxes = slots(p.layout, p.count, p.overlap), shapes = shapesOf(p);
56
77
  const parts = boxes.map(([x, y, w, h], i) => {
57
78
  const k = which(p.order, i), shrink = p.layout === 'nest' ? 1 : p.size;
58
79
  const bw = w * shrink, bh = h * shrink, bx = x + (w - bw) / 2, by = y + (h - bh) / 2;
59
80
  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);
81
+ return primitive(shapes[i], bx, by, bw, bh, Number(k === 'A' ? p.turnA : k === 'B' ? p.turnB : p.turnC || 0) / 90 + extra);
61
82
  });
62
83
  let acc = parts[0];
63
84
  for (const s of parts.slice(1)) {
package/src/tuning.js CHANGED
@@ -12,7 +12,9 @@ export const TUNING = {
12
12
  bars: { count: R(2, 4), weight: R(0.58, 0.8), cutSize: R(0.1, 0.2), cutAt: R(0.35, 0.65), lengths: { rare: 0.3 }, ends: { rare: 0.25 }, slant: rare(0.15, -20, 20), level: { rare: 0.1 }, cutAngle: rare(0.25, -35, 35), spine: { rare: 0.2 }, widths: { rare: 0.08, random: ['growing', 'thin-thick'] } },
13
13
  bands: { count: R(2, 3), weight: R(0.6, 0.8), ends: { rare: 0.3 }, slant: rare(0.15, -18, 18) },
14
14
  twin: { thickness: R(0.3, 0.42), slant: rare(0.3, -22, 22) },
15
- stack: { layout: of('stack', 'row', 'overlap', 'nest'), count: R(2, 3), order: of('AB', 'ABA', 'A'), step: { rare: 0.2 }, combine: of('gap', 'over', 'cut'), size: rare(0.3, 0.75, 1), overlap: R(0.2, 0.45) },
15
+ // a totem: three unlike shapes on one axis, the gap between (nests and overlaps threw outlines, eyes and busts: by hand only)
16
+ stack: { layout: of('stack', 'stack', 'row', 'stagger'), count: R(2, 3), order: of('ABC', 'ABC', 'ABA', 'AB'), step: { rare: 0.15 }, combine: of('gap'), size: rare(0.2, 0.8, 1), overlap: R(0.2, 0.45),
17
+ shapeA: of('square', 'half', 'quarter', 'triangle', 'parallelogram', 'pill', 'chevron', 'diamond', 'leaf', 'circle'), shapeB: of('square', 'half', 'quarter', 'triangle', 'parallelogram', 'pill', 'chevron', 'diamond', 'leaf', 'circle'), shapeC: of('square', 'half', 'quarter', 'triangle', 'parallelogram', 'pill', 'chevron', 'diamond', 'leaf', 'circle') },
16
18
  shear: { rows: R(1, 2), cols: R(2, 3), lean: of('same', 'rows', 'chevron'), angle: R(18, 32), drop: { rare: 0.25 }, spacing: R(1, 1.5), taper: rare(0.12, 0.1, 0.3), lengths: { rare: 0.3 }, slide: rare(0.2, 0.15, 0.4) },
17
19
  turns: { count: of('3', '4', '5', '6'), size: R(0.32, 0.46), stretch: rare(0.3, 0.8, 1.4), radius: R(0.06, 0.26), tilt: rare(0.35, -30, 30) },
18
20
  burst: { rays: R(5, 10), ray: of('bar', 'wedge', 'pill', 'drop'), width: R(0.1, 0.18), inner: R(0.06, 0.28), alternate: rare(0.2, 0.2, 0.45), twist: rare(0.2, -30, 30), move: { rare: 0.35 } },
@@ -25,7 +27,6 @@ export const TUNING = {
25
27
  waves: { count: R(2, 4), weight: R(0.55, 0.8), amplitude: R(0.05, 0.13), waves: R(0.75, 1.5), phase: rare(0.15, 30, 180), clip: { rare: 0.35 } },
26
28
  cut: { second: { rare: 0.2 } },
27
29
  split: { cuts: R(1, 2), twist: rare(0.15, 2, 6), spacing: R(1, 2) },
28
- venn: { count: R(2, 3), shape: of('circle', 'circle', 'rounded'), layout: of('row', 'triangle'), combine: of('xor', 'knockout'), overlap: R(0.28, 0.5) },
29
30
  spiral: { turns: R(1.25, 2.5), tail: rare(0.3, 0.2, 0.5), squash: rare(0.2, 0.75, 0.9) },
30
31
  bloom: { petals: R(4, 8), width: R(0.4, 0.8), twist: rare(0.25, -35, 35) },
31
32
  links: { weight: R(0.1, 0.16) },
@@ -48,7 +49,14 @@ export const TUNING = {
48
49
  capsules: { count: R(2, 3), lengths: of('stagger', 'grow', 'middle'), lean: R(16, 30), short: R(0.5, 0.75), softness: R(0.6, 1), cut: { rare: 0.15 }, spacing: R(1, 1.4) },
49
50
  flare: { rays: R(3, 5), inner: R(0.16, 0.3), spacing: R(1.2, 2), body: of('square', 'square', 'round') },
50
51
  seam: { body: of('square', 'square', 'rounded', 'disc', 'hexagon'), at: R(0.4, 0.6), size: R(0.2, 0.36), reach: R(0.14, 0.26), spacing: R(1, 1.5) },
51
- pixelarc: { curve: of('twin', 'twin', 'wave', 'wave', 'hook', 'arch'), grid: R(7, 10), weight: R(0.24, 0.42) },
52
+ // the composition recipes: the shapes are drawn evenly from their pools (a banned pair is steered in the build)
53
+ merge: { at: R(0.4, 0.6), width: R(0.45, 0.78) },
54
+ overlap: { way: of('over', 'over', 'knock', 'keep'), layout: of('diagonal', 'counter', 'row'), size: R(0.6, 0.74), spacing: R(1, 1.3) },
55
+ counter: { size: R(0.34, 0.5), place: of('centre', 'corner', 'side', 'low', 'high') },
56
+ pair: { at: R(0.4, 0.6), slide: rare(0.3, 0.12, 0.28), spin: of('0', '0', '90', '45', '135'), spacing: R(1, 1.5) },
57
+ corners: { reach: R(0.3, 0.5), second: rare(0.4, 0.5, 0.8), shape: of('square', 'square', 'square', 'wide', 'tall') },
58
+ offset: { way: of('shadow', 'shadow', 'knock', 'keep'), shift: R(0.2, 0.36), copies: R(1, 1), spacing: R(1, 1.3) },
59
+ quarters: { pattern: of('four', 'four', 'diagonal', 'three', 'rows'), spacing: R(1, 1.4) },
52
60
  };
53
61
 
54
62
  /** The two to four controls of each recipe that decide the mark: a page shows these first, the rest under "More". */
@@ -57,11 +65,14 @@ export const MAIN = {
57
65
  shear: ['rows', 'cols', 'lean', 'angle'], turns: ['unit', 'count', 'size', 'join'], burst: ['rays', 'ray', 'width', 'inner'], tiles: ['grid', 'layout', 'set', 'symmetry'],
58
66
  route: ['layout', 'steps', 'weight', 'node'], arcs: ['count', 'sweep', 'weight', 'legs'], rings: ['count', 'weight', 'gaps', 'shape'], stripes: ['shape', 'stripes', 'angle', 'move'],
59
67
  chevrons: ['count', 'angle', 'weight', 'point'], waves: ['count', 'weight', 'amplitude', 'clip'], cut: ['body', 'cut', 'side', 'size'], split: ['shape', 'cuts', 'angle', 'slide'],
60
- venn: ['count', 'shape', 'layout', 'combine'], spiral: ['turns', 'weight', 'start'], bloom: ['petals', 'petal', 'width', 'centre'], links: ['count', 'loop', 'layout', 'weight'],
68
+ spiral: ['turns', 'weight', 'start'], bloom: ['petals', 'petal', 'width', 'centre'], links: ['count', 'loop', 'layout', 'weight'],
61
69
  horizon: ['sun', 'size', 'lines', 'style'], steps: ['count', 'shape', 'tread'], hex: ['layout', 'density', 'symmetry'],
62
70
  iso: ['grid', 'layout', 'height'], letter: ['char', 'build', 'weight'],
63
71
  arcstep: ['layout', 'steps', 'weight', 'corners'], halfsq: ['grid', 'rule', 'facing'], invert: ['count', 'weight', 'region', 'angle'], leaves: ['tile', 'order', 'facing'],
64
72
  lobes: ['body', 'pieces', 'cuts', 'bend'], loops: ['petals', 'weight', 'spread', 'centre'], trine: ['body', 'offset', 'depth'],
65
73
  strips: ['layout', 'weight', 'angle'], bite: ['place', 'size', 'depth', 'body'], blades: ['count', 'grow', 'width', 'belly'],
66
- wavecut: ['body', 'move', 'waves', 'swell'], capsules: ['count', 'lengths', 'lean'], flare: ['origin', 'rays', 'body'], seam: ['joint', 'body', 'size', 'reach'], pixelarc: ['curve', 'grid', 'weight', 'facing'],
74
+ wavecut: ['body', 'move', 'waves', 'swell'], capsules: ['count', 'lengths', 'lean'], flare: ['origin', 'rays', 'body'], seam: ['joint', 'body', 'size', 'reach'],
75
+ merge: ['a', 'b', 'width', 'side'], overlap: ['a', 'b', 'way', 'layout'], counter: ['body', 'hole', 'size', 'place'], pair: ['a', 'b', 'at', 'spin'],
76
+ corners: ['nw', 'ne', 'se', 'sw'],
77
+ offset: ['shape', 'way', 'dir', 'shift'], quarters: ['a', 'b', 'pattern', 'rule'],
67
78
  };
@@ -1,59 +0,0 @@
1
- /**
2
- * Pixel Curve: one bold figure drawn in square pixels on a coarse grid, so its edges climb in steps: two arcs back to
3
- * back, a wave, an S, an open ring, a spiral turn, an arch or a hook. Heavy and in one or two pieces; never crumbs,
4
- * never a ring round a block (a target), never two holes side by side.
5
- */
6
- import { U, rect } from '@logomarks/core/geometry';
7
- import { BOX } from '../draw.js';
8
-
9
- /** @type {import('../index.js').Control[]} */
10
- export const controls = [
11
- { key: 'grid', label: 'Pixels', type: 'range', min: 5, max: 12, step: 1, value: 7 },
12
- { key: 'curve', label: 'Curve', type: 'choice', options: ['twin', 'wave', 'ess', 'cee', 'spiral', 'arch', 'hook', 'quarter'], value: 'twin' },
13
- { key: 'weight', label: 'Weight', type: 'range', min: 0.2, max: 0.42, step: 0.01, value: 0.3 },
14
- { key: 'facing', label: 'Facing', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
15
- ];
16
-
17
- /** Whether the point (u, v) of the unit square (v down) is ink. */
18
- function ink(p, u, v) {
19
- const t = p.weight, band = (r, R, w = t) => r <= R && r > R - w;
20
- if (p.curve === 'quarter') return band(Math.hypot(u, 1 - v), 1);
21
- if (p.curve === 'arch') { const r = Math.hypot(u - 0.5, Math.max(0, 0.5 - v)), x = Math.abs(u - 0.5); return v <= 0.5 ? band(r, 0.5) : band(x, 0.5); }
22
- // a hook: an arch upside down whose right leg stops short
23
- if (p.curve === 'hook') { const r = Math.hypot(u - 0.5, Math.max(0, v - 0.5)), x = Math.abs(u - 0.5); return v >= 0.5 ? band(r, 0.5) : u < 0.5 ? band(x, 0.5) : v > 0.3 && band(x, 0.5); }
24
- // twin: a quarter band round the top left corner and its twin round the bottom right, a clear lane between them
25
- if (p.curve === 'twin') { const w = Math.min(t, 0.3), R = 0.58; return band(Math.hypot(u, v), R, w) || band(Math.hypot(1 - u, 1 - v), R, w); }
26
- // wave: one band riding a full sine across the square
27
- if (p.curve === 'wave') { const w = Math.min(t * 1.25, 0.44), y = 0.5 - 0.5 * (1 - w) * Math.sin(u * Math.PI * 2); return Math.abs(v - y) <= w / 2; }
28
- // cee: a ring open to the right by at least one whole row of pixels (two on an even grid: one would close it and
29
- // leave a plus-shaped hole)
30
- if (p.curve === 'cee') { const x = u - 0.5, y = v - 0.5, r = Math.hypot(x, y), w = Math.min(t * 0.8, 0.3); return band(r, 0.5, w) && !(x > 0 && Math.abs(y) < Math.max((p.grid % 2 ? 0.51 : 1.01) / p.grid, w * 0.45)); }
31
- // spiral: one and a quarter turns of a band winding out from the middle
32
- if (p.curve === 'spiral') {
33
- const x = u - 0.5, y = v - 0.5, r = Math.hypot(x, y), a = (Math.atan2(y, x) + Math.PI * 2) % (Math.PI * 2), w = Math.min(t * 0.55, 0.17), pitch = 0.5 - w / 2 - 0.06;
34
- for (let k = 0; k < 2; k++) { const th = a + k * Math.PI * 2; if (th > Math.PI * 2.6) continue; const rc = 0.06 + w / 2 + (pitch * th) / (Math.PI * 2.6); if (Math.abs(r - rc) <= w / 2) return true; }
35
- return false;
36
- }
37
- // an S: two half rings, each open on its inner quarter
38
- const top = v < 0.5, r = Math.hypot(u - 0.5, v - (top ? 0.27 : 0.73)), R = 0.27;
39
- const open = top ? u > 0.5 && v > 0.27 : u < 0.5 && v < 0.73;
40
- return !open && r <= R && r > R - Math.min(t * 0.6, 0.17);
41
- }
42
-
43
- /** The mark for resolved params. */
44
- export function build(p) {
45
- // an open ring faces left or right only: opening up it is the power sign
46
- const n = p.grid, s = BOX.size / n, parts = [], q = p.curve === 'cee' ? (Number(p.facing) / 90) % 2 * 2 : Number(p.facing) / 90;
47
- for (let r = 0; r < n; r++) {
48
- let start = -1;
49
- for (let c = 0; c <= n; c++) {
50
- // the cell (r, c) seen from the facing: the grid turned by quarter turns
51
- let u = (c + 0.5) / n, v = (r + 0.5) / n;
52
- for (let k = 0; k < q; k++) [u, v] = [v, 1 - u];
53
- const on = c < n && ink(p, u, v);
54
- if (on && start < 0) start = c;
55
- if (!on && start >= 0) { parts.push(rect(BOX.x0 + start * s, BOX.y0 + r * s - 0.01, (c - start) * s, s + 0.02)); start = -1; }
56
- }
57
- }
58
- return parts.length ? U(...parts) : [];
59
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Venn: two to four circles or squares overlapping in a row, a triangle, a square or round a ring, combined by ONE
3
- * rule: exclusive-or (where they overlap is cut away), each laid over the one before with a gap round it, or the
4
- * overlaps knocked out by the gap. How far they overlap is a control. After overlapping-disc and interlocking-square
5
- * marks.
6
- */
7
- import { U, D, X, I, circle, rect, rr, grown } from '@logomarks/core/geometry';
8
- import { over } 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: 'count', label: 'Shapes', type: 'range', min: 2, max: 4, step: 1, value: 3 },
14
- { key: 'shape', label: 'Shape', type: 'choice', options: ['circle', 'square', 'rounded'], value: 'circle' },
15
- { key: 'layout', label: 'Layout', type: 'choice', options: ['row', 'triangle', 'square', 'ring'], value: 'triangle' },
16
- { key: 'overlap', label: 'Overlap', type: 'range', min: 0.15, max: 0.6, step: 0.01, value: 0.38 },
17
- { key: 'combine', label: 'Combine', type: 'choice', options: ['xor', 'over', 'knockout'], value: 'xor' },
18
- ];
19
-
20
- /** The centres for `n` shapes of radius r overlapping by `o` (a share of the diameter), before fitting. */
21
- function centres(layout, n, r, o) {
22
- const d = 2 * r * (1 - o);
23
- if (layout === 'row') return Array.from({ length: n }, (_, k) => [(k - (n - 1) / 2) * d, 0]);
24
- if (layout === 'square' && n === 4) return [[-d / 2, -d / 2], [d / 2, -d / 2], [d / 2, d / 2], [-d / 2, d / 2]];
25
- // triangle (and ring, and square for 2 or 3): round a circle so neighbours sit d apart
26
- const R = n === 2 ? d / 2 : d / (2 * Math.sin(Math.PI / n)), start = layout === 'ring' ? 0 : -90;
27
- return Array.from({ length: n }, (_, k) => { const a = ((start + (360 * k) / n) * Math.PI) / 180; return [R * Math.cos(a), R * Math.sin(a)]; });
28
- }
29
-
30
- /** One shape of radius r at (x, y). */
31
- function one(kind, x, y, r) {
32
- if (kind === 'square') return rect(x - r, y - r, 2 * r, 2 * r);
33
- if (kind === 'rounded') return rr(x - r, y - r, 2 * r, 2 * r, r * 0.35);
34
- return circle(x, y, r, 128);
35
- }
36
-
37
- /** The mark for resolved params. */
38
- export function build(p) {
39
- const n = p.count, r = 100, cs = centres(p.layout, n, r, p.overlap);
40
- const shapes = cs.map(([x, y]) => one(p.shape, BOX.cx + x, BOX.cy + y, r));
41
- let s = shapes[0];
42
- for (const q of shapes.slice(1)) {
43
- if (p.combine === 'xor') s = X(s, q);
44
- else if (p.combine === 'over') s = over(s, q, GAP);
45
- else s = U(D(s, grown(q, GAP / 2)), D(q, grown(s, GAP / 2))); // knockout: every overlap cut away with a gap
46
- }
47
- if (p.combine === 'knockout') {
48
- // knockout drawn pairwise: the overlap of any two goes, parted by the gap
49
- const ov = [];
50
- for (let i = 0; i < n; i++) for (let j = i + 1; j < n; j++) ov.push(I(shapes[i], shapes[j]));
51
- s = D(U(...shapes), grown(U(...ov), GAP / 2));
52
- }
53
- return tidy(s);
54
- }