@logomarks/generate 0.0.0-stage → 0.2.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 +56 -0
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/package.json +29 -4
- package/src/controls.js +41 -0
- package/src/draw.js +60 -0
- package/src/finish.js +172 -0
- package/src/generate.js +274 -0
- package/src/guard.js +66 -0
- package/src/index.d.ts +111 -0
- package/src/index.js +10 -0
- package/src/presets.js +37 -0
- package/src/random.js +23 -0
- package/src/raster.js +52 -0
- package/src/recipes/arcs.js +83 -0
- package/src/recipes/arcstep.js +45 -0
- package/src/recipes/bands.js +90 -0
- package/src/recipes/bars.js +106 -0
- package/src/recipes/bite.js +65 -0
- package/src/recipes/blades.js +38 -0
- package/src/recipes/bloom.js +53 -0
- package/src/recipes/burst.js +44 -0
- package/src/recipes/capsules.js +36 -0
- package/src/recipes/chevrons.js +45 -0
- package/src/recipes/cut.js +80 -0
- package/src/recipes/flare.js +39 -0
- package/src/recipes/halfsq.js +53 -0
- package/src/recipes/hex.js +58 -0
- package/src/recipes/horizon.js +51 -0
- package/src/recipes/index.js +95 -0
- package/src/recipes/invert.js +40 -0
- package/src/recipes/iso.js +35 -0
- package/src/recipes/leaves.js +45 -0
- package/src/recipes/letter.js +204 -0
- package/src/recipes/links.js +63 -0
- package/src/recipes/lobes.js +28 -0
- package/src/recipes/loops.js +28 -0
- package/src/recipes/pixelarc.js +51 -0
- package/src/recipes/rings.js +82 -0
- package/src/recipes/route.js +107 -0
- package/src/recipes/seam.js +30 -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/strips.js +39 -0
- package/src/recipes/tiles.js +60 -0
- package/src/recipes/trine.js +37 -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/wavecut.js +36 -0
- package/src/recipes/waves.js +40 -0
- package/src/shapes.js +54 -0
- package/src/tuning.js +67 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shear: a grid of heavy slanted tiles (one to three rows of two to four), each a parallelogram leaning one way or the
|
|
3
|
+
* other, the house gap between them, some dropped to make a figure. `lengths` varies the tiles (long and short, a stair,
|
|
4
|
+
* or the first row as one long slab) and `slide` moves every other row along its lean, so the grid breaks into a
|
|
5
|
+
* letter-like figure (the slab marks). After marks of sheared blocks and split slants.
|
|
6
|
+
*/
|
|
7
|
+
import { U, poly } from '@logomarks/core/geometry';
|
|
8
|
+
import { BOX, GAP } from '../draw.js';
|
|
9
|
+
|
|
10
|
+
/** @type {import('../index.js').Control[]} */
|
|
11
|
+
export const controls = [
|
|
12
|
+
{ key: 'rows', label: 'Rows', type: 'range', min: 1, max: 3, step: 1, value: 2 },
|
|
13
|
+
{ key: 'cols', label: 'Columns', type: 'range', min: 2, max: 4, step: 1, value: 3 },
|
|
14
|
+
{ key: 'lean', label: 'Lean', type: 'choice', options: ['same', 'rows', 'columns', 'chevron'], value: 'rows' },
|
|
15
|
+
{ key: 'angle', label: 'Angle', type: 'range', min: 10, max: 40, step: 1, value: 26 },
|
|
16
|
+
{ key: 'drop', label: 'Drop', type: 'choice', options: ['none', 'checker', 'corner', 'diagonal', 'middle'], value: 'none' },
|
|
17
|
+
{ key: 'spacing', label: 'Spacing', type: 'range', min: 1, max: 3, step: 0.1, value: 1 },
|
|
18
|
+
{ key: 'taper', label: 'Taper', type: 'range', min: 0, max: 0.4, step: 0.01, value: 0 },
|
|
19
|
+
{ key: 'lengths', label: 'Lengths', type: 'choice', options: ['equal', 'alternate', 'stair', 'one long'], value: 'equal' },
|
|
20
|
+
{ key: 'slide', label: 'Slide', type: 'range', min: 0, max: 0.5, step: 0.01, value: 0 },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** Whether tile (r, c) of an R × C grid is dropped. */
|
|
24
|
+
function dropped(drop, r, c, R, C) {
|
|
25
|
+
if (drop === 'checker') return (r + c) % 2 === 1;
|
|
26
|
+
if (drop === 'corner') return r === 0 && c === C - 1;
|
|
27
|
+
if (drop === 'diagonal') return R > 1 && c === Math.round((r * (C - 1)) / (R - 1)) && C > 2;
|
|
28
|
+
if (drop === 'middle') return C > 2 && r === Math.floor(R / 2) && c === Math.floor(C / 2);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Which way tile (r, c) leans: 1 right, −1 left. */
|
|
33
|
+
function leanOf(lean, r, c, C) {
|
|
34
|
+
if (lean === 'rows') return r % 2 ? -1 : 1;
|
|
35
|
+
if (lean === 'columns') return c % 2 ? -1 : 1;
|
|
36
|
+
if (lean === 'chevron') return c < C / 2 ? 1 : -1;
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The mark for resolved params. */
|
|
41
|
+
export function build(p) {
|
|
42
|
+
const R = p.rows, C = p.cols, g = GAP * p.spacing;
|
|
43
|
+
const cw = (BOX.size - (C - 1) * g) / C, ch = (BOX.size - (R - 1) * g) / R;
|
|
44
|
+
const d = Math.min(cw * 0.55, ch * Math.tan((p.angle * Math.PI) / 180)); // past about half the tile, its tips go needle-thin
|
|
45
|
+
const parts = [];
|
|
46
|
+
/** A tile from x, `len` wide, on the row from y0 to y1, leaning s. */
|
|
47
|
+
const tile = (x, len, y0, y1, s, t) => (s > 0 ? poly([[x, y1], [x + len - d - t, y1], [x + len - t, y0], [x + d, y0]]) : poly([[x + d, y1], [x + len - t, y1], [x + len - d - t, y0], [x, y0]]));
|
|
48
|
+
for (let r = 0; r < R; r++) {
|
|
49
|
+
const y0 = BOX.y0 + r * (ch + g), y1 = y0 + ch, dx = r % 2 ? p.slide * cw : 0;
|
|
50
|
+
if (p.lengths === 'one long' && r === 0 && R > 1) { parts.push(tile(BOX.x0 + dx, BOX.size, y0, y1, leanOf(p.lean, r, 0, C), 0)); continue; }
|
|
51
|
+
for (let c = 0; c < C; c++) {
|
|
52
|
+
if (dropped(p.drop, r, c, R, C)) continue;
|
|
53
|
+
const s = leanOf(p.lean, r, c, C), t = p.taper * (cw - d) * 0.5 * (c / Math.max(1, C - 1));
|
|
54
|
+
// the tile's own length: long and short in turn, or shortening down the rows (a stair); never under d + a gap
|
|
55
|
+
const k = p.lengths === 'alternate' ? ((r + c) % 2 ? 0.62 : 1) : p.lengths === 'stair' ? 1 - (0.32 * r) / Math.max(1, R - 1) : 1;
|
|
56
|
+
const len = Math.max(d + GAP * 3, cw * k);
|
|
57
|
+
parts.push(tile(BOX.x0 + c * (cw + g) + dx, len, y0, y1, s, t));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return U(...parts);
|
|
61
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spiral: ONE round band coiled one to three turns (an Archimedean spiral, so the gap between coils is even, the house gap
|
|
3
|
+
* or more), its inner end a dot or a square cut and its outer end running out as a straight tail if asked. Always round:
|
|
4
|
+
* a square spiral reads as a maze.
|
|
5
|
+
*/
|
|
6
|
+
import { U, circle, stroke, rot } from '@logomarks/core/geometry';
|
|
7
|
+
import { BOX, GAP } from '../draw.js';
|
|
8
|
+
|
|
9
|
+
/** @type {import('../index.js').Control[]} */
|
|
10
|
+
export const controls = [
|
|
11
|
+
{ key: 'turns', label: 'Turns', type: 'range', min: 1, max: 3, step: 0.25, value: 1.75 },
|
|
12
|
+
{ key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.75, step: 0.01, value: 0.58 },
|
|
13
|
+
{ key: 'start', label: 'Inner end', type: 'choice', options: ['dot', 'round', 'square'], value: 'round' },
|
|
14
|
+
{ key: 'tail', label: 'Tail', type: 'range', min: 0, max: 0.6, step: 0.01, value: 0 },
|
|
15
|
+
{ key: 'squash', label: 'Squash', type: 'range', min: 0.7, max: 1, step: 0.01, value: 1 },
|
|
16
|
+
{ key: 'spin', label: 'Spin', type: 'range', min: 0, max: 345, step: 15, value: 0 },
|
|
17
|
+
{ key: 'flip', label: 'Clockwise', type: 'toggle', value: true },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** The mark for resolved params. */
|
|
21
|
+
export function build(p) {
|
|
22
|
+
const R = BOX.size / 2, T = p.turns;
|
|
23
|
+
// coils `pitch` apart, the band `w` of it; the outermost coil's outer edge at R (a tail adds to the length, not the reach)
|
|
24
|
+
const pitch = Math.max((R * 0.92) / (T + 0.6), 0), w = Math.max(GAP * 1.2, Math.min(pitch - GAP, pitch * p.weight));
|
|
25
|
+
const r0 = pitch * (p.start === 'dot' ? 1.05 : 0.6), steps = Math.ceil(T * 96), dir = p.flip ? 1 : -1, pts = [];
|
|
26
|
+
for (let i = 0; i <= steps; i++) {
|
|
27
|
+
const t = (i / steps) * T * Math.PI * 2, r = r0 + (pitch * t) / (Math.PI * 2);
|
|
28
|
+
pts.push([BOX.cx + r * Math.cos(dir * t), BOX.cy + r * Math.sin(dir * t) * p.squash]);
|
|
29
|
+
}
|
|
30
|
+
if (p.tail > 0) {
|
|
31
|
+
// run straight on from the outer end along its tangent
|
|
32
|
+
const [ax, ay] = pts.at(-2), [bx, by] = pts.at(-1), L = Math.hypot(bx - ax, by - ay);
|
|
33
|
+
pts.push([bx + ((bx - ax) / L) * p.tail * R * 1.6, by + ((by - ay) / L) * p.tail * R * 1.6]);
|
|
34
|
+
}
|
|
35
|
+
let s = stroke(pts, w, { roundCaps: p.start !== 'square' });
|
|
36
|
+
if (p.start === 'dot') {
|
|
37
|
+
// a dot at the coil's centre, parted from the inner end by the gap (the coil starts further out to make room)
|
|
38
|
+
const dr = r0 - w / 2 - GAP;
|
|
39
|
+
if (dr > GAP * 0.8) s = U(s, circle(BOX.cx, BOX.cy, dr, 64));
|
|
40
|
+
}
|
|
41
|
+
return p.spin ? rot(s, p.spin, BOX.cx, BOX.cy) : s;
|
|
42
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split: a shape (a circle, a square, a hexagon or a diamond) cut by one to three straight lines at an angle into parts
|
|
3
|
+
* parted by the gap, each part slid along its cut and turned a little if asked, so the shape reads whole but broken.
|
|
4
|
+
* After split discs, sliced squares and offset halves.
|
|
5
|
+
*/
|
|
6
|
+
import { U, D, I, rect, poly, circle, rot, mapPts, grown } from '@logomarks/core/geometry';
|
|
7
|
+
import { BOX, GAP, tidy } from '../draw.js';
|
|
8
|
+
|
|
9
|
+
/** @type {import('../index.js').Control[]} */
|
|
10
|
+
export const controls = [
|
|
11
|
+
{ key: 'shape', label: 'Shape', type: 'choice', options: ['circle', 'square', 'hexagon', 'diamond'], value: 'circle' },
|
|
12
|
+
{ key: 'cuts', label: 'Cuts', type: 'range', min: 1, max: 3, step: 1, value: 2 },
|
|
13
|
+
{ key: 'angle', label: 'Angle', type: 'range', min: -75, max: 75, step: 1, value: -30 },
|
|
14
|
+
{ key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 3, step: 0.1, value: 1.3 },
|
|
15
|
+
{ key: 'slide', label: 'Slide', type: 'range', min: 0, max: 0.3, step: 0.01, value: 0.12 },
|
|
16
|
+
{ key: 'twist', label: 'Twist', type: 'range', min: 0, max: 8, step: 0.5, value: 0 },
|
|
17
|
+
{ key: 'spread', label: 'Cut spread', type: 'range', min: 0.3, max: 0.9, step: 0.01, value: 0.55 },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** The whole shape, filling the box (a little inset so slid parts stay inside). */
|
|
21
|
+
function whole(kind) {
|
|
22
|
+
const { cx, cy, size } = BOX, r = size * 0.42;
|
|
23
|
+
if (kind === 'square') return rect(cx - r, cy - r, 2 * r, 2 * r);
|
|
24
|
+
if (kind === 'hexagon') return poly(Array.from({ length: 6 }, (_, k) => { const a = (Math.PI / 3) * k - Math.PI / 2; return [cx + r * 1.1 * Math.cos(a), cy + r * 1.1 * Math.sin(a)]; }));
|
|
25
|
+
if (kind === 'diamond') return poly([[cx, cy - r * 1.2], [cx + r * 1.2, cy], [cx, cy + r * 1.2], [cx - r * 1.2, cy]]);
|
|
26
|
+
return circle(cx, cy, r, 128);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The mark for resolved params. */
|
|
30
|
+
export function build(p) {
|
|
31
|
+
const { cx, cy, size } = BOX, n = p.cuts, g = GAP * p.spacing, s = whole(p.shape), parts = [];
|
|
32
|
+
// the cuts run level in a frame turned `angle`: cut k at offset (k − (n−1)/2) × pitch across the middle
|
|
33
|
+
const pitch = (size * 0.84 * p.spread) / Math.max(1, n), cuts = Array.from({ length: n }, (_, k) => (k - (n - 1) / 2) * pitch);
|
|
34
|
+
const edges = [-size, ...cuts, size];
|
|
35
|
+
const a = (p.angle * Math.PI) / 180, ux = Math.cos(a), uy = Math.sin(a);
|
|
36
|
+
for (let k = 0; k < edges.length - 1; k++) {
|
|
37
|
+
const top = edges[k] + (k ? g / 2 : 0), bottom = edges[k + 1] - (k < edges.length - 2 ? g / 2 : 0);
|
|
38
|
+
const band = rot(rect(cx - size, cy + top, 2 * size, bottom - top), p.angle, cx, cy);
|
|
39
|
+
let part = I(s, band);
|
|
40
|
+
const i = k - (edges.length - 2) / 2; // −…+ from the middle part
|
|
41
|
+
if (p.slide) part = mapPts(part, ([x, y]) => [x + ux * i * p.slide * size * 0.4, y + uy * i * p.slide * size * 0.4]);
|
|
42
|
+
if (p.twist) part = rot(part, i * p.twist, cx, cy);
|
|
43
|
+
parts.push(part);
|
|
44
|
+
}
|
|
45
|
+
// a twisted part can graze its neighbour: then keep the gap by clearing each from the ones before
|
|
46
|
+
return tidy(p.twist ? clearAll(parts, g) : U(...parts));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Parts cleared from one another by the gap, in order. */
|
|
50
|
+
function clearAll(parts, g) {
|
|
51
|
+
let acc = parts[0];
|
|
52
|
+
for (const q of parts.slice(1)) acc = U(acc, D(q, grown(acc, g)));
|
|
53
|
+
return acc;
|
|
54
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stack: two to four primitive shapes laid out as a stack, a row, a grid, overlapping, nested or staggered, combined by
|
|
3
|
+
* ONE rule: kept apart by the house gap, laid over the one before with a gap round them, cut out of it, merged, or
|
|
4
|
+
* exclusive-or. Two shapes (A and B) and an order spread them over the slots; each can be turned. After marks that
|
|
5
|
+
* stack and tweak simple shapes together.
|
|
6
|
+
*/
|
|
7
|
+
import { U, D, X, rot } from '@logomarks/core/geometry';
|
|
8
|
+
import { over } from '@logomarks/core/geometry';
|
|
9
|
+
import { BOX, GAP, clear } from '../draw.js';
|
|
10
|
+
import { primitive, PRIMITIVES } from '../shapes.js';
|
|
11
|
+
|
|
12
|
+
const TURNS = ['0', '90', '180', '270'];
|
|
13
|
+
|
|
14
|
+
/** @type {import('../index.js').Control[]} */
|
|
15
|
+
export const controls = [
|
|
16
|
+
{ key: 'layout', label: 'Layout', type: 'choice', options: ['stack', 'row', 'grid', 'overlap', 'nest', 'stagger'], value: 'stack' },
|
|
17
|
+
{ key: 'count', label: 'Shapes', type: 'range', min: 2, max: 4, step: 1, value: 3 },
|
|
18
|
+
{ key: 'shapeA', label: 'Shape A', type: 'choice', options: PRIMITIVES, value: 'half' },
|
|
19
|
+
{ key: 'turnA', label: 'Turn A', type: 'choice', options: TURNS, value: '0' },
|
|
20
|
+
{ key: 'shapeB', label: 'Shape B', type: 'choice', options: PRIMITIVES, value: 'square' },
|
|
21
|
+
{ key: 'turnB', label: 'Turn B', type: 'choice', options: TURNS, value: '180' },
|
|
22
|
+
{ key: 'order', label: 'Order', type: 'choice', options: ['AB', 'AAB', 'ABB', 'ABA', 'A'], value: 'AB' },
|
|
23
|
+
{ key: 'step', label: 'Turn each', type: 'choice', options: ['none', 'quarter', 'half'], value: 'none' },
|
|
24
|
+
{ key: 'combine', label: 'Combine', type: 'choice', options: ['gap', 'over', 'cut', 'merge', 'xor'], value: 'gap' },
|
|
25
|
+
{ key: 'size', label: 'Shape size', type: 'range', min: 0.5, max: 1, step: 0.01, value: 1 },
|
|
26
|
+
{ key: 'overlap', label: 'Overlap', type: 'range', min: 0, max: 0.6, step: 0.01, value: 0.3 },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/** The slots (boxes) of a layout for `n` shapes, in drawing order. */
|
|
30
|
+
function slots(layout, n, overlap) {
|
|
31
|
+
const { x0, y0, size } = BOX, g = GAP;
|
|
32
|
+
if (layout === 'row') { const w = (size - (n - 1) * g) / n; return Array.from({ length: n }, (_, i) => [x0 + i * (w + g), y0, w, size]); }
|
|
33
|
+
if (layout === 'grid') {
|
|
34
|
+
const c = (size - g) / 2, cells = [[x0, y0], [x0 + c + g, y0], [x0, y0 + c + g], [x0 + c + g, y0 + c + g]];
|
|
35
|
+
const pick = n === 2 ? [0, 3] : n === 3 ? [0, 1, 2] : [0, 1, 2, 3];
|
|
36
|
+
return pick.map((k) => [cells[k][0], cells[k][1], c, c]);
|
|
37
|
+
}
|
|
38
|
+
if (layout === 'nest') return Array.from({ length: n }, (_, i) => { const s = size * (1 - (i * 0.62) / n); return [BOX.cx - s / 2, BOX.cy - s / 2, s, s]; });
|
|
39
|
+
if (layout === 'overlap') {
|
|
40
|
+
const s = size / (1 + (n - 1) * (1 - overlap) * 0.5), step = (size - s) / Math.max(1, n - 1);
|
|
41
|
+
return Array.from({ length: n }, (_, i) => [x0 + i * step, y0 + i * step, s, s]);
|
|
42
|
+
}
|
|
43
|
+
const h = (size - (n - 1) * g) / n;
|
|
44
|
+
if (layout === 'stagger') { const w = size * (1 - overlap * 0.6); return Array.from({ length: n }, (_, i) => [i % 2 ? x0 + size - w : x0, y0 + i * (h + g), w, h]); }
|
|
45
|
+
return Array.from({ length: n }, (_, i) => [x0, y0 + i * (h + g), size, h]); // stack
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Which of A and B fills slot i, by the order. */
|
|
49
|
+
function which(order, i) {
|
|
50
|
+
return order === 'A' ? 'A' : order[i % order.length] || 'A';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The mark for resolved params. */
|
|
54
|
+
export function build(p) {
|
|
55
|
+
const boxes = slots(p.layout, p.count, p.overlap);
|
|
56
|
+
const parts = boxes.map(([x, y, w, h], i) => {
|
|
57
|
+
const k = which(p.order, i), shrink = p.layout === 'nest' ? 1 : p.size;
|
|
58
|
+
const bw = w * shrink, bh = h * shrink, bx = x + (w - bw) / 2, by = y + (h - bh) / 2;
|
|
59
|
+
const extra = p.step === 'quarter' ? i : p.step === 'half' ? 2 * i : 0;
|
|
60
|
+
return primitive(k === 'A' ? p.shapeA : p.shapeB, bx, by, bw, bh, Number(k === 'A' ? p.turnA : p.turnB) / 90 + extra);
|
|
61
|
+
});
|
|
62
|
+
let acc = parts[0];
|
|
63
|
+
for (const s of parts.slice(1)) {
|
|
64
|
+
if (p.combine === 'merge') acc = U(acc, s);
|
|
65
|
+
else if (p.combine === 'xor') acc = X(acc, s);
|
|
66
|
+
else if (p.combine === 'cut') acc = D(acc, s);
|
|
67
|
+
else if (p.combine === 'over') acc = over(acc, s, GAP);
|
|
68
|
+
else acc = U(acc, clear(s, acc));
|
|
69
|
+
}
|
|
70
|
+
return acc;
|
|
71
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steps: a staircase of two to six blocks: rising one way, both ways (a ziggurat), or hanging down (inverted), each
|
|
3
|
+
* tread a set depth and each riser a set height, the blocks parted by the house gap or fused into one solid, their
|
|
4
|
+
* treads rounded if asked. After stair marks, ziggurats and stepped blocks.
|
|
5
|
+
*/
|
|
6
|
+
import { U, rect, rr } from '@logomarks/core/geometry';
|
|
7
|
+
import { BOX, GAP } from '../draw.js';
|
|
8
|
+
|
|
9
|
+
/** @type {import('../index.js').Control[]} */
|
|
10
|
+
export const controls = [
|
|
11
|
+
{ key: 'count', label: 'Steps', type: 'range', min: 2, max: 6, step: 1, value: 4 },
|
|
12
|
+
{ key: 'shape', label: 'Shape', type: 'choice', options: ['stair', 'ziggurat', 'inverted', 'zigzag'], value: 'ziggurat' },
|
|
13
|
+
{ key: 'tread', label: 'Tread', type: 'range', min: 0.3, max: 1, step: 0.01, value: 0.6 },
|
|
14
|
+
{ key: 'parted', label: 'Parted', type: 'toggle', value: true },
|
|
15
|
+
{ key: 'roundTreads', label: 'Round treads', type: 'range', min: 0, max: 0.5, step: 0.01, value: 0 },
|
|
16
|
+
{ key: 'gap', label: 'Gap', type: 'range', min: 1, max: 2.5, step: 0.1, value: 1 },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/** The mark for resolved params. */
|
|
20
|
+
export function build(p) {
|
|
21
|
+
const n = p.count, { x0, y0, size, cx } = BOX, g = p.parted ? GAP * p.gap : 0;
|
|
22
|
+
const h = (size - (n - 1) * g) / n, parts = [];
|
|
23
|
+
for (let i = 0; i < n; i++) {
|
|
24
|
+
// block i from the top: its width grows with i for a stair or ziggurat, shrinks for inverted
|
|
25
|
+
const k = p.shape === 'inverted' ? n - 1 - i : i;
|
|
26
|
+
const share = (1 - p.tread) + p.tread * ((k + 1) / n);
|
|
27
|
+
const w = size * share, y = y0 + i * (h + g);
|
|
28
|
+
let x = x0;
|
|
29
|
+
if (p.shape === 'ziggurat' || p.shape === 'inverted') x = cx - w / 2;
|
|
30
|
+
if (p.shape === 'zigzag') x = i % 2 ? x0 + size - w : x0;
|
|
31
|
+
const r = Math.min(h / 2, p.roundTreads * h);
|
|
32
|
+
parts.push(r > 0.5 ? rr(x, y, w, h + (g ? 0 : 0.02), p.shape === 'stair' ? [0, r, 0, 0] : [r, r, 0, 0]) : rect(x, y, w, h + (g ? 0 : 0.02)));
|
|
33
|
+
}
|
|
34
|
+
return U(...parts);
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripes: a silhouette (a disc, a square, a hexagon, an arch, a triangle, a half disc or a diamond) drawn in five to
|
|
3
|
+
* twelve parallel stripes at any angle, with ONE move: the stripes shifted in turn, bent into a wave, tapered, or cut by
|
|
4
|
+
* a slot, or broken into dashes. `cover` stripes only part of the shape and leaves the rest solid, and `ends` rounds
|
|
5
|
+
* every stripe's ends. After striped suns, Strange Trails and the Bold · Stripes family.
|
|
6
|
+
*/
|
|
7
|
+
import { U, D, I, rect, poly, mapPts, rot, grow } from '@logomarks/core/geometry';
|
|
8
|
+
import { BOX, GAP, tidy } from '../draw.js';
|
|
9
|
+
import { primitive } from '../shapes.js';
|
|
10
|
+
|
|
11
|
+
/** @type {import('../index.js').Control[]} */
|
|
12
|
+
export const controls = [
|
|
13
|
+
{ key: 'shape', label: 'Shape', type: 'choice', options: ['circle', 'square', 'hexagon', 'arch', 'triangle', 'half', 'diamond'], value: 'circle' },
|
|
14
|
+
{ key: 'stripes', label: 'Stripes', type: 'range', min: 4, max: 12, step: 1, value: 7 },
|
|
15
|
+
{ key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.8, step: 0.01, value: 0.6 },
|
|
16
|
+
{ key: 'angle', label: 'Angle', type: 'range', min: -90, max: 90, step: 5, value: 0 },
|
|
17
|
+
{ key: 'move', label: 'Move', type: 'choice', options: ['none', 'shift', 'wave', 'taper', 'slot', 'dash'], value: 'none' },
|
|
18
|
+
{ key: 'amount', label: 'Amount', type: 'range', min: 0, max: 1, step: 0.01, value: 0.5 },
|
|
19
|
+
{ key: 'cover', label: 'Striped part', type: 'range', min: 0.3, max: 1, step: 0.01, value: 1 },
|
|
20
|
+
{ key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round'], value: 'square' },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** The silhouette, filling the box. */
|
|
24
|
+
function silhouette(shape) {
|
|
25
|
+
const { x0, y0, size, cx, cy } = BOX;
|
|
26
|
+
if (shape === 'hexagon') return poly(Array.from({ length: 6 }, (_, k) => { const a = (Math.PI / 3) * k - Math.PI / 2; return [cx + (size / 2) * Math.cos(a), cy + (size / 2) * Math.sin(a)]; }));
|
|
27
|
+
return primitive(shape === 'arch' ? 'arch' : shape, x0, y0, size, size);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The mark for resolved params. */
|
|
31
|
+
export function build(p) {
|
|
32
|
+
const n = p.stripes, span = BOX.size * 1.5, pitch = span / n, gap = Math.max(GAP, pitch * (1 - p.weight)), w = pitch - gap;
|
|
33
|
+
const bands = [];
|
|
34
|
+
// cover: the stripes stop part way down the shape (in the stripes' own frame) and the rest is one solid
|
|
35
|
+
const yCut = BOX.y0 + (p.cover ?? 1) * BOX.size;
|
|
36
|
+
let solidFrom = null;
|
|
37
|
+
for (let k = 0; k < n; k++) {
|
|
38
|
+
const y = BOX.cy - span / 2 + k * pitch + gap / 2;
|
|
39
|
+
let width = w;
|
|
40
|
+
if (p.move === 'taper') width = Math.max(GAP * 0.8, w * (1 - p.amount * 0.75 * (k / (n - 1))));
|
|
41
|
+
if ((p.cover ?? 1) < 1 && y >= yCut) { solidFrom ??= y; continue; }
|
|
42
|
+
let band = rect(BOX.cx - span, y, 2 * span, width);
|
|
43
|
+
if (p.move === 'dash') {
|
|
44
|
+
// two breaks in each stripe, wandering from stripe to stripe by the amount
|
|
45
|
+
const wander = (k2) => Math.sin(k2 * 2.399 + 1.3) * p.amount * BOX.size * 0.22;
|
|
46
|
+
for (const at of [BOX.cx - BOX.size * 0.18 + wander(k), BOX.cx + BOX.size * 0.2 + wander(k + 7)]) band = D(band, rect(at - GAP * 0.7, y - 1, GAP * 1.4, width + 2));
|
|
47
|
+
}
|
|
48
|
+
bands.push(band);
|
|
49
|
+
}
|
|
50
|
+
if (solidFrom !== null) bands.push(rect(BOX.cx - span, solidFrom, 2 * span, span));
|
|
51
|
+
let stripes = U(...bands);
|
|
52
|
+
if (p.move === 'wave') stripes = mapPts(stripes, ([x, y]) => [x, y + Math.sin(((x - BOX.x0) / BOX.size) * Math.PI * 2) * pitch * 0.45 * p.amount]);
|
|
53
|
+
stripes = rot(stripes, p.angle, BOX.cx, BOX.cy);
|
|
54
|
+
let s = I(stripes, silhouette(p.shape));
|
|
55
|
+
if (p.move === 'shift') {
|
|
56
|
+
// every other stripe slid along its length: the silhouette breaks into a step
|
|
57
|
+
const d = p.amount * BOX.size * 0.12, a = (p.angle * Math.PI) / 180;
|
|
58
|
+
s = U(...[...s].map((q, k) => (k % 2 ? mapPts([q], ([x, y]) => [x + d * Math.cos(a), y + d * Math.sin(a)]) : [q])));
|
|
59
|
+
}
|
|
60
|
+
if (p.move === 'slot') s = D(s, rot(rect(BOX.cx - GAP * (1 + p.amount), BOX.y0 - 20, GAP * 2 * (1 + p.amount), BOX.size + 40), p.angle + 90, BOX.cx, BOX.cy));
|
|
61
|
+
if (p.ends === 'round') { const r = Math.max(4, w * 0.45); s = grow(grow(s, -r), r); } // every stripe's ends round (pills)
|
|
62
|
+
return tidy(s); // the stripes clipped at the silhouette's edge leave crumbs
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Stripes are many pieces by design. */
|
|
66
|
+
export const guard = { maxPieces: 30 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips: two to four straight strips of tape laid at angles, each passing over the last with the house gap and
|
|
3
|
+
* running a little past the joint: a woven triangle, a pair of chevrons, a woven diamond, a Z. Square-cut
|
|
4
|
+
* ends; never level-and-upright strips crossed, which is a plus or a hash sign.
|
|
5
|
+
*/
|
|
6
|
+
import { U, I, bar, over, rot, circle } 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: 'layout', label: 'Layout', type: 'choice', options: ['triangle', 'chevrons', 'diamond', 'zed'], value: 'triangle' },
|
|
12
|
+
{ key: 'weight', label: 'Weight', type: 'range', min: 0.14, max: 0.26, step: 0.01, value: 0.2 },
|
|
13
|
+
{ key: 'overhang', label: 'Overhang', type: 'range', min: 0, max: 0.16, step: 0.01, value: 0.08 },
|
|
14
|
+
{ key: 'spin', label: 'Spin', type: 'choice', options: ['0', '90', '180', '270'], value: '0' },
|
|
15
|
+
{ key: 'spacing', label: 'Gap', type: 'range', min: 0.8, max: 1.6, step: 0.1, value: 1 },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
/** The strips of a layout as [from, to] pairs in the unit square, in laying order; `loop` when they close a ring. */
|
|
19
|
+
function plan(layout) {
|
|
20
|
+
if (layout === 'triangle') { const a = [0.5, 0.06], b = [0.95, 0.86], c = [0.05, 0.86]; return { segs: [[a, b], [b, c], [c, a]], loop: true }; }
|
|
21
|
+
if (layout === 'diamond') { const a = [0.5, 0.08], b = [0.92, 0.5], c = [0.5, 0.92], d = [0.08, 0.5]; return { segs: [[a, b], [b, c], [c, d], [d, a]], loop: true }; }
|
|
22
|
+
if (layout === 'chevrons') return { segs: [[[0.08, 0.9], [0.46, 0.5]], [[0.08, 0.1], [0.46, 0.5]], [[0.54, 0.9], [0.92, 0.5]], [[0.54, 0.1], [0.92, 0.5]]], ends: [0, 1] };
|
|
23
|
+
return { segs: [[[0.06, 0.16], [0.94, 0.16]], [[0.06, 0.84], [0.94, 0.84]], [[0.88, 0.16], [0.12, 0.84]]], ends: [1, 1], last: true };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The mark for resolved params. */
|
|
27
|
+
export function build(p) {
|
|
28
|
+
const { x0, y0, size, cx, cy } = BOX, w = p.weight * size, g = GAP * p.spacing, e = p.overhang * size;
|
|
29
|
+
const { segs, loop, ends = [1, 1], last } = plan(p.layout);
|
|
30
|
+
const pt = ([x, y]) => [x0 + x * size, y0 + y * size];
|
|
31
|
+
// a strip from a to b, run on past each end by the overhang where `ends` says (like tape past a joint)
|
|
32
|
+
const strip = ([a, b], [ea, eb]) => { const A = pt(a), B = pt(b), L = Math.hypot(B[0] - A[0], B[1] - A[1]), ux = (B[0] - A[0]) / L, uy = (B[1] - A[1]) / L; return bar([A[0] - ux * e * ea, A[1] - uy * e * ea], [B[0] + ux * e * eb, B[1] + uy * e * eb], w); };
|
|
33
|
+
const all = segs.map((sg, i) => strip(sg, last && i < segs.length - 1 ? [0, 0] : ends));
|
|
34
|
+
let s = all[0];
|
|
35
|
+
for (const b of all.slice(1)) s = over(s, b, g);
|
|
36
|
+
// a closed ring is woven: the first strip passes back over the last at the corner they share
|
|
37
|
+
if (loop) { const A = pt(segs[0][0]); s = over(s, I(all[0], circle(A[0], A[1], w * 1.5 + e, 48)), g); }
|
|
38
|
+
return tidy(rot(s, Number(p.spin), cx, cy));
|
|
39
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiles: a two-by-two to four-by-four grid of cells, each a square, a quarter disc, a half disc, a disc, a triangle or
|
|
3
|
+
* nothing, laid out by a numbered layout (the same number, the same layout) and made symmetric if asked, the cells
|
|
4
|
+
* touching (merged into one figure) or parted by the house gap. After modular marks of squares and quarter rounds.
|
|
5
|
+
*/
|
|
6
|
+
import { U } from '@logomarks/core/geometry';
|
|
7
|
+
import { BOX, GAP } from '../draw.js';
|
|
8
|
+
import { primitive } from '../shapes.js';
|
|
9
|
+
import { rng } from '../random.js';
|
|
10
|
+
|
|
11
|
+
const SETS = { soft: ['square', 'quarter', 'quarter', 'half', 'circle'], sharp: ['square', 'triangle', 'parallelogram', 'diamond'], mixed: ['square', 'quarter', 'half', 'triangle', 'circle', 'leaf'] };
|
|
12
|
+
|
|
13
|
+
/** @type {import('../index.js').Control[]} */
|
|
14
|
+
export const controls = [
|
|
15
|
+
{ key: 'grid', label: 'Grid', type: 'range', min: 2, max: 4, step: 1, value: 3 },
|
|
16
|
+
{ key: 'layout', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 7 },
|
|
17
|
+
{ key: 'set', label: 'Shapes', type: 'choice', options: ['soft', 'sharp', 'mixed'], value: 'soft' },
|
|
18
|
+
{ key: 'density', label: 'Density', type: 'range', min: 0.4, max: 1, step: 0.01, value: 0.8 },
|
|
19
|
+
{ key: 'symmetry', label: 'Symmetry', type: 'choice', options: ['none', 'mirror', 'both', 'turn'], value: 'mirror' },
|
|
20
|
+
{ key: 'gap', label: 'Parted', type: 'toggle', value: true },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** The cell drawn at (r, c), from the layout's own random. */
|
|
24
|
+
function cellOf(p, r, c, rand) {
|
|
25
|
+
if (rand() > p.density) return null;
|
|
26
|
+
const set = SETS[p.set];
|
|
27
|
+
return { type: set[Math.floor(rand() * set.length)], turns: Math.floor(rand() * 4) };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The mark for resolved params. */
|
|
31
|
+
export function build(p) {
|
|
32
|
+
const n = p.grid, g = p.gap ? GAP : 0, c = (BOX.size - (n - 1) * g) / n, rand = rng(`tiles:${p.layout}:${n}:${p.set}`);
|
|
33
|
+
const cells = Array.from({ length: n }, () => Array(n).fill(null));
|
|
34
|
+
for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) cells[r][k] = cellOf(p, r, k, rand);
|
|
35
|
+
// symmetry: copy the source half (or quarter) over, turning each cell to match
|
|
36
|
+
for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) {
|
|
37
|
+
const src = cells[r][n - 1 - k];
|
|
38
|
+
if ((p.symmetry === 'mirror' || p.symmetry === 'both') && k >= Math.ceil(n / 2)) cells[r][k] = src && { type: src.type, turns: src.turns, flip: 'x' };
|
|
39
|
+
}
|
|
40
|
+
for (let r = Math.ceil(n / 2); r < n && p.symmetry === 'both'; r++) for (let k = 0; k < n; k++) { const s = cells[n - 1 - r][k]; cells[r][k] = s && { ...s, flip: s.flip === 'x' ? 'xy' : 'y' }; }
|
|
41
|
+
for (let r = 0; r < n && p.symmetry === 'turn'; r++) for (let k = 0; k < n; k++) if (r * n + k >= Math.ceil((n * n) / 2)) { const s = cells[n - 1 - r][n - 1 - k]; cells[r][k] = s && { type: s.type, turns: s.turns + 2 }; }
|
|
42
|
+
const parts = [];
|
|
43
|
+
for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) {
|
|
44
|
+
const cell = cells[r][k]; if (!cell) continue;
|
|
45
|
+
const x = BOX.x0 + k * (c + g), y = BOX.y0 + r * (c + g);
|
|
46
|
+
parts.push(flipCell(cell, x, y, c));
|
|
47
|
+
}
|
|
48
|
+
return parts.length ? U(...parts) : []; // an empty layout: the guard calls it nothing drawn
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A cell's shape, mirrored across its box as the symmetry asks. */
|
|
52
|
+
function flipCell(cell, x, y, c) {
|
|
53
|
+
// mirroring a cell is the same as turning its primitive: x-flip maps turn t to (4 − t) of a quarter, near enough for
|
|
54
|
+
// the primitives' own symmetry; apply by turns so every result is still one of the primitives
|
|
55
|
+
let t = cell.turns;
|
|
56
|
+
if (cell.flip === 'x') t = (5 - t) % 4;
|
|
57
|
+
if (cell.flip === 'y') t = (3 - t) % 4;
|
|
58
|
+
if (cell.flip === 'xy') t = t + 2;
|
|
59
|
+
return primitive(cell.type, x, y, c, c, t);
|
|
60
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trine: one solid cut into three by lines that run past the centre, never through it, so the three parts turn round
|
|
3
|
+
* a small triangle like a shutter. Three lines through the centre are a known badge; these miss it by design.
|
|
4
|
+
*/
|
|
5
|
+
import { D, I, U, circle, regular, poly } from '@logomarks/core/geometry';
|
|
6
|
+
import { BOX, GAP, tidy } from '../draw.js';
|
|
7
|
+
|
|
8
|
+
/** @type {import('../index.js').Control[]} */
|
|
9
|
+
export const controls = [
|
|
10
|
+
{ key: 'body', label: 'Body', type: 'choice', options: ['disc', 'hexagon', 'triangle', 'ring', 'hexring'], value: 'disc' },
|
|
11
|
+
{ key: 'offset', label: 'Past the centre', type: 'range', min: 0.12, max: 0.42, step: 0.01, value: 0.22 },
|
|
12
|
+
{ key: 'middle', label: 'Middle', type: 'choice', options: ['open', 'triangle'], value: 'open' },
|
|
13
|
+
{ key: 'spacing', label: 'Gap', type: 'range', min: 1, max: 2.2, step: 0.1, value: 1.2 },
|
|
14
|
+
{ key: 'spin', label: 'Spin', type: 'range', min: 0, max: 120, step: 1, value: 0 },
|
|
15
|
+
{ key: 'hand', label: 'Hand', type: 'choice', options: ['right', 'left'], value: 'right' },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
/** The half plane n·(x − c) ≥ d (or ≤ d with `below`), n at `deg`, as a big polygon. */
|
|
19
|
+
function half(deg, d, below) {
|
|
20
|
+
const { cx, cy } = BOX, a = (deg * Math.PI) / 180, n = [Math.cos(a), Math.sin(a)], t = [-n[1], n[0]], F = 2000, s = below ? -1 : 1;
|
|
21
|
+
const o = [cx + n[0] * d, cy + n[1] * d];
|
|
22
|
+
return poly([[o[0] - t[0] * F, o[1] - t[1] * F], [o[0] + t[0] * F, o[1] + t[1] * F], [o[0] + t[0] * F + n[0] * F * s, o[1] + t[1] * F + n[1] * F * s], [o[0] - t[0] * F + n[0] * F * s, o[1] - t[1] * F + n[1] * F * s]]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The mark for resolved params. */
|
|
26
|
+
export function build(p) {
|
|
27
|
+
const { cx, cy, size } = BOX, R = size / 2, g = GAP * p.spacing;
|
|
28
|
+
let s = p.body === 'hexagon' || p.body === 'hexring' ? regular(cx, cy, R, 6, -90) : p.body === 'triangle' ? regular(cx, cy + R * 0.14, R * 1.16, 3, -90) : circle(cx, cy, R, 128);
|
|
29
|
+
if (p.body === 'ring') s = D(s, circle(cx, cy, R * 0.46, 96));
|
|
30
|
+
if (p.body === 'hexring') s = D(s, regular(cx, cy, R * 0.46, 6, -90));
|
|
31
|
+
// three lines, each passing the centre at distance o; part i lies beyond line i and short of the next one round,
|
|
32
|
+
// each side set back half a gap. What all three leave in the middle is a small triangle: kept or left open.
|
|
33
|
+
const o = p.offset * R, k = p.hand === 'left' ? -1 : 1, base = (p.body === 'triangle' ? 30 : 0) + p.spin, parts = [];
|
|
34
|
+
for (let i = 0; i < 3; i++) parts.push(I(s, half(base + 120 * i, o + g / 2), half(base + 120 * (i + k), o - g / 2, true)));
|
|
35
|
+
if (p.middle === 'triangle' && o - g / 2 > GAP * 1.6) parts.push(I(s, half(base, o - g / 2, true), half(base + 120, o - g / 2, true), half(base + 240, o - g / 2, true)));
|
|
36
|
+
return tidy(U(...parts));
|
|
37
|
+
}
|
|
@@ -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
|
+
}
|