@logomarks/generate 0.2.0 → 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.
@@ -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
- }