An agent skill for creating detailed, interactive isometric illustrations of real-world machines and complex systems. Generates polished SVGs with optional WebGL shaders and 3D effects.
Add the spot-plate example, light colours for test-rig
R.0aa194eb40b0
diff --git a/.gitignore b/.gitignoreindex 1a8a703..dd5df78 100644--- a/.gitignore+++ b/.gitignore@@ -9,4 +9,3 @@ audit.txt/capture.png.scratch/tmp/-examples/aircraft-carrier/diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e53b505..c75ff25 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,8 +6,13 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha### Added+- `examples/spot-plate/`, a second React figure from the same site as `test-rig`: six pairs of glass drops that run together into one piece of glass as a fan of feeler blades sets `merge`. It draws in the light and dark themes.- A first workflow step, **Size it before you start**: every request is sized as a Figure (about 30–90 minutes), a Hero (2–4 hours) or an Epic (6 hours or more), and the estimate is told to the user first. An Epic is not started until the user chooses it over a proposed Hero version. Every size has a working page within the first hour, and Claude reports when a step runs past twice its share of the estimate.+### Fixed++- `examples/test-rig/` drew its glass button dark in the light theme. `stretch.css` now has light values for its own colours.+### Changed- The workflow steps are renumbered 1–10.diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 124550d..3f93274 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -42,7 +42,7 @@ node examples/turning-dial/build.mjs --light --verifynode examples/turning-dial/stress.mjs --light```-The Raptor builds take a few minutes each; the rest take seconds. `examples/test-rig/` is a React component with no build script.+The Raptor builds take a few minutes each; the rest take seconds. `examples/test-rig/` and `examples/spot-plate/` are React components with no build script.After a build, `git status --short` must show nothing unless you meant to change a figure. CI runs exactly these commands and then `git diff --exit-code`.diff --git a/README.md b/README.mdindex 9d9452a..7760d7f 100644--- a/README.md+++ b/README.md@@ -190,6 +190,7 @@ Each framework-free example has a Node build script that writes standalone pages| [`raptor-engine`](examples/raptor-engine) | A Raptor 2 engine in a test stand. It comes apart into 11 assemblies, and a WebGL plume, shock, splash and steam render between the back and front SVG. The reference for dense pipework, smooth shading, fades and the audit. The build takes a few minutes. | `node examples/raptor-engine/build.mjs` || [`ripple-tank`](examples/ripple-tank) | A school ripple tank on tall legs over a paper screen, seen from 44° up. Two WebGL layers are registered to the isometric planes and driven by a pure model in `model.mjs`. | `node examples/ripple-tank/build.mjs` || [`test-rig`](examples/test-rig) | A production figure from a React/Next.js site: a glass button on a spring-mounted carriage, a finger probe on a rail, and a dial gauge reading the lean. 53 solids. No build script: copy it into a React app. | none |+| [`spot-plate`](examples/spot-plate) | A second figure from the same site: six pairs of glass drops on a spot plate that run together into one piece of glass as a fan of feeler blades opens. Each pair is drawn from one distance field. No build script: copy it into a React app. | none || [`turning-dial`](examples/turning-dial) | The 3D mode: a combination dial that turns in true 3D with a small robot hand on it, a three-hinge finger that lifts, and a pod that breaks off as a free body. `stress.mjs` is a 380-part hand in a cluttered workshop, used to measure performance. | `node examples/turning-dial/build.mjs` |`node examples/raptor-engine/build.mjs --audit` and `node examples/turning-dial/build.mjs --light --audit` also run the geometry audit. The 3D audit is slow; see [`references/3d.md`](references/3d.md).@@ -233,7 +234,7 @@ anatomy/│ ├── inline-kit.mjs the kit as source, to inline into a standalone page│ ├── turn-check.mjs 3D checks in the browser (with turn-fidelity.mjs)│ └── turn-bench.mjs 3D timing in Node-├── examples/ six complete figures, built pages committed+├── examples/ seven complete figures, built pages committed├── evals/evals.json test prompts and what a good answer contains└── .github/ issue forms, PR template, CI, README images```@@ -247,7 +248,7 @@ anatomy/| **[Claude Code](https://code.claude.com/docs/en/overview)** | everything | The skill is written for it. || **Node.js 20.10+** | builds, kit, checks | Built-in modules only: nothing to `npm install`. The examples were rebuilt byte for byte on Node 20.19 and 22.11. On Node 20 the browser scripts restart themselves with `--experimental-websocket`. || **Chrome or Chromium** | the checks | `capture.mjs`, `drive.mjs`, `lines.mjs` and `turn-check.mjs` look in the usual places on macOS, Linux and Windows and in Playwright's cache. Set `CHROME_PATH` for any other binary. They run it headless with WebGL on. |-| **React 18+** | React output only | `kit/react/` and `examples/test-rig/`. |+| **React 18+** | React output only | `kit/react/`, `examples/test-rig/` and `examples/spot-plate/`. |## Limitsdiff --git a/SKILL.md b/SKILL.mdindex 7c2d612..35426b2 100644--- a/SKILL.md+++ b/SKILL.md@@ -7,13 +7,14 @@ description: Build crafted, highly detailed, interactive isometric SVG figures tThis skill makes figures like a small instrument on a bench: a heavy base on feet, rails with tick rulers, a carriage on bushings, knurled knobs, coil springs, a dial gauge whose needle moves, screws as tiny dots. The reader understands the idea because they recognise the machine. Every number the figure shows comes from the same model that moves its parts.-Six complete examples ship with the skill. Open the closest one before you start. Each framework-free example is built with `node examples/<name>/build.mjs`, which writes a standalone HTML page next to the script; add `--light` for the light theme.+Seven complete examples ship with the skill. Open the closest one before you start. Each framework-free example is built with `node examples/<name>/build.mjs`, which writes a standalone HTML page next to the script; add `--light` for the light theme.- `examples/dial-indicator/` is the smallest: a dial gauge on a stand, about 300 lines in all.- `examples/desk-computer/` is framework-free SVG: a desk computer with a keyboard you can type on. The typed line appears on a CRT screen drawn in the plane of the case front, and the picture collapses to a line and a dot when you switch it off. It has about 85 solids and 850 paths.- `examples/raptor-engine/` is a rocket engine hanging in a test stand. Its round parts come from `kit/lathe.mjs` and its pipes and harness from `kit/tube.mjs`. It comes apart into 11 assemblies with staggered springs and per-frame depth re-sorting. Every part records its true shape, and `node build.mjs --audit` (`kit/audit.mjs`) proves, at rest, apart and in every replayed frame of the explode, that nothing passes through anything, that every end sits on a real mount, that no bend pinches, folds or lands on another line, that no curved profile's slope wobbles, and that every overlap is drawn in depth order. A WebGL plume, shock, splash and steam render between the back and front SVG. It is the reference for dense pipework, smooth shading and fades.- `examples/ripple-tank/` is a school ripple tank on tall legs over a paper screen, seen from 44° up. Two WebGL layers (lamp light, shadows and caustics on the paper, and the water's reflections and glass) are registered to the isometric planes and driven by a pure dispersion and optics model (`model.mjs`); a frequency change travels out from the dippers through a history texture.- `examples/test-rig/` is a production figure from a real site (React/Next): a glass button on a spring-mounted carriage, a finger probe on a rail that presses and pulls, and a dial gauge reading the lean. It has 53 solids and about 470 paths.+- `examples/spot-plate/` is a second production figure from the same site: six pairs of glass drops on a spot plate, each pair drawn from one distance field, so a pair closer than `merge` runs together into one piece of glass. A fan of feeler blades sets `merge`, one blade per gap. It is the reference for shapes that morph into each other and for one control driving many parts.- `examples/turning-dial/` is the optional 3D mode: a combination dial that turns in true 3D with a small robot hand on it. It has about 90 live parts in metal materials, a second turn group, a hinge, a three-hinge finger that lifts and a pod that breaks off as a free body. A WebGL LED, its light pool and sparks follow the moving parts. `stress.mjs` beside it is a dense hand of about 380 parts in a cluttered workshop, used to measure performance.The test rig is the quality bar for the drawing itself. The Raptor is the bar for shader work: a WebGL effect has to reach its standard of world-space, no-pop, seamless rendering.diff --git a/examples/spot-plate/art.tsx b/examples/spot-plate/art.tsxnew file mode 100644index 0000000..fd87899--- /dev/null+++ b/examples/spot-plate/art.tsx@@ -0,0 +1,110 @@+import * as React from "react";+import { Dots, FaceText, Line, Solid } from "../../kit/react/draw";+import { BASE_ART, BOTTLE_ART, DECK_ART, LABEL, TRAY_ART } from "./geometry";+import { LiquidLive } from "./live";++function Lit({ id, children }: { id: string; children: React.ReactNode }) {+ return (+ <g data-part={id}>{children}</g>+ );+}++const BACK = (+ <g key="back">+ <Lit id="frame">+ <path className="iso-halo" d={BASE_ART.halo} />+ {BASE_ART.feet.map((parts, index) => (+ <g key={index}>+ {parts.map((paths, piece) => (+ <Solid key={piece} paths={paths} tone={piece ? "mid" : "lo"} crease="faint" />+ ))}+ </g>+ ))}+ <Solid paths={BASE_ART.slab} tone="mid" crease="faint" />+ <Line d={BASE_ART.groove} tone="lo" />+ <Line d={BASE_ART.inlay} tone="faint" />+ <Line d={BASE_ART.screwRings} tone="lo" />+ <Dots points={BASE_ART.screws} size={0.5} tone="mid" />+ <Solid className="ml-plate" paths={TRAY_ART.slab} tone="hi" crease="lo" />+ <Line d={TRAY_ART.groove} tone="lo" />+ <Line d={TRAY_ART.inlay} tone="faint" />+ {TRAY_ART.wells.map((well, index) => (+ <g key={index}>+ <path className="ml-floor" d={well.opening} />+ {well.wall ? <path className="ml-wall" d={well.wall} /> : null}+ <Line d={well.foot} tone="faint" />+ <Line d={well.opening} tone="mid" />+ </g>+ ))}+ <Dots points={TRAY_ART.counts} size={0.55} tone="mid" />+ <Line d={TRAY_ART.screwRings} tone="lo" />+ <Dots points={TRAY_ART.screws} size={0.5} tone="mid" />+ </Lit>+ <Lit id="apart">+ <Line d={TRAY_ART.minor} tone="lo" />+ <Line d={TRAY_ART.major} tone="mid" />+ <Line d={TRAY_ART.datum} tone="mid" />+ <Dots points={TRAY_ART.gapMarks} size={0.6} tone="hi" />+ </Lit>+ </g>+);++const DECK = (+ <g key="deck">+ <Lit id="frame">+ <Solid paths={DECK_ART.slab} tone="mid" crease="faint" />+ <Line d={DECK_ART.inlay} tone="faint" />+ <Line d={DECK_ART.screwRings} tone="lo" />+ <Dots points={DECK_ART.screws} size={0.45} tone="mid" />+ <Solid paths={BOTTLE_ART.coaster} tone="mid" crease="faint" />+ <Line d={BOTTLE_ART.coasterRing} tone="faint" />+ <Dots points={BOTTLE_ART.coasterDots} size={0.45} tone="mid" />+ <Solid className="ml-bottle" paths={BOTTLE_ART.body} tone="hi" crease="faint" />+ <Line d={BOTTLE_ART.foot} tone="faint" />+ <Line d={BOTTLE_ART.level} tone="lo" />+ <Line d={BOTTLE_ART.shine} tone="mid" />+ <Solid className="ml-bottle" paths={BOTTLE_ART.shoulder} tone="hi" crease="faint" />+ <Solid paths={BOTTLE_ART.neck} tone="mid" crease="faint" />+ <Solid paths={BOTTLE_ART.collar} tone="mid" crease="faint" />+ <Solid paths={BOTTLE_ART.cap} tone="hi" crease="lo" />+ <Line d={BOTTLE_ART.capKnurl} tone="lo" />+ <Line d={BOTTLE_ART.capRing} tone="faint" />+ <Solid paths={BOTTLE_ART.bulb} tone="mid" crease="faint" />+ <Line d={BOTTLE_ART.bulbShine} tone="lo" />+ <Line d={BOTTLE_ART.bulbRing} tone="faint" />+ <Dots points={[BOTTLE_ART.tip]} size={0.45} tone="mid" />+ </Lit>+ <Lit id="fan">+ <Line d={DECK_ART.guide} tone="faint" dashed />+ {DECK_ART.stops.map((paths, index) => (+ <Solid key={index} paths={paths} tone="mid" crease="faint" />+ ))}+ <Dots points={DECK_ART.stopTops} size={0.45} tone="hi" />+ <Solid paths={DECK_ART.bandBack} tone="mid" crease="faint" />+ <FaceText transform={DECK_ART.label} size={4.2} tone="lo">+ merge+ </FaceText>+ <Solid paths={DECK_ART.washer} tone="lo" crease="faint" />+ </Lit>+ </g>+);++const FRONT = (+ <Lit key="front" id="fan">+ <Solid paths={DECK_ART.bandFront} tone="mid" crease="faint" />+ <Line d={DECK_ART.bandLine} tone="faint" />+ <Line d={DECK_ART.minor} tone="lo" />+ <Line d={DECK_ART.major} tone="mid" />+ <Dots points={DECK_ART.gapDots} size={0.55} tone="hi" />+ <Dots points={[...DECK_ART.ends, DECK_ART.seam]} size={0.45} tone="mid" />+ <Solid paths={DECK_ART.cap} tone="mid" crease="faint" />+ <Solid paths={DECK_ART.nut} tone="hi" crease="lo" />+ <Line d={DECK_ART.nutKnurl} tone="lo" />+ <Line d={DECK_ART.nutRing} tone="faint" />+ <Dots points={[DECK_ART.pin]} size={0.6} tone="hi" />+ </Lit>+);++export function LiquidArt() {+ return <LiquidLive label={LABEL} back={BACK} deck={DECK} front={FRONT} />;+}diff --git a/examples/spot-plate/drops.ts b/examples/spot-plate/drops.tsnew file mode 100644index 0000000..471e86a--- /dev/null+++ b/examples/spot-plate/drops.ts@@ -0,0 +1,541 @@+import { type Flat, iso, pathOf, type Plane } from "../../kit/iso-kit";+import { BIG_Y, CLIMB, FLOOR, GAPS, LIGHT, P, RA, RB, THICK, VIEW, fieldOf, rowX, rowY, spanOf, type Field } from "./rig";++const STEP = 2;+const FINE = 0.5;+const FINE_HALF = 6;+const NUDGE = -0.05;+const KISS = 0.75;+const WINDOW = 4;+const BEND = 0.3;+const BEVEL = 2.2;+const TAPER = 10;+const SHADES = 4;+const STRIP = 8;+const SHINE_IN = 3.4;+const SHINE_FACING = 0.82;+const FADE_SHARE = 0.3;+const FADE_MOST = 9;+const FADE_STEPS = 6;++interface Grid {+ values: Float32Array;+ us: Float64Array;+ vs: Float64Array;+}++function ticksOf(centre: number, before: number, after: number) {+ const ticks: number[] = [];+ for (let k = -Math.ceil(before / STEP); k <= Math.ceil(after / STEP); k++) {+ if (Math.abs(k * STEP) > FINE_HALF) ticks.push(centre + k * STEP);+ }+ const fine = Math.round(FINE_HALF / FINE);+ for (let k = -fine; k <= fine; k++) ticks.push(centre + k * FINE);+ return Float64Array.from(ticks.sort((a, b) => a - b));+}++function sample(field: Field, gap: number): Grid {+ const middle = RA + gap / 2;+ const us = ticksOf(middle, middle + RA + 6, spanOf(gap) + RB + 6 - middle);+ const vs = ticksOf(0, RA + 6, RA + 6);+ const nx = us.length;+ const ny = vs.length;+ const values = new Float32Array(nx * ny);+ for (let j = 0; j < ny; j++) {+ const mirror = ny - 1 - j;+ if (mirror < j) {+ values.copyWithin(j * nx, mirror * nx, mirror * nx + nx);+ continue;+ }+ const v = vs[j]!;+ for (let i = 0; i < nx; i++) values[j * nx + i] = field(us[i]!, v);+ }+ return { values, us, vs };+}++const SEGMENTS: Record<number, [number, number][]> = {+ 1: [[3, 2]],+ 2: [[2, 1]],+ 3: [[3, 1]],+ 4: [[0, 1]],+ 6: [[0, 2]],+ 7: [[3, 0]],+ 8: [[3, 0]],+ 9: [[0, 2]],+ 11: [[0, 1]],+ 12: [[3, 1]],+ 13: [[2, 1]],+ 14: [[3, 2]],+};++function rings({ values, us, vs }: Grid, level: number): Plane[][] {+ const nx = us.length;+ const ny = vs.length;+ const at = (i: number, j: number) => values[j * nx + i]!;+ const links = new Map<number, number[]>();+ const points = new Map<number, Plane>();+ const pointOf = (id: number) => {+ if (points.has(id)) return;+ const cell = id >> 1;+ const i = cell % nx;+ const j = (cell - i) / nx;+ const down = id & 1;+ const a = at(i, j);+ const b = down ? at(i, j + 1) : at(i + 1, j);+ const t = Math.min(Math.max((level - a) / (b - a), 0), 1);+ points.set(id, down ? [us[i]!, vs[j]! + (vs[j + 1]! - vs[j]!) * t] : [us[i]! + (us[i + 1]! - us[i]!) * t, vs[j]!]);+ };+ const link = (a: number, b: number) => {+ pointOf(a);+ pointOf(b);+ (links.get(a) ?? links.set(a, []).get(a)!).push(b);+ (links.get(b) ?? links.set(b, []).get(b)!).push(a);+ };+ for (let j = 0; j < ny - 1; j++) {+ for (let i = 0; i < nx - 1; i++) {+ const tl = at(i, j);+ const tr = at(i + 1, j);+ const br = at(i + 1, j + 1);+ const bl = at(i, j + 1);+ const code = (tl < level ? 8 : 0) | (tr < level ? 4 : 0) | (br < level ? 2 : 0) | (bl < level ? 1 : 0);+ if (code === 0 || code === 15) continue;+ const edges = [(j * nx + i) * 2, ((j * nx + i + 1) * 2) | 1, ((j + 1) * nx + i) * 2, ((j * nx + i) * 2) | 1];+ let pairs = SEGMENTS[code];+ if (!pairs) {+ const centre = (tl + tr + br + bl) / 4 < level;+ if (code === 5) pairs = centre ? [[3, 0], [2, 1]] : [[0, 1], [3, 2]];+ else pairs = centre ? [[0, 1], [3, 2]] : [[3, 0], [2, 1]];+ }+ for (const [a, b] of pairs) link(edges[a]!, edges[b]!);+ }+ }+ const seen = new Set<number>();+ const found: Plane[][] = [];+ for (const start of links.keys()) {+ if (seen.has(start)) continue;+ const ring: Plane[] = [];+ let previous = -1;+ let current = start;+ while (!seen.has(current)) {+ seen.add(current);+ ring.push(points.get(current)!);+ const next = links.get(current)!.find((candidate) => candidate !== previous && !seen.has(candidate));+ if (next === undefined) break;+ previous = current;+ current = next;+ }+ if (ring.length > 3) found.push(ring);+ }+ return found;+}++function simplify(points: Plane[], tolerance: number): Plane[] {+ if (points.length < 3) return points;+ const first = points[0]!;+ const last = points[points.length - 1]!;+ const dx = last[0] - first[0];+ const dy = last[1] - first[1];+ const length = Math.hypot(dx, dy) || 1;+ let worst = 0;+ let index = 0;+ for (let step = 1; step < points.length - 1; step++) {+ const point = points[step]!;+ const off = Math.abs((point[0] - first[0]) * dy - (point[1] - first[1]) * dx) / length;+ if (off > worst) {+ worst = off;+ index = step;+ }+ }+ if (worst <= tolerance) return [first, last];+ return [...simplify(points.slice(0, index + 1), tolerance).slice(0, -1), ...simplify(points.slice(index), tolerance)];+}++function simplifyRing(ring: Plane[], tolerance: number): Plane[] {+ let far = 0;+ let best = 0;+ for (let index = 1; index < ring.length; index++) {+ const distance = Math.hypot(ring[index]![0] - ring[0]![0], ring[index]![1] - ring[0]![1]);+ if (distance > best) {+ best = distance;+ far = index;+ }+ }+ const one = simplify(ring.slice(0, far + 1), tolerance);+ const two = simplify([...ring.slice(far), ring[0]!], tolerance);+ return [...one.slice(0, -1), ...two.slice(0, -1)];+}++function signedArea(points: Plane[] | Flat[]) {+ let area = 0;+ for (let index = 0; index < points.length; index++) {+ const [ax, ay] = points[index]!;+ const [bx, by] = points[(index + 1) % points.length]!;+ area += ax * by - bx * ay;+ }+ return area / 2;+}++const oriented = (points: Flat[]) => (signedArea(points) < 0 ? [...points].reverse() : points);++function runsOf(flags: boolean[], want: boolean) {+ const count = flags.length;+ const runs: number[][] = [];+ const start = flags.findIndex((flag, index) => flag !== flags[(index + count - 1) % count]);+ if (start < 0) return flags[0] === want ? [Array.from({ length: count + 1 }, (_, index) => index % count)] : [];+ let run: number[] | null = null;+ for (let step = 0; step < count; step++) {+ const index = (start + step) % count;+ if (flags[index] === want) {+ if (!run) run = [index];+ run.push((index + 1) % count);+ } else if (run) {+ runs.push(run);+ run = null;+ }+ }+ if (run) runs.push(run);+ return runs;+}++export interface GlassShape {+ fill: string;+ shades: { d: string; shade: number }[];+ top: string;+ crease: string;+ bevel: string;+ outline: string;+ shine: string;+ depth: number;+}++const ease = (t: number) => t * t * (3 - 2 * t);++type Hidden = (x: number, y: number, z: number, edge: number) => boolean;++function hiddenBy(ring: Plane[], top: number): Hidden {+ const count = ring.length;+ const xs = new Float64Array(count);+ const ys = new Float64Array(count);+ for (let index = 0; index < count; index++) {+ xs[index] = ring[index]![0];+ ys[index] = ring[index]![1];+ }+ const inside = (x: number, y: number) => {+ let hit = false;+ for (let index = 0, previous = count - 1; index < count; previous = index++) {+ const ay = ys[index]!;+ const by = ys[previous]!;+ if (ay > y !== by > y && x < ((xs[previous]! - xs[index]!) * (y - ay)) / (by - ay) + xs[index]!) hit = !hit;+ }+ return hit;+ };+ return (x, y, z, edge) => {+ const reach = (top - z) / CLIMB;+ if (reach <= 0) return false;+ if (inside(x + VIEW[0] * 0.05, y + VIEW[1] * 0.05)) return true;+ const fx = x + VIEW[0] * reach;+ const fy = y + VIEW[1] * reach;+ const left = Math.min(x, fx);+ const right = Math.max(x, fx);+ const low = Math.min(y, fy);+ const high = Math.max(y, fy);+ for (let index = 0; index < count; index++) {+ if (index === edge || (edge < 0 && (index === -edge - 1 || (index + 1) % count === -edge - 1))) continue;+ const next = index + 1 === count ? 0 : index + 1;+ const ax = xs[index]!;+ const ay = ys[index]!;+ const bx = xs[next]!;+ const by = ys[next]!;+ if ((ax < left && bx < left) || (ax > right && bx > right) || (ay < low && by < low) || (ay > high && by > high)) continue;+ const ex = bx - ax;+ const ey = by - ay;+ const cross = VIEW[0] * ey - VIEW[1] * ex;+ if (Math.abs(cross) < 1e-12) continue;+ const ox = ax - x;+ const oy = ay - y;+ const t = (ox * ey - oy * ex) / cross;+ const u = (ox * VIEW[1] - oy * VIEW[0]) / cross;+ if (t > 0.05 && t < reach && u >= 0 && u <= 1) return true;+ }+ return false;+ };+}++function visibleRuns(ring: Plane[], run: number[], z: number, hidden: Hidden): Flat[][] {+ const runs: Flat[][] = [];+ let line: Flat[] = [];+ const shown = run.map((index) => !hidden(ring[index]![0], ring[index]![1], z, -index - 1));+ const lift = ([x, y]: Plane) => iso([x, y, z], P);+ const cut = (edge: number, fromShown: boolean): Plane => {+ const a = ring[edge]!;+ const b = ring[(edge + 1) % ring.length]!;+ let low = 0;+ let high = 1;+ for (let round = 0; round < 14; round++) {+ const mid = (low + high) / 2;+ const seen = !hidden(a[0] + (b[0] - a[0]) * mid, a[1] + (b[1] - a[1]) * mid, z, edge);+ if (seen === fromShown) low = mid;+ else high = mid;+ }+ const t = (low + high) / 2;+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];+ };+ for (let index = 0; index < run.length; index++) {+ const point = ring[run[index]!]!;+ if (index > 0 && shown[index] !== shown[index - 1]) {+ const edge = cut(run[index - 1]!, shown[index - 1]!);+ if (shown[index - 1]) {+ line.push(lift(edge));+ if (line.length > 1) runs.push(line);+ line = [];+ } else {+ line = [lift(edge)];+ }+ }+ if (shown[index]) line.push(lift(point));+ }+ if (line.length > 1) runs.push(line);+ return runs;+}++function solidOf(ring: Plane[], z: number, height: number, occlude: boolean): GlassShape {+ const count = ring.length;+ const counter = signedArea(ring) > 0;+ const normals = ring.map(([ax, ay], index) => {+ const [bx, by] = ring[(index + 1) % count]!;+ const dx = bx - ax;+ const dy = by - ay;+ const length = Math.hypot(dx, dy) || 1;+ return (counter ? [dy / length, -dx / length] : [-dy / length, dx / length]) as Plane;+ });+ const facing = normals.map(([nx, ny]) => nx * VIEW[0] + ny * VIEW[1] > 1e-9);+ const top = ring.map(([x, y]) => iso([x, y, z + height], P));+ const bottom = ring.map(([x, y]) => iso([x, y, z], P));+ const hidden = occlude ? hiddenBy(ring, z + height) : null;++ const strips: { depth: number; shade: number; d: string }[] = [];+ let open: { from: number; to: number; shade: number } | null = null;+ const close = () => {+ if (!open) return;+ const upper: Flat[] = [];+ const lower: Flat[] = [];+ let depth = 0;+ for (let index = open.from; index <= open.to + 1; index++) {+ const point = index % count;+ upper.push(top[point]!);+ lower.push(bottom[point]!);+ depth += ring[point]![0] * VIEW[0] + ring[point]![1] * VIEW[1];+ }+ strips.push({ depth: depth / upper.length, shade: open.shade, d: pathOf(oriented([...upper, ...lower.reverse()]), true) });+ open = null;+ };+ for (let index = 0; index < count; index++) {+ if (!facing[index]) {+ close();+ continue;+ }+ const [nx, ny] = normals[index]!;+ const lit = (nx * LIGHT[0] + ny * LIGHT[1] + 1) / 2;+ const shade = Math.min(SHADES - 1, Math.max(0, Math.floor(lit * SHADES)));+ if (open && open.shade === shade && index - open.from < STRIP) open.to = index;+ else {+ close();+ open = { from: index, to: index, shade };+ }+ }+ close();+ strips.sort((a, b) => a.depth - b.depth);+ const shades: { d: string; shade: number }[] = [];+ for (const strip of strips) {+ const last = shades[shades.length - 1];+ if (last && last.shade === strip.shade) last.d += strip.d;+ else shades.push({ d: strip.d, shade: strip.shade });+ }++ const inward = (index: number, by: number): Plane => {+ const [ax, ay] = normals[(index + count - 1) % count]!;+ const [bx, by2] = normals[index]!;+ const mx = ax + bx;+ const my = ay + by2;+ const length = Math.hypot(mx, my) || 1;+ const [x, y] = ring[index]!;+ return [x - (mx / length) * by, y - (my / length) * by];+ };++ const crease: string[] = [];+ const outline: string[] = [];+ const bevel: string[] = [];+ for (const run of runsOf(facing, false)) outline.push(pathOf(run.map((index) => top[index]!)));+ for (const run of runsOf(facing, true)) {+ crease.push(pathOf(run.map((index) => top[index]!)));+ if (hidden) for (const seen of visibleRuns(ring, run, z, hidden)) outline.push(pathOf(seen));+ else outline.push(pathOf(run.map((index) => bottom[index]!)));+ const along = [0];+ for (let step = 1; step < run.length; step++) {+ const [ax, ay] = ring[run[step - 1]!]!;+ const [bx, by] = ring[run[step]!]!;+ along.push(along[step - 1]! + Math.hypot(bx - ax, by - ay));+ }+ const total = along[along.length - 1]!;+ bevel.push(+ pathOf(+ run.map((index, step) => {+ const near = Math.min(along[step]!, total - along[step]!);+ const [x, y] = inward(index, BEVEL * ease(Math.min(1, near / TAPER)));+ return iso([x, y, z + height], P);+ }),+ ),+ );+ }+ for (let index = 0; index < count; index++) {+ if (facing[(index + count - 1) % count] === facing[index]) continue;+ const [x, y] = ring[index]!;+ let from = z;+ if (hidden && hidden(x, y, z, -index - 1)) {+ let low = z;+ let high = z + height;+ for (let round = 0; round < 12; round++) {+ const mid = (low + high) / 2;+ if (hidden(x, y, mid, -index - 1)) low = mid;+ else high = mid;+ }+ from = high;+ }+ if (z + height - from > 0.05) outline.push(pathOf([top[index]!, iso([x, y, from], P)]));+ }++ const toward = normals.map(([nx, ny], index) => {+ const [px, py] = normals[(index + count - 1) % count]!;+ return ((nx + px) * LIGHT[0] + (ny + py) * LIGHT[1]) / 2 > SHINE_FACING;+ });+ const shine = runsOf(toward, true)+ .filter((run) => run.length > 3)+ .map((run) => pathOf(run.slice(1, -1).map((index) => iso([...inward(index, SHINE_IN), z + height] as [number, number, number], P))))+ .join("");++ const cx = ring.reduce((sum, [x]) => sum + x, 0) / count;+ const cy = ring.reduce((sum, [, y]) => sum + y, 0) / count;+ return {+ fill: [pathOf(oriented(top), true), pathOf(oriented(bottom), true)].join(""),+ shades,+ top: pathOf(oriented(top), true),+ crease: crease.join(""),+ bevel: bevel.join(""),+ outline: outline.join(""),+ shine,+ depth: cx * VIEW[0] + cy * VIEW[1],+ };+}++export interface Glint {+ d: string;+ alpha: number;+}++export interface RowShape {+ row: number;+ gap: number;+ joined: boolean;+ glass: GlassShape[];+ neck: Glint[];+}++const atTop = (points: Plane[]) => points.map(([x, y]) => iso([x, y, FLOOR + THICK], P));++function concaveRuns(ring: Plane[]): number[][] {+ const count = ring.length;+ const along = [0];+ for (let index = 0; index < count; index++) {+ const [ax, ay] = ring[index]!;+ const [bx, by] = ring[(index + 1) % count]!;+ along.push(along[index]! + Math.hypot(bx - ax, by - ay));+ }+ const total = along[count]!;+ const pointAt = (distance: number): Plane => {+ const s = ((distance % total) + total) % total;+ let low = 0;+ let high = count;+ while (high - low > 1) {+ const mid = (low + high) >> 1;+ if (along[mid]! <= s) low = mid;+ else high = mid;+ }+ const [ax, ay] = ring[low]!;+ const [bx, by] = ring[(low + 1) % count]!;+ const t = (s - along[low]!) / Math.max(along[low + 1]! - along[low]!, 1e-9);+ return [ax + (bx - ax) * t, ay + (by - ay) * t];+ };+ const turn = signedArea(ring) > 0 ? 1 : -1;+ const flags = ring.map(([x, y], index) => {+ const [ax, ay] = pointAt(along[index]! - WINDOW);+ const [bx, by] = pointAt(along[index]! + WINDOW);+ return turn * ((x - ax) * (by - y) - (y - ay) * (bx - x)) < -BEND;+ });+ return runsOf(flags, true).filter((run) => run.length > 2);+}++function glintsOf(points: Flat[]): Glint[] {+ const along = [0];+ for (let index = 1; index < points.length; index++) {+ along.push(along[index - 1]! + Math.hypot(points[index]![0] - points[index - 1]![0], points[index]![1] - points[index - 1]![1]));+ }+ const total = along[along.length - 1]!;+ if (total < 0.5) return [];+ const cut = (from: number, to: number): Flat[] => {+ const out: Flat[] = [];+ const place = (distance: number) => {+ let index = 1;+ while (index < along.length - 1 && along[index]! < distance) index++;+ const t = (distance - along[index - 1]!) / Math.max(along[index]! - along[index - 1]!, 1e-9);+ const [ax, ay] = points[index - 1]!;+ const [bx, by] = points[index]!;+ return [ax + (bx - ax) * t, ay + (by - ay) * t] as Flat;+ };+ out.push(place(from));+ for (let index = 0; index < points.length; index++) if (along[index]! > from && along[index]! < to) out.push(points[index]!);+ out.push(place(to));+ return out;+ };+ const fade = Math.min(total * FADE_SHARE, FADE_MOST);+ const glints: Glint[] = [];+ let before = 0;+ for (let layer = 0; layer < FADE_STEPS; layer++) {+ const now = layer === FADE_STEPS - 1 ? 1 : ease((layer + 1) / FADE_STEPS);+ const alpha = Math.round((1 - (1 - now) / (1 - before)) * 100) / 100;+ before = now;+ const inset = (fade * layer) / (FADE_STEPS - 1);+ glints.push({ d: pathOf(cut(inset, total - inset)), alpha });+ }+ return glints;+}++const cache = new Map<number, RowShape>();+const CACHE_MOST = 420;++export const keyOf = (merge: number) => Math.round(merge * 4);++export function rowOf(row: number, merge: number): RowShape {+ const gap = GAPS[row]!;+ const plain = gap >= 2 * merge;+ const key = row * 1000 + (plain ? 999 : keyOf(merge));+ const known = cache.get(key);+ if (known) return known;+ const exact = plain ? 0 : keyOf(merge) / 4;+ const x0 = rowX(row);+ const y0 = rowY(row) + BIG_Y;+ const toWorld = ([u, v]: Plane): Plane => [x0 + v, y0 + u];+ const field = fieldOf(gap, exact);+ const kiss = !plain && keyOf(merge) === gap * 4;+ const level = kiss ? field(RA + gap / 2, KISS) : NUDGE;+ const found = rings(sample(field, gap), level).map((ring) => simplifyRing(ring, 0.06));+ const joined = gap < exact && found.length === 1;+ const whole = found.length === 1;+ const glass = found.map((local) => solidOf(local.map(toWorld), FLOOR, THICK, whole)).sort((a, b) => a.depth - b.depth);+ const neck = joined ? concaveRuns(found[0]!.map(toWorld)).flatMap((run) => glintsOf(atTop(run.map((index) => toWorld(found[0]![index]!))))) : [];+ const shape: RowShape = { row, gap, joined, glass, neck };+ if (cache.size >= CACHE_MOST) cache.delete(cache.keys().next().value!);+ cache.set(key, shape);+ return shape;+}++export const rowsOf = (merge: number) => GAPS.map((_, row) => rowOf(row, merge));diff --git a/examples/spot-plate/fan.ts b/examples/spot-plate/fan.tsnew file mode 100644index 0000000..122065d--- /dev/null+++ b/examples/spot-plate/fan.ts@@ -0,0 +1,84 @@+import { extrude, iso, pathOf, type Plane } from "../../kit/iso-kit";+import { BLADE_LONG, BLADE_Z, DECK_H, GAPS, LEAD_H, LEAD_LONG, P, PIVOT, ROWS, angleOf, thicknessOf } from "./rig";++const RADIANS = Math.PI / 180;+const BUTT = 7.2;+const TIP = 4.2;+const LEAD_TIP = 3.2;+const ARC = 10;++export interface BladePose {+ fill: string;+ shades: string[];+ top: string;+ crease: string;+ outline: string;+ line: string;+}++export interface FanPose {+ blades: BladePose[];+ halo: string;+ out: boolean[];+}++function outlineOf(length: number, tip: number): Plane[] {+ const out: Plane[] = [];+ for (let step = 0; step <= ARC; step++) {+ const angle = -90 + (180 * step) / ARC;+ out.push([length + tip * Math.cos(angle * RADIANS), tip * Math.sin(angle * RADIANS)]);+ }+ for (let step = 0; step <= ARC; step++) {+ const angle = 90 + (180 * step) / ARC;+ out.push([BUTT * Math.cos(angle * RADIANS), BUTT * Math.sin(angle * RADIANS)]);+ }+ return out;+}++const BLADE = outlineOf(BLADE_LONG, TIP);+const LEAD = outlineOf(LEAD_LONG, LEAD_TIP);++function place(shape: Plane[], degrees: number): Plane[] {+ const a = degrees * RADIANS;+ const dx = Math.sin(a);+ const dy = -Math.cos(a);+ const nx = Math.cos(a);+ const ny = Math.sin(a);+ return shape.map(([u, v]) => [PIVOT[0] + u * dx + v * nx, PIVOT[1] + u * dy + v * ny]);+}++function along(degrees: number, from: number, to: number, z: number) {+ const a = degrees * RADIANS;+ const dx = Math.sin(a);+ const dy = -Math.cos(a);+ return pathOf([iso([PIVOT[0] + from * dx, PIVOT[1] + from * dy, z], P), iso([PIVOT[0] + to * dx, PIVOT[1] + to * dy, z], P)]);+}++function bladeAt(shape: Plane[], degrees: number, z: number, height: number, length: number): BladePose {+ const ring = place(shape, degrees);+ const solid = extrude(ring, z, height, P, { convex: true });+ return {+ fill: solid.fill,+ shades: solid.shades ?? [],+ top: solid.top,+ crease: solid.crease,+ outline: solid.outline,+ line: along(degrees, 13, length - 6, z + height),+ };+}++export function fanOf(merge: number): FanPose {+ const lead = angleOf(merge);+ const blades: BladePose[] = [];+ const halo: string[] = [];+ const out: boolean[] = [];+ GAPS.forEach((gap, index) => {+ const angle = Math.min(lead, angleOf(gap));+ out.push(gap < merge);+ blades.push(bladeAt(BLADE, angle, BLADE_Z[index]!, thicknessOf(gap), BLADE_LONG));+ halo.push(pathOf(place(BLADE, angle).map(([x, y]) => iso([x, y, DECK_H], P)), true));+ });+ blades.push(bladeAt(LEAD, lead, BLADE_Z[ROWS]!, LEAD_H, LEAD_LONG));+ halo.push(pathOf(place(LEAD, lead).map(([x, y]) => iso([x, y, DECK_H], P)), true));+ return { blades, halo: halo.join(""), out };+}diff --git a/examples/spot-plate/figure.tsx b/examples/spot-plate/figure.tsxnew file mode 100644index 0000000..858e999--- /dev/null+++ b/examples/spot-plate/figure.tsx@@ -0,0 +1,25 @@+import { Plate } from "../../kit/react/draw";+import { LiquidArt } from "./art";+import { GAPS, MERGE, RADII, bladesOutOf, joinedListOf, readoutOf } from "./rig";+import "./spot-plate.css";++const [LARGE, SMALL] = RADII;++export function SpotPlateFigure() {+ return (+ <Plate+ fig="Fig 7"+ title="Spot plate"+ hint="Slide across to open the fan"+ readout={readoutOf(MERGE)}+ keys={[+ { mark: "raised", label: `Joined: one piece of glass, R${LARGE} + R${SMALL}` },+ { mark: "edge", label: "The neck, where a pair runs together" },+ { mark: "lit", label: "The merge blade" },+ ]}+ caption={`A spot plate with six channels, each holding a pair of glass drops at gaps from ${GAPS[0]} to ${GAPS[GAPS.length - 1]} px. Each pair is drawn from one distance field, so a pair closer than merge runs together into one piece of glass. The fan sets merge: each feeler blade stops at its own gap. At ${MERGE} px the ${joinedListOf(MERGE)} pairs have joined, so ${bladesOutOf(MERGE)}.`}+ >+ <LiquidArt />+ </Plate>+ );+}diff --git a/examples/spot-plate/geometry.ts b/examples/spot-plate/geometry.tsnew file mode 100644index 0000000..9b8f969--- /dev/null+++ b/examples/spot-plate/geometry.ts@@ -0,0 +1,280 @@+import { circleRing, extrude, insetPlan, onTop, pathOf, type Plan, type Plane, planOutline, type Point3, ringOf, type SolidPaths, topMatrix } from "../../kit/iso-kit";+import {+ BASE,+ BASE_H,+ BOTTLE,+ DATUM_Y,+ DECK,+ DECK_H,+ FOOT_H,+ GAPS,+ MERGE_MOST,+ P,+ PIVOT,+ SCALE_R,+ STACK_TOP,+ STOP_R,+ SWEEP,+ TRAY,+ TRAY_H,+ FLOOR,+ VIEW,+ WASHER_H,+ WELL_D,+ WELL_HALF,+ WELLS,+ BORDER,+ angleOf,+ at,+ rowX,+ rowY,+ ROW_RIM,+} from "./rig";++const RADIANS = Math.PI / 180;+const VIEW_ANGLE = Math.atan2(VIEW[1], VIEW[0]);++const line = (points: Point3[]) => pathOf(points.map(at));+const lines = (runs: Point3[][]) => runs.map(line).join("");++function clean(ring: Plane[]): Plane[] {+ return ring.filter(([x, y], index) => {+ const [nx, ny] = ring[(index + 1) % ring.length]!;+ return Math.hypot(nx - x, ny - y) > 1e-6;+ });+}++const solid = (plan: Plan, z: number, height: number, steps = 6, bevel = 0): SolidPaths =>+ extrude(clean(ringOf(plan, steps)), z, height, P, { convex: true, bevel });++const cyl = (x: number, y: number, r: number, z: number, h: number, steps = 28): SolidPaths => extrude(circleRing(x, y, r, steps), z, h, P);++const ring = (x: number, y: number, r: number, z: number, steps = 24) => onTop(circleRing(x, y, r, steps), z, P, true);++function knurl(x: number, y: number, r: number, z0: number, z1: number, count = 9) {+ const runs: Point3[][] = [];+ for (let index = 0; index < count; index++) {+ const angle = VIEW_ANGLE - Math.PI * 0.42 + (Math.PI * 0.84 * index) / (count - 1);+ const px = x + r * Math.cos(angle);+ const py = y + r * Math.sin(angle);+ runs.push([+ [px, py, z0 + 0.4],+ [px, py, z1 - 0.4],+ ]);+ }+ return lines(runs);+}++function normalsOf(points: Plane[]) {+ const count = points.length;+ let area = 0;+ for (let index = 0; index < count; index++) {+ const [ax, ay] = points[index]!;+ const [bx, by] = points[(index + 1) % count]!;+ area += ax * by - bx * ay;+ }+ const counter = area > 0;+ return points.map(([ax, ay], index) => {+ const [bx, by] = points[(index + 1) % count]!;+ const dx = bx - ax;+ const dy = by - ay;+ const length = Math.hypot(dx, dy) || 1;+ return (counter ? [dy / length, -dx / length] : [-dy / length, dx / length]) as Plane;+ });+}++function runOf(points: Plane[], want: boolean) {+ const count = points.length;+ const facing = normalsOf(points).map(([nx, ny]) => nx * VIEW[0] + ny * VIEW[1] > 1e-9);+ const start = facing.findIndex((flag, index) => flag === want && facing[(index + count - 1) % count] !== want);+ if (start < 0) return [] as Plane[];+ const run: Plane[] = [points[start]!];+ for (let step = 0; step < count && facing[(start + step) % count] === want; step++) run.push(points[(start + step + 1) % count]!);+ return run;+}++const visibleRun = (plan: Plan, z: number, steps = 8) => onTop(runOf(clean(ringOf(plan, steps)), true), z, P);++const corners = ({ x, y, w, d }: Plan, inset: number): Plane[] => [+ [x + inset, y + inset],+ [x + w - inset, y + inset],+ [x + w - inset, y + d - inset],+ [x + inset, y + d - inset],+];++const FEET = corners(BASE, 18);+const BASE_SCREWS = corners(BASE, 6);++export const BASE_ART = {+ halo: solid(insetPlan(BASE, 6), -BASE_H - FOOT_H, 0.4, 8).fill,+ feet: FEET.map(([x, y]) => [cyl(x, y, 3.6, -BASE_H - FOOT_H, FOOT_H - 1.2, 24), cyl(x, y, 4.8, -BASE_H - 1.2, 1.2, 28)]),+ slab: solid(BASE, -BASE_H, BASE_H, 10, 2.2),+ groove: visibleRun(BASE, -BASE_H * 0.45, 10),+ inlay: planOutline(insetPlan(BASE, 4), 0, P, 8),+ screws: BASE_SCREWS.map(([x, y]) => at([x, y, 0])),+ screwRings: BASE_SCREWS.map(([x, y]) => ring(x, y, 1.6, 0, 18)).join(""),+};++function wellOf(plan: Plan) {+ const points = clean(ringOf(plan, 12));+ const back = runOf(points, false);+ const wall = back.length > 1 ? pathOf([...back.map(([x, y]) => at([x, y, TRAY_H])), ...[...back].reverse().map(([x, y]) => at([x, y, FLOOR]))], true) : "";+ return {+ opening: onTop(points, TRAY_H, P, true),+ wall,+ foot: onTop(back, FLOOR, P),+ };+}++const RULE_X = WELL_HALF + 2.2;+const RULE_MINOR = 2.2;+const RULE_MAJOR = 4.6;+const RULE_REACH = MERGE_MOST;++function rulerOf(row: number) {+ const x0 = rowX(row) + RULE_X;+ const minor: Point3[][] = [];+ const major: Point3[][] = [];+ for (let step = 0; step <= RULE_REACH; step += 2) {+ const y = rowY(row) + DATUM_Y + step;+ (step % 8 === 0 ? major : minor).push([+ [x0, y, TRAY_H],+ [x0 + (step % 8 === 0 ? RULE_MAJOR : RULE_MINOR), y, TRAY_H],+ ]);+ }+ return { minor, major };+}++const RULERS = GAPS.map((_, row) => rulerOf(row));++const countY = (row: number) => rowY(row) + WELL_D + (row < 3 ? ROW_RIM : BORDER) / 2;++const TRAY_SCREWS = corners(TRAY, 7);++export const TRAY_ART = {+ screws: TRAY_SCREWS.map(([x, y]) => at([x, y, TRAY_H])),+ screwRings: TRAY_SCREWS.map(([x, y]) => ring(x, y, 1.7, TRAY_H, 18)).join(""),+ slab: solid(TRAY, 0, TRAY_H, 10, 2.4),+ groove: visibleRun(TRAY, TRAY_H * 0.42, 10),+ inlay: planOutline(insetPlan(TRAY, 4.2), TRAY_H, P, 10),+ wells: WELLS.map(wellOf),+ minor: lines(RULERS.flatMap((ruler) => ruler.minor)),+ major: lines(RULERS.flatMap((ruler) => ruler.major)),+ datum: lines(+ GAPS.map((_, row) => [+ [rowX(row) - WELL_HALF - 3.4, rowY(row) + DATUM_Y, TRAY_H],+ [rowX(row) - WELL_HALF - 0.8, rowY(row) + DATUM_Y, TRAY_H],+ ]),+ ),+ gapMarks: GAPS.map((gap, row) => at([rowX(row) + RULE_X + RULE_MAJOR + 2.4, rowY(row) + DATUM_Y + gap, TRAY_H])),+ counts: GAPS.flatMap((_, row) =>+ Array.from({ length: row + 1 }, (__, dot) => at([rowX(row) + (dot - row / 2) * 3.2, countY(row), TRAY_H])),+ ),+};++function sector(r0: number, r1: number, from: number, to: number, steps = 40): Plane[] {+ const out: Plane[] = [];+ const point = (r: number, degrees: number): Plane => [PIVOT[0] + r * Math.sin(degrees * RADIANS), PIVOT[1] - r * Math.cos(degrees * RADIANS)];+ for (let step = 0; step <= steps; step++) out.push(point(r1, from + ((to - from) * step) / steps));+ for (let step = steps; step >= 0; step--) out.push(point(r0, from + ((to - from) * step) / steps));+ return out;+}++const polar = (r: number, degrees: number, z: number): Point3 => [PIVOT[0] + r * Math.sin(degrees * RADIANS), PIVOT[1] - r * Math.cos(degrees * RADIANS), z];++const BAND_IN = SCALE_R - 2;+const BAND_OUT = SCALE_R + 10;+const BAND_FROM = -7;+const BAND_TO = SWEEP + 7;+const BAND_SPLIT = (Math.atan2(VIEW[1], VIEW[0]) * 180) / Math.PI;+const BAND_TOP = STACK_TOP;++function scaleTicks() {+ const minor: Point3[][] = [];+ const major: Point3[][] = [];+ for (let merge = 0; merge <= MERGE_MOST; merge += 2) {+ const angle = angleOf(merge);+ const long = merge % 8 === 0;+ (long ? major : minor).push([polar(BAND_IN + 1.2, angle, BAND_TOP), polar(BAND_IN + (long ? 6 : 3.6), angle, BAND_TOP)]);+ }+ return { minor: lines(minor), major: lines(major) };+}++const TICKS = scaleTicks();++const DECK_SCREWS = corners(DECK, 6);++const STOPS = GAPS.map((gap) => polar(STOP_R, angleOf(gap), DECK_H));++export const DECK_ART = {+ slab: solid(DECK, 0, DECK_H, 8, 1.6),+ inlay: planOutline(insetPlan(DECK, 3.4), DECK_H, P, 8),+ screws: DECK_SCREWS.map(([x, y]) => at([x, y, DECK_H])),+ screwRings: DECK_SCREWS.map(([x, y]) => ring(x, y, 1.5, DECK_H, 18)).join(""),+ guide: onTop(+ Array.from({ length: 61 }, (_, step) => {+ const [x, y] = polar(STOP_R + 3, (SWEEP * step) / 60, DECK_H);+ return [x, y] as Plane;+ }),+ DECK_H,+ P,+ ),+ stops: STOPS.map(([x, y]) => cyl(x, y, 1.3, DECK_H, 1.8, 16)),+ stopTops: STOPS.map(([x, y]) => at([x, y, DECK_H + 1.8])),+ bandBack: extrude(sector(BAND_IN, BAND_OUT, BAND_FROM, BAND_SPLIT, 24), DECK_H, BAND_TOP - DECK_H, P, { convex: false }),+ bandFront: extrude(sector(BAND_IN, BAND_OUT, BAND_SPLIT, BAND_TO, 64), DECK_H, BAND_TOP - DECK_H, P, { convex: false }),+ seam: at(polar((BAND_IN + BAND_OUT) / 2, BAND_SPLIT, BAND_TOP)),+ bandLine: onTop(sector(BAND_OUT - 1.6, BAND_OUT - 1.6, BAND_FROM + 1.2, BAND_TO - 1.2, 96).slice(0, 97), BAND_TOP, P),+ minor: TICKS.minor,+ major: TICKS.major,+ gapDots: GAPS.map((gap) => at(polar(BAND_OUT - 3.6, angleOf(gap), BAND_TOP))),+ ends: [0, SWEEP].map((angle) => at(polar(BAND_OUT - 3.6, angle, BAND_TOP))),+ label: topMatrix([PIVOT[0] - 13, PIVOT[1] + 150], DECK_H, P, "x"),+ washer: cyl(PIVOT[0], PIVOT[1], 9.4, DECK_H, WASHER_H, 32),+ cap: cyl(PIVOT[0], PIVOT[1], 8.2, STACK_TOP, 0.8, 32),+ nut: cyl(PIVOT[0], PIVOT[1], 5.8, STACK_TOP + 0.8, 4.2, 28),+ nutKnurl: knurl(PIVOT[0], PIVOT[1], 5.8, STACK_TOP + 0.8, STACK_TOP + 5, 13),+ nutRing: ring(PIVOT[0], PIVOT[1], 3.2, STACK_TOP + 5, 20),+ pin: at([PIVOT[0], PIVOT[1], STACK_TOP + 5]),+};++const [BX, BY] = BOTTLE;+const COASTER_TOP = DECK_H + 2;+const BODY_R = 19;+const BODY_TOP = COASTER_TOP + 32;+const SHOULDER_TOP = BODY_TOP + 2.2;+const NECK_TOP = SHOULDER_TOP + 2.2;+const COLLAR_TOP = NECK_TOP + 2.6;+const CAP_TOP = COLLAR_TOP + 11;+const BULB_TOP = CAP_TOP + 10;+const SHINE_ANGLE = VIEW_ANGLE + 0.95;+const shineAt = (r: number, z0: number, z1: number) =>+ line([+ [BX + r * Math.cos(SHINE_ANGLE), BY + r * Math.sin(SHINE_ANGLE), z0],+ [BX + r * Math.cos(SHINE_ANGLE), BY + r * Math.sin(SHINE_ANGLE), z1],+ ]);++export const BOTTLE_ART = {+ coaster: cyl(BX, BY, 25, DECK_H, COASTER_TOP - DECK_H, 44),+ coasterRing: ring(BX, BY, 22.6, COASTER_TOP, 40),+ coasterDots: [0, 1, 2, 3].map((index) => {+ const angle = Math.PI / 4 + (Math.PI / 2) * index;+ return at([BX + 23.8 * Math.cos(angle), BY + 23.8 * Math.sin(angle), COASTER_TOP]);+ }),+ body: cyl(BX, BY, BODY_R, COASTER_TOP, BODY_TOP - COASTER_TOP, 44),+ level: onTop(runOf(clean(circleRing(BX, BY, BODY_R, 44)), true), COASTER_TOP + 21, P),+ foot: onTop(runOf(clean(circleRing(BX, BY, BODY_R, 44)), true), COASTER_TOP + 2.4, P),+ shine: shineAt(BODY_R, COASTER_TOP + 5, BODY_TOP - 4),+ shoulder: cyl(BX, BY, 15.5, BODY_TOP, SHOULDER_TOP - BODY_TOP, 40),+ neck: cyl(BX, BY, 11, SHOULDER_TOP, NECK_TOP - SHOULDER_TOP, 36),+ collar: cyl(BX, BY, 9.4, NECK_TOP, COLLAR_TOP - NECK_TOP, 36),+ cap: cyl(BX, BY, 10, COLLAR_TOP, CAP_TOP - COLLAR_TOP, 36),+ capKnurl: knurl(BX, BY, 10, COLLAR_TOP + 1, CAP_TOP - 1, 15),+ capRing: ring(BX, BY, 7.2, CAP_TOP, 32),+ bulb: cyl(BX, BY, 6, CAP_TOP, BULB_TOP - CAP_TOP, 32),+ bulbShine: shineAt(6, CAP_TOP + 2, BULB_TOP - 2),+ bulbRing: ring(BX, BY, 3.4, BULB_TOP, 24),+ tip: at([BX, BY, BULB_TOP]),+};++export const LABEL = `A lab spot plate on a bench. The plate has six channels, each holding a pair of glass drops, R30 and R22, at gaps of ${GAPS.join(", ")} px, drawn to scale against a ruler on the rim. On the right, beside a dropper bottle, a fan of six feeler blades, one for each gap, turns on a pivot over a protractor marked 0 to ${MERGE_MOST} px; the top blade is merge. As it opens, each blade stops at its own gap, and the pair with that gap runs together into one piece of glass.`;diff --git a/examples/spot-plate/live.tsx b/examples/spot-plate/live.tsxnew file mode 100644index 0000000..2d164fd--- /dev/null+++ b/examples/spot-plate/live.tsx@@ -0,0 +1,339 @@+"use client";++import * as React from "react";+import { IsoFigure } from "../../kit/react/draw";+import { asksForStillness, useReadout } from "../../kit/react/live";+import { keyOf, rowsOf, type GlassShape, type RowShape } from "./drops";+import { fanOf, type FanPose } from "./fan";+import { HEIGHT, MERGE, MERGE_LEAST, MERGE_MOST, MERGE_STEP, ROWS, WIDTH, mergeAtX, readoutOf, roundMerge, spokenOf } from "./rig";++const FOLLOW = 150;+const GLIDE = 560;+const SETTLED = 0.004;+const TOUR_FIRST = 1800;+const TOUR_BACK = 4200;+const TOUR_TRAVEL = 1400;+const TOUR: { merge: number; hold: number }[] = [+ { merge: MERGE_MOST, hold: 2400 },+ { merge: MERGE_LEAST, hold: 2200 },+ { merge: MERGE, hold: 3800 },+];+const BLADES = ROWS + 1;++function Glass({ shape, joined }: { shape: GlassShape; joined: boolean }) {+ const quiet = joined ? "lo" : "faint";+ return (+ <g className="iso-solid ml-glass" data-joined={joined ? "" : undefined}>+ <path className="iso-fill" d={shape.fill} />+ {shape.shades.map((shade, index) => (+ <path key={index} className="iso-shade" data-shade={shade.shade} d={shade.d} />+ ))}+ <path className="iso-top" d={shape.top} />+ <path className="iso-line" data-tone={quiet} d={shape.crease} />+ {shape.bevel ? <path className="iso-line iso-bevel" data-tone={quiet} d={shape.bevel} /> : null}+ <path className="iso-line iso-edge" data-tone={joined ? "hi" : "mid"} d={shape.outline} />+ {shape.shine ? <path className="iso-line ml-shine" data-tone="mid" d={shape.shine} /> : null}+ </g>+ );+}++const Row = React.memo(function Row({ shape }: { shape: RowShape }) {+ return (+ <>+ <g>+ <g>+ {shape.glass.map((glass, index) => (+ <Glass key={index} shape={glass} joined={shape.joined} />+ ))}+ </g>+ </g>+ {shape.neck.length ? (+ <g>+ <g className="ml-neck">+ {shape.neck.map((glint, index) => (+ <path key={index} className="iso-line" data-tone="lit" strokeOpacity={glint.alpha < 1 ? glint.alpha : undefined} d={glint.d} />+ ))}+ </g>+ </g>+ ) : null}+ </>+ );+});++interface BladeNodes {+ group: SVGGElement | null;+ fill: SVGPathElement | null;+ shades: (SVGPathElement | null)[];+ top: SVGPathElement | null;+ crease: SVGPathElement | null;+ outline: SVGPathElement | null;+ line: SVGPathElement | null;+}++const emptyBlade = (): BladeNodes => ({ group: null, fill: null, shades: [null, null, null, null], top: null, crease: null, outline: null, line: null });++function apply(nodes: BladeNodes[], halo: SVGPathElement | null, pose: FanPose) {+ halo?.setAttribute("d", pose.halo);+ pose.blades.forEach((blade, index) => {+ const node = nodes[index];+ if (!node) return;+ node.fill?.setAttribute("d", blade.fill);+ blade.shades.forEach((d, shade) => node.shades[shade]?.setAttribute("d", d));+ node.top?.setAttribute("d", blade.top);+ node.crease?.setAttribute("d", blade.crease);+ node.outline?.setAttribute("d", blade.outline);+ node.line?.setAttribute("d", blade.line);+ if (index < ROWS) {+ if (pose.out[index]) node.group?.setAttribute("data-out", "");+ else node.group?.removeAttribute("data-out");+ }+ });+}++interface Props {+ label: string;+ back: React.ReactNode;+ deck: React.ReactNode;+ front: React.ReactNode;+}++export function LiquidLive({ label, back, deck, front }: Props) {+ const { anchor, say } = useReadout<HTMLDivElement>();+ const root = React.useRef<HTMLDivElement | null>(null);+ const blades = React.useRef<BladeNodes[]>(Array.from({ length: BLADES }, emptyBlade));+ const halo = React.useRef<SVGPathElement | null>(null);+ const rest = React.useMemo(() => fanOf(MERGE), []);+ const goal = React.useRef(MERGE);+ const lead = React.useRef(MERGE);+ const shown = React.useRef(MERGE);+ const ease = React.useRef(FOLLOW);+ const frame = React.useRef(0);+ const last = React.useRef(0);+ const [quant, setQuant] = React.useState(keyOf(MERGE) / 4);+ const [hovering, setHovering] = React.useState(false);+ const [focused, setFocused] = React.useState(false);+ const [visible, setVisible] = React.useState(false);+ const [idle, setIdle] = React.useState(true);+ const [poke, setPoke] = React.useState(0);++ const rows = React.useMemo(() => rowsOf(quant), [quant]);+ const value = roundMerge(quant);++ const draw = React.useCallback((merge: number) => {+ apply(blades.current, halo.current, fanOf(merge));+ setQuant(keyOf(merge) / 4);+ }, []);++ const stop = React.useCallback(() => {+ cancelAnimationFrame(frame.current);+ frame.current = 0;+ }, []);++ const run = React.useCallback(() => {+ if (frame.current) return;+ last.current = 0;+ const tick = (now: number) => {+ const dt = last.current ? Math.min(now - last.current, 64) : 16;+ last.current = now;+ const blend = 1 - Math.exp(-dt / ease.current);+ lead.current += (goal.current - lead.current) * blend;+ shown.current += (lead.current - shown.current) * blend;+ const done = Math.abs(goal.current - lead.current) < SETTLED && Math.abs(goal.current - shown.current) < SETTLED;+ if (done) {+ lead.current = goal.current;+ shown.current = goal.current;+ }+ draw(shown.current);+ frame.current = done ? 0 : requestAnimationFrame(tick);+ };+ frame.current = requestAnimationFrame(tick);+ }, [draw]);++ const aim = React.useCallback(+ (merge: number, pace = FOLLOW) => {+ const next = Math.min(MERGE_MOST, Math.max(MERGE_LEAST, merge));+ ease.current = pace;+ goal.current = next;+ if (asksForStillness()) {+ stop();+ lead.current = next;+ shown.current = next;+ draw(next);+ return;+ }+ run();+ },+ [draw, run, stop],+ );++ React.useEffect(() => stop, [stop]);++ React.useEffect(() => {+ say(readoutOf(value));+ }, [value, say]);++ React.useEffect(() => {+ const node = root.current;+ if (!node) return;+ const observer = new IntersectionObserver((entries) => setVisible(Boolean(entries.at(-1)?.isIntersecting)));+ observer.observe(node);+ return () => observer.disconnect();+ }, []);++ React.useEffect(() => {+ if (!visible) stop();+ }, [visible, stop]);++ const engaged = hovering || focused;++ React.useEffect(() => {+ if (engaged) {+ setIdle(false);+ return;+ }+ const timer = window.setTimeout(() => setIdle(true), TOUR_BACK);+ return () => window.clearTimeout(timer);+ }, [engaged, poke]);++ const touring = visible && idle && !engaged;++ React.useEffect(() => {+ if (!touring || asksForStillness()) return;+ let timer = 0;+ let step = 0;+ const next = () => {+ const stop = TOUR[step % TOUR.length]!;+ aim(stop.merge, GLIDE);+ step += 1;+ timer = window.setTimeout(next, stop.hold + TOUR_TRAVEL);+ };+ timer = window.setTimeout(next, TOUR_FIRST);+ return () => window.clearTimeout(timer);+ }, [touring, aim]);++ const mergeAt = (clientX: number) => {+ const svg = root.current?.querySelector("svg");+ const box = svg?.getBoundingClientRect();+ if (!box || !box.width) return null;+ return mergeAtX(((clientX - box.left) / box.width) * WIDTH);+ };++ const hold = () => {+ setIdle(false);+ setPoke((count) => count + 1);+ };++ const follow = (clientX: number) => {+ const merge = mergeAt(clientX);+ if (merge !== null) aim(merge, FOLLOW);+ };++ const stepBy = (by: number) => roundMerge(goal.current + by);++ const bindBlade = (index: number) => ({+ group: (node: SVGGElement | null) => {+ blades.current[index]!.group = node;+ },+ path: (key: "fill" | "top" | "crease" | "outline" | "line") => (node: SVGPathElement | null) => {+ blades.current[index]![key] = node;+ },+ shade: (shade: number) => (node: SVGPathElement | null) => {+ blades.current[index]!.shades[shade] = node;+ },+ });++ return (+ <div+ ref={(node) => {+ root.current = node;+ anchor.current = node;+ }}+ className="ml"+ role="slider"+ tabIndex={0}+ aria-label="Merge, in pixels"+ aria-valuemin={MERGE_LEAST}+ aria-valuemax={MERGE_MOST}+ aria-valuenow={value}+ aria-valuetext={spokenOf(value)}+ onPointerEnter={(event) => {+ if (event.pointerType === "mouse") setHovering(true);+ }}+ onPointerMove={(event) => {+ if (event.pointerType === "mouse" || event.currentTarget.hasPointerCapture(event.pointerId)) {+ hold();+ follow(event.clientX);+ }+ }}+ onPointerDown={(event) => {+ if (event.pointerType !== "mouse") event.currentTarget.setPointerCapture(event.pointerId);+ hold();+ follow(event.clientX);+ }}+ onPointerUp={(event) => {+ if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);+ }}+ onPointerLeave={(event) => {+ if (event.pointerType !== "mouse") return;+ setHovering(false);+ aim(MERGE, GLIDE);+ }}+ onFocus={() => {+ setFocused(true);+ aim(roundMerge(shown.current), FOLLOW);+ }}+ onBlur={() => setFocused(false)}+ onKeyDown={(event) => {+ let next: number | null = null;+ const big = event.shiftKey ? 4 : 1;+ if (event.key === "ArrowLeft" || event.key === "ArrowDown") next = stepBy(-MERGE_STEP * big);+ else if (event.key === "ArrowRight" || event.key === "ArrowUp") next = stepBy(MERGE_STEP * big);+ else if (event.key === "PageDown") next = stepBy(-MERGE_STEP * 8);+ else if (event.key === "PageUp") next = stepBy(MERGE_STEP * 8);+ else if (event.key === "Home") next = MERGE_LEAST;+ else if (event.key === "End") next = MERGE_MOST;+ if (next === null) return;+ event.preventDefault();+ hold();+ aim(next, FOLLOW);+ }}+ >+ <IsoFigure width={WIDTH} height={HEIGHT} label={label}>+ {back}+ {rows.map((shape) => (+ <Row key={shape.row} shape={shape} />+ ))}+ {deck}+ <g>+ <g>+ <path ref={(node) => void (halo.current = node)} className="iso-halo ml-fan-halo" d={rest.halo} />+ {rest.blades.map((blade, index) => {+ const bind = bindBlade(index);+ const isLead = index === ROWS;+ return (+ <g+ key={index}+ ref={bind.group}+ className="iso-solid ml-blade"+ data-lead={isLead ? "" : undefined}+ data-lit={isLead ? "" : undefined}+ data-out={!isLead && rest.out[index] ? "" : undefined}+ >+ <path ref={bind.path("fill")} className="iso-fill" d={blade.fill} />+ {[0, 1, 2, 3].map((shade) => (+ <path key={shade} ref={bind.shade(shade)} className="iso-shade" data-shade={shade} d={blade.shades[shade] ?? ""} />+ ))}+ <path ref={bind.path("top")} className="iso-top" d={blade.top} />+ <path ref={bind.path("crease")} className="iso-line" data-tone="faint" d={blade.crease} />+ <path ref={bind.path("outline")} className="iso-line iso-edge" data-tone={isLead ? "hi" : "mid"} d={blade.outline} />+ <path ref={bind.path("line")} className="iso-line ml-blade-line" data-tone={isLead ? "lit" : "lo"} d={blade.line} />+ </g>+ );+ })}+ </g>+ </g>+ {front}+ </IsoFigure>+ </div>+ );+}diff --git a/examples/spot-plate/rig.ts b/examples/spot-plate/rig.tsnew file mode 100644index 0000000..fc6d2b9--- /dev/null+++ b/examples/spot-plate/rig.ts@@ -0,0 +1,230 @@+import { cameraOf, type Flat, iso, type Plan, type Point3, type Projection } from "../../kit/iso-kit";++export const RADII = [30, 22] as const;+export const GAPS = [4, 10, 16, 24, 32, 44] as const;+export const MERGE = 20;+export const MERGE_LEAST = 0;+export const MERGE_MOST = 48;+export const MERGE_STEP = 1;++const UNIFORM = 2;+const SIDE = 0.35;+const FACING = 0.65;+const DEPTH = 0.25;++export const [RA, RB] = RADII;+export const ROWS = GAPS.length;+const FAR = GAPS[ROWS - 1];++export const spanOf = (gap: number) => RA + gap + RB;+export const reachOf = (merge: number) => merge * UNIFORM;+export const sideOf = (merge: number) => Math.round(reachOf(merge) * SIDE * 10) / 10;+export const seenGapOf = (gap: number, merge: number) => (gap >= 2 * merge ? gap : gap <= merge ? 0 : 2 * Math.sqrt(merge * (gap - merge)));+export const joinedAt = (merge: number) => GAPS.filter((gap) => gap < merge);++export type Field = (u: number, v: number) => number;++export function fieldOf(gap: number, merge: number): Field {+ const span = spanOf(gap);+ const most = reachOf(merge);+ return (u, v) => {+ const qu = u - span;+ const la = Math.sqrt(u * u + v * v);+ const lb = Math.sqrt(qu * qu + v * v);+ const a = la - RA;+ const b = lb - RB;+ const nearest = a < b ? a : b;+ if (most <= 0) return nearest;+ const spread = a < b ? b - a : a - b;+ if (spread >= most) return nearest;+ const raw = 0.5 - (0.5 * (u * qu + v * v)) / Math.max(la * lb, 0.0001);+ const facing = raw < 0 ? 0 : raw > 1 ? 1 : raw;+ const reach = most * (SIDE + FACING * facing);+ const h = Math.max(reach - spread, 0) / reach;+ return nearest - h * h * reach * DEPTH;+ };+}++function halfWidth(field: Field, u: number) {+ if (field(u, 0) >= 0) return 0;+ let low = 0;+ let high = RA + 12;+ for (let round = 0; round < 30; round++) {+ const mid = (low + high) / 2;+ if (field(u, mid) < 0) low = mid;+ else high = mid;+ }+ return low;+}++export function neckOf(gap: number, merge: number) {+ if (gap >= merge) return 0;+ const field = fieldOf(gap, merge);+ const from = RA - 8;+ const to = RA + gap + 8;+ const coarse = 48;+ let best = Infinity;+ let at = (from + to) / 2;+ for (let step = 0; step <= coarse; step++) {+ const u = from + ((to - from) * step) / coarse;+ const width = halfWidth(field, u);+ if (width > 0 && width < best) {+ best = width;+ at = u;+ }+ }+ const golden = (Math.sqrt(5) - 1) / 2;+ let low = Math.max(from, at - (to - from) / coarse);+ let high = Math.min(to, at + (to - from) / coarse);+ for (let round = 0; round < 24; round++) {+ const c = high - golden * (high - low);+ const d = low + golden * (high - low);+ if (halfWidth(field, c) < halfWidth(field, d)) high = d;+ else low = c;+ }+ return 2 * halfWidth(field, (low + high) / 2);+}++export const WIDTH = 600;+export const HEIGHT = 340;+const PAD_X = 80;+const PAD_Y = 34;+export const AZIMUTH = 50;++export const MARGIN = 6;+export const PITCH = 84;+export const WELL_HALF = RA + MARGIN;+export const BIG_Y = MARGIN + RA;+export const DATUM_Y = BIG_Y + RA;+export const WELL_D = DATUM_Y + FAR + 2 * RB + MARGIN;+export const BORDER = 14;++export const COLS = 3;+export const ROW_RIM = 16;+export const rowX = (row: number) => (row % COLS) * PITCH;+export const rowY = (row: number) => Math.floor(row / COLS) * (WELL_D + ROW_RIM);++export const WELLS: Plan[] = GAPS.map((_, row) => ({ x: rowX(row) - WELL_HALF, y: rowY(row), w: WELL_HALF * 2, d: WELL_D, r: WELL_HALF }));++export const TRAY: Plan = {+ x: -WELL_HALF - BORDER,+ y: -BORDER,+ w: rowX(COLS - 1) + (WELL_HALF + BORDER) * 2,+ d: rowY(ROWS - 1) + WELL_D + BORDER * 2,+ r: 16,+};+export const TRAY_H = 13;+export const WELL_SINK = 3;+export const FLOOR = TRAY_H - WELL_SINK;+export const THICK = 8;+export const GLASS_TOP = FLOOR + THICK;++export const DECK: Plan = { x: TRAY.x + TRAY.w + 10, y: TRAY.y, w: 172, d: TRAY.d, r: 12 };+export const DECK_H = 6;+export const PIVOT: [number, number] = [DECK.x + 22, DECK.y + DECK.d / 2 + 6];+export const BLADE_LONG = 104;+export const LEAD_LONG = 113;+export const STOP_R = 111;+export const SCALE_R = 120;+export const SWEEP = 180;+export const WASHER_H = 0.8;+export const STACK_Z = DECK_H + WASHER_H;+export const thicknessOf = (gap: number) => 0.45 + gap / 20;+export const LEAD_H = 1.1;++export const BLADE_Z: number[] = (() => {+ const out: number[] = [];+ let z = STACK_Z;+ for (const gap of GAPS) {+ out.push(z);+ z += thicknessOf(gap) + 0.12;+ }+ out.push(z);+ return out;+})();+export const STACK_TOP = BLADE_Z[ROWS]! + LEAD_H;++export const angleOf = (merge: number) => (Math.min(Math.max(merge, MERGE_LEAST), MERGE_MOST) / MERGE_MOST) * SWEEP;++export const BOTTLE: [number, number] = [DECK.x + DECK.w - 33, DECK.y + 35];+export const BOTTLE_TOP = DECK_H + 64;++export const BASE: Plan = { x: TRAY.x - 14, y: TRAY.y - 14, w: DECK.x + DECK.w + 14 - (TRAY.x - 14), d: TRAY.d + 28, r: 10 };+export const BASE_H = 10;+export const FOOT_H = 5;++const RADIANS = Math.PI / 180;++function fit(points: Point3[]): Projection {+ const unitView: Projection = { origin: [0, 0], scale: 1, azimuth: AZIMUTH };+ const flat = points.map((point) => iso(point, unitView));+ const xs = flat.map(([x]) => x);+ const ys = flat.map(([, y]) => y);+ const left = Math.min(...xs);+ const right = Math.max(...xs);+ const up = Math.min(...ys);+ const down = Math.max(...ys);+ const scale = Math.min((WIDTH - PAD_X * 2) / (right - left), (HEIGHT - PAD_Y * 2) / (down - up));+ return { origin: [WIDTH / 2 - ((left + right) / 2) * scale, HEIGHT / 2 - ((up + down) / 2) * scale], scale, azimuth: AZIMUTH };+}++const box = ({ x, y, w, d }: Plan, z0: number, z1: number): Point3[] => {+ const out: Point3[] = [];+ for (const px of [x, x + w]) for (const py of [y, y + d]) for (const pz of [z0, z1]) out.push([px, py, pz]);+ return out;+};++export const P = fit([...box(BASE, -BASE_H - FOOT_H, 0), ...box(DECK, 0, STACK_TOP + 6), [BOTTLE[0], BOTTLE[1], BOTTLE_TOP]]);+export const at = (point: Point3): Flat => iso(point, P);++const CAMERA = cameraOf(P);+export const VIEW: [number, number] = [CAMERA.cosA, CAMERA.sinA];+export const LIGHT: [number, number] = [-CAMERA.sinA, CAMERA.cosA];+export const CLIMB = CAMERA.sinE / CAMERA.cosE;+export const K = CAMERA.k;+export const SIN_A = Math.sin(AZIMUTH * RADIANS);+export const COS_A = Math.cos(AZIMUTH * RADIANS);++const SLIDE_FROM = 0.16;+const SLIDE_TO = 0.84;++export function mergeAtX(x: number) {+ const share = (x / WIDTH - SLIDE_FROM) / (SLIDE_TO - SLIDE_FROM);+ return MERGE_LEAST + Math.min(1, Math.max(0, share)) * (MERGE_MOST - MERGE_LEAST);+}++export const roundMerge = (merge: number) => Math.min(MERGE_MOST, Math.max(MERGE_LEAST, Math.round(merge)));++const listOf = (values: readonly (number | string)[]) =>+ values.length < 2 ? values.join("") : `${values.slice(0, -1).join(", ")} and ${values[values.length - 1]}`;++export function readoutOf(merge: number) {+ const shown = roundMerge(merge);+ return `merge ${shown} px · ${joinedAt(shown).length} of ${ROWS} joined`;+}++export function joinedListOf(merge: number) {+ const joined = joinedAt(roundMerge(merge));+ if (!joined.length) return "none of the six";+ if (joined.length === ROWS) return "all six";+ return `${listOf(joined)} px`;+}++export function bladesOutOf(merge: number) {+ const out = joinedAt(roundMerge(merge)).length;+ if (!out) return "no blade is out";+ if (out === ROWS) return "all six blades are out";+ return out === 1 ? "one blade is out" : `${["", "", "two", "three", "four", "five"][out]} blades are out`;+}++export function spokenOf(merge: number) {+ const shown = roundMerge(merge);+ const joined = joinedAt(shown);+ const apart = GAPS.filter((gap) => gap >= shown);+ const head = `merge ${shown} px: ${joined.length} of ${ROWS} pairs joined`;+ if (!joined.length) return `${head}, all six apart`;+ if (!apart.length) return `${head}, every gap from ${GAPS[0]} to ${FAR} px`;+ return `${head}, gaps ${listOf(joined)} px; ${listOf(apart)} px ${apart.length > 1 ? "stay" : "stays"} apart`;+}++export const listText = listOf;diff --git a/examples/spot-plate/spot-plate.css b/examples/spot-plate/spot-plate.cssnew file mode 100644index 0000000..c372ac9--- /dev/null+++ b/examples/spot-plate/spot-plate.css@@ -0,0 +1,92 @@+.ml {+ --ml-plate-top: #1c1c1c;+ --ml-floor: #121212;+ --ml-wall: #0b0b0b;+ --ml-glass-top: #202020;+ --ml-glass-joined: #262626;+ --ml-blade-top: #1b1b1b;+ --ml-blade-out: #232323;+ border-radius: 10px;+ cursor: ew-resize;+ touch-action: pan-y;+ -webkit-tap-highlight-color: transparent;+ -webkit-user-select: none;+ user-select: none;+}++.ml:focus-visible {+ outline: 1px solid var(--anatomy-muted);+ outline-offset: 6px;+}++.iso[data-theme="light"] .ml {+ --ml-plate-top: #fbfbfa;+ --ml-floor: #f2f2f1;+ --ml-wall: #e4e4e3;+ --ml-glass-top: #fdfdfc;+ --ml-glass-joined: #fefefd;+ --ml-blade-top: #fbfbf9;+ --ml-blade-out: #fefefc;+}++.ml .iso-svg {+ overflow: visible;+}++.ml-plate > .iso-top {+ fill: var(--ml-plate-top);+}++.ml-floor {+ fill: var(--ml-floor);+ stroke: none;+}++.ml-wall {+ fill: var(--ml-wall);+ stroke: none;+}++.ml-bottle > .iso-top,+.ml-glass > .iso-top {+ fill: var(--ml-glass-top);+}++.ml-glass[data-joined] > .iso-top {+ fill: var(--ml-glass-joined);+}++.ml-blade > .iso-top {+ fill: var(--ml-blade-top);+}++.ml-blade[data-out] > .iso-top {+ fill: var(--ml-blade-out);+}++.ml-blade[data-out] > .iso-edge {+ stroke: var(--anatomy-hi);+}++.ml-fan-halo {+ filter: blur(4px);+ opacity: 0.8;+ transform: translateY(1.5px);+}++@media (prefers-reduced-motion: reduce) {+ .ml * {+ transition: none !important;+ }+}++@media (max-width: 640px) {+ .ml {+ overflow: hidden;+ }++ .iso-plate .ml .iso-svg {+ width: 130%;+ margin: -10% -15% -8%;+ }+}diff --git a/examples/test-rig/stretch.css b/examples/test-rig/stretch.cssindex 8f80215..60bb81b 100644--- a/examples/test-rig/stretch.css+++ b/examples/test-rig/stretch.css@@ -9,6 +9,11 @@user-select: none;}+.iso[data-theme="light"] .ms {+ --ms-glass-top: #fefefd;+ --ms-glass-lit-top: #fffffe;+}+.ms[data-held] {cursor: grabbing;}