Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

site art and the delivery master (wip)

Alex Greenshpun5e8fe260961e
diff --git a/skills/anidoodle/SKILL.md b/skills/anidoodle/SKILL.md
index 5b78254..6d84259 100644
--- a/skills/anidoodle/SKILL.md
+++ b/skills/anidoodle/SKILL.md
@@ -37,7 +37,7 @@ say why in one line. Write the answers into a short brief before drawing.
| A story film, any length | Film workflow below, `references/workflows/long-film.md` |
| An explainer or infographic; a machine that comes apart to explain an idea, in any style | `references/workflows/explainer.md`, `references/workflows/machines.md` |
| A launch or product video (their screenshots welcome) | `references/workflows/launch-video.md`; build it on `references/workflows/launch-video-kit.md` |
-| An interactive web animation that reacts to the UI | `references/workflows/interactive.md` |
+| Art for a site (hero by a headline, tiles, spots, share card) on its page colour and brand; or a web animation that reacts to the UI | `references/workflows/site-art.md`; `references/workflows/interactive.md` |
| A drawing lesson, or "how do I draw this?" | `references/workflows/teach-drawing.md` |
| A character kept identical in any style (woodcut to toy brick) | `references/workflows/character-consistency.md`, `references/anatomy.md` |
| A style matched from their image | `references/workflows/adapt-a-style.md` |
diff --git a/skills/anidoodle/engine/src/canvas-core/assetKit.ts b/skills/anidoodle/engine/src/canvas-core/assetKit.ts
new file mode 100644
index 0000000..558979d
--- /dev/null
+++ b/skills/anidoodle/engine/src/canvas-core/assetKit.ts
@@ -0,0 +1,96 @@
+// ASSET KIT. Art that lives on someone's page: a hero beside a headline, a feature tile, a row of spots,
+// a social card. Three things change when a picture leaves its own card and sits on a site:
+// 1. placement: the art has a region, and the headline has a zone the art must never enter;
+// 2. ground: the paper IS the page colour, so every neutral moves to suit it, light or dark;
+// 3. brand: one hex becomes a whole material (body) or only its marks (ink), in either theme.
+// Placement is plain numbers. Ground and brand are a palette: `setPalette(pagePalette(...))` and every
+// material the kit paints is moved through it, so a machine is restyled without touching its parts.
+import type { Material } from "./mechanismKit";
+
+export type Rect = { x: number; y: number; w: number; h: number };
+export type Placement = { W: number; H: number; art: Rect; safe?: Rect; pad: number; note: string };
+
+/** canvases by where the art sits. Sizes are about 1 unit per CSS pixel at the size the art is shown. */
+export const PLACEMENTS: Record<string, Placement> = {
+ heroRight: { W: 1200, H: 640, art: { x: 520, y: 40, w: 640, h: 560 }, safe: { x: 0, y: 0, w: 480, h: 640 }, pad: 24, note: "headline left, art right; the moment faces the text" },
+ heroLeft: { W: 1200, H: 640, art: { x: 40, y: 40, w: 640, h: 560 }, safe: { x: 720, y: 0, w: 480, h: 640 }, pad: 24, note: "the mirror of heroRight" },
+ heroCentre: { W: 1200, H: 720, art: { x: 180, y: 210, w: 840, h: 480 }, safe: { x: 0, y: 0, w: 1200, h: 190 }, pad: 24, note: "headline above, a wide low object below" },
+ art: { W: 800, H: 600, art: { x: 0, y: 0, w: 800, h: 600 }, pad: 28, note: "the page lays out its own text" },
+ tile: { W: 640, H: 480, art: { x: 0, y: 0, w: 640, h: 480 }, pad: 32, note: "a feature card" },
+ spot: { W: 320, H: 320, art: { x: 0, y: 0, w: 320, h: 320 }, pad: 20, note: "one small object; cut detail, never shrink it to mush" },
+ banner: { W: 1600, H: 400, art: { x: 0, y: 24, w: 1600, h: 352 }, pad: 24, note: "a section divider; may bleed off a clean straight edge" },
+ social: { W: 1200, H: 630, art: { x: 560, y: 40, w: 600, h: 550 }, safe: { x: 0, y: 0, w: 520, h: 630 }, pad: 24, note: "a share card: words left, object right, carries its own ground" },
+ slide: { W: 1920, H: 1080, art: { x: 800, y: 80, w: 1060, h: 920 }, safe: { x: 0, y: 0, w: 760, h: 1080 }, pad: 32, note: "a deck slide" },
+};
+/** the art region shrunk by its pad, as the corner box [x0, y0, x1, y1] `Cam.fit` takes */
+export const fitBox = (p: Placement): [number, number, number, number] => [p.art.x + p.pad, p.art.y + p.pad, p.art.x + p.art.w - p.pad, p.art.y + p.art.h - p.pad];
+/** where the eye should land: a third of the way into the art region, on the side nearest the text */
+export const strongPoint = (p: Placement): [number, number] => {
+ const towardText = p.safe ? (p.safe.x + p.safe.w / 2 < p.art.x + p.art.w / 2 ? 1 / 3 : 2 / 3) : 1 / 2;
+ return [p.art.x + p.art.w * towardText, p.art.y + p.art.h * (p.safe && p.safe.w === p.W ? 1 / 3 : 0.45)];
+};
+
+// ---------------------------------------------------------------- colour in a perceptual space (OKLab)
+type Lab = [number, number, number];
+const toLin = (c: number) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
+const toSrgb = (c: number) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
+const hexRgb = (h: string): [number, number, number] => { const n = parseInt(h.replace("#", "").slice(0, 6), 16); return [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((v) => v / 255) as [number, number, number]; };
+export const toLab = (hex: string): Lab => {
+ const [r, g, b] = hexRgb(hex).map(toLin);
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b), m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b), s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
+ return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
+};
+const labRgb = ([L, a, b]: Lab): [number, number, number] => {
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3, m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3, s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
+ return [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s].map(toSrgb) as [number, number, number];
+};
+/** back to hex; a colour outside sRGB keeps its lightness and hue and gives up chroma until it fits */
+export const fromLab = (lab: Lab): string => {
+ let [L, a, b] = lab; L = Math.max(0, Math.min(1, L));
+ for (let k = 0; k < 24; k++) { const rgb = labRgb([L, a, b]); if (rgb.every((v) => v >= -1e-4 && v <= 1 + 1e-4)) break; a *= 0.88; b *= 0.88; }
+ return "#" + labRgb([L, a, b]).map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).padStart(2, "0")).join("");
+};
+export const isDark = (paper: string) => toLab(paper)[0] < 0.6;
+
+// ---------------------------------------------------------------- the page palette
+export type Colour = string | { hex: string; mode?: "body" | "ink" };
+export type PageOpts = {
+ paper: string; // the exact colour of the page the art sits on
+ kitPaper?: string; // the paper the materials were designed on (the kit's cream)
+ tint?: number; // 0 keeps neutral greys, 1 takes the page's whole colour cast; 0.5 by default
+ accent?: Colour; // the brand colour of the part to watch (materials with accent: true)
+ colours?: Record<string, Colour>; // per material name: a brand or material colour (brass, walnut, ebony)
+};
+
+/** one hex as a five-step material ramp in a theme: hue and chroma kept, lightness set where four tones still read */
+export const rampFrom = (hex: string, dark: boolean): { ramp: Material["ramp"]; seam: string; pigment: string } => {
+ const [L0, a, b] = toLab(hex), c = dark ? Math.max(0.32, Math.min(0.64, L0 * 0.78)) : Math.max(0.36, Math.min(0.8, L0));
+ const at = (L: number) => fromLab([L, a, b]);
+ return { ramp: [at(c - 0.17), at(c - 0.09), at(c - 0.02), at(c + 0.06), at(Math.min(0.97, c + 0.15))], seam: at(c - (dark ? -0.12 : 0.26)), pigment: at(c) };
+};
+
+/** a palette for `setPalette`: every material moved onto the page, brand colours put in, light or dark */
+export const pagePalette = (o: PageOpts): ((m: Material) => Material) => {
+ const dark = isDark(o.paper), P = toLab(o.paper), K = toLab(o.kitPaper ?? "#f3f0e8"), tint = o.tint ?? 0.5;
+ const da = (P[1] - K[1]) * tint, db = (P[2] - K[2]) * tint;
+ // light page: everything moves by the page's difference in lightness and, by `tint`, in colour.
+ // dark page: parts sit a little above the page, the lit top lightest, lines lighter than the faces.
+ const move = (hex: string, base: number) => {
+ const [L, a, b] = toLab(hex);
+ if (!dark) return fromLab([L + (P[0] - K[0]), a + da, b + db]);
+ return fromLab([P[0] + 0.07 + Math.max(0, L - base) * 0.85, a * 0.85 + da, b * 0.85 + db]);
+ };
+ const cache = new Map<string, Material>();
+ return (m) => {
+ const key = (m.name ?? "") + m.ramp.join("") + m.ink; let out = cache.get(key); if (out) return out;
+ const base = toLab(m.ramp[0])[0] - 0.02;
+ out = { ...m, ramp: m.ramp.map((c) => move(c, base)) as Material["ramp"], seam: dark ? fromLab([P[0] + 0.2, da, db]) : move(m.seam, base), ink: dark ? fromLab([Math.min(0.93, P[0] + 0.62), da, db]) : move(m.ink, base), pigment: m.pigment ? move(m.pigment, base - 0.25) : m.pigment };
+ const want = (m.accent ? o.accent : undefined) ?? (m.name ? o.colours?.[m.name] : undefined);
+ if (want) {
+ const { hex, mode = "body" } = typeof want === "string" ? { hex: want } : want, r = rampFrom(hex, dark);
+ // body: the part is made of the colour. ink: the part stays neutral and only its lines and dots take it.
+ out = mode === "body" ? { ...out, ramp: r.ramp, seam: r.seam, pigment: r.pigment } : { ...out, ink: r.pigment, seam: r.pigment };
+ }
+ cache.set(key, out); return out;
+ };
+};
diff --git a/skills/anidoodle/engine/src/canvas-core/film.ts b/skills/anidoodle/engine/src/canvas-core/film.ts
index 10d8e94..061da9a 100644
--- a/skills/anidoodle/engine/src/canvas-core/film.ts
+++ b/skills/anidoodle/engine/src/canvas-core/film.ts
@@ -21,6 +21,8 @@ export type Film = { meta: {
locked?: [from: number, to: number, reason: string][];
// a declared hold: the stillness is meant (a word read, an end card); the optional reason is printed by the gate
holds?: [from: number, to: number, reason?: string][];
+ /** silences the film means (a stop-down before a reveal, a held breath), [fromFrame, toFrame, reason]: verify-export does not count them as holes */
+ quiet?: [from: number, to: number, reason?: string][];
onTwos?: boolean;
step?: 1 | 2 | 3;
// the score as fitted to this film: its tempo and form; render prints it next to the grid's bpm.
@@ -42,7 +44,7 @@ export const validate = (film: Film): string[] => {
if (![W, H, fps, durationFrames].every((n) => Number.isSafeInteger(n) && n > 0)) p.push("W, H, fps and durationFrames must be positive integers");
if (!Number.isFinite(bpm) || bpm <= 0 || !Number.isInteger(beat)) p.push(`bpm ${bpm} at ${fps} fps does not give a whole-frame beat`);
if (film.meta.step !== undefined && ![1, 2, 3].includes(film.meta.step)) p.push("step must be 1, 2 or 3");
- for (const [from, to] of [...(film.meta.holds ?? []), ...(film.meta.locked ?? [])]) if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to > durationFrames || to <= from) p.push(`invalid declared range ${from}-${to}`);
+ for (const [from, to] of [...(film.meta.holds ?? []), ...(film.meta.locked ?? []), ...(film.meta.quiet ?? [])]) if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to > durationFrames || to <= from) p.push(`invalid declared range ${from}-${to}`);
for (const [, , reason] of film.meta.locked ?? []) if (!reason?.trim()) p.push("locked ranges need a reason");
let t = 0;
[...film.shots].sort((a, b) => a.start - b.start).forEach((s) => {
diff --git a/skills/anidoodle/engine/src/canvas-core/launchSound.ts b/skills/anidoodle/engine/src/canvas-core/launchSound.ts
index 874886f..4679145 100644
--- a/skills/anidoodle/engine/src/canvas-core/launchSound.ts
+++ b/skills/anidoodle/engine/src/canvas-core/launchSound.ts
@@ -10,6 +10,7 @@
// and one impact, at the big reveal only, and nothing at all on its other cuts.
import { placeSfx, sfxDuck, sfxAudibility, type SfxCue, type SfxPlan, type SfxAudibility, type PlacedCue } from "./music/sfx";
import { limiter } from "./music/render";
+import { deliver, layBed } from "./music/delivery";
import { loudness, truePeak } from "./music/meter";
import type { FilmAudio } from "./film";
@@ -45,7 +46,10 @@ export const mixLaunch = (music: [Float32Array, Float32Array] | null, plan: Laun
}
const L = new Float32Array(n), R = new Float32Array(n);
for (let i = 0; i < n; i++) { L[i] = mL[i] + fxL[i]; R[i] = mR[i] + fxR[i]; }
- limiter(L, R, sr, Math.pow(10, -1.3 / 20));
+ // no score: the cues sit on room tone instead of dropping to silence between them (delivery.ts)
+ if (!music && plan.bed !== false && placed.length) layBed(L, R, [fxL, fxR], sr, plan.cues.length * 7919 + plan.frames, plan.bed ?? 22);
+ // a launch film is dense: the whole mix to -14 LUFS, then the ceiling (delivery.ts); plan.master overrides
+ if ((plan.master ?? "dense") === "none") limiter(L, R, sr, Math.pow(10, -1.3 / 20)); else deliver(L, R, sr, plan.master ?? "dense", { ceilingDb: -1.3 });
const tp0 = truePeak([L, R]).dbtp; if (tp0 > -1.05) { const g = Math.pow(10, (-1.1 - tp0) / 20); for (let i = 0; i < n; i++) { L[i] *= g; R[i] *= g; } }
const fade = Math.min(n, Math.round(0.015 * sr)); for (let i = 0; i < fade; i++) { const g = i / fade; L[n - 1 - i] *= g; R[n - 1 - i] *= g; }
const lu = n >= 0.4 * sr ? loudness([L, R], sr).integrated : NaN;
diff --git a/skills/anidoodle/engine/src/canvas-core/mechanism.ts b/skills/anidoodle/engine/src/canvas-core/mechanism.ts
index 6293e8c..e89b771 100644
--- a/skills/anidoodle/engine/src/canvas-core/mechanism.ts
+++ b/skills/anidoodle/engine/src/canvas-core/mechanism.ts
@@ -28,7 +28,7 @@ import type { Film } from "./film";
import { isometricHand } from "./mechanismHands";
import {
Cam, V3, P2, Material, Item, prism, box, rrect, circle, turned, cyl, sphere, frameAlong, at, facingAt, screw, slab, leverRing, tubeAlong, stroke, fill,
- paintAll, sharesAt, ExplodePlan, card, smooth, clamp01, add, setReveal, tone, ink, inkDot, knock, Hand, setHand, flatHand, hand, freshPen,
+ paintAll, sharesAt, ExplodePlan, spin, hull, disc as circleOn, card, smooth, clamp01, add, setReveal, tone, ink, inkDot, knock, Hand, setHand, flatHand, hand, freshPen,
} from "./mechanismKit";
const W = 1080, H = 1080, FPS = 30, N = 310, N_DRAW = 350;
@@ -75,7 +75,7 @@ const CUES = [{ t: T.apart / FPS, apart: true }, { t: T.home / FPS, apart: false
const REV = 9.6; // seconds per drum turn: 0.3 s a step
/** drum angle: it turns while the movement is whole and playing */
const rotAt = (f: number) => { const run = (a: number, b: number) => Math.max(0, Math.min(f, b) - a); const fr = run(T.play, T.apart) + run(T.home + 30, N); return (fr / FPS / REV) * 2 * Math.PI; };
-export type State = { rot: number; shares: Record<string, number>; lit: string; read: string; bend: number[]; fan: number; crank: number };
+export type State = { rot: number; shares: Record<string, number>; lit: string; read: string; bend: number[]; fan: number; crank: number; blur?: number };
/** what the drum is doing at angle rot: how far each tooth bends, and which pin last spoke. One model for pins, teeth and words. */
export const play = (rot: number, quiet = 0) => {
const bend = TEETH.map(() => 0), turn = rot % (2 * Math.PI); let last = -1;
@@ -106,6 +106,7 @@ export const stateAt = (f: number): State => {
};
// ---------------------------------------------------------------- the parts list
+const circleAt = (c: Cam, o: V3, r: number, off: P2) => circleOn(c, o, [0, 0, 1], r, 40, off);
const vane = (psi: number, side: number): P2[] => { const c = Math.cos(psi), s = Math.sin(psi), e = 0.22; const pts: [number, number][] = side > 0 ? [[0.5, -e], [4.6, -e], [4.6, e], [0.5, e]] : [[-4.6, -e], [-0.5, -e], [-0.5, e], [-4.6, e]]; return pts.map(([x, y]) => [60 + x * c - y * s, 12 + x * s + y * c] as P2); };
const bar = (ctx: Ctx, c: Cam, x0: number, x1: number, yR: number, yT: number, z0: number, z1: number, dz: number, m: Material, off: P2) => {
const P = (x: number, y: number, z: number): P2 => { const s = c.p([x, y, z + (y < yR ? dz * ((yR - y) / (yR - yT)) ** 1.6 : 0)]); return [s[0] + off[0], s[1] + off[1]]; };
@@ -195,7 +196,10 @@ const parts = (c: Cam, s: State): Item[] => {
const F = frameAlong([60, 12, 19.4], [0, 0, 1]); turned(ctx, c, F, cyl(0, 4, 1.5), M("governor", STEEL), { off: o, lit: lit("governor") });
const KS = Math.round(20 / (hand().coarse ?? 1)); for (let i = 0; i < 9; i++) { const z0 = 0.3 + i * 0.42; for (let k = 0; k < KS; k++) { const th0 = (k / KS) * 2 * Math.PI + s.fan * 0.15, th1 = th0 + (2 * Math.PI) / KS, f = facingAt(c, F, (th0 + th1) / 2); if (f < 0.05) continue; const A = c.p(at(F, z0 + (k / KS) * 0.42, 1.5, th0)), B = c.p(at(F, z0 + ((k + 1) / KS) * 0.42, 1.5, th1)); ink(ctx, [[A[0] + o[0], A[1] + o[1]], [B[0] + o[0], B[1] + o[1]]], "seam", STEEL, false, smooth(0.05, 0.5, f)); } }
}, "governor");
- [1, -1].forEach((side) => { const ring = vane(s.fan, side), mid = ring.reduce((a, q) => [a[0] + q[0] / 4, a[1] + q[1] / 4], [0, 0]); put(`vane${side}`, [mid[0], mid[1], 26.5], (ctx, o) => prism(ctx, c, ring, 24.6, 4.2, M("governor", ZINC), { off: o, lit: lit("governor") }), "governor", 0); });
+ // the fan turns nine times a drum turn; with `blur` (radians of trail) it reads as spinning, not as a still cut-out
+ const sweep = (s.blur ?? 0), disc = (ctx: Ctx, o: P2) => () => tone(ctx, hull([...circleAt(c, [60, 12, 24.6], 4.6, o), ...circleAt(c, [60, 12, 28.8], 4.6, o)]), M("governor", ZINC), 4); // one shape: see-through bands would stack into stripes
+ [1, -1].forEach((side) => { const ring = vane(s.fan, side), mid = ring.reduce((a, q) => [a[0] + q[0] / 4, a[1] + q[1] / 4], [0, 0]); put(`vane${side}`, [mid[0], mid[1], 26.5], (ctx, o) => spin(s.fan, sweep, (ang) => prism(ctx, c, vane(ang, side), 24.6, 4.2, M("governor", ZINC), { off: o, lit: lit("governor") }), { disc: side > 0 ? disc(ctx, o) : undefined }), "governor", 0); });
+ /** the music box at rest on a page, playing: every part home, the drum turning, the fan a blur */
put("hub", [60, 12, 26.7], (ctx, o) => turned(ctx, c, frameAlong([60, 12, 24.4], [0, 0, 1]), cyl(0, 4.6, 0.95), M("governor", STEEL), { off: o }), "governor", 0.05);
put("gcap", [60, 12, 30.6], (ctx, o) => turned(ctx, c, frameAlong([60, 12, 30.2], [0, 0, 1]), cyl(0, 0.8, 1.3), STEEL, { off: o }), "governor", 2);
// travel lines: a chain line from where a part sits to where it went, drawn under everything that moved
@@ -260,6 +264,16 @@ export const paintFigure = (ctx: Ctx, s: State, hint: string, o: { cam?: Cam; bu
return CAM;
};
export const camApart = APART;
+/** the box at home, playing at drum angle `rot`, the fan's trail `blur` radians long (site art and loops) */
+/** the pins that have just plucked their teeth at drum angle `rot`: which tooth, where its tip is, how long ago (s) */
+export const plucks = (rot: number, within = 1.2) => PINS.flatMap((p) => {
+ const since = (((rot - p.step * DSTEP) % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI), age = (since / (2 * Math.PI)) * REV;
+ return age < within ? [{ tooth: p.tooth, age, tip: [toothX(p.tooth) + 0.67, TIP, 8.4] as V3 }] : [];
+});
+// the key turns back once a drum turn as the spring runs down, so a loop shows the whole motor working
+export const playing = (rot: number, blur = 0): State => { const pl = play(rot); return { rot, shares: Object.fromEntries(PLAN.order.map((id) => [id, 0])), lit: "drum", read: pl.read, bend: pl.bend, fan: pl.fan, crank: Math.PI * 0.3 - rot, blur }; };
+/** every corner of the box at home, for fitting a camera to a region */
+export const homePoints: V3[] = [...BENCH, [60, 12, 31], [74, 22, 18], [10, 11, 24]];
/** the run: it plays (the camera close on the pins), comes apart, tours its parts, folds home, plays on */
export const drawMechanism = (ctx: Ctx, f: number, env: Env) => {
ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);
diff --git a/skills/anidoodle/engine/src/canvas-core/mechanismHands.ts b/skills/anidoodle/engine/src/canvas-core/mechanismHands.ts
index 25f1667..9b15754 100644
--- a/skills/anidoodle/engine/src/canvas-core/mechanismHands.ts
+++ b/skills/anidoodle/engine/src/canvas-core/mechanismHands.ts
@@ -14,6 +14,7 @@ import type { Ctx, Env, Layer, P } from "./core";
import { Gfx, rng, PENCIL, GRAPHITE } from "./core";
import { kit, sheet, border, WHITE, CYAN, DIM, DRAFT } from "./blueprintKit";
import { letter } from "./drafting";
+import { isDark } from "./assetKit";
import { type Hand, type Material, type P2, type Role, offset, path, rawStroke, flatHand, reveal } from "./mechanismKit";
const hash = (...v: number[]) => { let h = 2166136261; for (const x of v) { h ^= Math.round(x * 8) | 0; h = Math.imul(h, 16777619); } return h >>> 0; };
@@ -169,7 +170,9 @@ export const stippleHand = (ctx0: Ctx, env: Env, frame: number): Hand => {
const mixHex = (a: string, b: string, t: number) => { const pa = [1, 3, 5].map((i) => parseInt(a.slice(i, i + 2), 16)), pb = [1, 3, 5].map((i) => parseInt(b.slice(i, i + 2), 16)); return "#" + pa.map((v, i) => Math.round(v + (pb[i] - v) * t).toString(16).padStart(2, "0")).join(""); };
export const isometricHand = (paper = "#efe8dc", ink = "#2b2a33"): Hand => {
const tones = new Map<string, [string, string, string]>();
- const three = (m: Material) => { const k = m.pigment ?? "#9a9a9a"; let t = tones.get(k); if (!t) { t = [mixHex(k, "#1d1a2a", 0.3), k, mixHex(k, "#ffffff", 0.5)]; tones.set(k, t); } return t; };
+ // on a dark page a top lifted halfway to white glares, so the lit top steps up less and the far face sinks more
+ const dark = isDark(paper), up = dark ? 0.26 : 0.5, down = dark ? 0.38 : 0.3;
+ const three = (m: Material) => { const k = m.pigment ?? "#9a9a9a"; let t = tones.get(k); if (!t) { t = [mixHex(k, "#1d1a2a", down), k, mixHex(k, "#ffffff", up)]; tones.set(k, t); } return t; };
const flat = (ctx: Ctx, pts: P2[], col: string, a = 1) => { ctx.globalAlpha = a; ctx.fillStyle = col; path(ctx, pts); ctx.fill(); ctx.strokeStyle = col; ctx.lineWidth = 0.5; ctx.lineJoin = "round"; ctx.stroke(); ctx.globalAlpha = 1; };
const base = flatHand(paper, "#7a7280", "#b9b0a3");
return {
@@ -184,7 +187,7 @@ export const isometricHand = (paper = "#efe8dc", ink = "#2b2a33"): Hand => {
else if (role === "chain") { ctx.save(); ctx.setLineDash([6, 4]); rawStroke(ctx, pts, ink, 0.8, false, 0.35 * a, prog); ctx.restore(); }
},
dot: (ctx, at, r, m, a) => { ctx.globalAlpha = a; ctx.fillStyle = three(m)[0]; ctx.beginPath(); ctx.arc(at[0], at[1], r, 0, Math.PI * 2); ctx.fill(); ctx.globalAlpha = 1; },
- shadow: (ctx, pts, s) => flat(ctx, pts.map(([x, y]) => [x + 6, y + 9] as P2), "#3a3346", 0.13 * s),
+ shadow: (ctx, pts, s) => flat(ctx, pts.map(([x, y]) => [x + 6, y + 9] as P2), dark ? "#000000" : "#3a3346", (dark ? 0.32 : 0.13) * s),
};
};
diff --git a/skills/anidoodle/engine/src/canvas-core/mechanismKit.ts b/skills/anidoodle/engine/src/canvas-core/mechanismKit.ts
index 4c4c9ee..4dd3c75 100644
--- a/skills/anidoodle/engine/src/canvas-core/mechanismKit.ts
+++ b/skills/anidoodle/engine/src/canvas-core/mechanismKit.ts
@@ -140,10 +140,28 @@ let OFFSET: P2 = [0, 0];
/** the screen offset of the part being painted: hands anchor their patterns to it, so marks travel with their part */
export const offset = (): P2 => OFFSET;
export const setHand = (h: Hand) => { HAND = h; };
+// a palette moves every material before the hand sees it: the page colour, the brand, light or dark (assetKit.ts)
+let PALETTE: ((m: Material) => Material) | null = null;
+export const setPalette = (f: ((m: Material) => Material) | null) => { PALETTE = f; };
+const pal = (m: Material) => (PALETTE ? PALETTE(m) : m);
+// a ghost is a part drawn faintly where it just was (a spinning blade's trail): no knock, so what is behind shows
+let GHOST = 1;
+export const ghost = (alpha: number, draw: () => void) => { const g = GHOST; GHOST = g * alpha; try { draw(); } finally { GHOST = g; } };
+/**
+ * Something that turns fast enough to blur. `draw(angle)` paints the blades at an angle; behind them go
+ * `trails` fainter copies, spread over `sweep` radians against the direction of travel, and under all of
+ * it the caller's swept `disc`, if any, as a faint sheen. Slow turns (sweep near 0) draw the blades alone.
+ */
+export const spin = (angle: number, sweep: number, draw: (angle: number) => void, o: { trails?: number; disc?: () => void } = {}) => {
+ const n = o.trails ?? 4, blur = Math.min(1, Math.abs(sweep) / 1.2);
+ if (blur > 0.02) { if (o.disc) ghost(0.16 * blur, o.disc); for (let k = n; k >= 1; k--) ghost(0.42 * blur * (1 - k / (n + 1)) ** 1.4, () => draw(angle - (sweep * k) / n)); }
+ draw(angle);
+};
export const hand = () => HAND;
/** a toned region in the current hand, honouring the making order (inked, then toned left to right) */
export const tone = (ctx: Ctx, pts: P2[], m: Material, q: number, alpha = 1) => {
- if (pts.length < 3) return;
+ if (pts.length < 3) return; m = pal(m);
+ if (GHOST < 1) { ctx.save(); ctx.globalAlpha = alpha * GHOST; HAND.region(ctx, pts, q, m, alpha * GHOST); ctx.restore(); return; }
if (REVEAL.tone >= 1) { if (!(HAND.opaque && alpha >= 1)) HAND.knock(ctx, pts); HAND.region(ctx, pts, q, m, alpha); return; }
if (REVEAL.ink < 1) return;
HAND.knock(ctx, pts); if (REVEAL.tone <= 0) return;
@@ -151,9 +169,9 @@ export const tone = (ctx: Ctx, pts: P2[], m: Material, q: number, alpha = 1) =>
ctx.save(); ctx.beginPath(); ctx.rect(x0 - 1, -1e5, (x1 - x0 + 2) * REVEAL.tone, 2e5); ctx.clip(); HAND.region(ctx, pts, q, m, alpha); ctx.restore();
};
/** paint the ground back over a shape without toning it (the paper inside a hull) */
-export const knock = (ctx: Ctx, pts: P2[]) => { if (pts.length >= 3 && (REVEAL.tone >= 1 || REVEAL.ink >= 1)) HAND.knock(ctx, pts); };
-export const ink = (ctx: Ctx, pts: P2[], role: Role, m: Material, close = false, alpha = 1) => { if (pts.length >= 2 && REVEAL.ink > 0) HAND.line(ctx, pts, role, m, close, alpha, REVEAL.ink); };
-export const inkDot = (ctx: Ctx, at: P2, r: number, m: Material, alpha = 1) => { if (REVEAL.ink >= 1) HAND.dot(ctx, at, r, m, alpha); };
+export const knock = (ctx: Ctx, pts: P2[]) => { if (GHOST >= 1 && pts.length >= 3 && (REVEAL.tone >= 1 || REVEAL.ink >= 1)) HAND.knock(ctx, pts); };
+export const ink = (ctx: Ctx, pts: P2[], role: Role, m: Material, close = false, alpha = 1) => { if (pts.length >= 2 && REVEAL.ink > 0) HAND.line(ctx, pts, role, pal(m), close, alpha * GHOST, REVEAL.ink); };
+export const inkDot = (ctx: Ctx, at: P2, r: number, m: Material, alpha = 1) => { if (REVEAL.ink >= 1) HAND.dot(ctx, at, r, pal(m), alpha * GHOST); };
const ruleFrame = (ctx: Ctx, W: number, H: number, colour: string, p: number, pad = 34) => {
if (p <= 0) return; ctx.strokeStyle = colour; ctx.lineWidth = 1.2; ctx.globalAlpha = 1; ctx.lineCap = "butt"; ctx.setLineDash([]);
const L = 2 * (W + H - 4 * pad) * clamp01(p), segs: [P2, P2][] = [[[pad, pad], [W - pad, pad]], [[W - pad, pad], [W - pad, H - pad]], [[W - pad, H - pad], [pad, H - pad]], [[pad, H - pad], [pad, pad]]];
diff --git a/skills/anidoodle/engine/src/canvas-core/music/delivery.ts b/skills/anidoodle/engine/src/canvas-core/music/delivery.ts
new file mode 100644
index 0000000..5692f01
--- /dev/null
+++ b/skills/anidoodle/engine/src/canvas-core/music/delivery.ts
@@ -0,0 +1,64 @@
+// THE DELIVERY MASTER. The last thing a film's whole mix passes through, score and effects together.
+// Before this, an effects-only film shipped at -27 LUFS and a scored one landed wherever the sum of its
+// parts fell, 4 to 13 LU under its web peers. A film that plays quiet reads unfinished, whatever its timbre.
+// One static gain to the target, then the smooth true-peak limiter, whose work is capped: when getting
+// to the target would need more than `maxLimitDb` of limiting (a mix of sharp hits on near silence), the
+// gain gives way instead of the hits being squashed, and the shortfall is reported, never hidden.
+import { loudness, truePeak } from "./meter";
+import { smoothLimiter } from "./mixDsp";
+import { db } from "./dsp";
+
+export type MasterMode = "gentle" | "dense" | "none" | number;
+export type Delivered = { targetLufs: number; gainDb: number; limitDb: number; lufs: number; dbtp: number; shortLu: number };
+/** -16 LUFS for gentle films (drawing films, explainers), -14 for dense ones (launch films, trailers) */
+export const targetOf = (m: MasterMode) => (typeof m === "number" ? m : m === "dense" ? -14 : -16);
+
+export const deliver = (L: Float32Array, R: Float32Array, sr: number, mode: MasterMode = "gentle", o: { ceilingDb?: number; maxLimitDb?: number } = {}): Delivered => {
+ const n = L.length, ceil = o.ceilingDb ?? -1, maxLim = o.maxLimitDb ?? (mode === "dense" ? 6 : 4), target = targetOf(mode);
+ const scale = (g: number) => { if (g === 1) return; for (let i = 0; i < n; i++) { L[i] *= g; R[i] *= g; } };
+ const before = n >= sr * 0.4 ? loudness([L, R], sr).integrated : -Infinity;
+ if (mode === "none" || !Number.isFinite(before)) { const tp = truePeak([L, R]).dbtp; return { targetLufs: target, gainDb: 0, limitDb: 0, lufs: before, dbtp: tp, shortLu: 0 }; }
+ // the limiter may take at most maxLim off the loudest peaks: try the gain on copies, and where it would
+ // limit harder, give gain back; where the peak estimate left room, take it, up to the target
+ const src = [L.slice(), R.slice()];
+ let gainDb = target - before, limitDb = 0;
+ for (let k = 0; k < 4; k++) {
+ L.set(src[0]); R.set(src[1]); scale(db(gainDb));
+ limitDb = smoothLimiter(L, R, sr, db(ceil - 0.15));
+ const lu = loudness([L, R], sr).integrated, roomLu = target - lu;
+ if (limitDb > maxLim + 0.05) gainDb -= limitDb - maxLim;
+ else if (roomLu > 0.1 && limitDb < maxLim - 0.1) gainDb += Math.min(roomLu, maxLim - limitDb);
+ else break;
+ }
+ // a last static trim for inter-sample overshoot the limiter's estimate missed
+ const tp = truePeak([L, R]).dbtp; if (tp > ceil) { gainDb -= tp - ceil + 0.02; scale(db(-(tp - ceil + 0.02))); }
+ const lufs = loudness([L, R], sr).integrated;
+ return { targetLufs: target, gainDb, limitDb, lufs, dbtp: truePeak([L, R]).dbtp, shortLu: Math.max(0, target - lufs) };
+};
+
+/**
+ * Room tone: the quiet air a foley track sits on, so an effects-only film never drops to digital
+ * silence between its cues. Seeded pink noise, band-limited (80 Hz to 5 kHz) and nearly mono (the two
+ * sides share most of their signal, so a phone's mono fold keeps it), faded in over 20 ms and out over
+ * the last 0.4 s. Returned at unit loudness scale; the caller sets its level against the cues.
+ */
+export const roomTone = (n: number, sr: number, seed = 1): [Float32Array, Float32Array] => {
+ let x = (seed * 2654435761) >>> 0; const rnd = () => { x ^= x << 13; x >>>= 0; x ^= x >>> 17; x ^= x << 5; x >>>= 0; return x / 4294967296 * 2 - 1; };
+ const pink = () => { let b0 = 0, b1 = 0, b2 = 0; return () => { const w = rnd(); b0 = 0.99765 * b0 + w * 0.099046; b1 = 0.963 * b1 + w * 0.2965164; b2 = 0.57 * b2 + w * 1.0526913; return (b0 + b1 + b2 + w * 0.1848) * 0.2; }; };
+ const shared = pink(), sideL = pink(), sideR = pink(), L = new Float32Array(n), R = new Float32Array(n);
+ const hp = 1 - Math.exp((-2 * Math.PI * 80) / sr), lp = 1 - Math.exp((-2 * Math.PI * 5000) / sr), st = [0, 0, 0, 0];
+ const fin = Math.round(0.02 * sr), fout = Math.round(0.4 * sr);
+ for (let i = 0; i < n; i++) {
+ const c = shared(), l = c + 0.35 * sideL(), r = c + 0.35 * sideR();
+ st[0] += (l - st[0]) * lp; st[1] += (r - st[1]) * lp; st[2] += (st[0] - st[2]) * hp; st[3] += (st[1] - st[3]) * hp;
+ const g = Math.min(1, i / fin, (n - 1 - i) / fout); L[i] = (st[0] - st[2]) * g; R[i] = (st[1] - st[3]) * g;
+ }
+ return [L, R];
+};
+/** lay room tone under an effects-only mix, `bedDb` under the effects' own loudness (no-op when they are silent) */
+export const layBed = (L: Float32Array, R: Float32Array, fx: [Float32Array, Float32Array], sr: number, seed: number, bedDb = 22) => {
+ const n = L.length; if (n < sr * 0.4) return;
+ const fxLu = loudness(fx, sr).integrated; if (!Number.isFinite(fxLu)) return;
+ const [bL, bR] = roomTone(n, sr, seed), bLu = loudness([bL, bR], sr).integrated, g = db(fxLu - bedDb - bLu);
+ for (let i = 0; i < n; i++) { L[i] += bL[i] * g; R[i] += bR[i] * g; }
+};
diff --git a/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts b/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts
index 3bbc4f5..6e4160b 100644
--- a/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts
+++ b/skills/anidoodle/engine/src/canvas-core/music/sfxMix.ts
@@ -8,6 +8,7 @@ import { Biquad, db } from "./dsp";
import { MODES } from "./theory";
import type { Piece } from "./plan";
import { loudness, truePeak } from "./meter";
+import { deliver, layBed, type Delivered, type MasterMode } from "./delivery";
export type SfxSnap = "none" | "bar" | "beat" | "8th" | "16th";
export type SfxHarshOptions = { mode?: "report" | "throw" | "tame"; maxLiftDb?: number; maxTiltDb?: number; maxPeakDb?: number };
@@ -38,6 +39,10 @@ export type SfxPlan = {
minDb?: number;
/** final true-peak ceiling in dBTP. Default -1. */
ceilingDb?: number;
+ /** the whole mix's loudness target (delivery.ts): "gentle" -16 LUFS (default), "dense" -14, a number, or "none" for the old peak-only ceiling */
+ master?: MasterMode;
+ /** an effects-only mix (no score) sits on quiet room tone this many dB under its cues, so it never drops to silence between them. Default 22; false for none. */
+ bed?: number | false;
/** Default report: samples stay frozen. Caps are cue-minus-score band RMS, band-minus-full RMS,
* and absolute sample peak dBFS. Tame scales cues only, never the score or duck envelope. */
harsh?: SfxHarshOptions;
@@ -52,7 +57,7 @@ export type SfxHarshness = {
violations: { metric: "liftDb" | "tiltDb" | "peakDb"; valueDb: number; capDb: number; excessDb: number }[];
ok: boolean; reductionDb: number; conflict: "audibility floor" | "tilt cannot be fixed by gain" | null;
};
-export type SfxMix = { L: Float32Array; R: Float32Array; sfx: SfxStereo; music: SfxStereo; duck: Float32Array; placed: PlacedCue[]; audibility: SfxAudibility[]; harshness: SfxHarshness[]; ok: boolean; lufs: number; dbtp: number; limiterDb: number };
+export type SfxMix = { L: Float32Array; R: Float32Array; sfx: SfxStereo; music: SfxStereo; duck: Float32Array; placed: PlacedCue[]; audibility: SfxAudibility[]; harshness: SfxHarshness[]; ok: boolean; lufs: number; dbtp: number; limiterDb: number; delivered?: Delivered };
// test/sfxKitSurvey.ts: all 44 variants, default gain/seed 1, C/90 bpm, 48 kHz, silence and
// a steady mid-level score. Maxima 16.49 / -0.80 / -1.00; margins 1.01 / 0.55 / 0.50 dB.
@@ -245,11 +250,15 @@ export const mixSfx = (music: SfxStereo | null, p: SfxPlan, sr = 48000): SfxMix
for (const pc of placed) { const { L, R } = pc.sound; for (let i = 0; i < L.length && pc.start + i < n; i++) { fxL[pc.start + i] += L[i]; fxR[pc.start + i] += R[i]; } }
const L = new Float32Array(n), R = new Float32Array(n);
for (let i = 0; i < n; i++) { L[i] = mL[i] + fxL[i]; R[i] = mR[i] + fxR[i]; }
- const limiterDb = ceiling(L, R, sr, db((p.ceilingDb ?? -1) - 0.3));
+ // no score: lay the cues on room tone, set against the cues' own loudness
+ if (!music && p.bed !== false && placed.length) layBed(L, R, [fxL, fxR], sr, mixSeed(p.cues.length, p.frames), p.bed ?? 22);
+ // the whole mix to its loudness target, then the ceiling; "none" keeps the old peak-only master
+ const delivered = (p.master ?? "gentle") === "none" ? undefined : deliver(L, R, sr, p.master ?? "gentle", { ceilingDb: (p.ceilingDb ?? -1) - 0.3 });
+ const limiterDb = delivered ? delivered.limitDb : ceiling(L, R, sr, db((p.ceilingDb ?? -1) - 0.3));
const fade = Math.min(n, secs(sr, 0.015)); for (let i = 0; i < fade; i++) { const g = i / fade; L[n - 1 - i] *= g; R[n - 1 - i] *= g; }
const audibility = sfxAudibility(placed, [mL, mR], sr, p);
const lu = n >= secs(sr, 0.4) ? loudness([L, R], sr).integrated : NaN;
- return { L, R, sfx: [fxL, fxR], music: [mL, mR], duck, placed, audibility, harshness, ok: audibility.every((a) => a.ok), lufs: lu, dbtp: truePeak([L, R]).dbtp, limiterDb };
+ return { L, R, sfx: [fxL, fxR], music: [mL, mR], duck, placed, audibility, harshness, ok: audibility.every((a) => a.ok), lufs: lu, dbtp: truePeak([L, R]).dbtp, limiterDb, delivered };
};
export const assertSfxAudible = (m: SfxMix) => {
diff --git a/skills/anidoodle/engine/src/canvas-core/siteHero.ts b/skills/anidoodle/engine/src/canvas-core/siteHero.ts
new file mode 100644
index 0000000..5b3363b
--- /dev/null
+++ b/skills/anidoodle/engine/src/canvas-core/siteHero.ts
@@ -0,0 +1,39 @@
+// SITE HERO. The music box as art for a landing page: placed right of a headline (assetKit PLACEMENTS.heroRight),
+// on the page's own colour, the part to watch in the brand colour, light and dark from one source. Its motion
+// is the object working: the drum plays one full turn, the teeth lift and drop, the air brake spins to a blur.
+// One drum turn is the whole loop, so it repeats without a seam; frame 0 is the rest pose a reduced-motion
+// visitor sees, so it is composed as the hero frame.
+import type { Ctx, Env } from "./core";
+import type { Film } from "./film";
+import { Cam, paintAll, setHand, setPalette, flatHand, hand, freshPen, rrect } from "./mechanismKit";
+import { isometricHand } from "./mechanismHands";
+import { parts, playing, homePoints, MOVE, REV } from "./mechanism";
+import { PLACEMENTS, fitBox, pagePalette, type Colour } from "./assetKit";
+
+const FPS = 30, N = Math.round(REV * FPS), P = PLACEMENTS.heroRight;
+// the fan turns nine times a drum turn; a trail of about a fifth of a second of its travel reads as speed
+const BLUR = ((2 * Math.PI * 9) / REV) * 0.2;
+
+export const heroOn = (title: string, paper: string, accent: Colour, colours: Record<string, Colour> = {}): Film => {
+ const CAM = Cam.fit(36, 30, homePoints, fitBox(P)), palette = pagePalette({ paper, accent, colours });
+ const draw = (ctx: Ctx, f: number, env: Env) => {
+ ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); freshPen(ctx);
+ ctx.fillStyle = paper; ctx.fillRect(0, 0, P.W, P.H);
+ setHand(isometricHand(paper)); setPalette(palette);
+ try {
+ const s = playing((2 * Math.PI * f) / N, BLUR);
+ hand().shadow?.(ctx, rrect(-3, 4.5, 76, 44.5, 3).map(([x, y]) => CAM.p([x, y, -9])), 1);
+ paintAll(ctx, CAM, parts(CAM, s), MOVE, s.shares);
+ } finally { setPalette(null); setHand(flatHand()); freshPen(ctx); }
+ };
+ return {
+ // calm by design: site art beside a headline must not pull the eye off it. The box works (drum, teeth,
+ // key, air brake) at about 0.2% of the frame a moment, under the film floor, so it is declared, not padded
+ meta: { title, W: P.W, H: P.H, fps: FPS, bpm: 100, durationFrames: N, kind: "loop", poster: 0, holds: [[1, N, "site hero: calm by design, the machine working is the only motion"]] },
+ assets: { images: {} },
+ shots: [{ id: "hero", start: 0, end: N, draw }],
+ };
+};
+
+/** the light page: a warm off-white site, a vermilion brand */
+export const siteHero = heroOn("Site hero · music box on a light page", "#faf7f2", "#e4572e");
diff --git a/skills/anidoodle/engine/src/canvas-core/siteHeroDark.ts b/skills/anidoodle/engine/src/canvas-core/siteHeroDark.ts
new file mode 100644
index 0000000..bfc40c5
--- /dev/null
+++ b/skills/anidoodle/engine/src/canvas-core/siteHeroDark.ts
@@ -0,0 +1,4 @@
+// The site hero from the same source on a dark page: a blue brand, the plinth in walnut.
+import { heroOn } from "./siteHero";
+
+export const siteHeroDark = heroOn("Site hero · music box on a dark page", "#12151f", "#3d7bff", { wood: "#7a5536" });
diff --git a/skills/anidoodle/engine/src/hosts/page-siteHero.ts b/skills/anidoodle/engine/src/hosts/page-siteHero.ts
new file mode 100644
index 0000000..a186064
--- /dev/null
+++ b/skills/anidoodle/engine/src/hosts/page-siteHero.ts
@@ -0,0 +1,4 @@
+import { siteHero } from "../canvas-core/siteHero";
+import { mountFilm } from "./page";
+
+mountFilm(siteHero);
diff --git a/skills/anidoodle/engine/src/hosts/page-siteHeroDark.ts b/skills/anidoodle/engine/src/hosts/page-siteHeroDark.ts
new file mode 100644
index 0000000..327b2f6
--- /dev/null
+++ b/skills/anidoodle/engine/src/hosts/page-siteHeroDark.ts
@@ -0,0 +1,4 @@
+import { siteHeroDark } from "../canvas-core/siteHeroDark";
+import { mountFilm } from "./page";
+
+mountFilm(siteHeroDark);
diff --git a/skills/anidoodle/engine/test/assetKit.test.ts b/skills/anidoodle/engine/test/assetKit.test.ts
new file mode 100644
index 0000000..a371bef
--- /dev/null
+++ b/skills/anidoodle/engine/test/assetKit.test.ts
@@ -0,0 +1,47 @@
+// ASSET KIT TESTS. Site art's claims: the colour maths round-trips, a brand ramp steps light to dark in
+// its own hue, a page palette keeps every material's light order on a light page and on a dark one, the
+// brand lands only on the part to watch, and a placement's art region never overlaps its headline zone.
+// node tools/test.mjs assetKit
+import { toLab, fromLab, rampFrom, pagePalette, isDark, PLACEMENTS, fitBox } from "../src/canvas-core/assetKit";
+import type { Material } from "../src/canvas-core/mechanismKit";
+
+export const name = "assetKit";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const L = (h: string) => toLab(h)[0], hue = (h: string) => { const [, a, b] = toLab(h); return Math.atan2(b, a); };
+ const near = (a: string, b: string) => { const x = parseInt(a.slice(1), 16), y = parseInt(b.slice(1), 16); return [16, 8, 0].every((s) => Math.abs(((x >> s) & 255) - ((y >> s) & 255)) <= 1); };
+
+ // 1. colour maths
+ ok(["#000000", "#ffffff", "#e4572e", "#3d7bff", "#12151f", "#faf7f2"].every((h) => near(fromLab(toLab(h)), h)), "OKLab round-trips to the same hex");
+ ok(Math.abs(L("#ffffff") - 1) < 1e-3 && L("#000000") < 1e-3, "white is lightness 1, black 0");
+ ok(/^#[0-9a-f]{6}$/.test(fromLab([0.7, 0.4, 0.4])), "a colour outside sRGB gives up chroma and still comes back as a hex");
+ ok(isDark("#12151f") && !isDark("#faf7f2"), "a navy page is dark, an off-white page is light");
+
+ // 2. a brand ramp: five tones, dark to light, in the brand's own hue, in either theme
+ for (const dark of [false, true]) for (const hex of ["#e4572e", "#3d7bff", "#2a9d5c"]) {
+ const r = rampFrom(hex, dark), ls = r.ramp.map(L);
+ ok(ls.every((v, i) => !i || v > ls[i - 1] + 0.03), `${hex} ${dark ? "dark" : "light"}: the ramp steps up in lightness (${ls.map((v) => v.toFixed(2)).join(" ")})`);
+ ok(r.ramp.every((c) => Math.abs(hue(c) - hue(hex)) < 0.12), `${hex} ${dark ? "dark" : "light"}: every tone keeps the brand's hue`);
+ }
+ ok(L(rampFrom("#e4572e", true).ramp[4]) < 0.85, "on a dark page the brand's lit top does not glare");
+
+ // 3. a page palette keeps light order and puts the brand only on the part to watch
+ const zinc: Material = { name: "zinc", ramp: ["#a9a69f", "#bdbab3", "#cfccc4", "#dedbd3", "#f4f1ea"], ink: "#232227", seam: "#8a877f", pigment: "#8d8b86" };
+ const watch: Material = { ...zinc, name: "accent", accent: true, pigment: "#d0502a" };
+ for (const paper of ["#faf7f2", "#12151f", "#f0f4ff"]) {
+ const p = pagePalette({ paper, accent: "#3d7bff" }), z = p(zinc), ls = z.ramp.map(L);
+ ok(ls.every((v, i) => !i || v >= ls[i - 1]), `on ${paper}: zinc keeps its light order`);
+ ok(isDark(paper) ? ls[0] > L(paper) : ls[4] <= L(paper) + 0.06, `on ${paper}: parts sit ${isDark(paper) ? "above" : "at or below"} the page`);
+ ok(!near(p(watch).pigment!, z.pigment!) && Math.abs(hue(p(watch).pigment!) - hue("#3d7bff")) < 0.12, `on ${paper}: the part to watch takes the brand`);
+ ok(near(p({ ...zinc }).ramp[2], z.ramp[2]), `on ${paper}: a plain part does not`);
+ }
+ const ink = pagePalette({ paper: "#faf7f2", colours: { zinc: { hex: "#e4572e", mode: "ink" } } })(zinc);
+ ok(Math.abs(hue(ink.ink) - hue("#e4572e")) < 0.12 && near(ink.ramp[2], pagePalette({ paper: "#faf7f2" })(zinc).ramp[2]), "ink mode colours the lines and leaves the body neutral");
+ ok(near(pagePalette({ paper: "#f3f0e8" })(zinc).ramp[2], zinc.ramp[2]), "on the kit's own paper nothing moves");
+
+ // 4. placements
+ for (const [id, p] of Object.entries(PLACEMENTS)) {
+ const [x0, y0, x1, y1] = fitBox(p), s = p.safe;
+ ok(x0 >= 0 && y0 >= 0 && x1 <= p.W && y1 <= p.H && x1 > x0 && y1 > y0, `${id}: the fit box lies inside the canvas`);
+ if (s) ok(x1 <= s.x || x0 >= s.x + s.w || y1 <= s.y || y0 >= s.y + s.h, `${id}: the art never overlaps the headline zone`);
+ }
+};
diff --git a/skills/anidoodle/engine/test/delivery.test.ts b/skills/anidoodle/engine/test/delivery.test.ts
new file mode 100644
index 0000000..849f9f0
--- /dev/null
+++ b/skills/anidoodle/engine/test/delivery.test.ts
@@ -0,0 +1,42 @@
+// DELIVERY TESTS. The whole film mix lands on its loudness target under the -1 dBTP ceiling, a quiet
+// effects-only film is brought up instead of shipping at -27 LUFS, the limiter's work is capped (the gain
+// gives way and says so), and "none" leaves the mix alone.
+// node tools/test.mjs delivery
+import { deliver, targetOf } from "../src/canvas-core/music/delivery";
+import { loudness, truePeak } from "../src/canvas-core/music/meter";
+import { mixSfx } from "../src/canvas-core/music/sfxMix";
+// @ts-ignore: a plain ES module shared with the tools
+import { filmShape } from "../tools/filmshape.mjs";
+
+export const name = "delivery";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const sr = 48000, n = sr * 4;
+ const tone = (amp: number, hits = false) => { const L = new Float32Array(n), R = new Float32Array(n); for (let i = 0; i < n; i++) { const t = i / sr, h = hits ? (i % (sr / 2) < 200 ? 0.9 : 0) : 0, v = amp * Math.sin(2 * Math.PI * 220 * t) * (0.6 + 0.4 * Math.sin(2 * Math.PI * 0.5 * t)) + h * Math.sin(2 * Math.PI * 3000 * t); L[i] = v; R[i] = v * 0.95; } return [L, R] as [Float32Array, Float32Array]; };
+
+ for (const mode of ["gentle", "dense"] as const) {
+ const [L, R] = tone(0.01), d = deliver(L, R, sr, mode);
+ ok(Math.abs(d.lufs - targetOf(mode)) <= 0.5 && d.dbtp <= -1 + 1e-6, `${mode}: a quiet mix lands on ${targetOf(mode)} LUFS (${d.lufs.toFixed(2)}) under -1 dBTP (${d.dbtp.toFixed(2)})`);
+ }
+ const [L2, R2] = tone(0.002, true), d2 = deliver(L2, R2, sr, "gentle");
+ ok(d2.limitDb <= 4 + 0.1 && d2.dbtp <= -1 + 1e-6, `sharp hits over near silence: the limiter takes at most 4 dB (${d2.limitDb.toFixed(2)})`);
+ ok(d2.shortLu < 0.1 || d2.limitDb > 3.8, `and uses its allowance before falling short (${d2.limitDb.toFixed(2)} dB limited, ${d2.shortLu.toFixed(2)} LU short)`);
+ ok(Math.abs(d2.shortLu - Math.max(0, -16 - d2.lufs)) < 1e-9, `and any shortfall is reported (${d2.shortLu.toFixed(2)} LU short)`);
+ const [L3, R3] = tone(0.3), before = L3.slice(), d3 = deliver(L3, R3, sr, "none");
+ ok(d3.gainDb === 0 && L3.every((v, i) => v === before[i]), "none leaves the mix untouched");
+ ok(Math.abs(loudness(tone(0.01), sr).integrated - loudness(tone(0.01), sr).integrated) < 1e-12, "the master is deterministic in, deterministic out");
+
+ // an effects-only film used to ship wherever its cues fell; now it is delivered at the gentle target
+ const fx = mixSfx(null, { fps: 30, frames: 120, cues: [{ frame: 10, kind: "tick" }, { frame: 40, kind: "pop" }, { frame: 80, kind: "impact" }] } as never, sr);
+ ok(fx.delivered !== undefined && fx.dbtp <= -1 + 1e-6, `effects-only mix: delivered (${fx.lufs.toFixed(1)} LUFS, ${fx.dbtp.toFixed(2)} dBTP, limiter ${fx.limiterDb.toFixed(1)} dB)`);
+ const old = mixSfx(null, { fps: 30, frames: 120, master: "none", cues: [{ frame: 10, kind: "tick" }, { frame: 40, kind: "pop" }, { frame: 80, kind: "impact" }] } as never, sr);
+ ok(Math.abs(fx.lufs + 16) <= 0.5, `on target, where the old peak-only master left it wherever its cues fell (${old.lufs.toFixed(1)} LUFS)`);
+ void truePeak;
+
+ // between its cues an effects-only film sits on room tone, never on digital silence
+ const sparse = { fps: 30, frames: 240, cues: [{ frame: 6, kind: "tick" }, { frame: 150, kind: "impact" }] } as never;
+ const bedded = mixSfx(null, sparse, sr), bare = mixSfx(null, { ...(sparse as object), bed: false } as never, sr);
+ ok(filmShape(bare.L, bare.R, sr).problems.some((p: { kind: string }) => p.kind === "hole"), "without a bed, two cues 5 s apart leave a hole");
+ ok(!filmShape(bedded.L, bedded.R, sr).problems.some((p: { kind: string }) => p.kind === "hole"), "with room tone the hole is gone");
+ let c = 0, l2 = 0, r2 = 0; for (let i = sr; i < 3 * sr; i++) { c += bedded.L[i] * bedded.R[i]; l2 += bedded.L[i] ** 2; r2 += bedded.R[i] ** 2; }
+ ok(c / Math.sqrt(l2 * r2) > 0.7, `room tone is nearly mono, so a phone keeps it (correlation ${(c / Math.sqrt(l2 * r2)).toFixed(2)})`);
+};
diff --git a/skills/anidoodle/engine/test/filmshape.test.ts b/skills/anidoodle/engine/test/filmshape.test.ts
new file mode 100644
index 0000000..dca4263
--- /dev/null
+++ b/skills/anidoodle/engine/test/filmshape.test.ts
@@ -0,0 +1,20 @@
+// FILM SHAPE TESTS. A finished film's sound starts with the picture, never drops out, and ends with it;
+// a silence the film declares in meta.quiet is not a fault.
+// node tools/test.mjs filmshape
+// @ts-ignore: a plain ES module shared with the tools
+import { filmShape } from "../tools/filmshape.mjs";
+
+export const name = "filmshape";
+export const run = (ok: (cond: boolean, label: string) => void) => {
+ const sr = 8000, film = (secs: number, on: (t: number) => boolean) => { const n = sr * secs, L = new Float32Array(n), R = new Float32Array(n); for (let i = 0; i < n; i++) { const t = i / sr, v = on(t) ? 0.2 * Math.sin(2 * Math.PI * 330 * t) : 0; L[i] = v; R[i] = v; } return [L, R] as const; };
+ const kinds = (r: ReturnType<typeof filmShape>) => r.problems.map((p: { kind: string }) => p.kind).join(",");
+ ok(kinds(filmShape(...film(6, () => true), sr)) === "", "sound from start to end: a finished shape");
+ ok(kinds(filmShape(...film(6, (t) => t > 1.2), sr)) === "late start", "a film that starts 1.2 s late is caught");
+ const dead = filmShape(...film(16, (t) => t < 5.4), sr);
+ ok(kinds(dead) === "dead end" && Math.abs(dead.endS - 10.6) < 0.15, `sound that stops at 5.4 s of 16 is a dead end (${dead.endS.toFixed(1)} s)`);
+ const hole = filmShape(...film(8, (t) => t < 3.1 || t > 6.4), sr);
+ ok(kinds(hole) === "hole" && Math.abs(hole.holeS - 3.3) < 0.15, `a 3.3 s hole in the middle is caught (${hole.holeS.toFixed(1)} s)`);
+ ok(kinds(filmShape(...film(8, (t) => t < 3.1 || t > 3.3), sr)) === "", "a 0.2 s breath is not a hole");
+ ok(kinds(filmShape(...film(8, (t) => t < 3.1 || t > 4.0), sr, { fps: 30, quiet: [[90, 123, "stop-down before the reveal"]] })) === "", "a declared stop-down is not a fault");
+ ok(kinds(filmShape(...film(4, () => false), sr)) === "silent", "a silent film is caught");
+};
diff --git a/skills/anidoodle/engine/test/mechanism.test.ts b/skills/anidoodle/engine/test/mechanism.test.ts
index 5523d22..7fccd5c 100644
--- a/skills/anidoodle/engine/test/mechanism.test.ts
+++ b/skills/anidoodle/engine/test/mechanism.test.ts
@@ -2,7 +2,7 @@
// light ladder is monotone, the springs are exact closed forms, an exploded view staggers out and folds
// back last-out-first-home, hatching stays inside its shape, and the music box's words come from its pins.
// node tools/test.mjs mechanism
-import { Cam, level, springAt, sharesAt, type ExplodePlan, hand, flatHand } from "../src/canvas-core/mechanismKit";
+import { Cam, level, springAt, sharesAt, type ExplodePlan, hand, flatHand, spin } from "../src/canvas-core/mechanismKit";
import { Iso } from "../src/canvas-core/isometricKit";
import { hatchSegs } from "../src/canvas-core/mechanismHands";
import { play, PLAN, REV } from "../src/canvas-core/mechanism";
@@ -64,4 +64,9 @@ export const run = (ok: (cond: boolean, label: string) => void) => {
ok(loop.read === first.read && loop.bend.every((v, i) => near(v, first.bend[i], 0.05)), "the drum's story repeats every turn");
ok(REV > 0 && hand().id === "flat", "the kit's default hand is the plain reference hand");
void flatHand;
+
+ // 7. spin: a slow turn draws the blades once; a fast one trails fainter copies behind, against the travel
+ const calls = (sweep: number) => { const a: number[] = []; spin(1, sweep, (ang) => a.push(ang)); return a; };
+ ok(calls(0).length === 1 && calls(0)[0] === 1, "a slow turn draws only the blades");
+ const fast = calls(1.2); ok(fast.length === 5 && fast[fast.length - 1] === 1 && fast.slice(0, -1).every((v) => v < 1), `a fast turn trails ${fast.length - 1} copies behind the blades, drawn first`);
};
diff --git a/skills/anidoodle/engine/test/sfxHarsh.test.ts b/skills/anidoodle/engine/test/sfxHarsh.test.ts
index 624cfb8..61233d6 100644
--- a/skills/anidoodle/engine/test/sfxHarsh.test.ts
+++ b/skills/anidoodle/engine/test/sfxHarsh.test.ts
@@ -61,7 +61,8 @@ export const run = (ok: (cond: boolean, label: string) => void) => {
// loaded by git show and bundled with these fixtures before the mixer was edited.
const hashes = ["5db7c646b1e61b0016c5dd8a114e875f6cedbaed17f6b702a225ba2dcc187a85", "3064c924f76acb857c509a5c294cf043380451d544fda0b5372ce06d33ef133a", "3a42c3f453a9a1a0285bd2287bc9874e6e330fc3bd6baa263587e10443eaa94e"];
const frozen = frozenPlans(sr);
- frozen.plans.forEach((p, i) => { const m = mixSfx(frozen.music, p, sr), f = filmSfx(() => frozen.music, p)(sr);
+ // the old peak-only master stays bit-identical when asked for; the loudness master is tested in delivery.test.ts
+ frozen.plans.forEach((p0, i) => { const p = { ...p0, master: "none" as const }, m = mixSfx(frozen.music, p, sr), f = filmSfx(() => frozen.music, p)(sr);
ok(hash(m.L, m.R) === hashes[i] && hash(...f) === hashes[i], `launch cue plan ${i}: mixSfx and filmSfx match base SHA-256 ${hashes[i]}`);
});
for (const row of survey()) ok(row.ok, `${row.kind}:${row.variant} over ${row.context}: default gain passes the measured default caps`);
diff --git a/skills/anidoodle/engine/tools/filmshape.mjs b/skills/anidoodle/engine/tools/filmshape.mjs
new file mode 100644
index 0000000..60032e0
--- /dev/null
+++ b/skills/anidoodle/engine/tools/filmshape.mjs
@@ -0,0 +1,30 @@
+// FILM SHAPE. Whether a film's sound has the shape of a finished piece: it starts with the picture, it
+// never drops out mid-film, and it ends with the film instead of stopping early and leaving dead air.
+// Measured in 100 ms blocks against the mix's own body level (the median of its active blocks), so a
+// quiet film and a loud one are judged alike. A silence the film means (a stop-down before a reveal, a
+// held breath) is declared in meta.quiet as [fromFrame, toFrame, reason] and is not a fault.
+// import { filmShape } from "./filmshape.mjs"; filmShape(L, R, sr, { fps, quiet })
+export const SHAPE = Object.freeze({ firstS: 0.5, holeS: 0.25, endS: 0.5, quietDb: 30, bodyDb: 20 });
+
+export const filmShape = (L, R, sr, o = {}) => {
+ const B = Math.round(sr * 0.1), nb = Math.floor(L.length / B), lv = new Float64Array(nb);
+ for (let b = 0; b < nb; b++) { let s = 0; for (let i = b * B; i < (b + 1) * B; i++) s += L[i] * L[i] + R[i] * R[i]; lv[b] = 10 * Math.log10(s / (2 * B) + 1e-20); }
+ const active = [...lv].filter((v) => v > -70).sort((a, b) => a - b), body = active.length ? active[Math.floor(active.length / 2)] : -Infinity;
+ const fps = o.fps ?? 30, quiet = (o.quiet ?? []).map(([a, b]) => [a / fps, b / fps]);
+ const declared = (t0, t1) => quiet.some(([a, b]) => a <= t0 + 0.05 && b >= t1 - 0.05);
+ const silent = (b) => lv[b] < body - SHAPE.quietDb, problems = [];
+ if (!Number.isFinite(body)) return { body, problems: [{ kind: "silent", atS: 0, durS: nb / 10, msg: "the whole film is silent" }], firstS: NaN, endS: NaN, holeS: 0 };
+ let first = 0; while (first < nb && lv[first] < body - SHAPE.bodyDb) first++;
+ const firstS = first / 10; if (firstS > SHAPE.firstS && !declared(0, firstS)) problems.push({ kind: "late start", atS: 0, durS: firstS, msg: `nothing reaches body level until ${fmt(firstS)}` });
+ let last = nb - 1; while (last >= 0 && silent(last)) last--;
+ const endS = (nb - 1 - last) / 10; if (endS > SHAPE.endS && !declared((last + 1) / 10, nb / 10)) problems.push({ kind: "dead end", atS: (last + 1) / 10, durS: endS, msg: `the sound stops at ${fmt((last + 1) / 10)} and the picture runs ${endS.toFixed(1)} s more` });
+ let holeS = 0;
+ for (let b = first; b <= last; ) {
+ if (!silent(b)) { b++; continue; }
+ const a = b; while (b <= last && silent(b)) b++;
+ const d = (b - a) / 10; holeS = Math.max(holeS, d);
+ if (d > SHAPE.holeS && !declared(a / 10, b / 10)) problems.push({ kind: "hole", atS: a / 10, durS: d, msg: `a ${d.toFixed(1)} s hole at ${fmt(a / 10)}` });
+ }
+ return { body, problems, firstS, endS, holeS };
+};
+const fmt = (s) => `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, "0")}`;
diff --git a/skills/anidoodle/engine/tools/listen.mjs b/skills/anidoodle/engine/tools/listen.mjs
index f8f4199..eea24c7 100644
--- a/skills/anidoodle/engine/tools/listen.mjs
+++ b/skills/anidoodle/engine/tools/listen.mjs
@@ -91,7 +91,7 @@ const DARK = `--bg: #101814; --fg: #eef3ef; --panel: #18231e; --line: #33443b; -
// from Google Fonts and nothing else off-box; every colour a variable, dark repeated both ways.
const STYLE = ` :root {
--bg: #f3f5f1; --fg: #14201b; --panel: #ffffff; --line: #c9d3cc; --accent: #0f6b52; --accent-fg: #ffffff;
- --display: "Fraunces", Georgia, serif; --body: "Figtree", system-ui, sans-serif;
+ --display: "Poppins", system-ui, sans-serif; --body: "Poppins", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { ${DARK} } }
:root[data-theme="dark"] { ${DARK} }
@@ -139,7 +139,7 @@ const takeCard = (t) => ` <div class="take">
<audio data-piece="${esc(t.piece)}" controls preload="auto" src="${esc(t.file)}"></audio>
</div>`;
const page = (title, intro, pieces) => `<title>${esc(title)}</title>
-<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,[email protected],600&family=Figtree:wght@400;600&display=swap">
+<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap">
<style>
${STYLE}
</style>
diff --git a/skills/anidoodle/engine/tools/placement.mjs b/skills/anidoodle/engine/tools/placement.mjs
new file mode 100644
index 0000000..8db5d57
--- /dev/null
+++ b/skills/anidoodle/engine/tools/placement.mjs
@@ -0,0 +1,37 @@
+// PLACEMENT. Site art has a zone the art must never enter: the headline's. This reads a rendered still
+// and fails if anything (a part, a shadow, a sheen) is drawn there, then writes the picture at phone
+// width so you look at it the size most visitors will.
+// node tools/placement.mjs out/hero.png --W 1200 --safe 0,0,480,640 [--paper #faf7f2] [--tol 6] [--phone out/hero-390.png]
+// --W is the film's logical width (meta.W); --safe is in the same units (assetKit PLACEMENTS[...].safe).
+// --paper defaults to the commonest colour in the picture, which on site art is the page.
+import { execFileSync } from "node:child_process";
+import { existsSync } from "node:fs";
+import { resolve } from "node:path";
+
+const arg = (k, d) => { const i = process.argv.indexOf(`--${k}`); return i > 0 ? process.argv[i + 1] : d; };
+const file = process.argv[2] && resolve(process.argv[2]);
+if (!file || !existsSync(file)) { console.error("usage: node tools/placement.mjs <still.png> --W <logical width> --safe x,y,w,h [--paper #hex] [--tol 6] [--phone out.png]"); process.exit(2); }
+const { width: w, height: h } = JSON.parse(execFileSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "json", file])).streams[0];
+const raw = execFileSync("ffmpeg", ["-v", "error", "-i", file, "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], { maxBuffer: w * h * 3 + 1024 });
+const k = w / Number(arg("W", w)), tol = Number(arg("tol", 6));
+
+let paper = arg("paper");
+if (!paper) { const n = new Map(); for (let i = 0; i < raw.length; i += 3 * 7) { const c = (raw[i] << 16) | (raw[i + 1] << 8) | raw[i + 2]; n.set(c, (n.get(c) ?? 0) + 1); } paper = "#" + [...n].sort((a, b) => b[1] - a[1])[0][0].toString(16).padStart(6, "0"); }
+const pv = parseInt(paper.slice(1), 16), pr = (pv >> 16) & 255, pg = (pv >> 8) & 255, pb = pv & 255;
+
+let fail = false;
+const safe = arg("safe");
+if (safe) {
+ const [sx, sy, sw, sh] = safe.split(",").map((v) => Math.round(Number(v) * k));
+ let count = 0, x0 = 1e9, y0 = 1e9, x1 = -1, y1 = -1;
+ for (let y = Math.max(0, sy); y < Math.min(h, sy + sh); y++) for (let x = Math.max(0, sx); x < Math.min(w, sx + sw); x++) {
+ const i = (y * w + x) * 3;
+ if (Math.abs(raw[i] - pr) > tol || Math.abs(raw[i + 1] - pg) > tol || Math.abs(raw[i + 2] - pb) > tol) { count++; x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }
+ }
+ fail = count > 0;
+ console.log(` ${fail ? "FAIL" : "PASS"} headline zone ${safe} on ${paper}: ${count ? `${count} px of art inside, x ${(x0 / k).toFixed(0)}-${(x1 / k).toFixed(0)}, y ${(y0 / k).toFixed(0)}-${(y1 / k).toFixed(0)}` : "clean"}`);
+}
+const phone = arg("phone");
+if (phone) { execFileSync("ffmpeg", ["-v", "error", "-y", "-i", file, "-vf", "scale=390:-1:flags=area", phone]); console.log(` phone width (390 px): ${resolve(phone)} look at it`); }
+console.log(`PLACEMENT: ${fail ? "FAIL" : "PASS"}`);
+process.exit(fail ? 1 : 0);
diff --git a/skills/anidoodle/engine/tools/verify-export.mjs b/skills/anidoodle/engine/tools/verify-export.mjs
index 1bf95dc..8422f01 100644
--- a/skills/anidoodle/engine/tools/verify-export.mjs
+++ b/skills/anidoodle/engine/tools/verify-export.mjs
@@ -36,6 +36,7 @@ import { basename, resolve } from "node:path";
import { defaultOutput, requireFilm } from "./names.mjs";
import { firstFrameBlank } from "./thumb.mjs";
import { mono, onsetNear, xcorrOffset } from "./avsync.mjs";
+import { filmShape } from "./filmshape.mjs";
const VAL = new Set(["file", "adapter", "width", "first-frame", "tol", "fidelity-psnr", "scale", "frame", "sync-tol"]);
const pos = [], opt = {};
@@ -117,6 +118,10 @@ if (isMp4) {
for (let i = 0; i < dL.length; i++) { dL[i] = di[2 * i]; dR[i] = di[2 * i + 1]; }
const master = await s.audio(SR), mb = Buffer.from(master.float32, "base64"), mi = new Float32Array(mb.buffer.slice(mb.byteOffset, mb.byteOffset + mb.byteLength)), mL = new Float32Array(master.frames), mR = new Float32Array(master.frames);
for (let i = 0; i < master.frames; i++) { mL[i] = mi[2 * i]; mR[i] = mi[2 * i + 1]; }
+ // the shape of a finished piece: sound from the first frame, no hole, no dead air after it stops
+ const shape = filmShape(dL, dR, SR, { fps: meta.fps, quiet: meta.quiet });
+ for (const [from, to, why] of meta.quiet ?? []) if (why) note(`QUIET ${from}-${to}: ${why}`, "a declared silence");
+ say(shape.problems.length === 0, `the sound has a finished shape (starts ${shape.firstS.toFixed(1)} s, longest hole ${shape.holeS.toFixed(1)} s, dead air at the end ${shape.endS.toFixed(1)} s)`, shape.problems.map((p) => p.msg).join("; ") || "sound from the start, no hole over 0.25 s, the last sound within 0.5 s of the end");
const ref = mono(mL, mR), got = mono(dL, dR), tol = Number(opt["sync-tol"] ?? 1);
const marks = meta.sync?.length ? meta.sync : [0.25, 0.5, 0.75].map((q) => ({ frame: Math.round(q * N), label: `${Math.round(q * 100)} % in` }));
if (!meta.sync?.length) note("no sync markers in meta.sync", "checking three points of the mix instead (a launch template film names its presses and its impact)");
@@ -137,7 +142,14 @@ if (isMp4) {
const eb = spawnSync("ffmpeg", ["-v", "info", "-nostats", "-i", file, "-map", "0:a:0", "-af", "ebur128=peak=true", "-f", "null", "-"], { encoding: "utf8", maxBuffer: 1 << 26 });
const txt = eb.stdout + eb.stderr, tp = Number((txt.match(/True peak:\s*\n\s*Peak:\s*(-?[0-9.]+|-inf) dBFS/) ?? [])[1]), il = Number((txt.match(/Integrated loudness:\s*\n\s*I:\s*(-?[0-9.]+) LUFS/) ?? [])[1]);
if (!Number.isFinite(tp)) note("true peak unreadable from ffmpeg's ebur128", txt.split("\n").slice(-4).join(" "));
- else if (opt.delivery) say(tp <= -1.0, `true peak after the encode ${tp.toFixed(2)} dBTP`, `ceiling -1 dBTP; integrated ${Number.isFinite(il) ? il.toFixed(1) : "?"} LUFS`);
+ else if (opt.delivery) {
+ say(tp <= -1.0, `true peak after the encode ${tp.toFixed(2)} dBTP`, `ceiling -1 dBTP; integrated ${Number.isFinite(il) ? il.toFixed(1) : "?"} LUFS`);
+ // a film that plays quiet reads unfinished: -16 LUFS for gentle films, -14 for dense, a 1 LU window around each
+ // -19 is the floor: a gentle score held under -16 by its own peaks (never compressed, by design) may sit near
+ // -17.5; under -19 the film is simply quiet. Warn from -17 so the musical cure ("Peaks", music/README.md) is tried
+ say(Number.isFinite(il) && il >= -19 && il <= -13, `integrated loudness ${Number.isFinite(il) ? il.toFixed(1) : "?"} LUFS`, "-19..-13 (the delivery master puts gentle films at -16, dense at -14)");
+ if (Number.isFinite(il) && il < -17 && il >= -19) note(`quiet: ${il.toFixed(1)} LUFS`, "its peaks hold it down: in a score, stagger the bass under the loudest downbeat and roll the big chord (music/README.md, Peaks); in effects, soften the sharpest cue's attack or lower it a little so the rest can come up");
+ }
else note(`true peak after the encode ${tp.toFixed(2)} dBTP${tp > -1 ? " (over -1: --delivery fails this)" : ""}`, `integrated ${Number.isFinite(il) ? il.toFixed(1) : "?"} LUFS`);
}
}
diff --git a/skills/anidoodle/references/craft-bar.md b/skills/anidoodle/references/craft-bar.md
index bab6955..b4021c5 100644
--- a/skills/anidoodle/references/craft-bar.md
+++ b/skills/anidoodle/references/craft-bar.md
@@ -25,6 +25,9 @@ The test: would a proud human illustrator ship this, or is it mechanical shape-a
| Words laid over busy art, a face or the UI | Type gets its own frame by default; over the picture only as a composed label or kinetic line on a calm area (`workflows/launch-video.md`, Type) |
| A loop playing in place and called "alive" | Real travel through a world that changes as the subject moves |
| An unmatched hard cut or a sharp swoosh between scenes | A gentle move (a bloom, a flip, a push, the card grows into the frame), or a cut matched on shape, position or beat |
+| Site art on its own white or cream while the page is another colour | `paper` is the page's exact colour; neutrals moved onto it, light and dark from one source (`workflows/site-art.md`) |
+| A part, shadow or sheen creeping under the headline | The headline zone is empty, proved by `tools/placement.mjs` |
+| A spinner drawn as still blades turning slowly | A sheen disc and fading trails (`spin`), so it reads as speed |
**No dead air** in anything that moves: something visibly changes in every second, from frame 0.
Check it with the tool AND by eye: a creeping camera changes every pixel and satisfies the tool
diff --git a/skills/anidoodle/references/formats.md b/skills/anidoodle/references/formats.md
index 0ffdd51..4190672 100644
--- a/skills/anidoodle/references/formats.md
+++ b/skills/anidoodle/references/formats.md
@@ -10,6 +10,8 @@ node <skill>/engine/tools/scaffold.mjs ~/art --film intro # something that
## Stills: hero art, spots, covers, cards, diagrams
+Art that sits on a site beside a headline, on its page colour and brand: `workflows/site-art.md`.
+
- **Size is `meta.W` x `meta.H`**, in logical units; `--scale` multiplies it at render time, so
one source gives a thumbnail (`--scale 0.5`), the page (`1`) and print (`--scale 3`). Common
shapes: 1600x900 web hero, 1200x630 social card, 1080x1080 square post, 1080x1350 portrait
diff --git a/skills/anidoodle/references/music/README.md b/skills/anidoodle/references/music/README.md
index ddca2be..7d4f5fc 100644
--- a/skills/anidoodle/references/music/README.md
+++ b/skills/anidoodle/references/music/README.md
@@ -115,6 +115,8 @@ MusicPlan + notes (you write) -> perform -> instruments (one stem per part)
2:1 bus glue) exists but is off by default: Alex's call. If the peak still blocks the gain, the loudness goes
down. The cure is musical (see "Peaks" below): a solo piano with a 10 LU range (the nocturne demo) masters at -17.5.
- **Dense styles** (lofiElectronic, lofi, drive, house, synthwave, hipHop, rock, chiptune): **-14 LUFS** through a look-ahead true-peak limiter, then a static trim if an inter-sample peak still passes -1 dBTP.
+ - **A film's whole mix** (score plus effects, or effects alone) goes through the delivery master last:
+ `sound-design.md`, The finished mix.
A film's `audio` is `filmAudio(piece, seconds)`, which returns `(sampleRate) => [L, R]` at exactly
the film's length. It fits the score first (`fitScore`, below), so the music ends on its phrase at
diff --git a/skills/anidoodle/references/music/sound-design.md b/skills/anidoodle/references/music/sound-design.md
index 5cdf9b6..be46aa3 100644
--- a/skills/anidoodle/references/music/sound-design.md
+++ b/skills/anidoodle/references/music/sound-design.md
@@ -120,6 +120,37 @@ music, and its test only checked that they existed.)
when it starts the groove and mud anywhere else.
- Hear it in context before it ships. Render the kit page (`node tools/sfx.mjs kit <dir>`) and a
demo over the real score, and check the audibility table.
+- **The numbers that keep it designed.** About five effects per ten seconds. Hard cuts and cursor
+ drifts get nothing. About two whooshes a film, each starting 100-450 ms before the move and peaking
+ on its fastest frame. One riser, then 0.1-0.5 s of near silence, then the impact on the reveal frame,
+ the loudest moment of the film, 30-60% of the way in. One click voice for the whole UI: press, then
+ release 60-110 ms later, the same level every time. Typing at most about twelve keys a second.
+- **Where a cue may land.** A hit's attack no earlier than 45 ms before its frame and its peak no
+ later than 75 ms after. A whoosh's loudest point within 45 ms of the move's fastest frame. A riser
+ ends between 250 ms before the hit and 30 ms after it. Later than these reads as lag; earlier reads
+ as a mistake.
+- **The ending.** The music stops on a bar or filters down, 0.2-0.7 s of near silence, one soft note
+ in key, and its tail rings out to the last frame, 8-20 dB under the film's peak. Never a cut-off.
+
+## The finished mix
+
+What the whole film's sound must be before it ships, score and effects together:
+
+- **On its loudness target.** The delivery master (`music/delivery.ts`, the last stage of `mixSfx` and
+ `mixLaunch`) sets one static gain to -16 LUFS (gentle) or -14 (dense, launch films), then a smooth
+ true-peak limiter with its work capped (4 dB gentle, 6 dense): past the cap the gain gives way
+ instead of the hits being squashed, and the shortfall is reported. `master: "none"` keeps the old
+ peak-only ceiling. A score-only film keeps its own master (music/README.md, Master).
+- **Never digital silence.** An effects-only film sits on room tone 22 dB under its cues (`bed`), nearly
+ mono so a phone keeps it, from the first frame to the last.
+- **A finished shape.** Sound from the first frame (within 0.5 s), no hole over 0.25 s, the last sound
+ within 0.5 s of the last frame. A silence the film means (a stop-down, a held breath) is declared in
+ `meta.quiet` as `[fromFrame, toFrame, reason]`. `verify-export --delivery` fails the shape, a true
+ peak over -1 dBTP after the encode, and loudness under -19 LUFS; it warns from -17.
+- **Fix one thing at a time, with one fixer.** Read the film through separate lenses (sync, edges and
+ clicks, masking, tone, the director's arc), each proposing its fix as a variant it has measured.
+ Then one fixer merges them and re-runs every check, and a fix that breaks another lens is dropped.
+ Lenses that each edit the mix fight: a tonal cut at 2-6 kHz undoes the masking lens's raised hit.
## Tools and checks
diff --git a/skills/anidoodle/references/workflows/site-art.md b/skills/anidoodle/references/workflows/site-art.md
new file mode 100644
index 0000000..bf075dc
--- /dev/null
+++ b/skills/anidoodle/references/workflows/site-art.md
@@ -0,0 +1,96 @@
+# Site art: a picture that works on someone's page
+
+A hero beside a headline, a feature tile, a row of spots, a share card. The picture no longer owns its
+canvas: a headline does, a page colour does, a brand does. Kit: `engine/src/canvas-core/assetKit.ts`.
+Worked example: `siteHero.ts` (light page) and `siteHeroDark.ts` (dark page), one source.
+
+## 1. The brief, before any drawing
+
+Write five lines, from the request or as defaults you say out loud:
+
+1. **Where it goes:** product, page, section, shown size, what sits beside it.
+2. **The one thing it says:** a promise ("ships in a minute"), a feeling ("unhurried"), or a fact ("works offline").
+3. **Who looks:** engineers read instruments and machines; a family app wants warm, soft, homely things.
+4. **The page:** its exact colour, light or dark or both, and the brand colours.
+5. **The style:** any of the 32. Style is free; craft is not.
+
+## 2. One real object that says it
+
+Three kinds, and write one concept of each before choosing:
+
+- **Literal:** the product as a fine object (a camera for a photo app).
+- **Metaphor:** a real thing whose working is the promise. Software has no body, so this is usually the strongest.
+- **Scene:** a small world on a tray or a shelf, one hero object among a few supporting ones. Good for wide heroes and for sets.
+
+Choose with five quick tests: **glance** (named in a second at its shown size), **promise** (its working says
+it, no caption), **parts** (fifty real parts, not a smooth blob), **page** (its silhouette suits the slot:
+wide and low beside a headline, tall in a column), **brand** (material and era match the mood). Say which
+you pick and why in one line, then build it. If the user already named the object, skip the round.
+
+| The promise | A thing that does it |
+|---|---|
+| Nothing gets lost | A post-office sorting frame, every letter in its slot, one being placed |
+| Fast setup | A flat-pack chair half assembled, the last dowel going in |
+| Team chat | A switchboard, one cable mid-plug, a lamp lit |
+| Privacy | A letterbox with a combination dial, its flap shut |
+| Automation | A marble run: one marble on the track, the next waiting at the gate |
+| Insights | A weather station: anemometer turning, barometer needle, a logbook |
+| Translation | A typewriter with two type baskets, one key mid-strike |
+| Savings | A coin sorter with tubes by size, one coin rolling down the ramp |
+| Learning | A desk globe on a brass meridian, a pin in one city |
+| Music | A cylinder music box, the drum turning, the governor a blur |
+
+## 3. The moment
+
+A picture shown once gets one place for the eye: a drawer half out, a key mid-strike, a lamp lit, a
+coin in the slot. Exactly one, carried by the accent, about a third of the way into the art region on
+the side nearest the text (`strongPoint`). If the accent lands on structure, the eye lands on structure.
+
+## 4. Placement
+
+`PLACEMENTS` holds the canvas, the art region and the headline zone for each slot (heroRight, heroLeft,
+heroCentre, art, tile, spot, banner, social, slide). `Cam.fit(A, E, points, fitBox(p))` fits the object
+into its region; pass every extreme point, lifted parts included. The object leads toward the text: pick
+the azimuth that turns its long face and its moment that way. Nothing enters the headline zone, not a
+shadow, not a sheen; prove it with `node tools/placement.mjs still.png --W <meta.W> --safe x,y,w,h`.
+Keep a few units of air at every edge the object does not deliberately bleed off.
+
+## 5. Page colour, light and dark
+
+`setPalette(pagePalette({ paper, accent, colours, tint }))` moves every material onto the page: on a
+light page the neutrals shift by the page's difference in lightness and, by `tint`, its colour cast; on
+a dark page the parts sit just above the page, the lit top lightest, the lines lighter than the faces.
+The fill colour of the page and of `paper` must be identical, or every part shows a pale halo. A site
+with both themes gets both films from one source (`heroOn(title, paper, accent)`).
+
+## 6. Brand colour
+
+`accent: "#hex"` puts the brand on the part to watch (`accent: true`); `colours: { wood: "#7a5536" }`
+recolours any material by name, which is also how brass, walnut or ebony are made. Mode **body** makes
+the part of the colour (a five-step ramp in its own hue, lightness set so four tones read and nothing
+glares on dark). Mode **ink** keeps the part neutral and colours only its lines and dots (an LED, a
+pointer, an engraved mark). Default to one brand family: the subject in body, one or two small echoes.
+Colour the moment, never the base or the biggest faces, unless the product is that colour.
+
+## 7. Motion is the object working
+
+Loop one full cycle of the machine so it repeats without a seam. Anything that would turn in life turns;
+fast spinners get `spin(angle, sweep, draw, { disc })`, a sheen disc and fading trails, because bare blades
+read as a paper cut-out. At most three or four kinds of motion, out of step. Beside a headline, calm wins:
+if the real machine moves little, declare it with a `meta.holds` reason instead of inventing motion. Frame 0
+is what a reduced-motion visitor sees, so compose it as the hero frame.
+
+## 8. Sets and small sizes
+
+Spots in a row share one family of parts (the same screws, feet, bevels, label plates) and similar
+weight: add parts to the sparse one, never strip the dense one. Under about 320 px cut detail instead of
+shrinking it: bigger screws, fewer ticks, no knurls. Check every piece at its shown size and at 390 px
+wide (`placement.mjs --phone out.png`), and look.
+
+| Mood | Shape and parts | Colour |
+|---|---|---|
+| Precise | Thin plates, fine bevels, rulers, many small screws | Greys and one sharp accent |
+| Friendly | Big radii, chunky buttons, rubber feet, few large screws | Warm page, a soft accent on the body |
+| Crafted | Wood cheeks, brass fittings, label plates, hinges | Cream page, a deep accent |
+| Calm | Few objects with air between, low heights, one slow motion | Low contrast, a muted accent |
+| Launch | A diagonal, something lifted or in flight | The accent on the moving thing |