Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.
TypeScript agent-skillsanimationcanvasclaude-codeclaude-pluginclaude-skillscodex-plugincreative-codecreative-codingcreative-toolsdeterministicgenerative-arthand-drawnillustrationlaunch-videomotion-designmotion-graphicspluginprocedural-generationskill
the hook: the first prompt is the hero, typed at frame 0 in a big composer across most of the frame (68 px on every shape, >= 64 on phones and 56 on 16x9, 2-3 lines, never clipped; a prompt too long for that throws), which shrinks and docks as Generate is pressed; drawChatFrame takes a separate composer geometry; test holds the hook's size per shape
Alex Greenshpun14159a799b7d
diff --git a/skills/anidoodle/engine/src/canvas-core/launchKit.ts b/skills/anidoodle/engine/src/canvas-core/launchKit.tsindex 3622f06..3d92c4c 100644--- a/skills/anidoodle/engine/src/canvas-core/launchKit.ts+++ b/skills/anidoodle/engine/src/canvas-core/launchKit.ts@@ -126,6 +126,8 @@ export type ChatState = {title?: string; subtitle?: string; genLabel?: string; accent?: string;// focus pulls: the header's and the composer's opacity while the camera is close on something else (default 1)head?: number; composer?: number;+ // the composer laid out on its own (the hero hook: a big composer that shrinks and docks); default the chat's+ composerGeom?: ChatGeom;};// THE CHAT'S GEOMETRY. One chat component, laid out per frame shape (launchLayout.ts): the window,@@ -192,16 +194,17 @@ export const drawChatFrame = (ctx: Ctx, s: ChatState, g: ChatGeom = CHAT_GEOM) =}if (s.label) { ctx.globalAlpha = s.labelAlpha ?? 1; ctx.fillStyle = P.ink; ctx.beginPath(); ctx.arc(REPLY.x + 9 * k, REPLY.y - 26 * k, 7 * k, 0, Math.PI * 2); ctx.fill(); ctx.font = SANS(600, px.label); ctx.textBaseline = "middle"; ctx.fillText(s.label, REPLY.x + 26 * k, REPLY.y - 25 * k); ctx.globalAlpha = 1; }// the composer+ { const g2 = s.composerGeom ?? g, { INPUT, GEN, TEXT, k, px } = g2;if (s.composer !== undefined) ctx.globalAlpha = s.composer;ctx.fillStyle = P.paper; rr(ctx, INPUT.x, INPUT.y, INPUT.w, INPUT.h, INPUT.r); ctx.fill();ctx.lineWidth = 2 * k; ctx.strokeStyle = P.line; ctx.stroke();ctx.font = SANS(500, TEXT.px); ctx.textBaseline = "alphabetic";if (!s.typed && s.placeholder) { ctx.fillStyle = P.mute; ctx.fillText(s.placeholder, TEXT.x, TEXT.base); }const acc = s.accent ?? P.accent;- if (g.wrap > 0) {- const lines = composerLines(ctx, s.typed, g); ctx.font = SANS(500, TEXT.px); ctx.fillStyle = P.ink;- lines.forEach((l, i) => ctx.fillText(l, TEXT.x, TEXT.base + i * g.lineH));- if (s.caret) { const i = lines.length - 1, x = TEXT.x + ctx.measureText(lines[i]).width + 3 * k; ctx.fillStyle = acc; ctx.fillRect(x, TEXT.base + i * g.lineH - 0.94 * TEXT.px, 3 * k, 1.18 * TEXT.px); }+ if (g2.wrap > 0) {+ const lines = composerLines(ctx, s.typed, g2); ctx.font = SANS(500, TEXT.px); ctx.fillStyle = P.ink;+ lines.forEach((l, i) => ctx.fillText(l, TEXT.x, TEXT.base + i * g2.lineH));+ if (s.caret) { const i = lines.length - 1, x = TEXT.x + ctx.measureText(lines[i]).width + 3 * k; ctx.fillStyle = acc; ctx.fillRect(x, TEXT.base + i * g2.lineH - 0.94 * TEXT.px, 3 * k, 1.18 * TEXT.px); }} else {ctx.fillStyle = P.ink; ctx.fillText(s.typed, TEXT.x, TEXT.base);if (s.caret) { const x = TEXT.x + ctx.measureText(s.typed).width + 3; ctx.fillStyle = acc; ctx.fillRect(x, TEXT.base - 32, 3, 40); }@@ -210,7 +213,7 @@ export const drawChatFrame = (ctx: Ctx, s: ChatState, g: ChatGeom = CHAT_GEOM) =const pr = s.genPress ?? 0, hot = s.genHot ?? 0, q = 1 - 0.07 * pr, gx = GEN.x + (GEN.w * (1 - q)) / 2, gy = GEN.y + (GEN.h * (1 - q)) / 2;ctx.fillStyle = hot > 0 ? mixHex(acc, s.accent ? deepen(acc) : P.accentDeep, 0.35 * hot + 0.4 * pr) : acc; rr(ctx, gx, gy, GEN.w * q, GEN.h * q, GEN.r * q); ctx.fill();ctx.fillStyle = "#fff"; ctx.font = SANS(600, px.gen * q); ctx.textBaseline = "middle"; ctx.textAlign = "center"; ctx.fillText(s.genLabel ?? "Generate", GEN.x + GEN.w / 2, GEN.y + GEN.h / 2 + 1 * k); ctx.textAlign = "left";- if (s.composer !== undefined) ctx.globalAlpha = 1;+ if (s.composer !== undefined) ctx.globalAlpha = 1; }};// where the caret is: the end of the typed words (on their last line in a wrapping composer)export const caretAt = (ctx: Ctx, typed: string, g: ChatGeom = CHAT_GEOM): P => {diff --git a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts b/skills/anidoodle/engine/src/canvas-core/launchTemplate.tsindex e306f24..41903c2 100644--- a/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts+++ b/skills/anidoodle/engine/src/canvas-core/launchTemplate.ts@@ -29,6 +29,7 @@ import {lerp, lerpP, out3, plateLayer, pointer, press, ramp, rr, spring, toScreen, typedAt, useCam, type Cam, type Drop, type ChatGeom, type Rect,} from "./launchKit";import { launchLayout, estWidth, wrapEst, SHAPES, type LaunchLayout, type Shape } from "./launchLayout";+import { chatGeom } from "./launchKit";import { beatGrid, bloomFrame, bloomRadius, makeCut, pic, type, typeFrame, type Seg, type TypeLine } from "./launchCut";import { measure, writeOn, setType } from "./kinetic";import { drawProductUI, springLand, uiActionAt, uiCommandAt, uiSettles, uiWindow, type ProductUI, type UiTheme } from "./productUI";@@ -132,6 +133,7 @@ const uiTiming = (prompt: string | undefined, i: number, ASK: number, a0: numberexport type LaunchFilm = Omit<Film, "reshape"> & {cut: ReturnType<typeof makeCut>; layout: LaunchLayout; reshape: (shape: string) => LaunchFilm;cues: LaunchCue[]; // the sound cues the picture emits (frames of this film)+ heroPx: number | null; // the hook's prompt size (px at the delivered size), when the film opens on a chat askseams: Seam[]; // the motif's seams, each checked (checkRelay)timing: { base: number; len: number; tin: number; b: number; down: number; up: number; drop: Drop; times: number[] }[]; // each ask's own timing, content frames at 30 fpscaptions: { from: number; to: number; text: string }[]; // = meta.captions@@ -199,8 +201,8 @@ export const makeLaunchFilm = (spec: LaunchSpec): LaunchFilm => {const seen = (cam: Cam, x0: number, y0: number, x1: number, y1: number) => { const hw = W / 2 / cam.z, hh = H / 2 / cam.z, d = Math.min(x0 - (cam.c[0] - hw), cam.c[0] + hw - x1, y0 - (cam.c[1] - hh), cam.c[1] + hh - y1) * cam.z; return clamp(d / (24 * k)); };// (on a phone the close-up is nearly the whole window, so the header and thread stay, cut only by `seen`)const chat = (ctx: Ctx, env: Env, f: number, typed: string, caret: boolean, pr: number, hot: number, fo: Focus = { macro: 0, lean: 0, keep: -1, cam: CAM.home }, Gc: ChatGeom = G) => {- const C0 = G.CHAT, mf = L.phone ? 0 : fo.macro, headA = Math.min(1 - mf, seen(fo.cam, C0.x + 40 * k, C0.y + 30 * k, C0.x + C0.w - 40 * k, C0.y + 76 * k)), compA = seen(fo.cam, Gc.INPUT.x, Gc.INPUT.y, Gc.INPUT.x + Gc.INPUT.w, Gc.INPUT.y + Gc.INPUT.h);- drawChatFrame(ctx, { typed, caret, placeholder: spec.placeholder ?? "Describe what you want…", genPress: pr, genHot: hot, title: spec.title, subtitle: spec.subtitle ?? "", genLabel: spec.genLabel, accent: ACC, head: headA, composer: compA }, Gc);+ const C0 = G.CHAT, mf = L.phone || Gc !== G ? 0 : fo.macro, headA = Math.min(1 - mf, seen(fo.cam, C0.x + 40 * k, C0.y + 30 * k, C0.x + C0.w - 40 * k, C0.y + 76 * k)), compA = seen(fo.cam, Gc.INPUT.x, Gc.INPUT.y, Gc.INPUT.x + Gc.INPUT.w, Gc.INPUT.y + Gc.INPUT.h);+ drawChatFrame(ctx, { typed, caret, placeholder: spec.placeholder ?? "Describe what you want…", genPress: pr, genHot: hot, title: spec.title, subtitle: spec.subtitle ?? "", genLabel: spec.genLabel, accent: ACC, head: headA, composer: compA, composerGeom: Gc === G ? undefined : Gc }, G);const sc = scrollAt(f), rest = (1 - mf) * (1 - fo.lean), [, cyT, , chH] = TH.clip;ctx.save(); ctx.beginPath(); ctx.rect(...TH.clip); ctx.clip();items.forEach((it, k) => {@@ -241,14 +243,36 @@ export const makeLaunchFilm = (spec: LaunchSpec): LaunchFilm => {const prevChat = (i: number) => i > 0 && isChat(spec.asks[i - 1]) && T[i].tin === 0;// the empty state: on a phone the first ask's composer starts in the middle of the empty thread (the// way a chat app opens) and docks at the bottom as Generate is pressed; the hook is the prompt, centred- const liftDy = (i: number, l: number) => (L.phone && i === chatIdx[0] && !prevChat(i) ? (G.CHAT.y + G.CHAT.h * 0.52 - (G.INPUT.y + G.INPUT.h / 2)) * (1 - expo(ramp(l, T[i].b - 4, T[i].down))) : 0);- const lifted = (dy: number): ChatGeom => (dy ? { ...G, INPUT: { ...G.INPUT, y: G.INPUT.y + dy }, GEN: { ...G.GEN, y: G.GEN.y + dy }, TEXT: { ...G.TEXT, base: G.TEXT.base + dy } } : G);+ // THE HOOK: the first prompt is the hero. It is typed in a big composer in the middle of the frame+ // (at least 64 px type on a phone frame, 56 px on 16x9, wrapping to 2-3 lines, never clipped),+ // which shrinks and docks at the bottom of the chat as Generate is pressed.+ const HERO = (() => {+ if (!isChat(spec.asks[0])) return null;+ const prompt = spec.asks[0].prompt, min = L.phone ? 64 : 56, inW = Math.min(L.phone ? W * 0.9 : W * 0.72, G.CHAT.w - 60 * k); // most of the width, inside the chat window+ for (let px = L.phone ? 76 : 68; px >= min; px -= 2) {+ const kh = px / 34, genW = 166 * kh, textW = inW - 44 * kh - genW - 44 * kh, lines = wrapEst(prompt, px, textW).length;+ if (lines > 3 && px > min) continue;+ if (lines > 3) throw new Error(`launchTemplate ${shape}: the first prompt "${prompt}" needs ${lines} lines at the hook's ${min} px; shorten it (the hook must read muted in the first 2 s)`);+ const h = 104 * kh + (lines - 1) * Math.round(px * 1.3), fake = { x: (W - inW) / 2 - 60 * kh, y: 0, w: inW + 120 * kh, h: H * 0.5 + h / 2 + 36 * kh };+ const g = chatGeom(fake, kh, { ...G.px, gen: 24 * kh }, px, lines, genW);+ return { ...g, CHAT: G.CHAT, theme: G.theme, drop: G.drop, iris: G.iris } as ChatGeom;+ }+ return null;+ })();+ const heroAt = (i: number, l: number): ChatGeom => {+ if (!HERO || i !== 0) return G;+ const u = expo(ramp(l, T[i].b - 4, T[i].down)); if (u >= 1) return G;+ const mix = (a: number, b: number) => a + (b - a) * u, R = <T extends Record<string, number>>(a: T, b: T) => Object.fromEntries(Object.keys(a).map((key) => [key, mix(a[key], b[key])])) as T;+ const dockLines = Math.max(1, G.wrap);+ return { ...G, INPUT: R(HERO.INPUT, G.INPUT), GEN: R(HERO.GEN, G.GEN), TEXT: R(HERO.TEXT, G.TEXT), k: mix(HERO.k, G.k), px: R(HERO.px, G.px), lineH: mix(HERO.lineH, G.lineH), wrap: u < 0.5 ? HERO.wrap : dockLines };+ };// `lean` (0..1) is how far the camera leans in, `macro` how close it is on the composer; the corner// mark steps aside while it leans, since the lean carries the composer under the cornerconst camAt = (_caret: CaretFn, f: number, i: number): { cam: Cam; lean: number; macro: number; keep: number } => {const t = T[i], l = f - t.base;// the close-up creeps in while the words arrive: the frame is never a still- const mz = MZ * (1 + 0.03 * ramp(l, -20, t.b)), dy = liftDy(i, l), macro: Cam = { c: inView([G.INPUT.x + G.INPUT.w / 2, G.INPUT.y + G.INPUT.h / 2 + dy], mz), z: mz };+ // (the hero hook is its own close-up: the camera holds the whole frame, creeping 2 %)+ const hero = !!HERO && i === 0, mz = hero ? 1 + 0.02 * ramp(l, -20, t.b) : MZ * (1 + 0.03 * ramp(l, -20, t.b)), macro: Cam = { c: inView(hero ? HOME.c : [G.INPUT.x + G.INPUT.w / 2, G.INPUT.y + G.INPUT.h / 2], mz), z: mz };if (prevChat(i) && l < 16) { const q = inOut(ramp(l, 0, 16)); return { cam: camLerp(leanOn(i - 1), macro, q), lean: 1 - q, macro: q, keep: i - 1 }; }if (l > t.drop.full - 10) { const q = inOut(ramp(l, t.drop.full - 10, t.len)); return { cam: camLerp(HOME, leanOn(i), q), lean: q, macro: 0, keep: i }; }const w = l < t.b - 4 ? 1 : 1 - expo(ramp(l, t.b - 4, t.down));@@ -264,13 +288,13 @@ export const makeLaunchFilm = (spec: LaunchSpec): LaunchFilm => {if (l >= t.b - 4 && l < t.up + 24) pointer(ctx, l < t.up + 4 ? lerpP(off, on, out3(ramp(l, t.b - 4, t.down))) : lerpP(on, off, inOut(ramp(l, t.up + 4, t.up + 24))), pr * 0.8, CAM.pointerS);};const chatScene = (ctx: Ctx, env: Env, f: number, i: number) => {- const t = T[i], l = f - t.base, Gc = lifted(liftDy(i, l)), caret: CaretFn = (s) => caretAt(ctx, s, Gc);+ const t = T[i], l = f - t.base, Gc = heroAt(i, l), caret: CaretFn = (s) => caretAt(ctx, s, Gc);const { cam, lean, macro, keep } = camAt(caret, f, i);useCam(ctx, env, cam);const typed = typedAt((spec.asks[i] as PlateAsk).prompt, l, t.times), pr = press(l, t.down, t.up);chat(ctx, env, f, l < t.up ? typed : "", l < t.up, pr, ramp(l, t.down - 10, t.down - 2), { macro, lean, keep, cam }, Gc);// the pointer comes in for the press and glides back out; it never pops- pointerPath(ctx, l, t, [CAM.pointerOn[0], CAM.pointerOn[1] + (Gc.GEN.y - G.GEN.y)], pr);+ pointerPath(ctx, l, t, [Gc.GEN.x + Gc.GEN.w / 2 + 18 * Gc.k, Gc.GEN.y + Gc.GEN.h / 2 + 6 * Gc.k], pr);// the mark is gone BEFORE the lean moves the composer under it, and back only once the camera has leftconst show = lean > 0 && l > ASK / 2 ? 1 - ramp(l, t.drop.full - 18, t.drop.full - 10) : prevChat(i) && l < 24 ? ramp(l, 16, 24) : 1;if (show > 0) { ctx.globalAlpha = show; bug(ctx, env); ctx.globalAlpha = 1; }@@ -531,7 +555,7 @@ export const makeLaunchFilm = (spec: LaunchSpec): LaunchFilm => {assets: { images: {} },shots: [{ id: "cut", start: 0, end: cut.N * m, draw }],audio,- cut, layout: L, cues, seams, timing: T, captions: caps.map((c) => ({ from: Math.round(c.from * m), to: Math.round(c.to * m), text: c.text })),+ cut, layout: L, cues, seams, heroPx: HERO ? HERO.TEXT.px : null, timing: T, captions: caps.map((c) => ({ from: Math.round(c.from * m), to: Math.round(c.to * m), text: c.text })),// the same film composed for another frame shape (one timeline: the cut, the timing and the sound do not change)reshape: (s: string) => { if (s === shape) return self; memo ??= new Map(); let f = memo.get(s); if (!f) { f = makeLaunchFilm({ ...spec, shape: s as Shape }); memo.set(s, f); } return f; },};diff --git a/skills/anidoodle/engine/test/launchLayout.test.ts b/skills/anidoodle/engine/test/launchLayout.test.tsindex bc10ce0..3e58c9c 100644--- a/skills/anidoodle/engine/test/launchLayout.test.ts+++ b/skills/anidoodle/engine/test/launchLayout.test.ts@@ -47,5 +47,9 @@ export const run = (ok: (cond: boolean, label: string) => void) => {// a film ask (any film in a card) with its words beside it builds in every shape, its seam into the end card matchedconst fa = makeLaunchFilm({ title: "Tally", asks: [{ prompt: content.prompts[0], plate, label: "l" }, { kind: "film", film: plate, split: [{ text: "Any film.", style: "ink", color: "#000" }] }], tagline: "t", install: ["npm i tally"], bpm: 90, score: null });ok((Object.keys(SHAPES) as Shape[]).every((sh) => fa.reshape(sh).seams.every((q) => Math.hypot(q.out.p[0] - q.into.p[0], q.out.p[1] - q.into.p[1]) < 2)), "a film ask builds in every shape, the motif's seam matched");+ // the hook: the first prompt is the hero, large enough to read muted in the first 2 s, in every shape+ ok((Object.keys(SHAPES) as Shape[]).every((sh) => { const x = f.reshape(sh); return (x.heroPx ?? 0) >= (x.layout.phone ? 64 : 56); }), `the first prompt is the hero: ${(Object.keys(SHAPES) as Shape[]).map((sh) => `${sh} ${f.reshape(sh).heroPx} px`).join(", ")} (>= 64 on a phone frame, 56 on 16x9)`);+ let long = ""; try { makeLaunchFilm({ title: "Tally", shape: "9x16", asks: [{ prompt: "a very long first prompt that goes on and on about everything it could possibly want drawn today", plate, label: "l" }], tagline: "t", install: ["npm i tally"], bpm: 90, score: null }); } catch (e) { long = (e as Error).message; }+ ok(/shorten it/.test(long), "a first prompt too long for a readable hook is an error, never tiny type");ok(wide.length === 1 && tall.length === 2, `a word page re-sets its lines for a narrow frame (16x9: ${wide.length} line, 9x16: ${tall.map((l) => l.text).join(" / ")})`);};diff --git a/skills/anidoodle/references/workflows/launch-video-kit.md b/skills/anidoodle/references/workflows/launch-video-kit.mdindex 7cd5f06..ac31b8c 100644--- a/skills/anidoodle/references/workflows/launch-video-kit.md+++ b/skills/anidoodle/references/workflows/launch-video-kit.md@@ -66,9 +66,11 @@ export const myLaunch = makeLaunchFilm({What you get, from data:-- **Chat asks** (`kind` omitted): the first prompt already being typed at frame 0, the whole- composer in frame so every typed word stays readable (a hook that reads muted; on a phone frame- the composer starts in the middle of the empty thread and docks on send, the way a chat app opens), the camera easing out for the press, an ink drop arcing from Generate+- **Chat asks** (`kind` omitted): the hook: the first prompt is the hero, already being typed at+ frame 0 in a big composer across most of the frame (at least 64 px type on 1x1/4x5/9x16, 56 px on+ 16x9, wrapping to 2-3 lines, never clipped; a prompt too long for that is an error), which shrinks+ and docks at the bottom of the chat as Generate is pressed. Later prompts are typed with the whole+ composer in frame, the camera easing out for the press, an ink drop arcing from Generateinto the thread and blooming open into a card where the plate draws itself live (the card openson a spring), the thread keeping earlier answers and scrolling, a gentle lean onto each new card that keeps it whole with a margin (what the camera is aboutto cut fades first).