@logomarks/generate 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +41 -2
- package/package.json +29 -4
- package/src/controls.js +34 -0
- package/src/draw.js +60 -0
- package/src/finish.js +172 -0
- package/src/generate.js +194 -0
- package/src/guard.js +66 -0
- package/src/index.d.ts +96 -0
- package/src/index.js +9 -0
- package/src/presets.js +26 -0
- package/src/random.js +23 -0
- package/src/raster.js +52 -0
- package/src/recipes/arcs.js +83 -0
- package/src/recipes/bands.js +90 -0
- package/src/recipes/bars.js +106 -0
- package/src/recipes/blobs.js +74 -0
- package/src/recipes/bloom.js +53 -0
- package/src/recipes/burst.js +44 -0
- package/src/recipes/chevrons.js +45 -0
- package/src/recipes/cut.js +80 -0
- package/src/recipes/dashes.js +61 -0
- package/src/recipes/dots.js +47 -0
- package/src/recipes/fan.js +73 -0
- package/src/recipes/fold.js +66 -0
- package/src/recipes/hex.js +58 -0
- package/src/recipes/horizon.js +51 -0
- package/src/recipes/index.js +79 -0
- package/src/recipes/iso.js +35 -0
- package/src/recipes/letter.js +204 -0
- package/src/recipes/line.js +142 -0
- package/src/recipes/links.js +63 -0
- package/src/recipes/orbit.js +50 -0
- package/src/recipes/pixel.js +38 -0
- package/src/recipes/rings.js +82 -0
- package/src/recipes/route.js +107 -0
- package/src/recipes/shear.js +61 -0
- package/src/recipes/spiral.js +42 -0
- package/src/recipes/split.js +54 -0
- package/src/recipes/stack.js +71 -0
- package/src/recipes/steps.js +35 -0
- package/src/recipes/stripes.js +66 -0
- package/src/recipes/tiles.js +60 -0
- package/src/recipes/tri.js +126 -0
- package/src/recipes/turns.js +41 -0
- package/src/recipes/twin.js +64 -0
- package/src/recipes/venn.js +54 -0
- package/src/recipes/waves.js +40 -0
- package/src/shapes.js +54 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tri: a grid of equilateral triangles, the cells inside a big triangle switched on by a numbered layout
|
|
3
|
+
* and made mirror-symmetric if asked (a layout that comes out as three like pieces round the centre, a known game's
|
|
4
|
+
* emblem or the radiation trefoil, or a triangle with a triangle hole at its middle, is drawn again from its next
|
|
5
|
+
* sub-seed), parted by the house gap or merged into one figure. Never a full
|
|
6
|
+
* hexagram (two crossed triangles, a religious symbol), and at least three rows: two rows with the middle cell out is a
|
|
7
|
+
* known game's triangle emblem.
|
|
8
|
+
*/
|
|
9
|
+
import { U, poly } from '@logomarks/core/geometry';
|
|
10
|
+
import { BOX, GAP, tidy } from '../draw.js';
|
|
11
|
+
import { rng } from '../random.js';
|
|
12
|
+
|
|
13
|
+
/** @type {import('../index.js').Control[]} */
|
|
14
|
+
export const controls = [
|
|
15
|
+
{ key: 'size', label: 'Rows (triangle)', type: 'range', min: 3, max: 4, step: 1, value: 3 },
|
|
16
|
+
{ key: 'layout', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 2 },
|
|
17
|
+
{ key: 'density', label: 'Density', type: 'range', min: 0.35, max: 0.9, step: 0.01, value: 0.65 },
|
|
18
|
+
{ key: 'symmetry', label: 'Symmetry', type: 'choice', options: ['mirror', 'none'], value: 'mirror' },
|
|
19
|
+
{ key: 'parted', label: 'Parted', type: 'toggle', value: false },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/** The triangle cells (a, b, c corners in lattice coords) inside a big triangle of `n` rows, apex up. */
|
|
23
|
+
function triangleCells(n) {
|
|
24
|
+
const out = [];
|
|
25
|
+
for (let row = 0; row < n; row++) for (let i = 0; i <= 2 * row; i++) out.push({ row, i, up: i % 2 === 0 });
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A ring's area and centre (vertex mean; fine for the convex cells here). */
|
|
30
|
+
function measure(ring) {
|
|
31
|
+
let a = 0;
|
|
32
|
+
for (let i = 0; i < ring.length; i++) { const [x0, y0] = ring[i], [x1, y1] = ring[(i + 1) % ring.length]; a += x0 * y1 - x1 * y0; }
|
|
33
|
+
const c = ring.reduce((s, [x, y]) => [s[0] + x / ring.length, s[1] + y / ring.length], [0, 0]);
|
|
34
|
+
return { a: Math.abs(a / 2), c };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether a drawn grid is a banned read: three like pieces spaced round the centre about 120° apart (the three-triangle
|
|
39
|
+
* emblem of a known game, or the radiation trefoil), or one piece whose only hole is a triangle at its middle (the same
|
|
40
|
+
* emblem merged).
|
|
41
|
+
*/
|
|
42
|
+
function emblem(shape) {
|
|
43
|
+
if (!shape.length) return false;
|
|
44
|
+
if (shape.length === 3) {
|
|
45
|
+
const m = shape.map((poly) => measure(poly[0])), areas = m.map((x) => x.a);
|
|
46
|
+
if (Math.max(...areas) / Math.min(...areas) > 1.4) return false;
|
|
47
|
+
const c = m.reduce((s, x) => [s[0] + x.c[0] / 3, s[1] + x.c[1] / 3], [0, 0]);
|
|
48
|
+
const r = m.map((x) => Math.hypot(x.c[0] - c[0], x.c[1] - c[1])), ang = m.map((x) => Math.atan2(x.c[1] - c[1], x.c[0] - c[0])).sort((a, b) => a - b);
|
|
49
|
+
const gaps = [ang[1] - ang[0], ang[2] - ang[1], 2 * Math.PI + ang[0] - ang[2]].map((g) => (g * 180) / Math.PI);
|
|
50
|
+
return Math.max(...r) / Math.max(1e-9, Math.min(...r)) < 1.35 && gaps.every((g) => Math.abs(g - 120) < 25);
|
|
51
|
+
}
|
|
52
|
+
if (shape.length === 1 && shape[0].length === 2) {
|
|
53
|
+
const outer = measure(shape[0][0]), hole = measure(shape[0][1]);
|
|
54
|
+
return hole.a > 0.08 * outer.a && Math.hypot(hole.c[0] - outer.c[0], hole.c[1] - outer.c[1]) < 0.12 * Math.sqrt(outer.a) && shape[0][1].length <= 6;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The mark for resolved params: a layout that draws a banned read is drawn again from its next sub-seed. */
|
|
60
|
+
export function build(p) {
|
|
61
|
+
for (let attempt = 0; attempt < 8; attempt++) {
|
|
62
|
+
const s = draw(p, attempt);
|
|
63
|
+
if (s && !emblem(s)) return s;
|
|
64
|
+
}
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether a big triangle's cells (on/off, row by row) make the three-triangle emblem: an apex-up pair of rows with its
|
|
70
|
+
* three up cells on and its middle down cell off (merged: anywhere; parted: holding all but at most two of the cells
|
|
71
|
+
* that are on); or every up
|
|
72
|
+
* cell on and every down cell off (the Sierpiński look, the same emblem grown).
|
|
73
|
+
*/
|
|
74
|
+
function triforce(on, n, parted) {
|
|
75
|
+
const idx = (row, i) => row * row + i, count = on.filter(Boolean).length;
|
|
76
|
+
let allUp = true;
|
|
77
|
+
for (let row = 0; row < n; row++) for (let i = 0; i <= 2 * row; i++) if (on[idx(row, i)] !== (i % 2 === 0)) allUp = false;
|
|
78
|
+
if (allUp) return true;
|
|
79
|
+
for (let row = 0; row + 1 < n; row++) for (let i = 0; i <= 2 * row; i += 2) {
|
|
80
|
+
const ups = [idx(row, i), idx(row + 1, i), idx(row + 1, i + 2)], down = idx(row + 1, i + 1);
|
|
81
|
+
// merged, any such triangular hole ringed by three triangles is the emblem; parted, only when it is nearly all there is
|
|
82
|
+
if (ups.every((k) => on[k]) && !on[down] && (!parted || count - 3 <= 2)) return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** One drawing of the grid; attempt 0 is the layout's own seed (so layouts that pass draw as they always have). */
|
|
88
|
+
function draw(p, attempt) {
|
|
89
|
+
// a parted triangle under about 110 units a side is needle-thin once the gap is taken: the big triangle takes 3–4 rows
|
|
90
|
+
const n = p.size, seedKey = '0', rand = rng(attempt ? `tri:${p.layout}:${n}:${seedKey}:${attempt}` : `tri:${p.layout}:${n}:${seedKey}`), g = p.parted ? GAP : 0;
|
|
91
|
+
const side = BOX.size, h = (side * Math.sqrt(3)) / 2;
|
|
92
|
+
const cellW = side / n, cellH = h / n;
|
|
93
|
+
// the big triangle's cells, as points, apex at the top centre
|
|
94
|
+
const triCells = triangleCells(n).map(({ row, i, up }) => {
|
|
95
|
+
const xL = -row * cellW / 2 + (i / 2) * cellW, y0 = row * cellH, y1 = y0 + cellH;
|
|
96
|
+
return up ? [[xL, y1], [xL + cellW / 2, y0], [xL + cellW, y1]] : [[xL, y0], [xL + cellW, y0], [xL + cellW / 2, y1]];
|
|
97
|
+
});
|
|
98
|
+
const groups = 1; // a hexagon of six triangles makes a hexagram or a nut: the big triangle only
|
|
99
|
+
const cells = [];
|
|
100
|
+
for (let gIdx = 0; gIdx < groups; gIdx++) {
|
|
101
|
+
const a = (gIdx * Math.PI) / 3;
|
|
102
|
+
for (const [ci, pts] of triCells.entries()) {
|
|
103
|
+
const placed = pts.map(([x, y]) => groups === 1 ? [BOX.cx + x, BOX.cy - h / 2 + y + (BOX.size - h) / 2 - (BOX.size - h) / 2] : [x * Math.cos(a) - (y - 0) * Math.sin(a), x * Math.sin(a) + y * Math.cos(a)]);
|
|
104
|
+
cells.push({ g: gIdx, ci, pts: groups === 1 ? placed : placed.map(([x, y]) => [BOX.cx + x, BOX.cy + y]) });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// on or off: drawn per cell of one group, then copied by the symmetry
|
|
108
|
+
const base = triCells.map(() => rand() < p.density);
|
|
109
|
+
const mirrorOf = (ci) => { // the cell mirrored left-right within the big triangle
|
|
110
|
+
let k = 0; for (let row = 0; row < n; row++) for (let i = 0; i <= 2 * row; i++, k++) if (k === ci) { const mi = 2 * row - i; return row * row + mi; }
|
|
111
|
+
return ci;
|
|
112
|
+
};
|
|
113
|
+
const on = cells.map(({ g: gi, ci }) => {
|
|
114
|
+
let v = base[ci];
|
|
115
|
+
if (p.symmetry === 'mirror') v = base[Math.min(ci, mirrorOf(ci))];
|
|
116
|
+
if (groups === 6 && p.symmetry !== 'none') v = base[Math.min(ci, mirrorOf(ci))];
|
|
117
|
+
return v;
|
|
118
|
+
});
|
|
119
|
+
if (triforce(on, n, !!p.parted)) return null;
|
|
120
|
+
const shrink = (pts) => { if (!g) return pts; const c = pts.reduce((s, q) => [s[0] + q[0] / 3, s[1] + q[1] / 3], [0, 0]); const k = 1 - (g * Math.sqrt(3)) / cellW; return pts.map(([x, y]) => [c[0] + (x - c[0]) * k, c[1] + (y - c[1]) * k]); };
|
|
121
|
+
const parts = cells.filter((_, k) => on[k]).map(({ pts }) => poly(shrink(pts)));
|
|
122
|
+
return parts.length ? tidy(U(...parts), { share: 0.003, width: 10 }) : [];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A grid of triangles is many pieces. */
|
|
126
|
+
export const guard = { maxPieces: 60, minPieceShare: 0.003, maxThinShare: 0.1 }; // 60° corners by design
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns: ONE unit (a primitive shape) set round the centre three, four, five, six or eight times, each copy turned with
|
|
3
|
+
* it, either tucked under the next by the gap (a rotor), kept apart by the gap, or merged. After marks of a few blades,
|
|
4
|
+
* chevrons or tiles turned round a point. Hooked units turned four times are never offered (a swastika read). A blade (a
|
|
5
|
+
* crescent) is never turned four times (it hooks), and three kites point in or tilt (pointing out they are a known car
|
|
6
|
+
* badge or a trefoil).
|
|
7
|
+
*/
|
|
8
|
+
import { U, rot } from '@logomarks/core/geometry';
|
|
9
|
+
import { BOX, GAP, clear } from '../draw.js';
|
|
10
|
+
import { primitive } from '../shapes.js';
|
|
11
|
+
|
|
12
|
+
/** The units turns offers: none of them hooks, so no count makes a swastika. */
|
|
13
|
+
export const UNITS = ['chevron', 'parallelogram', 'square', 'leaf', 'pill', 'half', 'quarter', 'triangle', 'diamond', 'arch', 'circle', 'blade', 'kite'];
|
|
14
|
+
|
|
15
|
+
/** @type {import('../index.js').Control[]} */
|
|
16
|
+
export const controls = [
|
|
17
|
+
{ key: 'unit', label: 'Unit', type: 'choice', options: UNITS, value: 'chevron' },
|
|
18
|
+
{ key: 'count', label: 'Count', type: 'choice', options: ['3', '4', '5', '6', '8'], value: '3' },
|
|
19
|
+
{ key: 'size', label: 'Unit size', type: 'range', min: 0.2, max: 0.5, step: 0.01, value: 0.4 },
|
|
20
|
+
{ key: 'stretch', label: 'Stretch', type: 'range', min: 0.5, max: 2, step: 0.05, value: 1 },
|
|
21
|
+
{ key: 'radius', label: 'Distance', type: 'range', min: 0, max: 0.35, step: 0.01, value: 0.16 },
|
|
22
|
+
{ key: 'tilt', label: 'Tilt', type: 'range', min: -60, max: 60, step: 1, value: 0 },
|
|
23
|
+
{ key: 'face', label: 'Unit turn', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
|
|
24
|
+
{ key: 'join', label: 'Join', type: 'choice', options: ['tuck', 'gap', 'merge'], value: 'gap' },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/** The mark for resolved params. */
|
|
28
|
+
export function build(params) {
|
|
29
|
+
const p = { ...params };
|
|
30
|
+
if (p.unit === 'blade' && p.count === '4') p.count = '5';
|
|
31
|
+
if (p.unit === 'kite' && p.count === '3' && p.face !== '180' && Math.abs(p.tilt) < 15) p.tilt = p.tilt < 0 ? -15 : 15;
|
|
32
|
+
const n = Number(p.count), s = p.size * BOX.size, w = s * Math.sqrt(p.stretch), h = s / Math.sqrt(p.stretch);
|
|
33
|
+
const cy = BOX.cy - p.radius * BOX.size - h / 2;
|
|
34
|
+
const unit = rot(primitive(p.unit, BOX.cx - w / 2, cy - h / 2, w, h, Number(p.face) / 90), p.tilt, BOX.cx, cy);
|
|
35
|
+
const copies = Array.from({ length: n }, (_, k) => rot(unit, (360 * k) / n, BOX.cx, BOX.cy));
|
|
36
|
+
if (p.join === 'merge') return U(...copies);
|
|
37
|
+
if (p.join === 'tuck') return U(...copies.map((u, k) => clear(u, copies[(k + 1) % n], GAP)));
|
|
38
|
+
let acc = copies[0];
|
|
39
|
+
for (const c of copies.slice(1)) acc = U(acc, clear(c, acc, GAP));
|
|
40
|
+
return acc;
|
|
41
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twin: ONE heavy piece in the top half and the same piece turned 180° about the centre, the piece first cleared by
|
|
3
|
+
* the house gap from its turned twin so the pair stays point-symmetric with an even gap. Each piece reaches past the
|
|
4
|
+
* centre so the two lock together: an L (a bar and a stem down its near end), a hook (a stub down its far end) or an
|
|
5
|
+
* arc (a quarter ring into a bar). Its outer corner is square, round or cut, its free ends square, round or angled, and
|
|
6
|
+
* it can slant. After marks of two interlocking halves (Bold · Twin Turn, Drop 65).
|
|
7
|
+
*/
|
|
8
|
+
import { U, D, I, rect, poly, circle, rot } from '@logomarks/core/geometry';
|
|
9
|
+
import { BOX, GAP, clear, shear, level, upright } from '../draw.js';
|
|
10
|
+
|
|
11
|
+
/** @type {import('../index.js').Control[]} */
|
|
12
|
+
export const controls = [
|
|
13
|
+
{ key: 'piece', label: 'Piece', type: 'choice', options: ['L', 'hook', 'arc'], value: 'L' },
|
|
14
|
+
{ key: 'arm', label: 'Arm length', type: 'range', min: 0.62, max: 1, step: 0.01, value: 0.78 },
|
|
15
|
+
{ key: 'thickness', label: 'Thickness', type: 'range', min: 0.24, max: 0.42, step: 0.01, value: 0.32 },
|
|
16
|
+
{ key: 'stem', label: 'Stem depth', type: 'range', min: 0.45, max: 0.75, step: 0.01, value: 0.55 },
|
|
17
|
+
{ key: 'corner', label: 'Outer corner', type: 'choice', options: ['square', 'round', 'cut'], value: 'round' },
|
|
18
|
+
{ key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round', 'angled'], value: 'square' },
|
|
19
|
+
{ key: 'slant', label: 'Slant', type: 'range', min: -30, max: 30, step: 1, value: 0 },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/** The outer (top-left) corner of a piece: square, rounded to the thickness, or cut at 45°. */
|
|
23
|
+
function corner(shape, p, t) {
|
|
24
|
+
const { x0, y0 } = BOX;
|
|
25
|
+
if (p.corner === 'round') return D(shape, D(rect(x0, y0, t, t), circle(x0 + t, y0 + t, t, 96)));
|
|
26
|
+
if (p.corner === 'cut') return D(shape, poly([[x0 - 1, y0 - 1], [x0 + t * 0.7, y0 - 1], [x0 - 1, y0 + t * 0.7]]));
|
|
27
|
+
return shape;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A bar along the top from x0 to x1, its right end shaped by `ends` (its left end is square: it joins the piece). */
|
|
31
|
+
function barTo(x0, x1, t, ends) {
|
|
32
|
+
const { y0 } = BOX;
|
|
33
|
+
return ends === 'square' ? rect(x0, y0, x1 - x0, t) : U(rect(x0, y0, x1 - x0 - t, t), level(x1 - 2 * t, x1, y0, t, ends));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A stem down from the top at x to depth y1, its foot shaped by `ends`. */
|
|
37
|
+
function stemTo(x, y1, t, ends) {
|
|
38
|
+
const { y0 } = BOX;
|
|
39
|
+
return ends === 'square' ? rect(x, y0, t, y1 - y0) : U(rect(x, y0, t, y1 - y0 - t), upright(x, y1 - 2 * t, y1, t, ends));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The piece in the top-left of the box, for resolved params. */
|
|
43
|
+
function piece(p) {
|
|
44
|
+
const { x0, y0, size } = BOX;
|
|
45
|
+
const x1 = x0 + p.arm * size, y1 = y0 + p.stem * size;
|
|
46
|
+
// shaped ends need room: a bar or stem shorter than about 2.5 thicknesses turns into a blob of caps
|
|
47
|
+
const t = p.ends === 'square' ? p.thickness * size : Math.min(p.thickness * size, (x1 - x0) / 2.6, (y1 - y0) / 2.3);
|
|
48
|
+
if (p.piece === 'hook') return corner(U(barTo(x0, x1, t, 'square'), stemTo(x1 - t, y1, t, p.ends)), p, t);
|
|
49
|
+
if (p.piece === 'arc') {
|
|
50
|
+
const R = Math.max(t * 1.6, Math.min(y1 - y0, (x1 - x0) * 0.6)), cx = x0 + R, cy = y0 + R, xe = Math.max(x1, cx + 2.2 * t);
|
|
51
|
+
const ring = I(D(circle(cx, cy, R, 128), circle(cx, cy, R - t, 128)), rect(x0, y0, R, R));
|
|
52
|
+
const parts = [ring, barTo(cx, xe, t, p.ends)];
|
|
53
|
+
if (y1 > cy + 1) parts.push(rect(x0, cy, t, y1 - cy));
|
|
54
|
+
return U(...parts);
|
|
55
|
+
}
|
|
56
|
+
return corner(U(barTo(x0, x1, t, p.ends), stemTo(x0, y1, t, p.ends)), p, t);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The mark for resolved params. */
|
|
60
|
+
export function build(p) {
|
|
61
|
+
const a = shear(piece(p), p.slant);
|
|
62
|
+
const half = clear(a, rot(a, 180), GAP);
|
|
63
|
+
return U(half, rot(half, 180));
|
|
64
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waves: two to six wavy bands, the house gap between them, each a sine of its own phase (step it for a twist, or keep
|
|
3
|
+
* it for parallel waves), clipped to a square, a disc or nothing. After stacked waves, Havyon-style triple waves and wavy
|
|
4
|
+
* stripes.
|
|
5
|
+
*/
|
|
6
|
+
import { U, I, poly, rect, circle } from '@logomarks/core/geometry';
|
|
7
|
+
import { BOX, GAP } from '../draw.js';
|
|
8
|
+
|
|
9
|
+
/** @type {import('../index.js').Control[]} */
|
|
10
|
+
export const controls = [
|
|
11
|
+
{ key: 'count', label: 'Bands', type: 'range', min: 2, max: 6, step: 1, value: 3 },
|
|
12
|
+
{ key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.85, step: 0.01, value: 0.6 },
|
|
13
|
+
{ key: 'amplitude', label: 'Height', type: 'range', min: 0.02, max: 0.2, step: 0.005, value: 0.08 },
|
|
14
|
+
{ key: 'waves', label: 'Waves across', type: 'range', min: 0.5, max: 3, step: 0.25, value: 1 },
|
|
15
|
+
{ key: 'phase', label: 'Phase step', type: 'range', min: 0, max: 180, step: 5, value: 0 },
|
|
16
|
+
{ key: 'clip', label: 'Clip', type: 'choice', options: ['none', 'square', 'circle'], value: 'none' },
|
|
17
|
+
{ key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round'], value: 'round' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** The mark for resolved params. */
|
|
21
|
+
export function build(p) {
|
|
22
|
+
const n = p.count, A = p.amplitude * BOX.size, span = BOX.size - 2 * A;
|
|
23
|
+
const pitch = span / n, gap = Math.max(GAP, pitch * (1 - p.weight)), t = pitch - gap, parts = [], steps = 80;
|
|
24
|
+
const clip = p.clip !== 'none';
|
|
25
|
+
const x0 = clip ? BOX.x0 - 40 : BOX.x0, x1 = clip ? BOX.x1 + 40 : BOX.x1;
|
|
26
|
+
for (let k = 0; k < n; k++) {
|
|
27
|
+
const yc = BOX.y0 + A + k * pitch + t / 2, ph = (p.phase * k * Math.PI) / 180;
|
|
28
|
+
const y = (x) => yc + A * Math.sin(((x - BOX.x0) / BOX.size) * Math.PI * 2 * p.waves + ph);
|
|
29
|
+
const xs = Array.from({ length: steps + 1 }, (_, i) => x0 + ((x1 - x0) * i) / steps);
|
|
30
|
+
const r = p.ends === 'round' && !clip ? t / 2 : 0;
|
|
31
|
+
const xa = x0 + r, xb = x1 - r, xr = xs.filter((x) => x >= xa && x <= xb);
|
|
32
|
+
const band = [poly([...xr.map((x) => [x, y(x) - t / 2]), ...xr.slice().reverse().map((x) => [x, y(x) + t / 2])])];
|
|
33
|
+
if (r) band.push(circle(xa, y(xa), r, 40), circle(xb, y(xb), r, 40));
|
|
34
|
+
parts.push(U(...band));
|
|
35
|
+
}
|
|
36
|
+
const s = U(...parts);
|
|
37
|
+
if (p.clip === 'square') return I(s, rect(BOX.x0, BOX.y0, BOX.size, BOX.size));
|
|
38
|
+
if (p.clip === 'circle') return I(s, circle(BOX.cx, BOX.cy, BOX.size / 2, 128));
|
|
39
|
+
return s;
|
|
40
|
+
}
|
package/src/shapes.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The primitive shapes the recipes stack, turn and tile: each drawn inside a box (x, y, w, h) and turned a number of
|
|
3
|
+
* quarter turns about the box's centre.
|
|
4
|
+
*/
|
|
5
|
+
import { U, D, I, rect, poly, circle, ellipse, rot, mapPts } from '@logomarks/core/geometry';
|
|
6
|
+
|
|
7
|
+
/** Every primitive's name, in the order a picker lists them. */
|
|
8
|
+
export const PRIMITIVES = ['square', 'circle', 'half', 'quarter', 'triangle', 'parallelogram', 'pill', 'ring', 'arch', 'chevron', 'diamond', 'leaf'];
|
|
9
|
+
|
|
10
|
+
/** A quarter circle's points from angle a0 to a1 (degrees) round (cx, cy) at radius r. */
|
|
11
|
+
function arc(cx, cy, r, a0, a1, n = 32) {
|
|
12
|
+
return Array.from({ length: n + 1 }, (_, i) => {
|
|
13
|
+
const a = ((a0 + ((a1 - a0) * i) / n) * Math.PI) / 180;
|
|
14
|
+
return [cx + r * Math.cos(a), cy + r * Math.sin(a)];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** An ellipse or circle filling a box. */
|
|
19
|
+
function oval(x, y, w, h) {
|
|
20
|
+
return 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);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Primitive `type` in the box (x, y, w, h), turned `turns` quarter turns about the box's centre. */
|
|
24
|
+
export function primitive(type, x, y, w, h, turns = 0) {
|
|
25
|
+
const s = draw(type, x, y, w, h);
|
|
26
|
+
const t = ((turns % 4) + 4) % 4;
|
|
27
|
+
if (!t) return s;
|
|
28
|
+
// a quarter turn of a non-square box would spill out of it: squash back to the box
|
|
29
|
+
const cx = x + w / 2, cy = y + h / 2, turned = rot(s, 90 * t, cx, cy);
|
|
30
|
+
if (t % 2 === 0 || Math.abs(w - h) < 0.5) return turned;
|
|
31
|
+
return mapPts(turned, ([px, py]) => [cx + ((px - cx) * w) / h, cy + ((py - cy) * h) / w]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The primitive, unturned. */
|
|
35
|
+
function draw(type, x, y, w, h) {
|
|
36
|
+
const x1 = x + w, y1 = y + h, cx = x + w / 2, cy = y + h / 2, m = Math.min(w, h);
|
|
37
|
+
switch (type) {
|
|
38
|
+
case 'circle': return oval(x, y, w, h);
|
|
39
|
+
case 'half': return poly([[x, y1], ...arc(cx, y1, w / 2, 180, 360).map(([px, py]) => [px, y1 - ((y1 - py) * h) / (w / 2)])]);
|
|
40
|
+
case 'quarter': return poly([[x, y1], ...arc(x, y1, 1, 270, 360).map(([px, py]) => [x + (px - x) * w, y1 + (py - y1) * h])]);
|
|
41
|
+
case 'triangle': return poly([[x, y1], [cx, y], [x1, y1]]);
|
|
42
|
+
case 'parallelogram': { const d = Math.min(w * 0.45, h); return poly([[x, y1], [x1 - d, y1], [x1, y], [x + d, y]]); }
|
|
43
|
+
case 'pill': return w >= h ? U(rect(x + h / 2, y, w - h, h), circle(x + h / 2, cy, h / 2, 64), circle(x1 - h / 2, cy, h / 2, 64)) : U(rect(x, y + w / 2, w, h - w), circle(cx, y + w / 2, w / 2, 64), circle(cx, y1 - w / 2, w / 2, 64));
|
|
44
|
+
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)); }
|
|
45
|
+
case 'arch': { const t = m * 0.32, r = w / 2; const outer = U(rect(x, y + r, w, Math.max(0, h - r)), I(circle(cx, y + r, r, 96), rect(x, y, w, r))); const ir = r - t; return ir > 4 ? D(outer, U(rect(x + t, y + r, w - 2 * t, h), I(circle(cx, y + r, ir, 96), rect(x + t, y + t, w - 2 * t, r)))) : outer; }
|
|
46
|
+
case 'chevron': { const t = m * 0.36; return poly([[x, y1], [cx, y], [x1, y1], [x1 - t * 1.1, y1], [cx, y + t * 1.6], [x + t * 1.1, y1]]); }
|
|
47
|
+
case 'diamond': return poly([[cx, y], [x1, cy], [cx, y1], [x, cy]]);
|
|
48
|
+
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));
|
|
49
|
+
// not in PRIMITIVES (turns only): a crescent, a disc less the same disc shifted right; a kite with a notched tail
|
|
50
|
+
case 'blade': return D(oval(x, y, w, h), oval(x + w * 0.42, y - h * 0.08, w, h));
|
|
51
|
+
case 'kite': return D(poly([[cx, y], [x1, y + h * 0.38], [cx, y1], [x, y + h * 0.38]]), poly([[cx - w * 0.14, y1 + 1], [cx, y1 - h * 0.24], [cx + w * 0.14, y1 + 1]]));
|
|
52
|
+
default: return rect(x, y, w, h);
|
|
53
|
+
}
|
|
54
|
+
}
|