@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2026-11-26)
|
|
4
|
+
|
|
5
|
+
Everything below came after 0.1.0 went to npm the same day: the quality pass (nine recipes removed, tuned shuffles,
|
|
6
|
+
`qualityOf`, `shuffled`, the weighted mix, `MAIN`) and fifteen new recipes. Removing recipes is a breaking change, hence
|
|
7
|
+
the minor version.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
- Fifteen recipes after live house families (40 in all), each judged on sheets of its shuffles: `arcstep` (Arc Step),
|
|
11
|
+
`halfsq` (Half Square), `invert` (Inverted Rings), `leaves` (Leaf Tiles), `lobes` (Soft Pieces), `loops` (Petal
|
|
12
|
+
Loop), `trine` (three parts past the centre, never through it), `strips` (tape strips woven by the gap), `bite`
|
|
13
|
+
(Bite Link, its points rounded by exact arcs, no offsetting), `blades` (Blade Sweep), `wavecut` (Squiggle), `capsules`
|
|
14
|
+
(Capsule), `flare` (rays from a corner or a foot), `pixelarc` (Pixel Curve, one band) and `seam` (Notched Block: a
|
|
15
|
+
block parted by a seam with a joint). Each has its `TUNING`, `MAIN` and `MIX_WEIGHT`; five presets (29). Tried and
|
|
16
|
+
left out: Wedge (every keeper was one flat chevron, which `chevrons` draws), Dot Burst (sparse, a texture), Cross
|
|
17
|
+
Stripes (ragged once the edge crumbs go; its chevron divide is an envelope) and Bent Lines (too light at this
|
|
18
|
+
weight). Covered already: Stripe Shift (`stripes`), Chevron Stack (`chevrons`), Arch Nest and the Modernist corner
|
|
19
|
+
bands (`arcs`), Twin Turn (`twin`), Notched Block's single cuts (`cut`). Not drawn: Taper Lines, Dash Field (thin or
|
|
20
|
+
Morse), Ring Wave (a known symbol), Bead Wave.
|
|
21
|
+
|
|
22
|
+
- The quality pass (before release): nine recipes whose shuffles rarely gave a mark worth keeping are gone (`line`,
|
|
23
|
+
`orbit`, `blobs`, `dots`, `pixel`, `dashes`, `fan`, `fold`, and `tri`, whose three-diamond layouts read as a known
|
|
24
|
+
logo; 25 remain). `TUNING` (per recipe: `random` ranges and
|
|
25
|
+
options, `rare` second moves) makes a shuffle draw heavy, simple, one-move marks while the sliders keep their range;
|
|
26
|
+
`qualityOf()` scores a shape (ink, box, pieces, thin parts, thin gaps, balance, calm outline); `shuffled()` keeps the
|
|
27
|
+
best of a few draws; `variations()` and `mix()` use it, `mix()` weighted by `MIX_WEIGHT`, no recipe twice running, no
|
|
28
|
+
drawing twice. `MAIN` lists each recipe's main controls. `PRESETS` is 24 marks picked by eye from ranked sheets. The
|
|
29
|
+
same params now always draw the same bytes (the booleans' retry jitter is seeded from the params).
|
|
30
|
+
|
|
31
|
+
- First release (32 recipes, then the study's top 12, `line`, 18 presets; then `letter`, containers, pieces): the recipes `bars`, `bands`, `twin`, `stack` (primitives stacked, overlapped or nested, combined by
|
|
32
|
+
gap, over, cut, merge or xor), `shear`, `turns`, `burst`, `tiles`, `route`, `arcs`, `rings`, `stripes`, `dots`, `pixel`, `chevrons`, `waves`, `cut`, `split`, `venn`, `blobs`, `dashes`, `fan`, `fold`,
|
|
33
|
+
`spiral`, `orbit`, `bloom`, `links`, `horizon`, `steps`, `hex`, `tri`, `iso` and `line` (33), each with its controls and, where it needs them, its own guard limits; `tidy()` for crumbs; the shared finish
|
|
34
|
+
controls (turn, mirror, round with `roundWhich`: all, diagonal, top, bottom, left, right, alternate or inner, which
|
|
35
|
+
keeps the necks an opening would wipe out, and outline), left alone by shuffles unless asked; `mix()` (a bulk random mix across every recipe), `nearby()` and `similar()` (small whole-number controls step by one, layout numbers move a few along); the primitives (`src/shapes.js`); `generate()`, `randomParams()`,
|
|
36
|
+
`variations()` with locked controls; the quality guard (specks, slivers, thin parts by a bitmap opening, too
|
|
37
|
+
plain, too sparse); the playground (`npm run demo`; double-click a control to reset it, Reset all).
|
|
38
|
+
- From the study of the owner's references (generator-study.md): arcs `corner`, `chamfer`, `slant`, `core: quarter`;
|
|
39
|
+
shear `lengths`, `slide`; bars `spine`, `spineWeight`, `widths`, `cutAngle`, `cut: notch`; rings `shape`,
|
|
40
|
+
`breakKind`; route `frame`, `turns`; cut `angle`, `second`, `cut: arc`; turns units `blade`, `kite`; stripes
|
|
41
|
+
`move: dash`, `cover`, `ends`; the finish's `roundWhich` each-right, each-top, each-corner and the `accent` dot; the
|
|
42
|
+
recipe `line`; `PRESETS` (18). New controls default to the old drawing.
|
|
43
|
+
- Containers: the finish's `container` (circle, square, rounded, hexagon), `containerMode` badge or clip and
|
|
44
|
+
`containerSize`; badges shrink each hole so bridges stay readable, and the guard turns away hairline holes.
|
|
45
|
+
- `pieces` on every generated mark and `svgOf()` for two colours (alternate, first, rows, size); `piecesOf()`.
|
|
46
|
+
- `letter`: A–Z and 0–9 as slabs, stencil, route, tiles, blocks or pixel.
|
|
47
|
+
- Fixes: rising bars hang from a top spine (on a foot they are the signal-bars icon, on a bottom spine a bar chart);
|
|
48
|
+
`line` puts a loop only where the legs open 100° or more (a loop on a narrow V is the awareness ribbon); `tri` redraws
|
|
49
|
+
a layout that makes the three-triangle emblem or the trefoil, and lost its hexagon silhouette (hexagrams and nuts);
|
|
50
|
+
rings' `turn`, steps' `round` and tri's `outline` were overwritten by the finish's keys of the same name: now `spin`,
|
|
51
|
+
`roundTreads` and gone (a test checks no recipe repeats a key).
|
|
52
|
+
|
|
53
|
+
## 0.1.0 (2026-11-26)
|
|
54
|
+
|
|
55
|
+
- The first release: 34 recipes, the finish, the guard, `generate`, `randomParams`, `variations`, `nearby`, `similar`,
|
|
56
|
+
`mix`, `svgOf` and the presets.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ArrayPress Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @logomarks/generate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Abstract logomarks from rules and controls, no AI. Each recipe is one construction (40 of them: bars, bands, twin,
|
|
4
|
+
stack, shear, turns, burst, tiles, route, arcs, rings, stripes, chevrons, waves, cut, split, venn, spiral, bloom, links,
|
|
5
|
+
horizon, steps, hex, iso and letter, then fifteen after live house families: arcstep, halfsq, invert, leaves, lobes, loops, trine, strips, bite, blades, wavecut, capsules, flare, pixelarc, seam) that lists its controls
|
|
6
|
+
and draws a mark from them, fitted to the Logomarks standard: a 512 canvas, the longest side 448, centred,
|
|
7
|
+
`currentColor`, the house gap. Every recipe also takes the finish controls (turn, mirror, round corners, outline, an
|
|
8
|
+
accent dot, a container: badge or clip). Each mark comes with its `pieces`, and `svgOf()` draws them in two colours. A
|
|
9
|
+
quality guard skips draws with specks, slivers, thin necks, hairline holes, a bare primitive or too little ink. Runs in
|
|
10
|
+
the browser and in Node.
|
|
11
|
+
|
|
12
|
+
A shuffle is curated, not uniform: each recipe's `TUNING` keeps random draws to the settings that give a mark worth
|
|
13
|
+
keeping and makes one move at a time (`random`, `rare` on a control; a hand still has every slider's whole range);
|
|
14
|
+
`shuffled()` keeps the best of a few draws by `qualityOf()` (ink, pieces, thin parts, thin gaps, balance, a calm
|
|
15
|
+
outline), and `mix()` weights the strongest recipes (`MIX_WEIGHT`). `MAIN` names the controls a page shows first.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @logomarks/generate
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { RECIPES, generate, randomParams, variations, svgOf } from '@logomarks/generate';
|
|
27
|
+
|
|
28
|
+
const mark = generate('bands', { count: 2, join: 'curve' }); // { recipe, params, svg, pieces, problems }
|
|
29
|
+
const shuffled = generate('twin', randomParams('twin', 42));
|
|
30
|
+
const grid = variations('bars', { count: 24, seed: 7, base: mark.params, locked: ['count'] });
|
|
31
|
+
const badge = generate('letter', { char: 'K', build: 'slabs', container: 'circle' });
|
|
32
|
+
const twoTone = svgOf(mark.pieces, { colors: ['#0b0b0b', '#c8ff00'], pattern: 'rows' });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`PRESETS` lists 18 one-click starting points. `RECIPES[id].controls` describes every control (range, choice or toggle) so a UI can build its sliders from it.
|
|
36
|
+
|
|
37
|
+
## Playground
|
|
38
|
+
|
|
39
|
+
`npm run demo`, then open http://localhost:4393/demo/.
|
|
40
|
+
|
|
41
|
+
## Docs
|
|
42
|
+
|
|
43
|
+
- [docs/recipes.md](docs/recipes.md): each recipe, its controls and the guard.
|
|
44
|
+
|
|
45
|
+
## Licence
|
|
46
|
+
|
|
47
|
+
MIT © ArrayPress Limited. What you generate is yours to use.
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logomarks/generate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Abstract logomarks from rules and controls, no AI: 34 recipes (bars, bands, twin, stack, shear, turns, burst, tiles, route, arcs, rings, stripes, dots, pixel, chevrons, waves, cut, split, venn, blobs, dashes, fan, fold, spiral, orbit, bloom, links, horizon, steps, hex, tri, iso, line, letter) that each list their controls and draw a mark from them and a seed, fitted to the Logomarks standard (512 canvas, 448 fit, the house gap), a shared finish (rounding, outline, an accent dot, a container), two-colour pieces, seeded variations and presets. Runs in the browser and in Node.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.d.ts",
|
|
12
|
+
"import": "./src/index.js",
|
|
13
|
+
"default": "./src/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": ["src", "README.md", "CHANGELOG.md", "LICENSE"],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --test tests/*.test.js",
|
|
20
|
+
"demo": "node demo/serve.mjs"
|
|
21
|
+
},
|
|
22
|
+
"keywords": ["logo", "logo-generator", "logomark", "generative", "svg", "geometry"],
|
|
23
|
+
"author": "David Sherlock",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"homepage": "https://logomarks.ai",
|
|
26
|
+
"repository": { "type": "git", "url": "git+https://github.com/Logomarks/generate.git" },
|
|
27
|
+
"engines": { "node": ">=20" },
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@logomarks/core": "^0.2.3"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/controls.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A recipe's controls: what each one is, its defaults, clamping a value to it, and drawing a random one.
|
|
3
|
+
* A control is `{ key, label, type: 'range', min, max, step, value }`, `{ key, label, type: 'choice', options, value }`
|
|
4
|
+
* or `{ key, label, type: 'toggle', value }`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** The defaults of every control, as `{ key: value }`. */
|
|
8
|
+
export function defaults(controls) {
|
|
9
|
+
return Object.fromEntries(controls.map((c) => [c.key, c.value]));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A value made to fit its control: a range clamped and snapped to its step, a choice one of its options. */
|
|
13
|
+
export function clampTo(control, v) {
|
|
14
|
+
if (control.type === 'range') {
|
|
15
|
+
const n = Number(v);
|
|
16
|
+
if (!Number.isFinite(n)) return control.value;
|
|
17
|
+
const snapped = control.min + Math.round((Math.min(control.max, Math.max(control.min, n)) - control.min) / control.step) * control.step;
|
|
18
|
+
return Number(snapped.toFixed(6));
|
|
19
|
+
}
|
|
20
|
+
if (control.type === 'choice') return control.options.includes(v) ? v : control.value;
|
|
21
|
+
return Boolean(v);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Every control's value from `params`, clamped, with the default where one is missing. */
|
|
25
|
+
export function resolve(controls, params = {}) {
|
|
26
|
+
return Object.fromEntries(controls.map((c) => [c.key, c.key in params ? clampTo(c, params[c.key]) : c.value]));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A random value for a control, from `r` (a random function; two draws, always). A control may narrow what a shuffle
|
|
31
|
+
* draws without narrowing what a hand can set: `random` ([min, max] of a range, or some of a choice's options), and
|
|
32
|
+
* `rare` (the chance, 0–1, that a shuffle moves it off its default at all: the second moves a mark can take, a slant,
|
|
33
|
+
* a taper, a twist, stay home most of the time, so a shuffled mark makes one move, not five).
|
|
34
|
+
*/
|
|
35
|
+
export function randomValue(control, r) {
|
|
36
|
+
const a = r(), b = r();
|
|
37
|
+
if (control.rare !== undefined && b >= control.rare) return control.value;
|
|
38
|
+
if (control.type === 'range') { const [lo, hi] = control.random || [control.min, control.max]; return clampTo(control, lo + a * (hi - lo)); }
|
|
39
|
+
if (control.type === 'choice') { const o = control.random || control.options; return o[Math.floor(a * o.length)]; }
|
|
40
|
+
return a < 0.5;
|
|
41
|
+
}
|
package/src/draw.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drawing helpers shared by the recipes, on @logomarks/core's geometry: the 448 box on the 512 canvas, pieces with
|
|
3
|
+
* square, round or angled ends, shear, and clearing one shape from another by the gap.
|
|
4
|
+
*/
|
|
5
|
+
import { U, D, rect, poly, circle, mapPts, rot, grown, signedArea, perimeter } from '@logomarks/core/geometry';
|
|
6
|
+
|
|
7
|
+
/** The box every recipe draws in: 448 square, centred on the 512 canvas. */
|
|
8
|
+
export const BOX = { x0: 32, y0: 32, size: 448, x1: 480, y1: 480, cx: 256, cy: 256 };
|
|
9
|
+
/** The house gap, the narrowest space between two parts once fitted. */
|
|
10
|
+
export const GAP = 22;
|
|
11
|
+
|
|
12
|
+
/** An upright piece from (x, y0) to (x + w, y1), its two ends 'square', 'round' or 'angled' (cut at 45°, top to the right). */
|
|
13
|
+
export function upright(x, y0, y1, w, ends = 'square') {
|
|
14
|
+
const h = y1 - y0;
|
|
15
|
+
if (ends === 'round' && h > w) return U(rect(x, y0 + w / 2, w, h - w), circle(x + w / 2, y0 + w / 2, w / 2, 64), circle(x + w / 2, y1 - w / 2, w / 2, 64));
|
|
16
|
+
if (ends === 'angled' && h > w * 1.2) return poly([[x, y0 + w], [x + w, y0], [x + w, y1 - w], [x, y1]]);
|
|
17
|
+
return rect(x, y0, w, h);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A level piece from (x0, y) to (x1, y + h), its ends as `upright()`'s (angled: left end low, right end high). */
|
|
21
|
+
export function level(x0, x1, y, h, ends = 'square') {
|
|
22
|
+
const w = x1 - x0;
|
|
23
|
+
if (ends === 'round' && w > h) return U(rect(x0 + h / 2, y, w - h, h), circle(x0 + h / 2, y + h / 2, h / 2, 64), circle(x1 - h / 2, y + h / 2, h / 2, 64));
|
|
24
|
+
if (ends === 'angled' && w > h * 1.2) return poly([[x0 + h, y], [x1, y], [x1 - h, y + h], [x0, y + h]]);
|
|
25
|
+
return rect(x0, y, w, h);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A shape sheared sideways by `deg` about the box's middle line (tops lean right for a positive angle). */
|
|
29
|
+
export function shear(shape, deg) {
|
|
30
|
+
if (!deg) return shape;
|
|
31
|
+
const k = Math.tan((deg * Math.PI) / 180);
|
|
32
|
+
return mapPts(shape, ([x, y]) => [x - k * (y - BOX.cy), y]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `a` with everything within the gap `g` of `b` taken away, so the two stay at least `g` apart. */
|
|
36
|
+
export function clear(a, b, g = GAP) {
|
|
37
|
+
return D(a, grown(b, g));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A shape turned 90° about the canvas centre. */
|
|
41
|
+
export function quarterTurn(shape) {
|
|
42
|
+
return rot(shape, 90);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A shape with its crumbs dropped: every piece under `share` of the ink, or thinner on average than `width` (2 × area /
|
|
47
|
+
* perimeter), left out. For constructions that clip or cut (stripes in a disc, a slot through rings), where the edge
|
|
48
|
+
* pieces are too small to read.
|
|
49
|
+
*/
|
|
50
|
+
export function tidy(shape, { share = 0.015, width = 16 } = {}) {
|
|
51
|
+
if (!shape || !shape.length) return [];
|
|
52
|
+
const polys = typeof shape[0][0][0] === 'number' ? [shape] : shape;
|
|
53
|
+
const measured = polys.map((poly) => {
|
|
54
|
+
const a = Math.abs(signedArea(poly[0])) - poly.slice(1).reduce((t, h) => t + Math.abs(signedArea(h)), 0);
|
|
55
|
+
const per = poly.reduce((t, ring) => t + perimeter(ring), 0);
|
|
56
|
+
return { poly, a, w: (2 * a) / Math.max(per, 1e-9) };
|
|
57
|
+
});
|
|
58
|
+
const total = measured.reduce((t, m) => t + m.a, 0);
|
|
59
|
+
return measured.filter((m) => m.a >= share * total && m.w >= width).map((m) => m.poly);
|
|
60
|
+
}
|
package/src/finish.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The finish: controls every recipe shares, applied after it draws. Turn the mark, mirror it, round its corners or draw
|
|
3
|
+
* it as an outline. Rounding is an opening (shrink, then grow back), which rounds every outer corner; `roundWhich` keeps
|
|
4
|
+
* it to some of them, the designer's trick of rounding only a few: a diagonal pair, one side, every other piece, or the
|
|
5
|
+
* inner corners instead (a closing, kept under half the house gap so separate pieces never fuse), or each piece's own
|
|
6
|
+
* right end, top or outer corner (measured from the piece's own box). `accent` adds one accent dot, a house gap off the
|
|
7
|
+
* mark's right end or corner, or inside its biggest counter (never a round one: a ring with a dot is an eye).
|
|
8
|
+
* `container` puts the finished mark in a circle, square, rounded square or hexagon: clipped to it (`clip`: the mark
|
|
9
|
+
* zoomed by 1 / `containerSize` and cut at the shape's edge) or knocked out of it (`badge`: the shape solid, the mark a
|
|
10
|
+
* house gap's worth of hole, sitting at `containerSize` of the shape).
|
|
11
|
+
*/
|
|
12
|
+
import { U, D, I, rect, rot, mapPts, grow, signedArea, perimeter, circle, rr, regular } from '@logomarks/core/geometry';
|
|
13
|
+
import { BOX, GAP, tidy } from './draw.js';
|
|
14
|
+
|
|
15
|
+
/** @type {import('./index.js').Control[]} */
|
|
16
|
+
export const FINISH = [
|
|
17
|
+
{ key: 'turn', label: 'Turn', type: 'choice', options: ['0', '90', '180', '270'], value: '0', group: 'finish' },
|
|
18
|
+
{ key: 'mirror', label: 'Mirror', type: 'toggle', value: false, group: 'finish' },
|
|
19
|
+
{ key: 'round', label: 'Round corners', type: 'range', min: 0, max: 40, step: 1, value: 0, group: 'finish' },
|
|
20
|
+
{ key: 'roundWhich', label: 'Which corners', type: 'choice', options: ['all', 'diagonal', 'top', 'bottom', 'left', 'right', 'alternate', 'inner', 'each-right', 'each-top', 'each-corner'], value: 'all', group: 'finish' },
|
|
21
|
+
{ key: 'outline', label: 'Outline', type: 'range', min: 0, max: 60, step: 1, value: 0, group: 'finish' },
|
|
22
|
+
{ key: 'accent', label: 'Accent dot', type: 'choice', options: ['none', 'end', 'corner', 'inside'], value: 'none', group: 'finish' },
|
|
23
|
+
{ key: 'accentSize', label: 'Dot size', type: 'range', min: 0.8, max: 1.4, step: 0.05, value: 1, group: 'finish' },
|
|
24
|
+
{ key: 'container', label: 'Container', type: 'choice', options: ['none', 'circle', 'square', 'rounded', 'hexagon'], value: 'none', group: 'finish' },
|
|
25
|
+
{ key: 'containerMode', label: 'Container mode', type: 'choice', options: ['badge', 'clip'], value: 'badge', group: 'finish' },
|
|
26
|
+
{ key: 'containerSize', label: 'Mark size inside', type: 'range', min: 0.5, max: 0.9, step: 0.01, value: 0.78, group: 'finish' },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/** The mark with the finish applied, in this order: round, outline, accent, mirror, turn, container. */
|
|
30
|
+
export function finish(shape, p) {
|
|
31
|
+
let s = shape;
|
|
32
|
+
if (p.round > 0) s = rounded(s, p.round, p.roundWhich || 'all');
|
|
33
|
+
if (p.outline > 0) s = D(s, grow(s, -p.outline));
|
|
34
|
+
if (p.accent && p.accent !== 'none') s = accent(s, p.accent, p.accentSize || 1);
|
|
35
|
+
if (p.mirror) s = mapPts(s, ([x, y]) => [2 * BOX.cx - x, y]);
|
|
36
|
+
if (p.turn && p.turn !== '0') s = rot(s, Number(p.turn), BOX.cx, BOX.cy);
|
|
37
|
+
if (p.container && p.container !== 'none') s = contain(s, p.container, p.containerMode || 'badge', p.containerSize ?? 0.78);
|
|
38
|
+
return s;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The container's shape, filling the box. */
|
|
42
|
+
function containerShape(kind) {
|
|
43
|
+
const { x0, y0, size, cx, cy } = BOX;
|
|
44
|
+
if (kind === 'circle') return circle(cx, cy, size / 2, 160);
|
|
45
|
+
if (kind === 'rounded') return rr(x0, y0, size, size, size * 0.22);
|
|
46
|
+
if (kind === 'hexagon') return regular(cx, cy, size / 2, 6, -90);
|
|
47
|
+
return rect(x0, y0, size, size);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** How much of a container's width a mark's box can take and still sit inside it with room round its corners. */
|
|
51
|
+
const INSCRIBE = { circle: 0.74, square: 1, rounded: 0.94, hexagon: 0.8 };
|
|
52
|
+
|
|
53
|
+
/** The mark scaled about the box's centre so its longest side is `side`, centred. */
|
|
54
|
+
function scaledTo(shape, side) {
|
|
55
|
+
const polys = typeof shape[0][0][0] === 'number' ? [shape] : shape;
|
|
56
|
+
const [x0, y0, x1, y1] = boxOf(polys), k = side / Math.max(x1 - x0, y1 - y0, 1e-9);
|
|
57
|
+
const mx = (x0 + x1) / 2, my = (y0 + y1) / 2;
|
|
58
|
+
return mapPts(polys, ([x, y]) => [BOX.cx + (x - mx) * k, BOX.cy + (y - my) * k]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The mark in a container: clipped to it, or knocked out of it as a badge. */
|
|
62
|
+
function contain(shape, kind, mode, size) {
|
|
63
|
+
if (!shape || !shape.length) return shape;
|
|
64
|
+
const box = containerShape(kind);
|
|
65
|
+
if (mode === 'clip') return tidy(I(scaledTo(shape, (BOX.size * 0.9) / size), box));
|
|
66
|
+
// badge: the mark sits at `size` of the shape, its pieces knocked out; a mark spilling past the shape's edge would cut
|
|
67
|
+
// it open, so it is kept inside by a house gap. Scaled down, the mark's own gaps would become hairline bridges between
|
|
68
|
+
// the holes, so each hole is shrunk by half of what the scale took off the gap (the bridges get it back). A mark too
|
|
69
|
+
// thin for this leaves hairline holes, which the guard turns away.
|
|
70
|
+
const k = (size * INSCRIBE[kind]);
|
|
71
|
+
const mark = I(scaledTo(shape, BOX.size * k), grow(box, -GAP));
|
|
72
|
+
const back = (GAP * Math.max(0, 1 - k)) / 2;
|
|
73
|
+
return tidy(D(box, back > 0.5 ? grow(mark, -back) : mark));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The parts of the box a `which` keeps rounded (the rest keeps its sharp corners). */
|
|
77
|
+
function region(which) {
|
|
78
|
+
const { x0, y0, cx, cy, size } = BOX, h = size / 2 + 40, o = 40;
|
|
79
|
+
if (which === 'top') return rect(x0 - o, y0 - o, size + 2 * o, h);
|
|
80
|
+
if (which === 'bottom') return rect(x0 - o, cy, size + 2 * o, h);
|
|
81
|
+
if (which === 'left') return rect(x0 - o, y0 - o, h, size + 2 * o);
|
|
82
|
+
if (which === 'right') return rect(cx, y0 - o, h, size + 2 * o);
|
|
83
|
+
if (which === 'diagonal') return U(rect(x0 - o, y0 - o, h, h), rect(cx, cy, h, h));
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* An opening that rounds corners but keeps necks: the opening also wipes out any part thinner than 2r (a band's S-bend,
|
|
89
|
+
* a joint), so whatever it took that is bigger than a corner's offcut (about r² × 0.21 for a right angle; anything over
|
|
90
|
+
* r² × 1.2 can't be one) goes back.
|
|
91
|
+
*/
|
|
92
|
+
function open(shape, r) {
|
|
93
|
+
const soft = grow(grow(shape, -r), r);
|
|
94
|
+
const lost = D(shape, soft), keep = [];
|
|
95
|
+
for (const poly of lost) {
|
|
96
|
+
const a = Math.abs(signedArea(poly[0])) - poly.slice(1).reduce((t, h) => t + Math.abs(signedArea(h)), 0);
|
|
97
|
+
if (a > r * r * 1.2) keep.push(poly);
|
|
98
|
+
}
|
|
99
|
+
return keep.length ? U(soft, ...keep.map((q) => grow([q], 0.5))) : soft;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The shape with some or all of its corners rounded by r. */
|
|
103
|
+
function rounded(shape, r, which) {
|
|
104
|
+
if (which === 'inner') { const c = Math.min(r, 10); return grow(grow(shape, c), -c); }
|
|
105
|
+
const soft = I(open(shape, r), shape);
|
|
106
|
+
if (which === 'all') return soft;
|
|
107
|
+
if (which === 'alternate') {
|
|
108
|
+
// every other piece, in reading order (top to bottom, then left to right)
|
|
109
|
+
const pieces = [...shape].sort((a, b) => top(a) - top(b) || left(a) - left(b));
|
|
110
|
+
return U(...pieces.map((poly, k) => (k % 2 ? [poly] : I(open([poly], r), [poly]))));
|
|
111
|
+
}
|
|
112
|
+
if (which.startsWith('each-')) {
|
|
113
|
+
// each piece rounds only its own right half, top half, or the quarter of its box facing away from the mark's centre
|
|
114
|
+
return U(...[...shape].map((poly) => { const m = pieceRegion([poly], which); return U(I(open([poly], r), [poly], m), D([poly], m)); }));
|
|
115
|
+
}
|
|
116
|
+
const m = region(which);
|
|
117
|
+
return U(I(soft, m), D(shape, m));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The box of polygons: [x0, y0, x1, y1]. */
|
|
121
|
+
function boxOf(polys) {
|
|
122
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
123
|
+
for (const poly of polys) for (const [x, y] of poly[0]) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }
|
|
124
|
+
return [x0, y0, x1, y1];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The part of a piece's own box an each-… rounding keeps rounded. */
|
|
128
|
+
function pieceRegion(piece, which) {
|
|
129
|
+
const [x0, y0, x1, y1] = boxOf(piece), mx = (x0 + x1) / 2, my = (y0 + y1) / 2, o = 4;
|
|
130
|
+
if (which === 'each-right') return rect(mx, y0 - o, x1 - mx + o, y1 - y0 + 2 * o);
|
|
131
|
+
if (which === 'each-top') return rect(x0 - o, y0 - o, x1 - x0 + 2 * o, my - y0 + o);
|
|
132
|
+
const right = mx >= BOX.cx, below = my >= BOX.cy; // each-corner: the quarter facing away from the centre
|
|
133
|
+
return rect(right ? mx : x0 - o, below ? my : y0 - o, (right ? x1 - mx : mx - x0) + o, (below ? y1 - my : my - y0) + o);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A piece's area, less its holes. */
|
|
137
|
+
const areaOf = (poly) => Math.abs(signedArea(poly[0])) - poly.slice(1).reduce((t, h) => t + Math.abs(signedArea(h)), 0);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* One accent dot, the mark's own stroke wide (its biggest piece's mean width, 2 × area / perimeter) × `size`: a house gap
|
|
141
|
+
* off the right of the mark at the height of its lowest rightmost ink ('end'), off its bottom-right corner ('corner'),
|
|
142
|
+
* or in its biggest counter ('inside', never a round counter, and only where it fits with a gap all round).
|
|
143
|
+
*/
|
|
144
|
+
function accent(shape, where, size) {
|
|
145
|
+
const polys = !shape.length ? [] : typeof shape[0][0][0] === 'number' ? [shape] : shape;
|
|
146
|
+
if (!polys.length) return shape;
|
|
147
|
+
const big = polys.reduce((a, b) => (areaOf(b) > areaOf(a) ? b : a));
|
|
148
|
+
const stroke = (2 * areaOf(big)) / big.reduce((t, ring) => t + perimeter(ring), 0);
|
|
149
|
+
const r = Math.max(GAP * 0.7, Math.min(stroke * size, 80)) * 0.5 * 1.15;
|
|
150
|
+
const [x0, y0, x1, y1] = boxOf(polys);
|
|
151
|
+
if (where === 'inside') {
|
|
152
|
+
let best = null;
|
|
153
|
+
for (const poly of polys) for (const hole of poly.slice(1)) { const a = Math.abs(signedArea(hole)); if (!best || a > best.a) best = { hole, a }; }
|
|
154
|
+
if (!best) return shape;
|
|
155
|
+
const per = perimeter(best.hole), round = (4 * Math.PI * best.a) / (per * per);
|
|
156
|
+
if (round > 0.8) return shape; // a dot in a round counter is an eye
|
|
157
|
+
const [hx0, hy0, hx1, hy1] = boxOf([[best.hole]]), cx = (hx0 + hx1) / 2, cy = (hy0 + hy1) / 2;
|
|
158
|
+
const fit = Math.min(hx1 - hx0, hy1 - hy0) / 2 - GAP;
|
|
159
|
+
if (fit < GAP * 0.5) return shape;
|
|
160
|
+
const dot = circle(cx, cy, Math.min(r, fit), 64);
|
|
161
|
+
return I(dot, shape).length ? shape : U(shape, D(dot, grow(shape, GAP)));
|
|
162
|
+
}
|
|
163
|
+
if (where === 'corner') return U(shape, circle(x1 + GAP + r * 0.7, y1 + GAP * 0.2 - r * 0.3, r, 64));
|
|
164
|
+
// end: beside the lowest point of the rightmost ink
|
|
165
|
+
let ex = -Infinity, ey = y0;
|
|
166
|
+
for (const poly of polys) for (const [x, y] of poly[0]) if (x > ex - 0.5) { if (x > ex + 0.5 || y > ey) ey = y; ex = Math.max(ex, x); }
|
|
167
|
+
return U(shape, circle(x1 + GAP + r, Math.min(y1 - r, Math.max(y0 + r, ey - r)), r, 64));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A polygon's top and left edges, for reading order. */
|
|
171
|
+
const top = (poly) => Math.min(...poly[0].map(([, y]) => y));
|
|
172
|
+
const left = (poly) => Math.min(...poly[0].map(([x]) => x));
|