@logomarks/generate 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/tuning.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Tuning: for each recipe, what a shuffle draws. The sliders keep their whole range for a hand; a shuffle stays in the
3
+ * part of it that gives a mark worth keeping (heavy weight, few big parts, the house gap) and makes ONE move: the
4
+ * second moves (a slant, a taper, a twist, a second cut) are `rare`, the chance a shuffle touches them at all. From
5
+ * contact sheets of every recipe's shuffles, judged against the live set. `value` here replaces a control's default.
6
+ */
7
+ const R = (lo, hi) => ({ random: [lo, hi] });
8
+ const rare = (p, lo, hi) => (lo === undefined ? { rare: p } : { rare: p, random: [lo, hi] });
9
+ const of = (...o) => ({ random: o });
10
+
11
+ export const TUNING = {
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
+ bands: { count: R(2, 3), weight: R(0.6, 0.8), ends: { rare: 0.3 }, slant: rare(0.15, -18, 18) },
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) },
16
+ 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
+ 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
+ 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 } },
19
+ tiles: { grid: R(2, 3), density: R(0.72, 1), symmetry: of('mirror', 'both', 'turn') },
20
+ route: { tracks: R(1, 1), steps: R(2, 3), weight: R(0.14, 0.2), node: of('none', 'diamond', 'square'), ends: of('square', 'node'), frame: { rare: 0.12 }, turns: { rare: 0.3 } },
21
+ arcs: { count: R(2, 3), weight: R(0.55, 0.8), core: { rare: 0.3 }, legs: R(0, 0.45), move: { rare: 0.3 }, corner: { rare: 0.35 }, slant: rare(0.1, -15, 15) },
22
+ rings: { count: R(2, 3), weight: R(0.55, 0.8), gaps: R(1, 2), gapSize: R(1.4, 3), centre: of('open', 'open', 'dot'), shape: of('circle', 'circle', 'rounded', 'hexagon'), offset: rare(0.15, 0.2, 0.5), breakKind: { rare: 0.15 } },
23
+ stripes: { stripes: R(4, 7), weight: R(0.5, 0.75), angle: R(-60, 60), move: of('none', 'shift', 'wave', 'taper', 'slot'), cover: rare(0.25, 0.5, 0.85), ends: { rare: 0.3 } },
24
+ chevrons: { count: R(2, 4), weight: R(0.5, 0.75), angle: R(75, 120), grow: rare(0.3, 0.15, 0.45), move: { rare: 0.35 } },
25
+ 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
+ cut: { second: { rare: 0.2 } },
27
+ 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
+ spiral: { turns: R(1.25, 2.5), tail: rare(0.3, 0.2, 0.5), squash: rare(0.2, 0.75, 0.9) },
30
+ bloom: { petals: R(4, 8), width: R(0.4, 0.8), twist: rare(0.25, -35, 35) },
31
+ links: { weight: R(0.1, 0.16) },
32
+ horizon: { lines: R(2, 4), stripes: R(2, 4), size: R(0.6, 0.9) },
33
+ steps: { count: R(3, 5), tread: R(0.45, 1), gap: rare(0.25, 1.2, 2), roundTreads: rare(0.25, 0.2, 0.5) },
34
+ hex: { rings: R(1, 1), density: R(0.5, 0.9), cell: { rare: 0.15 }, gap: R(1, 1.5) },
35
+ iso: { grid: R(2, 3), height: R(1, 2), density: R(0.5, 1) },
36
+ letter: { build: of('stencil', 'route', 'blocks'), weight: R(0.17, 0.26), slant: rare(0.12, -12, 12), spacing: R(1, 1.6) },
37
+ arcstep: { steps: R(1, 3), weight: R(0.66, 0.86), rise: rare(0.3, 0.7, 1.3), ends: { rare: 0.3 } },
38
+ halfsq: { grid: of('2x2'), rule: of('rows', 'same', 'checker', 'zigzag', 'diagonal'), spacing: R(1, 1.3) },
39
+ invert: { count: R(1, 3), weight: R(0.5, 0.66), region: of('half', 'half', 'quarter', 'disc'), shape: of('circle', 'circle', 'circle', 'rounded', 'hexagon'), size: R(0.34, 0.5) },
40
+ leaves: { softness: rare(0.3, 0.6, 1), spacing: rare(0.3, 0.8, 1.6), centre: { rare: 0.2 } },
41
+ lobes: { body: of('pebble', 'disc', 'square'), pieces: R(2, 3), cuts: of('tee'), bend: R(0.35, 0.95), balance: R(-0.1, 0.14), angle: R(0, 345), soften: R(0.5, 0.9), spacing: R(1, 1.4) },
42
+ loops: { petals: R(3, 6), weight: R(0.42, 0.56), spread: R(0.9, 1), stretch: rare(0.15, 1, 1.2), centre: of('open', 'open', 'dot') },
43
+ trine: { body: of('disc', 'disc', 'hexagon', 'square'), offset: R(0.24, 0.42), depth: R(0.66, 0.88), even: { rare: 0.25 }, spacing: R(1.3, 2), spin: rare(0.5, 0, 120) },
44
+ strips: { layout: of('square', 'square', 'zed', 'lean', 'vee'), weight: R(0.17, 0.24), angle: R(14, 45), overhang: R(0.04, 0.12), spacing: R(0.9, 1.3), flip: { rare: 0.5 } },
45
+ bite: { size: R(0.15, 0.22), depth: R(0.65, 1), slide: R(0.12, 0.2), softness: R(0.16, 0.28) },
46
+ blades: { count: R(2, 3), grow: R(0.25, 0.65), width: R(1.5, 2.4), belly: R(0.6, 1), edge: { rare: 0.2 }, lean: rare(0.3, -14, 14) },
47
+ wavecut: { move: of('split'), waves: R(1.5, 2.5), swell: R(0.07, 0.12), at: R(0.42, 0.58), spacing: R(1.1, 1.7) },
48
+ 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
+ flare: { rays: R(3, 5), inner: R(0.16, 0.3), spacing: R(1.2, 2), body: of('square', 'square', 'round') },
50
+ 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
+ };
53
+
54
+ /** The two to four controls of each recipe that decide the mark: a page shows these first, the rest under "More". */
55
+ export const MAIN = {
56
+ bars: ['count', 'weight', 'cut', 'ends'], bands: ['count', 'weight', 'join', 'extra'], twin: ['piece', 'thickness', 'corner', 'ends'], stack: ['layout', 'shapeA', 'shapeB', 'combine'],
57
+ shear: ['rows', 'cols', 'lean', 'angle'], turns: ['unit', 'count', 'size', 'join'], burst: ['rays', 'ray', 'width', 'inner'], tiles: ['grid', 'layout', 'set', 'symmetry'],
58
+ route: ['layout', 'steps', 'weight', 'node'], arcs: ['count', 'sweep', 'weight', 'legs'], rings: ['count', 'weight', 'gaps', 'shape'], stripes: ['shape', 'stripes', 'angle', 'move'],
59
+ 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'],
61
+ horizon: ['sun', 'size', 'lines', 'style'], steps: ['count', 'shape', 'tread'], hex: ['layout', 'density', 'symmetry'],
62
+ iso: ['grid', 'layout', 'height'], letter: ['char', 'build', 'weight'],
63
+ arcstep: ['layout', 'steps', 'weight', 'corners'], halfsq: ['grid', 'rule', 'facing'], invert: ['count', 'weight', 'region', 'angle'], leaves: ['tile', 'order', 'facing'],
64
+ lobes: ['body', 'pieces', 'cuts', 'bend'], loops: ['petals', 'weight', 'spread', 'centre'], trine: ['body', 'offset', 'depth'],
65
+ 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'],
67
+ };
@@ -1,74 +0,0 @@
1
- /**
2
- * Blobs: two to five discs of different sizes fused by soft necks (a metaball bridge between each pair of neighbours:
3
- * the quad between the two circles' tangent points with two fillet circles, tangent to both, taken out of its sides),
4
- * in a row, an arc or a cluster laid out by a number. Organic, never a
5
- * face: the sizes always differ, so no two equal discs sit side by side over a third.
6
- */
7
- import { U, D, poly, circle } from '@logomarks/core/geometry';
8
- import { BOX } from '../draw.js';
9
- import { rng } from '../random.js';
10
-
11
- /** @type {import('../index.js').Control[]} */
12
- export const controls = [
13
- { key: 'count', label: 'Blobs', type: 'range', min: 2, max: 5, step: 1, value: 3 },
14
- { key: 'layout', label: 'Layout', type: 'choice', options: ['row', 'arc', 'cluster'], value: 'cluster' },
15
- { key: 'shape', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 8 },
16
- { key: 'spread', label: 'Size spread', type: 'range', min: 0.2, max: 0.7, step: 0.01, value: 0.45 },
17
- { key: 'neck', label: 'Neck', type: 'range', min: 10, max: 90, step: 1, value: 40 },
18
- { key: 'apart', label: 'Apart', type: 'range', min: 0.75, max: 1.15, step: 0.01, value: 0.95 },
19
- ];
20
-
21
- /** The discs: [x, y, r], each touching (or nearly) the one before, sizes all different. */
22
- function discs(p) {
23
- const rand = rng(`blobs:${p.shape}:${p.count}`), n = p.count, out = [];
24
- // radii: a falling run, shuffled a little, so no two are equal
25
- const radii = Array.from({ length: n }, (_, k) => 100 * (1 - p.spread * (k / Math.max(1, n - 1))) * (0.92 + rand() * 0.16));
26
- if (p.layout !== 'row') radii.sort(() => rand() - 0.5);
27
- let a = rand() * Math.PI * 2;
28
- for (let k = 0; k < n; k++) {
29
- const r = radii[k];
30
- if (!k) { out.push([0, 0, r]); continue; }
31
- const prev = out[k - 1], d = (prev[2] + r) * p.apart;
32
- if (p.layout === 'row') a = 0;
33
- else if (p.layout === 'arc') a += 0.75;
34
- else {
35
- // cluster: try angles until the new disc keeps clear of all but the one it hangs on
36
- let best = a, score = -Infinity;
37
- for (let t = 0; t < 12; t++) {
38
- const cand = rand() * Math.PI * 2, x = prev[0] + d * Math.cos(cand), y = prev[1] + d * Math.sin(cand);
39
- const s = Math.min(...out.slice(0, -1).map(([ox, oy, or]) => Math.hypot(x - ox, y - oy) - or - r), 999);
40
- if (s > score) { score = s; best = cand; }
41
- }
42
- a = best;
43
- }
44
- out.push([prev[0] + d * Math.cos(a), prev[1] + d * Math.sin(a), r]);
45
- }
46
- return out;
47
- }
48
-
49
- /**
50
- * The soft neck between two discs: two fillet circles of radius f, each tangent to both discs, and the quad between
51
- * their tangent points with the fillets taken out. Null when the discs are too far apart for a fillet of that size.
52
- */
53
- function bridge([x1, y1, r1], [x2, y2, r2], f) {
54
- const d = Math.hypot(x2 - x1, y2 - y1), a1 = r1 + f, a2 = r2 + f;
55
- if (d >= a1 + a2 || d <= Math.abs(a1 - a2)) return null;
56
- const ux = (x2 - x1) / d, uy = (y2 - y1) / d, cos = (a1 * a1 + d * d - a2 * a2) / (2 * a1 * d), sin = Math.sqrt(Math.max(0, 1 - cos * cos));
57
- const pts = [], cuts = [];
58
- for (const s of [1, -1]) {
59
- const fx = x1 + a1 * (ux * cos - uy * sin * s), fy = y1 + a1 * (uy * cos + ux * sin * s);
60
- pts.push([[x1 + ((fx - x1) * r1) / a1, y1 + ((fy - y1) * r1) / a1], [x2 + ((fx - x2) * r2) / a2, y2 + ((fy - y2) * r2) / a2]]);
61
- cuts.push(circle(fx, fy, f, 64));
62
- }
63
- return D(poly([pts[0][0], pts[0][1], pts[1][1], pts[1][0]]), U(...cuts));
64
- }
65
-
66
- /** The mark for resolved params. */
67
- export function build(p) {
68
- const ds = discs(p).map(([x, y, r]) => [BOX.cx + x, BOX.cy + y, r]), parts = ds.map(([x, y, r]) => circle(x, y, r, 96));
69
- for (let i = 0; i < ds.length; i++) for (let j = i + 1; j < ds.length; j++) {
70
- const b = bridge(ds[i], ds[j], p.neck);
71
- if (b) parts.push(b);
72
- }
73
- return U(...parts);
74
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Dashes: two to five rows of dashes, the house gap between rows and between dashes, each row broken by ONE rhythm
3
- * (long then short, short then long, even halves, a dash and a dot, one then two), the rows set flush left, centred,
4
- * flush right or staggered, their lengths equal, falling or rising, the ends square or round. The breaks drift from row to
5
- * row by default: short pieces lined up down one side read as a bulleted list (a UI icon). After Hematonix-style
6
- * dash marks and speed lines.
7
- */
8
- import { U, rect, rr } from '@logomarks/core/geometry';
9
- import { BOX, GAP } from '../draw.js';
10
-
11
- /** @type {import('../index.js').Control[]} */
12
- export const controls = [
13
- { key: 'rows', label: 'Rows', type: 'range', min: 2, max: 5, step: 1, value: 3 },
14
- { key: 'rhythm', label: 'Rhythm', type: 'choice', options: ['long-short', 'short-long', 'halves', 'dash-dot', 'one-two', 'alternate'], value: 'long-short' },
15
- { key: 'align', label: 'Align', type: 'choice', options: ['left', 'centre', 'right', 'stagger'], value: 'left' },
16
- { key: 'lengths', label: 'Lengths', type: 'choice', options: ['equal', 'falling', 'rising', 'middle'], value: 'equal' },
17
- { key: 'weight', label: 'Weight', type: 'range', min: 0.22, max: 0.6, step: 0.01, value: 0.34 },
18
- { key: 'split', label: 'Break at', type: 'range', min: 0.2, max: 0.5, step: 0.01, value: 0.3 },
19
- { key: 'drift', label: 'Drift', type: 'range', min: -0.15, max: 0.15, step: 0.01, value: 0.1 },
20
- { key: 'spacing', label: 'Dash gap', type: 'range', min: 1, max: 3, step: 0.1, value: 1.6 },
21
- { key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round'], value: 'square' },
22
- ];
23
-
24
- /** A row's dashes as [from, to] shares of its length, for a rhythm, row k. */
25
- function pieces(rhythm, k, split, gapShare) {
26
- const g = gapShare, a = split;
27
- if (rhythm === 'long-short') return [[0, 1 - a - g / 2], [1 - a + g / 2, 1]];
28
- if (rhythm === 'halves') return [[0, 0.5 - g / 2], [0.5 + g / 2, 1]];
29
- if (rhythm === 'dash-dot') return [[0, 1 - a * 0.6 - g], [1 - a * 0.6, 1]];
30
- if (rhythm === 'one-two') return k % 2 ? [[0, 0.5 - g / 2], [0.5 + g / 2, 1]] : [[0, 1]];
31
- if (rhythm === 'alternate') return k % 2 ? [[0, 1 - a - g / 2], [1 - a + g / 2, 1]] : [[0, a - g / 2], [a + g / 2, 1]];
32
- return [[0, a - g / 2], [a + g / 2, 1]]; // short-long
33
- }
34
-
35
- /** How long row k of n is, as a share of the box, for a lengths setting. */
36
- function lengthOf(lengths, k, n) {
37
- const t = n === 1 ? 0 : k / (n - 1);
38
- if (lengths === 'falling') return 1 - 0.4 * t;
39
- if (lengths === 'rising') return 0.6 + 0.4 * t;
40
- if (lengths === 'middle') return 1 - 0.4 * Math.abs(2 * t - 1);
41
- return 1;
42
- }
43
-
44
- /** The mark for resolved params. */
45
- export function build(p) {
46
- const n = p.rows, pitch = (BOX.size + GAP) / n, h = Math.max(GAP * 1.2, Math.min(pitch - GAP, pitch * p.weight * 1.6, BOX.size * 0.2)), parts = [];
47
- const used = n * h + (n - 1) * Math.max(GAP, pitch - h), top = BOX.cy - used / 2, step = h + Math.max(GAP, pitch - h);
48
- for (let k = 0; k < n; k++) {
49
- const L = BOX.size * lengthOf(p.lengths, k, n), y = top + k * step;
50
- let x0 = p.align === 'right' ? BOX.x1 - L : p.align === 'centre' ? BOX.cx - L / 2 : BOX.x0;
51
- if (p.align === 'stagger') x0 = k % 2 ? BOX.x1 - L * 0.88 : BOX.x0, x0 = Math.max(BOX.x0, x0);
52
- const len = p.align === 'stagger' ? L * 0.88 : L, gapShare = (GAP * p.spacing) / len;
53
- const split = Math.min(0.75, Math.max(0.12, p.split + p.drift * (k - (n - 1) / 2)));
54
- for (const [a, b] of pieces(p.rhythm, k, split, gapShare)) {
55
- const xa = x0 + a * len, w = (b - a) * len;
56
- if (w < 2) continue;
57
- parts.push(p.ends === 'round' ? rr(xa, y, w, h, Math.min(h, w) / 2) : rect(xa, y, w, h));
58
- }
59
- }
60
- return U(...parts);
61
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * Dots: a grid of dots (discs, squares or diamonds) whose size follows ONE rule: a gradient across, a radial swell from
3
- * the centre, a ring, or a wave, the smallest left out, so a shape appears from the sizes alone. After halftone discs,
4
- * dot gradients and dissolves.
5
- */
6
- import { U, circle, rect, poly } 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: 'Grid', type: 'range', min: 4, max: 9, step: 1, value: 7 },
12
- { key: 'dot', label: 'Dot', type: 'choice', options: ['circle', 'square', 'diamond'], value: 'circle' },
13
- { key: 'rule', label: 'Rule', type: 'choice', options: ['gradient', 'radial', 'ring', 'wave', 'corner'], value: 'radial' },
14
- { key: 'angle', label: 'Direction', type: 'range', min: 0, max: 315, step: 45, value: 0 },
15
- { key: 'size', label: 'Biggest', type: 'range', min: 0.6, max: 1, step: 0.01, value: 0.92 },
16
- { key: 'cutoff', label: 'Leave out under', type: 'range', min: 0.1, max: 0.5, step: 0.01, value: 0.28 },
17
- { key: 'invert', label: 'Invert', type: 'toggle', value: false },
18
- ];
19
-
20
- /** How big the dot at u, v (−1 to 1 across the grid) is, 0–1, for a rule. */
21
- function weight(rule, u, v, angle) {
22
- const a = (angle * Math.PI) / 180, along = (u * Math.cos(a) + v * Math.sin(a) + 1.414) / 2.828, r = Math.hypot(u, v) / 1.414;
23
- if (rule === 'gradient') return along;
24
- if (rule === 'ring') return 1 - Math.min(1, Math.abs(r - 0.6) * 2.6);
25
- if (rule === 'wave') return 0.5 + 0.5 * Math.sin((u * Math.cos(a) + v * Math.sin(a)) * Math.PI * 1.5);
26
- if (rule === 'corner') return 1 - Math.hypot(u - Math.cos(a) * 1, v - Math.sin(a) * 1) / 2.6;
27
- return 1 - r; // radial
28
- }
29
-
30
- /** The mark for resolved params. */
31
- export function build(p) {
32
- const n = p.grid, cell = BOX.size / n, parts = [];
33
- for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) {
34
- const u = n === 1 ? 0 : (2 * i) / (n - 1) - 1, v = n === 1 ? 0 : (2 * j) / (n - 1) - 1;
35
- let w = Math.max(0, Math.min(1, weight(p.rule, u, v, p.angle)));
36
- if (p.invert) w = 1 - w;
37
- if (w < p.cutoff) continue;
38
- const s = cell * p.size * Math.sqrt(w);
39
- if (s < 26) continue; // under about 1.8 px at 32 px: noise
40
- const cx = BOX.x0 + (i + 0.5) * cell, cy = BOX.y0 + (j + 0.5) * cell;
41
- parts.push(p.dot === 'square' ? rect(cx - s / 2, cy - s / 2, s, s) : p.dot === 'diamond' ? poly([[cx, cy - s * 0.6], [cx + s * 0.6, cy], [cx, cy + s * 0.6], [cx - s * 0.6, cy]]) : circle(cx, cy, s / 2, 40));
42
- }
43
- return parts.length ? U(...parts) : [];
44
- }
45
-
46
- /** Dots are many pieces by design; small ones are the point, so specks are judged by size alone. */
47
- export const guard = { maxPieces: 81, minPieceShare: 0.002, minMeanWidth: 10, maxThinShare: 0.15 };
@@ -1,73 +0,0 @@
1
- /**
2
- * Fan: three to nine blades (bars, wedges, pills or leaves) fanned out from a pivot at a corner, the middle of the foot
3
- * or the centre, over a spread angle, the house gap between them at the narrow end so they open out, their lengths even,
4
- * arched or long and short. Never rising: blades that grow across read as a signal-strength icon. After fanned-blade and sunrise marks.
5
- * The default is a quarter fan of pills from a corner: wedges spread in a half circle from the foot read as a
6
- * rising sun (too near the flag).
7
- */
8
- import { U, D, I, poly, circle, pill, rot, sector } 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: 'blades', label: 'Blades', type: 'range', min: 3, max: 9, step: 1, value: 4 },
14
- { key: 'blade', label: 'Blade', type: 'choice', options: ['wedge', 'bar', 'pill', 'leaf'], value: 'pill' },
15
- { key: 'pivot', label: 'Pivot', type: 'choice', options: ['corner', 'foot', 'centre'], value: 'corner' },
16
- { key: 'spread', label: 'Spread', type: 'range', min: 60, max: 240, step: 5, value: 90 },
17
- { key: 'inner', label: 'Open centre', type: 'range', min: 0, max: 0.45, step: 0.01, value: 0.18 },
18
- { key: 'lengths', label: 'Lengths', type: 'choice', options: ['even', 'arch', 'alternate'], value: 'even' },
19
- { key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 2.5, step: 0.1, value: 1.2 },
20
- ];
21
-
22
- /** The pivot point, the reach of the longest blade, and the middle angle (degrees, 0 = right, −90 = up). */
23
- function frame(pivot, spread) {
24
- const { x0, y1, cx, cy, size } = BOX;
25
- if (pivot === 'corner') return { px: x0, py: y1, R: size, mid: -45, spread: Math.min(spread, 90) };
26
- if (pivot === 'centre') return { px: cx, py: cy + (spread <= 180 ? size * 0.22 : 0), R: spread <= 180 ? size * 0.72 : size / 2, mid: -90, spread };
27
- return { px: cx, py: y1, R: size * (spread > 180 ? 0.5 : 0.92), mid: -90, spread: Math.min(spread, 180) };
28
- }
29
-
30
- /** How long blade k of n is, a share of the reach. */
31
- function lengthOf(lengths, k, n) {
32
- const t = n === 1 ? 0 : k / (n - 1);
33
- if (lengths === 'arch') return 1 - 0.4 * Math.abs(2 * t - 1);
34
- if (lengths === 'alternate') return k % 2 ? 0.72 : 1;
35
- return 1;
36
- }
37
-
38
- /** One blade along angle 0 (pointing right) from r0 to r1, `w` its angular width in degrees at its outer end. */
39
- function blade(kind, px, py, r0, r1, a0, a1) {
40
- const mid = (a0 + a1) / 2, half = (((a1 - a0) / 2) * Math.PI) / 180, wOut = 2 * r1 * Math.sin(half);
41
- const along = (r) => { const t = (mid * Math.PI) / 180; return [px + r * Math.cos(t), py + r * Math.sin(t)]; };
42
- if (kind === 'bar') { const w = Math.max(GAP * 1.4, 2 * ((r0 + r1) / 2) * Math.sin(half) * 0.9); const [ax, ay] = along(r0), [bx, by] = along(r1); return rot(poly([[ax, ay - w / 2], [ax + (r1 - r0), ay - w / 2], [ax + (r1 - r0), ay + w / 2], [ax, ay + w / 2]]), mid, ax, ay); }
43
- if (kind === 'pill') { const w = Math.max(GAP * 1.4, 2 * ((r0 + r1) / 2) * Math.sin(half) * 0.9); return pill(along(r0 + w / 2), along(r1 - w / 2), w); }
44
- if (kind === 'leaf') {
45
- const [ax, ay] = along(r0), [bx, by] = along(r1), L = Math.hypot(bx - ax, by - ay), w = Math.min(wOut * 0.9, L * 0.45);
46
- if (w < GAP || L < GAP * 2) return D(sector(px, py, r1, a0, a1, 48), circle(px, py, r0, 96)); // too short for a leaf
47
- const R = (L * L / 4 + w * w / 4) / w; // the arc through both tips and the leaf's widest point
48
- const mx = (ax + bx) / 2, my = (ay + by) / 2, nx = -(by - ay) / L, ny = (bx - ax) / L, off = R - w / 2;
49
- return I(circle(mx + nx * off, my + ny * off, R, 160), circle(mx - nx * off, my - ny * off, R, 160));
50
- }
51
- return D(sector(px, py, r1, a0, a1, 48), circle(px, py, r0, 96)); // wedge
52
- }
53
-
54
- /** The mark for resolved params. */
55
- export function build(p) {
56
- const f = frame(p.pivot, p.spread), g = GAP * p.spacing, spreadRad = (f.spread * Math.PI) / 180;
57
- const n = Math.max(3, Math.min(p.blades, Math.floor(f.spread / 22))); // about one blade per 22° at most: crowded blades go to needles
58
- // the blades start far enough out that their gaps take at most 40% of the arc there and every blade's inner end is at
59
- // least 1.2 gaps wide (a wedge tapering to a needle is a thin part at 32 px)
60
- const r0 = Math.min(f.R * 0.62, Math.max(p.inner * f.R, GAP * 2, ((n - 1) * g) / (0.4 * spreadRad), (1.2 * GAP * n) / (0.6 * spreadRad)));
61
- const gapDeg = (g / r0) * (180 / Math.PI);
62
- const each = (f.spread - (n - 1) * gapDeg) / n;
63
- if (each <= 1) return [];
64
- const parts = [];
65
- for (let k = 0; k < n; k++) {
66
- const a0 = f.mid - f.spread / 2 + k * (each + gapDeg), a1 = a0 + each;
67
- parts.push(blade(p.blade, f.px, f.py, r0, f.R * lengthOf(p.lengths, k, n), a0, a1));
68
- }
69
- return tidy(U(...parts));
70
- }
71
-
72
- /** Wedges and leaves end in points by design: a little more of the ink may be thin. */
73
- export const guard = { maxThinShare: 0.07 };
@@ -1,66 +0,0 @@
1
- /**
2
- * Fold: ONE heavy band zigzagging two to five times. As a crease (sharp mitred turns), round (rounded turns), notched
3
- * (each run its own piece, the house gap at every turn, as if the band were cut at its folds) or a ribbon (the band run
4
- * across and back, row under row, a 45° fold line slit through it at every turn). Level
5
- * or upright. After folded-ribbon and zigzag-band marks.
6
- */
7
- import { U, D, rect, stroke, grown, rot } from '@logomarks/core/geometry';
8
- import { BOX, GAP, tidy } from '../draw.js';
9
-
10
- /** @type {import('../index.js').Control[]} */
11
- export const controls = [
12
- { key: 'folds', label: 'Folds', type: 'range', min: 2, max: 5, step: 1, value: 3 },
13
- { key: 'style', label: 'Style', type: 'choice', options: ['ribbon', 'crease', 'round', 'notch'], value: 'ribbon' },
14
- { key: 'weight', label: 'Weight', type: 'range', min: 0.1, max: 0.26, step: 0.005, value: 0.17 },
15
- { key: 'depth', label: 'Depth', type: 'range', min: 0.3, max: 1, step: 0.01, value: 0.7 },
16
- { key: 'upright', label: 'Upright', type: 'toggle', value: false },
17
- ];
18
-
19
- /** A zigzag's turning points: `folds` + 1 runs across the box, rising and falling by `depth` of the box. */
20
- function zigzag(folds, depth, w) {
21
- const n = folds + 1, { x0, size, cy } = BOX, a = ((size - w) * depth) / 2;
22
- return Array.from({ length: n + 1 }, (_, k) => [x0 + w / 2 + ((size - w) * k) / n, cy + (k % 2 ? -a : a)]);
23
- }
24
-
25
- /**
26
- * A ribbon folded flat: the band runs across the box and back, row under row, and at every turn a fold line, a slit the
27
- * gap wide on the 45° from the turn's inner corner to its outer one, so it reads as one strip creased.
28
- */
29
- function ribbon(folds, w) {
30
- const rows = folds + 1, { x0, x1, y0, size } = BOX, gap = Math.max(GAP, (size - rows * w) / Math.max(1, rows - 1));
31
- const pitch = w + gap, xa = x0 + w / 2, xb = x1 - w / 2, pts = [], slits = [];
32
- for (let k = 0; k < rows; k++) {
33
- const y = y0 + w / 2 + k * pitch, right = k % 2 === 0;
34
- pts.push(right ? [xa, y] : [xb, y], right ? [xb, y] : [xa, y]);
35
- }
36
- const band = stroke(pts, w);
37
- // the fold lines: at each corner of the run, from its inner corner to its outer one
38
- for (let i = 1; i < pts.length - 1; i++) {
39
- const [x, y] = pts[i], [px, py] = pts[i - 1], [nx, ny] = pts[i + 1];
40
- const din = [Math.sign(px - x) + Math.sign(nx - x), Math.sign(py - y) + Math.sign(ny - y)]; // towards the inner corner
41
- const len = w * 1.6, ang = (Math.atan2(din[1], din[0]) * 180) / Math.PI;
42
- slits.push(rot(rect(x - len / 2, y - (GAP * 0.9) / 2, len, GAP * 0.9), ang, x, y));
43
- }
44
- return D(band, U(...slits));
45
- }
46
-
47
- /** The mark for resolved params. */
48
- export function build(p) {
49
- const w = p.weight * BOX.size;
50
- let s;
51
- if (p.style === 'ribbon') s = ribbon(p.folds, w);
52
- else {
53
- const pts = zigzag(p.folds, p.depth, w);
54
- if (p.style === 'notch') {
55
- // each run its own bar, the later ones cleared from the earlier by the gap at the turns
56
- let acc = null;
57
- for (let k = 0; k < pts.length - 1; k++) {
58
- const bar = stroke([pts[k], pts[k + 1]], w);
59
- acc = acc ? U(acc, D(bar, grown(acc, GAP))) : bar;
60
- }
61
- s = acc;
62
- } else s = stroke(pts, w, { roundCaps: p.style === 'round' });
63
- if (p.style === 'round') s = U(s, ...pts.slice(1, -1).map(([x, y]) => rect(x - 0.5, y - 0.5, 1, 1)));
64
- }
65
- return tidy(p.upright ? rot(s, 90, BOX.cx, BOX.cy) : s);
66
- }
@@ -1,142 +0,0 @@
1
- /**
2
- * Line: ONE heavy stroke walked through three to six points of a 4 × 4 lattice, mitred or rounded at its turns, with
3
- * round, square or angled ends and ONE optional move: a round loop at a turn, a hairpin fold at its end, or its start
4
- * crossing its end with a gap (over and under). After monoline marks: a looped A, a hooked path, a folded stroke.
5
- * Banned reads: never two loops; a four-point zigzag is the lightning bolt and three points with a short first leg at a
6
- * right angle are the tick icon, so those layouts are passed over for the next. A loop at the tip of a narrow V (its
7
- * two legs opening under 100°) is the awareness ribbon, so a loop only goes at a wider turn, and a layout with none
8
- * passes to the next walk.
9
- */
10
- import { U, D, poly, circle, stroke } from '@logomarks/core/geometry';
11
- import { BOX, GAP, clear } from '../draw.js';
12
- import { rng } from '../random.js';
13
-
14
- /** @type {import('../index.js').Control[]} */
15
- export const controls = [
16
- { key: 'points', label: 'Points', type: 'range', min: 3, max: 6, step: 1, value: 4 },
17
- { key: 'layout', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 9 },
18
- { key: 'stroke', label: 'Stroke', type: 'range', min: 0.12, max: 0.22, step: 0.005, value: 0.16 },
19
- { key: 'joins', label: 'Joins', type: 'choice', options: ['round', 'mitre'], value: 'round' },
20
- { key: 'caps', label: 'Ends', type: 'choice', options: ['round', 'square', 'angled'], value: 'round' },
21
- { key: 'move', label: 'Move', type: 'choice', options: ['none', 'loop', 'fold', 'overlap'], value: 'loop' },
22
- ];
23
-
24
- /** A lattice point (i, j from 0 to 3) on the box. */
25
- const at = (i, j) => [BOX.x0 + (i * BOX.size) / 3, BOX.y0 + (j * BOX.size) / 3];
26
-
27
- /** Whether segments ab and cd cross (strictly). */
28
- function crosses(a, b, c, d) {
29
- const o = (p, q, r) => Math.sign((q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]));
30
- return o(a, b, c) * o(a, b, d) < 0 && o(c, d, a) * o(c, d, b) < 0;
31
- }
32
-
33
- /** The turn at b, in degrees (0 straight on, 180 straight back). */
34
- function turnAt(a, b, c) {
35
- const u = [b[0] - a[0], b[1] - a[1]], v = [c[0] - b[0], c[1] - b[1]];
36
- return (Math.acos(Math.max(-1, Math.min(1, (u[0] * v[0] + u[1] * v[1]) / (Math.hypot(...u) * Math.hypot(...v))))) * 180) / Math.PI;
37
- }
38
-
39
- /** A walk of n lattice points from a seed: no repeats, no crossing itself, every turn between 30° and 150°. */
40
- function walk(rand, n) {
41
- for (let tries = 0; tries < 60; tries++) {
42
- const pts = [[Math.floor(rand() * 4), Math.floor(rand() * 4)]];
43
- while (pts.length < n) {
44
- const options = [];
45
- for (let i = 0; i < 4; i++) for (let j = 0; j < 4; j++) {
46
- const q = [i, j], last = pts.at(-1);
47
- if (pts.some((p) => p[0] === i && p[1] === j) || Math.hypot(i - last[0], j - last[1]) < 1.4) continue;
48
- const P = pts.map(([a, b]) => at(a, b)), Q = at(i, j), L = P.at(-1);
49
- if (pts.length >= 2) { const t = turnAt(P.at(-2), L, Q); if (t < 30 || t > 150) continue; }
50
- if (P.slice(0, -2).some((p, k) => crosses(p, P[k + 1], L, Q))) continue;
51
- options.push(q);
52
- }
53
- if (!options.length) break;
54
- pts.push(options[Math.floor(rand() * options.length)]);
55
- }
56
- if (pts.length === n) return pts.map(([i, j]) => at(i, j));
57
- }
58
- return null;
59
- }
60
-
61
- /** Whether a walk is a banned read: a four-point zigzag (the bolt) or a short-legged right angle (the tick). */
62
- function banned(pts) {
63
- if (pts.length === 4) {
64
- const s1 = Math.sign((pts[1][0] - pts[0][0]) * (pts[2][1] - pts[1][1]) - (pts[1][1] - pts[0][1]) * (pts[2][0] - pts[1][0]));
65
- const s2 = Math.sign((pts[2][0] - pts[1][0]) * (pts[3][1] - pts[2][1]) - (pts[2][1] - pts[1][1]) * (pts[3][0] - pts[2][0]));
66
- if (s1 !== s2 && turnAt(pts[0], pts[1], pts[2]) > 100 && turnAt(pts[1], pts[2], pts[3]) > 100) return true;
67
- }
68
- if (pts.length === 3) {
69
- const l1 = Math.hypot(pts[1][0] - pts[0][0], pts[1][1] - pts[0][1]), l2 = Math.hypot(pts[2][0] - pts[1][0], pts[2][1] - pts[1][1]);
70
- if (Math.abs(turnAt(...pts) - 90) < 20 && l1 < l2 * 0.6) return true;
71
- }
72
- return false;
73
- }
74
-
75
- /**
76
- * One cursive loop at point k: the stroke runs on past the turn, circles round outside it (a circle tangent to both legs
77
- * run on past the point) and comes back through the point along the next leg, crossing itself there.
78
- */
79
- function withLoop(pts, k, w) {
80
- const [a, v, b] = [pts[k - 1], pts[k], pts[k + 1]];
81
- const unit = (x, y) => { const l = Math.hypot(x, y) || 1; return [x / l, y / l]; };
82
- const u1 = unit(v[0] - a[0], v[1] - a[1]), u2 = unit(b[0] - v[0], b[1] - v[1]);
83
- const alpha = Math.acos(Math.max(-1, Math.min(1, -(u1[0] * u2[0] + u1[1] * u2[1])))); // between u1 and −u2
84
- const R = w * 0.95 + GAP, s = R / Math.tan(alpha / 2), d = R / Math.sin(alpha / 2);
85
- const bis = unit(u1[0] - u2[0], u1[1] - u2[1]), c = [v[0] + bis[0] * d, v[1] + bis[1] * d];
86
- const T1 = [v[0] + u1[0] * s, v[1] + u1[1] * s], T2 = [v[0] - u2[0] * s, v[1] - u2[1] * s];
87
- const a1 = Math.atan2(T1[1] - c[1], T1[0] - c[0]), a2 = Math.atan2(T2[1] - c[1], T2[0] - c[0]);
88
- const dir = Math.sign((T1[0] - c[0]) * u1[1] - (T1[1] - c[1]) * u1[0]) || 1;
89
- let sweep = a2 - a1;
90
- if (dir > 0) { while (sweep <= 0) sweep += Math.PI * 2; } else { while (sweep >= 0) sweep -= Math.PI * 2; }
91
- const arc = Array.from({ length: 49 }, (_, i) => { const t = a1 + (sweep * i) / 48; return [c[0] + R * Math.cos(t), c[1] + R * Math.sin(t)]; });
92
- return [...pts.slice(0, k), ...arc, ...pts.slice(k + 1)];
93
- }
94
-
95
- /** The stroke along a path: mitred, or with a disc at each turn for round joins; round or square caps. */
96
- function line(pts, w, p) {
97
- const s = stroke(pts, w, { roundCaps: p.caps === 'round' });
98
- if (p.joins !== 'round') return s;
99
- return U(s, ...pts.slice(1, -1).map(([x, y]) => circle(x, y, w / 2, 32)));
100
- }
101
-
102
- /** An end cut at 45° across the stroke: a triangle off the end's corner. */
103
- function angled(s, end, prev, w) {
104
- const ux = (end[0] - prev[0]) / Math.hypot(end[0] - prev[0], end[1] - prev[1]), uy = (end[1] - prev[1]) / Math.hypot(end[0] - prev[0], end[1] - prev[1]);
105
- const nx = -uy, ny = ux, h = w / 2;
106
- return D(s, poly([[end[0] + nx * h + ux * 2, end[1] + ny * h + uy * 2], [end[0] + nx * h - ux * w, end[1] + ny * h - uy * w], [end[0] - nx * h + ux * 2, end[1] - ny * h + uy * 2]]));
107
- }
108
-
109
- /** The mark for resolved params. */
110
- export function build(p) {
111
- const w = p.stroke * BOX.size;
112
- const loopAt = (q) => {
113
- // one loop only, at the gentlest turn (a sharp one throws the loop far out), and never where the legs open under
114
- // 100° (a turn over 80°): a loop on a narrow V is the awareness ribbon
115
- let k = -1, best = 999;
116
- for (let i = 1; i < q.length - 1; i++) { const t = turnAt(q[i - 1], q[i], q[i + 1]); if (t <= 80 && t < best) { best = t; k = i; } }
117
- return k;
118
- };
119
- let pts = null;
120
- for (let k = 0; k < 12 && !pts; k++) {
121
- const q = walk(rng(`line:${p.layout}:${p.points}:${k}`), p.points);
122
- if (q && !banned(q) && (p.move !== 'loop' || loopAt(q) > 0)) pts = q;
123
- }
124
- if (!pts) return [];
125
- if (p.move === 'loop' && pts.length >= 3) return line(withLoop(pts, loopAt(pts), w), w, p);
126
- if (p.move === 'fold') {
127
- // a hairpin: the last leg comes back alongside itself, a gap apart, for half its length
128
- const e = pts.at(-1), b = pts.at(-2), L = Math.hypot(e[0] - b[0], e[1] - b[1]), ux = (e[0] - b[0]) / L, uy = (e[1] - b[1]) / L, off = w + GAP;
129
- const back = [[e[0] - uy * off, e[1] + ux * off], [e[0] - uy * off - ux * L * 0.5, e[1] + ux * off - uy * L * 0.5]];
130
- return line([...pts, ...back], w, p);
131
- }
132
- if (p.move === 'overlap' && pts.length >= 3) {
133
- // the end runs on across the first leg; the first leg passes under it, cleared by the gap
134
- const a = pts[0], b = pts[1], m = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2], e = pts.at(-1);
135
- const dx = m[0] - e[0], dy = m[1] - e[1], dl = Math.hypot(dx, dy) || 1, tail = [m[0] + (dx / dl) * w * 1.6, m[1] + (dy / dl) * w * 1.6];
136
- const first = line(pts.slice(0, 2), w, p), rest = line([...pts.slice(1), tail], w, p);
137
- return U(clear(first, rest, GAP), rest);
138
- }
139
- let s = line(pts, w, p);
140
- if (p.caps === 'angled') s = angled(angled(s, pts.at(-1), pts.at(-2), w), pts[0], pts[1], w);
141
- return s;
142
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Orbit: a planet (a disc, or a ring) and one or two tilted elliptical rings round it, each passing in front of the
3
- * planet across its near half and behind it across its far half, cut free by the house gap at every crossing; a moon
4
- * if asked. After Saturn-style orbit marks.
5
- */
6
- import { D, I, ellipse, circle, rect, rot, over, annulus } 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: 'planet', label: 'Planet size', type: 'range', min: 0.24, max: 0.42, step: 0.01, value: 0.36 },
12
- { key: 'body', label: 'Planet', type: 'choice', options: ['solid', 'ring'], value: 'solid' },
13
- { key: 'rings', label: 'Rings', type: 'range', min: 1, max: 2, step: 1, value: 1 },
14
- { key: 'width', label: 'Ring width', type: 'range', min: 0.05, max: 0.12, step: 0.005, value: 0.075 },
15
- { key: 'flatten', label: 'Ring depth', type: 'range', min: 0.16, max: 0.4, step: 0.01, value: 0.22 },
16
- { key: 'tilt', label: 'Tilt', type: 'range', min: -40, max: 40, step: 1, value: -16 },
17
- { key: 'moon', label: 'Moon', type: 'choice', options: ['none', 'beside'], value: 'none' },
18
- ];
19
-
20
- /** An elliptical band round the centre, rx across, ry deep, w wide, turned `deg`. */
21
- function band(rx, ry, w, deg) {
22
- const { cx, cy } = BOX;
23
- return rot(D(ellipse(cx, cy, rx, ry, 0, 72), ellipse(cx, cy, rx - w, Math.max(2, ry - w), 0, 72)), deg, cx, cy);
24
- }
25
-
26
- /** The near half of the plane for a ring turned `deg` (below its long axis). */
27
- function near(deg) {
28
- const { cx, cy } = BOX;
29
- return rot(rect(cx - 600, cy, 1200, 600), deg, cx, cy);
30
- }
31
-
32
- /** The mark for resolved params. */
33
- export function build(p) {
34
- const { cx, cy, size } = BOX, R = p.planet * size * 0.75 + size * 0.02;
35
- const w = p.width * size, rx = size / 2;
36
- let s = p.body === 'ring' ? annulus(cx, cy, R - w * 0.75, w * 1.5) : circle(cx, cy, R, 72);
37
- const tilts = p.rings === 2 ? [p.tilt, -p.tilt * 0.6 + (p.tilt >= 0 ? -28 : 28)] : [p.tilt];
38
- for (const [k, deg] of tilts.entries()) {
39
- const ry = rx * p.flatten * (k ? 0.9 : 1), ring = band(rx * (k ? 0.92 : 1), ry, w, deg);
40
- const front = I(ring, near(deg)), back = D(ring, near(deg));
41
- s = over(over(back, s, GAP), front, GAP);
42
- }
43
- if (p.moon === 'beside') {
44
- // a moon off the planet's upper shoulder, on the side the ring rises toward
45
- const m = Math.max(w * 0.9, size * 0.05), sx = p.tilt <= 0 ? 1 : -1;
46
- s = over(s, circle(cx + sx * R * 1.2, cy - R * 1.2, m, 48), GAP);
47
- }
48
- // where a ring slips behind the planet at a shallow angle, the gap leaves thin tails: dropped
49
- return tidy(s, { share: 0.01, width: 18 });
50
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * Pixel: a pixel figure on a 5, 7 or 9 wide grid, mirrored left to right (a face-free identicon), drawn from a numbered
3
- * layout at a density, the pixels joined into solid shapes or parted by a gap. A left-right mirror alone often makes a
4
- * face or a video-game alien, so the default mirrors both ways (an ornament). After the pixel ornaments and the pixel
5
- * families.
6
- */
7
- import { U, rect, rr } from '@logomarks/core/geometry';
8
- import { BOX, GAP } from '../draw.js';
9
- import { rng } from '../random.js';
10
-
11
- /** @type {import('../index.js').Control[]} */
12
- export const controls = [
13
- { key: 'grid', label: 'Grid', type: 'choice', options: ['5', '7', '9'], value: '7' },
14
- { key: 'layout', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 21 },
15
- { key: 'density', label: 'Density', type: 'range', min: 0.3, max: 0.75, step: 0.01, value: 0.5 },
16
- { key: 'symmetry', label: 'Symmetry', type: 'choice', options: ['both', 'mirror', 'turn'], value: 'both' },
17
- { key: 'parted', label: 'Parted', type: 'toggle', value: false },
18
- { key: 'pixel', label: 'Pixel', type: 'choice', options: ['square', 'rounded', 'dot'], value: 'square' },
19
- ];
20
-
21
- /** The mark for resolved params. */
22
- export function build(p) {
23
- const n = Number(p.grid), rand = rng(`pixel:${p.layout}:${n}`), on = Array.from({ length: n }, () => Array(n).fill(false));
24
- const half = Math.ceil(n / 2);
25
- for (let j = 0; j < n; j++) for (let i = 0; i < half; i++) on[j][i] = rand() < p.density;
26
- for (let j = 0; j < n; j++) for (let i = half; i < n; i++) on[j][i] = p.symmetry === 'turn' ? on[n - 1 - j][n - 1 - i] : on[j][n - 1 - i];
27
- if (p.symmetry === 'both') for (let j = half; j < n; j++) for (let i = 0; i < n; i++) on[j][i] = on[n - 1 - j][i];
28
- const g = p.parted ? GAP * 0.8 : 0, c = (BOX.size - (n - 1) * g) / n, parts = [];
29
- for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) {
30
- if (!on[j][i]) continue;
31
- const x = BOX.x0 + i * (c + g), y = BOX.y0 + j * (c + g);
32
- parts.push(p.pixel === 'dot' ? rr(x, y, c, c, c / 2) : p.pixel === 'rounded' ? rr(x, y, c, c, c * 0.28) : rect(x - (g ? 0 : 0.01), y - (g ? 0 : 0.01), c + (g ? 0 : 0.02), c + (g ? 0 : 0.02)));
33
- }
34
- return parts.length ? U(...parts) : [];
35
- }
36
-
37
- /** A parted pixel figure is many pieces. */
38
- export const guard = { maxPieces: 60 };