Skip to content

alexgreensh/anidoodle / skills/anidoodle

anidoodle

Flagged

Code-drawn stills, films, 3D motion graphics, explainers and web animations in 32 styles, with scores, narration and subtitles. Use when asked for an illustration, animation, video or drawing lesson.

FileKindSize
SKILL.mdskill md13.7 KB
assets/styles.jpgbinary1.6 MB
engine/SFX_VERSIONING.mdmarkdown862 B
engine/assets/brand/lantern/brand.jsonconfig1.8 KB
engine/assets/brand/lantern/brand.tsscript1.7 KB
engine/assets/brand/lantern/lanternMark.svgother687 B
engine/assets/fonts/InstrumentSans-Bold.ttfbinary66.5 KB
engine/assets/fonts/InstrumentSans-OFL.txtmarkdown4.3 KB
engine/assets/fonts/InstrumentSans-Regular.ttfbinary66.4 KB
engine/assets/fonts/Lora-Bold.ttfbinary130.7 KB
engine/assets/fonts/Lora-OFL.txtmarkdown4.3 KB
engine/assets/fonts/PROVENANCE.mdmarkdown3.2 KB
engine/assets/fonts/Poppins-Bold.ttfbinary152.3 KB
engine/assets/fonts/Poppins-OFL.txtmarkdown4.3 KB
engine/assets/fonts/poppinsBold.tsscript203.7 KB
engine/assets/narration/narrationDemo.jsonconfig700 B
engine/assets/refs/PROVENANCE.jsonconfig836 B
engine/assets/refs/vangogh-almond-blossom.jpgbinary1021.9 KB
engine/facts/launchClip.jsonconfig789 B
engine/facts/launchExample.jsonconfig708 B
engine/facts/launchExampleBrand.jsonconfig1.2 KB
engine/facts/launchExampleClean.jsonconfig1.4 KB
engine/facts/launchExampleCleanChat.jsonconfig1.1 KB
engine/package-lock.jsonmanifest122.6 KB
engine/package.jsonmanifest934 B
engine/reviews/launchClip.jsonconfig4.8 KB
engine/reviews/launchExample.jsonconfig4.4 KB
engine/reviews/launchExampleBrand.jsonconfig9.2 KB
engine/reviews/launchExampleClean.jsonconfig4.4 KB
engine/reviews/launchExampleCleanChat.jsonconfig13.3 KB
engine/src/canvas-core/adaptAlmond.tsscript15.2 KB
engine/src/canvas-core/adaptAquarelle.tsscript14.1 KB
engine/src/canvas-core/adaptScrapbook.tsscript11.5 KB
engine/src/canvas-core/assetKit.tsscript8.4 KB
engine/src/canvas-core/bake.tsscript8.0 KB
engine/src/canvas-core/bakerSheet.tsscript4.7 KB
engine/src/canvas-core/balloon.tsscript20.0 KB
engine/src/canvas-core/balloonDraw.tsscript4.7 KB
engine/src/canvas-core/banner.tsscript42.3 KB
engine/src/canvas-core/bitRig.tsscript23.9 KB
engine/src/canvas-core/blueprint.tsscript42.5 KB
engine/src/canvas-core/blueprintKit.tsscript15.1 KB
engine/src/canvas-core/brandKit.tsscript10.4 KB
engine/src/canvas-core/brickBalloon.tsscript31.1 KB
engine/src/canvas-core/brokenColour.tsscript31.2 KB
engine/src/canvas-core/brokenColourKit.tsscript9.7 KB
engine/src/canvas-core/callout.tsscript9.6 KB
engine/src/canvas-core/calloutDemo.tsscript3.6 KB
engine/src/canvas-core/camera.tsscript13.2 KB
engine/src/canvas-core/character/build.tsscript2.9 KB
engine/src/canvas-core/character/check.tsscript9.5 KB
engine/src/canvas-core/character/design.tsscript7.3 KB
engine/src/canvas-core/character/human/balance.tsscript8.2 KB
engine/src/canvas-core/character/human/canon.tsscript3.8 KB
engine/src/canvas-core/character/human/clothing.tsscript4.5 KB
engine/src/canvas-core/character/human/figure.tsscript4.0 KB
engine/src/canvas-core/character/human/hands.tsscript10.9 KB
engine/src/canvas-core/character/human/head.tsscript23.2 KB
engine/src/canvas-core/character/human/mannequin.tsscript15.7 KB
engine/src/canvas-core/character/human/skeleton.tsscript10.3 KB
engine/src/canvas-core/character/human/walk.tsscript7.9 KB
engine/src/canvas-core/character/identity.tsscript2.3 KB
engine/src/canvas-core/character/math3.tsscript5.6 KB
engine/src/canvas-core/character/render/brick.tsscript4.0 KB
engine/src/canvas-core/character/render/grid.tsscript5.2 KB
engine/src/canvas-core/character/render/marker.tsscript3.5 KB
engine/src/canvas-core/character/render/pencil.tsscript6.6 KB
engine/src/canvas-core/character/render/pixel.tsscript3.1 KB
engine/src/canvas-core/character/render/riso.tsscript7.1 KB
engine/src/canvas-core/character/render/scratch.tsscript6.2 KB
engine/src/canvas-core/character/render/storybook.tsscript5.6 KB
engine/src/canvas-core/character/render/sumi.tsscript5.3 KB
engine/src/canvas-core/character/render/woodcut.tsscript4.3 KB
engine/src/canvas-core/character/shape2d.tsscript4.7 KB
engine/src/canvas-core/character/types.tsscript3.3 KB
engine/src/canvas-core/character/view25d.tsscript2.9 KB
engine/src/canvas-core/characters/mira/drawn.tsscript5.1 KB
engine/src/canvas-core/characters/mira/index.tsscript19.1 KB
engine/src/canvas-core/characters/mira/palettes.tsscript7.0 KB
engine/src/canvas-core/characters/mira/poses.tsscript10.2 KB
engine/src/canvas-core/characters/theo/baker.tsscript15.0 KB
engine/src/canvas-core/characters/theo/index.tsscript6.1 KB
engine/src/canvas-core/characters/theo/poses.tsscript10.6 KB
engine/src/canvas-core/characters/theo/wardrobe.tsscript12.4 KB
engine/src/canvas-core/charcoalErasure.tsscript30.7 KB
engine/src/canvas-core/charcoalErasureKit.tsscript9.4 KB
engine/src/canvas-core/cheetahBody.tsscript16.5 KB
engine/src/canvas-core/cheetahDusk.tsscript20.9 KB
engine/src/canvas-core/cheetahRig.tsscript8.9 KB
engine/src/canvas-core/cheetahRun.tsscript19.0 KB
engine/src/canvas-core/cheetahRunSigned.tsscript173 B
engine/src/canvas-core/cheetahScenery.tsscript11.8 KB
engine/src/canvas-core/cheetahTurn.tsscript5.5 KB
engine/src/canvas-core/colouredPencil.tsscript45.0 KB
engine/src/canvas-core/colouredPencilCrow.tsscript13.4 KB
engine/src/canvas-core/colouredPencilKit.tsscript17.8 KB
engine/src/canvas-core/core.tsscript30.0 KB
engine/src/canvas-core/cues.tsscript7.7 KB
engine/src/canvas-core/drafting.tsscript7.4 KB
engine/src/canvas-core/drawingMarks.tsscript13.3 KB
engine/src/canvas-core/drawingScore.tsscript17.5 KB
engine/src/canvas-core/dreamGlaze.tsscript30.9 KB
engine/src/canvas-core/dreamGlazeDraw.tsscript10.4 KB
engine/src/canvas-core/dreamGlazeKit.tsscript19.1 KB
engine/src/canvas-core/embroidery.tsscript32.2 KB
engine/src/canvas-core/embroideryAlive.tsscript19.6 KB
engine/src/canvas-core/embroideryKit.tsscript14.6 KB
engine/src/canvas-core/endCard.tsscript8.8 KB
engine/src/canvas-core/figureSheet.tsscript8.2 KB
engine/src/canvas-core/film.tsscript6.4 KB
engine/src/canvas-core/fixtureDeck.tsscript165 B
engine/src/canvas-core/fixtureMotion.tsscript5.4 KB
engine/src/canvas-core/fixtureRigBrokenGrip.tsscript250 B
engine/src/canvas-core/fixtureShip.tsscript7.4 KB
engine/src/canvas-core/fixtureShipBlind.tsscript159 B
engine/src/canvas-core/fixtureShipGreen.tsscript159 B
engine/src/canvas-core/fixtureShipLocked.tsscript126 B
engine/src/canvas-core/fixtureShipRed.tsscript157 B
engine/src/canvas-core/fixtureShipTrack.tsscript125 B
engine/src/canvas-core/fixtureWorld.tsscript166 B
engine/src/canvas-core/flatVector.tsscript22.8 KB
engine/src/canvas-core/folkTale.tsscript56.9 KB
engine/src/canvas-core/folkTaleKit.tsscript42.7 KB
engine/src/canvas-core/formMascot.tsscript4.9 KB
engine/src/canvas-core/fox.tsscript15.7 KB
engine/src/canvas-core/foxDraw.tsscript5.6 KB
engine/src/canvas-core/fromPhoto.tsscript8.7 KB
engine/src/canvas-core/gallery.tsscript9.5 KB
engine/src/canvas-core/halftone.tsscript10.3 KB
engine/src/canvas-core/halftoneKit.tsscript9.7 KB
engine/src/canvas-core/halftoneScene.tsscript26.5 KB
engine/src/canvas-core/input.tsscript16.8 KB
engine/src/canvas-core/isometric.tsscript36.2 KB
engine/src/canvas-core/isometricKit.tsscript3.9 KB
engine/src/canvas-core/kinetic.tsscript42.6 KB
engine/src/canvas-core/kineticDemo.tsscript3.6 KB
engine/src/canvas-core/koi.tsscript28.9 KB
engine/src/canvas-core/koiAlive.tsscript34 B
engine/src/canvas-core/koiDraw.tsscript3.5 KB
engine/src/canvas-core/koiDrawKit.tsscript6.9 KB
engine/src/canvas-core/koiWorld.tsscript9.3 KB
engine/src/canvas-core/launch.tsscript39.5 KB
engine/src/canvas-core/launch2.tsscript27.6 KB
engine/src/canvas-core/launch3.tsscript9.2 KB
engine/src/canvas-core/launchClip.tsscript39 B
engine/src/canvas-core/launchCode.tsscript3.8 KB
engine/src/canvas-core/launchCut.tsscript6.9 KB
engine/src/canvas-core/launchExample.tsscript3.4 KB
engine/src/canvas-core/launchExampleBrand.tsscript7.7 KB
engine/src/canvas-core/launchExampleClean.tsscript6.7 KB
engine/src/canvas-core/launchExampleCleanChat.tsscript5.0 KB
engine/src/canvas-core/launchExampleCleanScore.tsscript3.4 KB
engine/src/canvas-core/launchExampleScore.tsscript3.7 KB
engine/src/canvas-core/launchGallery.tsscript9.2 KB
engine/src/canvas-core/launchKit.tsscript28.1 KB
engine/src/canvas-core/launchLayout.tsscript19.9 KB
engine/src/canvas-core/launchLook.tsscript17.7 KB
engine/src/canvas-core/launchSound.tsscript5.8 KB
engine/src/canvas-core/launchTemplate.tsscript117.8 KB
engine/src/canvas-core/lesson.tsscript9.4 KB
engine/src/canvas-core/lessonCat.tsscript22.4 KB
engine/src/canvas-core/lessonCatFinal.tsscript204 B
engine/src/canvas-core/lessonCatSheet.tsscript263 B
engine/src/canvas-core/lessonOwl.tsscript49.3 KB
engine/src/canvas-core/lessonOwlFinal.tsscript204 B
engine/src/canvas-core/lessonOwlLayout.tsscript11.0 KB
engine/src/canvas-core/lessonOwlScore.tsscript8.7 KB
engine/src/canvas-core/lessonOwlSheet.tsscript446 B
engine/src/canvas-core/lessonOwlSocial.tsscript6.2 KB
engine/src/canvas-core/lettering.tsscript5.9 KB
engine/src/canvas-core/lighthouse.tsscript12.3 KB
engine/src/canvas-core/lighthouseDraw.tsscript5.5 KB
engine/src/canvas-core/lowPoly.tsscript24.5 KB
engine/src/canvas-core/mascotHero.tsscript4.6 KB
engine/src/canvas-core/mechanism.tsscript27.9 KB
engine/src/canvas-core/mechanismBlueprint.tsscript260 B
engine/src/canvas-core/mechanismDraw.tsscript297 B
engine/src/canvas-core/mechanismExplorer.tsscript4.8 KB
engine/src/canvas-core/mechanismHands.tsscript17.1 KB
engine/src/canvas-core/mechanismKit.tsscript38.9 KB
engine/src/canvas-core/mechanismPencil.tsscript277 B
engine/src/canvas-core/mechanismStipple.tsscript250 B
engine/src/canvas-core/mellan.tsscript9.7 KB
engine/src/canvas-core/mellanUnspool.tsscript3.2 KB
engine/src/canvas-core/midCentury.tsscript24.6 KB
engine/src/canvas-core/miraComic.tsscript4.3 KB
engine/src/canvas-core/miraEveryHand.tsscript5.2 KB
engine/src/canvas-core/miraRiso.tsscript3.6 KB
engine/src/canvas-core/miraSheet.tsscript8.0 KB
engine/src/canvas-core/miraTile.tsscript5.1 KB
engine/src/canvas-core/miraTriptych.tsscript2.7 KB
engine/src/canvas-core/miraWalk.tsscript7.7 KB
engine/src/canvas-core/moonPhases.tsscript16.7 KB
engine/src/canvas-core/moonPhasesDraw.tsscript4.3 KB
engine/src/canvas-core/morph.tsscript8.8 KB
engine/src/canvas-core/morphDemo.tsscript2.4 KB
engine/src/canvas-core/motif.tsscript2.5 KB
engine/src/canvas-core/motionKit.tsscript9.3 KB
engine/src/canvas-core/motionMeta.tsscript1.1 KB
engine/src/canvas-core/music/arc.tsscript6.2 KB

engine/src/canvas-core/koi.ts

View on GitHub
import { Gfx, PENCIL, rng, type Ctx, type Env, type P } from "./core";
import type { Film } from "./film";
import { area, blob, body, clipped, fillShape, ink, lerpP, mix, profile, resample, smooth, type Body, type InkOpts } from "./gallery";
import { cut, part, stagger, streakClip, streaks } from "./koiDrawKit";

// KOI · marker comic. Bold cel fills with a hard shadow edge, one heavy confident contour that
// thickens away from the light, and a single dramatic C-curve for the whole fish.
//
// Anatomy, seen from above: a blunt snout with two pairs of barbels, eyes set on the sides of the
// head, gill covers, the body widest just behind the pectorals and tapering to a narrow caudal
// peduncle; big paddle pectorals (black at the base, "motoguro"), small pelvics mid-body, a
// dorsal fin running down the spine, and a long flowing caudal fin. Markings are Sanke-style:
// red "hi" patches on white with a few black "sumi" spots, placed in the body's own (t, s) frame
// so they bend with it. Light from the upper left.

const INK = "#15122a", LIGHT: P = [-0.62, -0.78];
export const WATER = "#137582", WATER_D = "#0c5360", WATER_L = "#3aa6ad";
const WHITE = "#fdf8ee", WHITE_S = "#c9d6e0", HI = "#ec4a22", HI_S = "#b72c1a", SUMI = "#1b1830";
const FIN = "#f7efe4", FIN_S = "#d5dde2";

// THE PROCESS HOOK (koiDraw). drawKoi takes an optional clock: progress 0..1 for each (element,
// pass) of a marker comic being made: "pencil" lay-in, "flat" cel fills laid in marker streaks,
// "shade" hard shadow shapes, "detail" (scales, rays, gel-pen whites), "line" the heavy contour.
// With no clock every gate is 1 and every branch below takes the ORIGINAL call, byte for byte.
export type KoiClock = (el: string, pass: string) => number;
const ALL: KoiClock = () => 1;
// a flat laid by a chisel marker: draw fn only where the marker has been by p
const lay = (g: Gfx, p: number, shapes: P[][], fn: () => void, seed: number, w = 30, ang = -0.5, reach = 1e9) => {
  if (p >= 1) return fn(); if (p <= 0) return;
  const c = g.cur; c.save(); streakClip(c, streaks(shapes, w, ang, seed, reach), p); fn(); c.restore();
};
// the contour grows along its centreline; a closed one is drawn open until it closes
export const inkP = (g: Gfx, center: P[], color: string, o: InkOpts, alpha: number | undefined, q: number) => {
  if (q >= 1) return alpha === undefined ? ink(g, center, color, o) : ink(g, center, color, o, alpha); if (q <= 0) return;
  const path = o.closed ? [...center, center[0]] : center, side = o.closed ? (area(center) > 0 ? -1 : 1) : o.side;
  ink(g, cut(path, q), color, { ...o, closed: false, side, taper: [o.closed ? 0.04 : (o.taper?.[0] ?? 0.12), 0.08] }, alpha ?? 1);
};

// ALIVE. The same koi, swimming: t in seconds. A carangiform swimmer: the wave travels nose to
// tail, its amplitude growing toward the tail (the head barely yaws, the peduncle swings wide),
// one tail beat every 2 s, the way a koi cruises. Everything hung on the body (fins, tail,
// markings, scales, shadow) follows it for free. Undefined = the still plate, pixel for pixel.
export type KoiLive = { t: number; amp?: number; beat?: number; pose?: KoiPose }; // amp 0..1 eases the swim in from the still pose; beat = seconds per tail beat
// where the fish is: its spine's centroid placed at (x, y), turned by rot, scaled by k. koiWorld swims it along a path.
export type KoiPose = { x: number; y: number; rot: number; k: number; straight?: number; bend?: number }; // straight 0..1: the plate's turning curve relaxed toward a straight cruise; bend: into a turn (+ = tail swings right of travel)
const SPINE: P[] = [[300, 222], [404, 292], [502, 408], [556, 556], [534, 694], [468, 792]];
export const KOI_BEAT = 2; // seconds per tail beat: every live motion's period divides 2 s, so 2 s loops
export const SPINE_C: P = [SPINE.reduce((a, p) => a + p[0], 0) / SPINE.length, SPINE.reduce((a, p) => a + p[1], 0) / SPINE.length];
export const SPINE_HEADING = Math.atan2(SPINE[0][1] - SPINE_C[1], SPINE[0][0] - SPINE_C[0]); // the way the plate's koi is facing
const swim = (live: KoiLive): P[] => {
  const ph = (2 * Math.PI * live.t) / (live.beat ?? KOI_BEAT), q = live.pose;
  const place = (p: P): P => { if (!q) return p; const c = Math.cos(q.rot), s = Math.sin(q.rot), dx = p[0] - SPINE_C[0], dy = p[1] - SPINE_C[1]; return [q.x + (dx * c - dy * s) * q.k, q.y + (dx * s + dy * c) * q.k]; };
  // a cruising fish is nearly straight: relax the authored curve toward a straight spine of the same
  // length (laid back from the head along the plate's facing), then bend it into the current turn
  const st = q?.straight ?? 0, bd = q?.bend ?? 0, ax: P = [Math.cos(SPINE_HEADING), Math.sin(SPINE_HEADING)];
  let acc = 0; const seg = SPINE.map((p, i) => (i ? (acc += Math.hypot(p[0] - SPINE[i - 1][0], p[1] - SPINE[i - 1][1])) : 0));
  const line = seg.map((d) => [-ax[0] * d, -ax[1] * d] as P), lc: P = [line.reduce((a, p) => a + p[0], 0) / line.length, line.reduce((a, p) => a + p[1], 0) / line.length];
  const base = SPINE.map((p, i) => { const u = i / (SPINE.length - 1), sp: P = [SPINE_C[0] + line[i][0] - lc[0], SPINE_C[1] + line[i][1] - lc[1]], m: P = [p[0] + (sp[0] - p[0]) * st, p[1] + (sp[1] - p[1]) * st], side = bd * 70 * u * u; return [m[0] - ax[1] * side, m[1] + ax[0] * side] as P; });
  return base.map((p, i) => {
    const a = base[Math.max(0, i - 1)], c = base[Math.min(base.length - 1, i + 1)], dx = c[0] - a[0], dy = c[1] - a[1], l = Math.hypot(dx, dy) || 1, u = i / (base.length - 1);
    const amp = (4 + 30 * Math.pow(u, 1.7)) * (live.amp ?? 1), off = amp * Math.sin(ph - u * 2.6);
    return place([p[0] - (dy / l) * off, p[1] + (dx / l) * off]);
  });
};
export const koiBody = (live?: KoiLive): Body => body(
  live ? swim(live) : SPINE,
  profile([[0, 0], [0.012, 27], [0.035, 46], [0.08, 64], [0.16, 80], [0.27, 90], [0.4, 88], [0.55, 78], [0.7, 60], [0.82, 40], [0.92, 26], [1, 22]]),
);

// a fin in the body's frame: rays fan from a root between two edge points out to a rounded paddle
export const fin = (root0: P, root1: P, tip: P, spread: number, bulge: number, seed: number, rays = 8): { shape: P[]; rays: P[][] } => {
  const r = rng(seed), mid = lerpP(root0, root1, 0.5), dx = tip[0] - mid[0], dy = tip[1] - mid[1], len = Math.hypot(dx, dy), ux = dx / len, uy = dy / len, nx = -uy, ny = ux;
  const tipAt = (a: number): P => { const k = len * (1 - a * a * 0.34) * (0.985 + r() * 0.03); return [mid[0] + ux * k + nx * (a * spread + bulge * (1 - a * a)), mid[1] + uy * k + ny * (a * spread + bulge * (1 - a * a))]; };
  const tips = Array.from({ length: rays }, (_, i) => tipAt(-1 + (2 * i) / (rays - 1)));
  const edge: P[] = [];
  tips.forEach((t, i) => { edge.push(t); if (i < tips.length - 1) { const m = lerpP(t, tips[i + 1], 0.5); edge.push(lerpP(mid, m, 0.992)); } }); // the membrane sags only a touch between rays
  const shape = smooth([root0, ...edge, root1], true, 6);
  const out = tips.map((t, i) => { const base = lerpP(root0, root1, i / (rays - 1)); return smooth([base, lerpP(lerpP(base, t, 0.5), mid, -0.04), t], false, 6); });
  return { shape, rays: out };
};

// the caudal fin: a centreline that keeps turning at the body's own curvature, two long lobes
// either side of it that open out, wave, and part at a notch
export const tail = (b: Body): { shape: P[]; rays: P[][] } => {
  const t1 = b.tan(1), t0 = b.tan(0.9), th0 = Math.atan2(t1[1], t1[0]), dTh = Math.atan2(t0[1] * t1[0] - t0[0] * t1[1], t0[0] * t1[0] + t0[1] * t1[1]);
  const kappa = (-dTh / 60) * 2.6, root = b.at(0.955, 0), line: P[] = [root], heads: number[] = [th0];
  for (let i = 1; i <= 26; i++) { const th = th0 + kappa * i * 10; heads.push(th); const q = line[i - 1]; line.push([q[0] + Math.cos(th) * 10, q[1] + Math.sin(th) * 10]); }
  const off = (i: number, w: number): P => { const th = heads[i]; return [line[i][0] - Math.sin(th) * w, line[i][1] + Math.cos(th) * w]; };
  const up = (i: number) => 22 + Math.pow(i / 26, 0.85) * 124 + Math.sin(i * 0.42) * 11, lo = (i: number) => 22 + Math.pow(i / 26, 1.0) * 104 + Math.sin(i * 0.47 + 2) * 10;
  const upper: P[] = [], lower: P[] = [];
  for (let i = 0; i <= 24; i++) { upper.push(off(i, up(i))); lower.push(off(Math.min(26, i + 2), -lo(Math.min(26, i + 2)))); }
  const notch = off(19, 14), edge = smooth([upper[24], lerpP(lerpP(upper[24], notch, 0.5), off(23, 60), 0.35), notch, lerpP(lerpP(lower[24], notch, 0.5), off(24, -44), 0.3), lower[24]], false, 8);
  const shape = [...upper, ...edge, ...[...lower].reverse()];
  const rays: P[][] = [];
  for (let k = 0; k <= 14; k++) { const f = k / 14, e = edge[Math.round(f * (edge.length - 1))], s0 = lerpP(off(0, 16), off(0, -16), f); rays.push(smooth([s0, lerpP(lerpP(s0, e, 0.5), line[12], 0.12), e], false, 8)); }
  return { shape, rays };
};

const water = (g: Gfx, k: KoiClock = ALL) => {
  const fl = k("water", "flat"), dt = k("water", "detail");
  g.group("plain", () => {
    const sq: P[] = [[0, 0], [1080, 0], [1080, 1080], [0, 1080]], b1 = blob(560, 540, 610, 470, 401, 0.1, 20, -0.75), b2 = blob(520, 520, 400, 290, 402, 0.12, 18, -0.9);
    lay(g, part(fl, 0, 3), [sq], () => fillShape(g, sq, WATER_D), 4001, 64, -0.62, 300);
    // the colourist's flats: a lit body of water through the middle, deep water in the corners
    lay(g, part(fl, 1, 3), [b1], () => fillShape(g, b1, WATER), 4002, 60, -0.62, 300);
    lay(g, part(fl, 2, 3), [b2], () => fillShape(g, b2, mix(WATER, WATER_L, 0.22)), 4003, 56, -0.62, 280);
    const r = rng(311);
    for (let i = 0; i < 12; i++) { const x = 60 + r() * 960, y = 60 + r() * 960, l = 70 + r() * 150, a = -0.42 + (r() - 0.5) * 0.12; const ln = smooth([[x, y], [x + Math.cos(a) * l * 0.5, y + Math.sin(a) * l * 0.5 + 3], [x + Math.cos(a) * l, y + Math.sin(a) * l]], false, 6); inkP(g, ln, WATER_L, { w: 5 + r() * 5, shadow: 0, taper: [0.4, 0.4], seed: 500 + i }, 0.45, part(dt, i, 12)); }
  });
};

export const padShape = (cx: number, cy: number, rr: number, notch: number, seed: number): P[] => {
  const r = rng(seed), rim: P[] = [];
  for (let i = 0; i <= 40; i++) { const a = notch + 0.2 + (i / 40) * (Math.PI * 2 - 0.4); rim.push([cx + Math.cos(a) * rr * (1 + (r() - 0.5) * 0.03), cy + Math.sin(a) * rr * 0.93 * (1 + (r() - 0.5) * 0.03)]); }
  return [[cx, cy], ...rim];
};
export const lilyPad = (g: Gfx, cx: number, cy: number, rr: number, notch: number, seed: number, k: KoiClock = ALL, el = "pad") => {
  const pad = padShape(cx, cy, rr, notch, seed), rim = pad.slice(1);
  const fl = k(el, "flat"), sh = k(el, "shade"), dt = k(el, "detail"), ln = k(el, "line");
  g.group("plain", () => {
    const shadow = pad.map(([x, y]) => [x + 16, y + 22] as P);
    lay(g, sh, [shadow], () => fillShape(g, shadow, "#0a3f49", 0.55), seed + 71, 26, 0.9); // its shadow on the water
    const cel = () => { fillShape(g, pad, "#2f9a4f"); clipped(g, pad, () => { fillShape(g, pad.map(([x, y]) => [x - 20, y - 18] as P), "#56bb5c"); fillShape(g, blob(cx - rr * 0.35, cy - rr * 0.35, rr * 0.35, rr * 0.16, seed + 3, 0.2, 12, -0.6), "#9ee07f", 0.8); }); };
    if (sh >= 1) cel(); else { lay(g, fl, [pad], () => fillShape(g, pad, "#56bb5c"), seed + 72, 30, -0.5); lay(g, sh, [pad], cel, seed + 73, 24, 0.7); }
    for (let i = 0; i < 11; i++) { const a = notch + 0.35 + (i / 10) * (Math.PI * 2 - 0.7); inkP(g, smooth([[cx, cy], [cx + Math.cos(a) * rr * 0.5, cy + Math.sin(a) * rr * 0.46], [cx + Math.cos(a + 0.05) * rr * 0.9, cy + Math.sin(a + 0.05) * rr * 0.84]], false, 6), "#1c6a3a", { w: 2.4, seed: seed + i, shadow: 0, taper: [0.1, 0.5] }, 0.7, part(dt, i, 11)); }
    inkP(g, rim, INK, { w: 5.5, light: LIGHT, shadow: 0.9, seed: seed + 20, taper: [0.02, 0.02] }, undefined, part(ln, 0, 1.25));
    inkP(g, [rim[rim.length - 1], [cx, cy], rim[0]], INK, { w: 4.5, light: LIGHT, shadow: 0.9, seed: seed + 21, taper: [0.08, 0.08] }, undefined, stagger(ln, 0.8, 0.2));
  });
};

export const waterLily = (g: Gfx, cx: number, cy: number, s: number, seed: number, kc: KoiClock = ALL, el = "lily") => {
  const r = rng(seed), fl = kc(el, "flat"), shd = kc(el, "shade"), dt = kc(el, "detail"), ln = kc(el, "line");
  let j = 0; // petals are laid in the order they stack: back row first
  const petal = (a: number, len: number, wid: number, col: string, sh: string, k: number) => {
    const tip: P = [cx + Math.cos(a) * len, cy + Math.sin(a) * len], nx = -Math.sin(a), ny = Math.cos(a);
    const shape = smooth([[cx + nx * 3, cy + ny * 3], [cx + Math.cos(a) * len * 0.45 + nx * wid, cy + Math.sin(a) * len * 0.45 + ny * wid], tip, [cx + Math.cos(a) * len * 0.45 - nx * wid, cy + Math.sin(a) * len * 0.45 - ny * wid], [cx - nx * 3, cy - ny * 3]], true, 6);
    const pf = part(fl, j, 21), ps = part(shd, j, 20), pl = part(ln, j, 21); j++;
    const cel = () => { fillShape(g, shape, sh); clipped(g, shape, () => fillShape(g, shape.map(([x, y]) => [x - 5 - nx * 4 * k, y - 6 - ny * 4 * k] as P), col)); };
    if (ps >= 1) cel(); else { lay(g, pf, [shape], () => fillShape(g, shape, col), seed + j * 7, 12, a + 1.57); lay(g, ps, [shape], cel, seed + j * 7 + 3, 10, a); }
    inkP(g, shape, INK, { w: 3.2, closed: true, light: LIGHT, shadow: 0.8, seed: seed + Math.round(a * 100) }, undefined, pl);
  };
  g.group("plain", () => {
    for (let i = 0; i < 8; i++) petal(i * 0.785 + 0.2 + (r() - 0.5) * 0.1, 70 * s, 22 * s, "#ffc3d6", "#e886a6", 1);
    for (let i = 0; i < 7; i++) petal(i * 0.9 + 0.55 + (r() - 0.5) * 0.1, 54 * s, 18 * s, "#ffe0ea", "#f2a2bd", -1);
    for (let i = 0; i < 5; i++) petal(i * 1.26 + 0.1, 34 * s, 13 * s, "#fff1f5", "#f6bfd0", 1);
    const eye = blob(cx, cy, 15 * s, 13 * s, seed + 9, 0.15, 12);
    lay(g, part(fl, 20, 21), [eye], () => fillShape(g, blob(cx, cy, 15 * s, 13 * s, seed + 9, 0.15, 12), "#ffcc2e"), seed + 90, 9, 0.3);
    inkP(g, blob(cx, cy, 15 * s, 13 * s, seed + 9, 0.15, 12), INK, { w: 2.6, closed: true, seed: seed + 10 }, undefined, part(ln, 20, 21));
    for (let i = 0; i < 14; i++) { const a = i * 0.45, d = 6 + (i % 3) * 3; if (part(dt, i, 14) >= 1) fillShape(g, blob(cx + Math.cos(a) * d * s, cy + Math.sin(a) * d * s, 2.2, 2.2, seed + 30 + i, 0.1, 8), "#c98a00"); }
  });
};

export const ripples = (g: Gfx, cx: number, cy: number, seed: number, kc: KoiClock = ALL, drift = 0, scale = 1) => {
  // surface rings, broken where the light catches them: the one place the water shows its skin
  const r = rng(seed), dt = kc("ripples", "detail");
  g.group("plain", () => {
    [58, 104, 156].forEach((rad0, k) => {
      let a = r() * 6; const rad = rad0 + 48 * drift, fade = drift ? Math.max(0, Math.min(1, (rad - 58) / 30, (212 - rad) / 50)) : 1; if (fade <= 0) { for (let s = 0; s < 5; s++) r(), r(), r(); return; }
      for (let s = 0; s < 5; s++) { const span = 0.55 + r() * 0.6, pts: P[] = []; for (let i = 0; i <= 12; i++) { const t = a + (i / 12) * span; pts.push([cx + Math.cos(t) * rad * 1.35 * scale, cy + Math.sin(t) * rad * 0.62 * scale]); } inkP(g, pts, "#d9fbf6", { w: (4.4 - k * 1.1) * Math.sqrt(scale), shadow: 0, taper: [0.3, 0.3], seed: seed + k * 10 + s }, (0.85 - k * 0.18) * fade, part(dt, k * 5 + s, 15)); a += span + 0.35 + r() * 0.5; }
    });
  });
};

// the lay-in, in non-photo blue: the gesture of the spine first, then the masses, then the parts
const BLUE = "#6b98cc";
const pencilLayIn = (g: Gfx, k: KoiClock, b: Body, fins: { shape: P[] }[], cau: { shape: P[] }, pads: P[][], lily: [number, number, number]) => {
  const fish = k("fish", "pencil"), pk = k("pads", "pencil"), lk = k("lily", "pencil");
  const n = b.outline.length / 2, left = b.outline.slice(0, n), right = b.outline.slice(n).reverse();
  const eyes = [-1, 1].map((sd) => { const e = b.at(0.085, sd * 0.8); return Array.from({ length: 9 }, (_, i) => [e[0] + Math.cos(i * 0.8) * 14, e[1] + Math.sin(i * 0.8) * 12] as P); });
  const fishStrokes: P[][] = [b.spine, left, right, cau.shape, ...fins.map((f) => f.shape), ...eyes];
  const padStrokes: P[][] = pads.map((p) => p.slice(1));
  const [lx, ly, ls] = lily, lilyStrokes: P[][] = [Array.from({ length: 15 }, (_, i) => [lx + Math.cos(i * 0.47) * 76 * ls, ly + Math.sin(i * 0.47) * 72 * ls] as P), ...Array.from({ length: 8 }, (_, i) => { const a = i * 0.785 + 0.2; return [[lx, ly], [lx + Math.cos(a) * 70 * ls, ly + Math.sin(a) * 70 * ls]] as P[]; })];
  g.group("ink", () => {
    const run = (list: P[][], p: number, seed: number) => list.forEach((s, i) => { const q = part(p, i, list.length); if (q > 0) g.pen(resample(s, Math.max(3, Math.min(40, Math.round(s.length / 5)))), { w: 1.25, color: BLUE, seed: seed + i, wobble: 1.8, opacity: 0.9, progress: q }); });
    run(fishStrokes, fish, 6100); run(padStrokes, pk, 6200); run(lilyStrokes, lk, 6300);
  });
};

// pectorals on the outside of the curve spread wide; the inside one is tucked and foreshortened
// live: the pectorals scull, out of phase with each other, a half beat behind the tail
export const koiFins = (b: Body, live?: KoiLive) => { const sc = live ? Math.sin((2 * Math.PI * live.t) / KOI_BEAT - 1.4) * (live.amp ?? 1) : 0; return [
  fin(b.at(0.17, 0.9), b.at(0.285, 0.9), b.at(0.33 - 0.03 * sc, 2.85 + 0.35 * sc), 70, 16, 71, 9),
  fin(b.at(0.18, -0.9), b.at(0.27, -0.9), b.at(0.35 + 0.03 * sc, -2.25 + 0.3 * sc), 44, -10, 72, 8),
  fin(b.at(0.53, 0.9), b.at(0.6, 0.9), b.at(0.66, 1.95), 30, 6, 73, 6),
  fin(b.at(0.54, -0.9), b.at(0.6, -0.9), b.at(0.67, -1.8), 26, -5, 74, 6),
]; };
// the red hi markings, in the body's (t, s) frame: [t, s, half-length, half-width, seed]
export const KOI_HI: [number, number, number, number, number][] = [[0.105, -0.05, 0.075, 0.95, 11], [0.36, -0.25, 0.1, 1.2, 12], [0.47, 0.35, 0.07, 0.9, 13], [0.66, -0.1, 0.085, 1.15, 14], [0.82, 0.3, 0.05, 0.9, 15]];
// THE FISH: its floor shadow, fins, body and markings, dorsal, head and tail, on whatever b is.
// Split out of drawKoi so the same fish can be posed anywhere (koiWorld swims it through a pond).
export const drawFish = (g: Gfx, k: KoiClock, b: Body, fins: ReturnType<typeof koiFins>, cau: ReturnType<typeof tail>) => {
  // the fish's shadow on the pond floor, flat and hard, down-right away from the light
  const floor = [b.outline, cau.shape, ...fins.map((f) => f.shape)].map((s) => s.map(([x, y]) => [x + 30, y + 40] as P));
  g.group("plain", () => lay(g, k("floor", "shade"), floor, () => floor.forEach((s) => fillShape(g, s, "#083b45", 0.5)), 5001, 34, 0.9));

  // fins under the body: translucent, cel-shaded, a black base on the pectorals
  g.group("plain", () => {
    fins.forEach((f, i) => {
      const el = `fin${i}`, fl = k(el, "flat"), sh = k(el, "shade"), dt = k(el, "detail"), ln = k(el, "line");
      const moto = () => { if (i < 2) fillShape(g, blob(...(i === 0 ? b.at(0.25, 1.35) : b.at(0.245, -1.25)), i === 0 ? 46 : 32, i === 0 ? 30 : 22, 80 + i, 0.2, 12, i === 0 ? 1.0 : -0.8), SUMI, 0.95); }; // motoguro: black at the base of the pectorals
      const cel = () => { fillShape(g, f.shape, FIN_S, 0.88); clipped(g, f.shape, () => { fillShape(g, f.shape.map(([x, y]) => [x - 9, y - 11] as P), FIN, 0.92); moto(); }); };
      if (sh >= 1) cel();
      else { lay(g, part(fl, 0, 2), [f.shape], () => fillShape(g, f.shape, FIN, 0.92), 5100 + i, 18, -0.9); lay(g, part(fl, 1, 2), [f.shape], () => clipped(g, f.shape, moto), 5110 + i, 14, -0.9); lay(g, sh, [f.shape], cel, 5120 + i, 13, 0.7); }
      f.rays.forEach((ray, kk) => inkP(g, ray, mix(INK, FIN_S, 0.35), { w: 1.7, shadow: 0, taper: [0.05, 0.5], seed: 900 + i * 40 + kk }, 0.75, part(dt, kk, f.rays.length)));
      inkP(g, f.shape, INK, { w: 4.2, closed: true, light: LIGHT, shadow: 0.85, seed: 700 + i * 7 }, undefined, ln);
    });
  });

  // the body: shade cel underneath, the lit white pushed toward the light, then the markings
  const bs = b.outline, bsL = bs.map(([x, y]) => [x + LIGHT[0] * 22, y + LIGHT[1] * 22] as P);
  const bfl = k("body", "flat"), bsh = k("body", "shade");
  g.group("plain", () => {
    if (bsh >= 1) fillShape(g, bs, WHITE_S);
    else { lay(g, bfl, [bs], () => fillShape(g, bs, WHITE), 5201, 34, -0.35); lay(g, bsh, [bs], () => { fillShape(g, bs, WHITE_S); clipped(g, bs, () => fillShape(g, bsL, WHITE)); }, 5202, 24, 0.62); }
    clipped(g, bs, () => {
      if (bsh >= 1) fillShape(g, bsL, WHITE);
      // red hi: head crown, a saddle across the back, a patch toward the tail. Crisp back edges.
      const hf = k("hi", "flat"), hs = k("hi", "shade");
      const patches = KOI_HI;
      patches.forEach(([t, s, dt, ds, seed], pi) => {
        const r = rng(seed * 17), pts: P[] = [];
        for (let i = 0; i < 16; i++) { const a = (i / 16) * Math.PI * 2, kk = 0.8 + r() * 0.35; pts.push(b.at(t + Math.cos(a) * dt * kk, s + Math.sin(a) * ds * kk)); }
        const sh = smooth(pts, true, 6), ps = part(hs, pi, 5);
        const cel = () => { fillShape(g, sh, HI_S); clipped(g, sh, () => fillShape(g, bsL, HI)); };
        if (ps >= 1) cel(); else { lay(g, part(hf, pi, 5), [sh], () => fillShape(g, sh, HI), 5300 + pi, 24, -0.35); lay(g, ps, [sh], cel, 5310 + pi, 18, 0.62); }
      });
      // sumi: a few black spots, never on the head
      const sf = k("sumi", "flat");
      ([[0.3, 0.55, 0.028, 0.32, 31], [0.55, -0.55, 0.03, 0.3, 32], [0.61, 0.42, 0.018, 0.22, 33], [0.78, -0.2, 0.026, 0.4, 34], [0.43, 0.02, 0.016, 0.18, 35]] as number[][]).forEach(([t, s, dt, ds, seed], si) => {
        const r = rng(seed), pts: P[] = []; for (let i = 0; i < 12; i++) { const a = (i / 12) * Math.PI * 2, kk = 0.8 + r() * 0.4; pts.push(b.at(t + Math.cos(a) * dt * kk, s + Math.sin(a) * ds * kk)); }
        const sp = smooth(pts, true, 5); lay(g, part(sf, si, 5), [sp], () => fillShape(g, sp, SUMI), 5400 + si, 12, -0.3);
      });
      // scales: a loose lattice of arcs, strongest on the lit back, gone into the shade
      const r = rng(55), sc = k("scales", "detail");
      for (let t = 0.2; t < 0.93; t += 0.034) for (let s = -0.75; s <= 0.8; s += 0.3) {
        const tt = t + (Math.round(s / 0.3) % 2 ? 0.017 : 0), ss = s + (r() - 0.5) * 0.06, p = b.at(tt, ss), q = b.at(tt + 0.014, ss - 0.13), u = b.at(tt + 0.014, ss + 0.13), m = b.at(tt + 0.022, ss);
        const lit = ss < 0.35 && !(r() < 0.3);
        if (lit) inkP(g, smooth([q, m, u], false, 5), "#2a1f3a", { w: 1.5, shadow: 0, taper: [0.3, 0.3], seed: 2000 + Math.round(t * 1000 + s * 50) }, 0.28, stagger(sc, ((tt - 0.2) / 0.75) * 0.85, 0.15));
        void p;
      }
      // the wet highlight along the back, and a glint on the head
      const hl = k("gloss", "detail");
      [[0.2, 0.3, -0.6, 7], [0.335, 0.42, -0.64, 6], [0.46, 0.5, -0.66, 4.5], [0.58, 0.6, -0.66, 3]].forEach(([t0, t1, sv, w], kk) => { const pts: P[] = []; for (let i = 0; i <= 8; i++) pts.push(b.at(t0 + ((t1 - t0) * i) / 8, sv)); inkP(g, pts, "#ffffff", { w, shadow: 0, taper: [0.35, 0.45], seed: 1800 + kk }, 0.9, part(hl, kk, 5)); });
      const glint = blob(...b.at(0.075, -0.35), 22, 9, 91, 0.1, 10, -0.7);
      lay(g, part(hl, 4, 5), [glint], () => fillShape(g, blob(...b.at(0.075, -0.35), 22, 9, 91, 0.1, 10, -0.7), "#ffffff", 0.85), 5501, 8, 0);
    });
    // dorsal fin down the spine: a narrow flutter of translucent fin with ray ticks
    const df: P[] = [], dfr: P[] = [];
    for (let i = 0; i <= 16; i++) { const f = i / 16, t = 0.36 + f * 0.3, h = Math.pow(Math.sin(Math.min(1, f * 2.6) * Math.PI / 2), 1.2) * (1 - f * 0.78); df.push(b.at(t, 0.0)); dfr.push(b.at(t + 0.04 * h, h * 0.72 + Math.sin(i * 1.4) * 0.02 * h)); }
    const dorsal = [...smooth(df, false, 3), ...smooth(dfr, false, 3).reverse()], dsh = dorsal.map(([x, y]) => [x + 6, y + 8] as P);
    const dfl = k("dorsal", "flat"), dsd = k("dorsal", "shade"), ddt = k("dorsal", "detail"), dln = k("dorsal", "line");
    lay(g, dsd, [dsh], () => fillShape(g, dsh, "#2a1f3a", 0.18), 5601, 10, 0.4); // the fin's own shadow on the back
    const dcel = () => { fillShape(g, dorsal, FIN_S, 0.95); clipped(g, dorsal, () => fillShape(g, dorsal.map(([x, y]) => [x - 6, y - 7] as P), FIN, 0.95)); };
    if (dsd >= 1) dcel(); else { lay(g, dfl, [dorsal], () => fillShape(g, dorsal, FIN, 0.95), 5602, 10, 0.3); lay(g, dsd, [dorsal], dcel, 5603, 9, -0.6); }
    for (let i = 1; i < 16; i += 2) inkP(g, [df[i], lerpP(df[i], dfr[i], 0.5), dfr[i]], mix(INK, FIN_S, 0.4), { w: 1.4, shadow: 0, taper: [0.1, 0.5], seed: 1300 + i }, 0.7, part(ddt, (i - 1) / 2, 8));
    inkP(g, dorsal, INK, { w: 3.4, closed: true, light: LIGHT, shadow: 0.8, seed: 1400 }, undefined, dln);

    // head: gill covers, eyes set into the sides, nostrils, barbels
    const hln = k("head", "line"), efl = k("eyes", "flat"), edt = k("eyes", "detail");
    [-1, 1].forEach((sd) => {
      const hi = sd < 0 ? 0 : 1;
      const gill: P[] = []; for (let i = 0; i <= 6; i++) gill.push(b.at(0.155 - Math.sin((i / 6) * Math.PI) * 0.03, sd * (0.98 - i * 0.1)));
      inkP(g, gill, INK, { w: 3.4, shadow: 0, taper: [0.08, 0.7], seed: 1500 + sd }, undefined, part(hln, hi * 4, 8));
      const e = b.at(0.085, sd * 0.8), ew = sd > 0 ? 12 : 10, iris = blob(e[0], e[1], ew + 3, ew, 1600 + sd, 0.05, 12);
      lay(g, part(efl, hi * 2, 4), [iris], () => fillShape(g, blob(e[0], e[1], ew + 3, ew, 1600 + sd, 0.05, 12), "#e6cf8c"), 5700 + hi, 7, 0.3);
      lay(g, part(efl, hi * 2 + 1, 4), [iris], () => fillShape(g, blob(e[0] + 1, e[1] + 1, ew * 0.78, ew * 0.74, 1610 + sd, 0.05, 12), "#1a1427"), 5710 + hi, 6, -0.3);
      if (part(edt, hi * 2, 4) >= 1) fillShape(g, blob(e[0] - 3, e[1] - 4, 3.2, 2.6, 1620 + sd, 0.05, 8), "#ffffff");
      inkP(g, blob(e[0], e[1], ew + 3, ew, 1600 + sd, 0.05, 12), INK, { w: 3, closed: true, light: LIGHT, shadow: 0.7, seed: 1630 + sd }, undefined, part(hln, hi * 4 + 1, 8));
      if (part(edt, hi * 2 + 1, 4) >= 1) fillShape(g, blob(...b.at(0.03, sd * 0.36), 4, 3, 1640 + sd, 0.1, 8), "#3a1e22");
      const m = b.at(0.006, sd * 0.5), m2 = b.at(-0.02, sd * 1.2), m3 = b.at(-0.035, sd * 1.9);
      inkP(g, smooth([m, lerpP(m2, b.at(-0.01, sd * 1.1), 0.5), m3], false, 8), INK, { w: 3, shadow: 0, taper: [0.02, 0.9], seed: 1650 + sd }, undefined, part(hln, hi * 4 + 2, 8));
      const k0 = b.at(0.02, sd * 0.78), k1 = b.at(0.0, sd * 1.25);
      inkP(g, smooth([k0, lerpP(k0, k1, 0.5), k1], false, 6), INK, { w: 2.4, shadow: 0, taper: [0.02, 0.9], seed: 1660 + sd }, undefined, part(hln, hi * 4 + 3, 8));
    });
  });
  // the tail goes on over the body's end, so fin and peduncle are one continuous piece
  const tf = k("tail", "flat"), tsd = k("tail", "shade"), tdt = k("tail", "detail"), tln = k("tail", "line"), bln = k("body", "line");
  g.group("plain", () => {
    const tcel = () => { fillShape(g, cau.shape, FIN_S, 0.9); clipped(g, cau.shape, () => fillShape(g, cau.shape.map(([x, y]) => [x - 10, y - 12] as P), FIN, 0.93)); };
    if (tsd >= 1) tcel(); else { lay(g, tf, [cau.shape], () => fillShape(g, cau.shape, FIN, 0.93), 5801, 22, 0.35); lay(g, tsd, [cau.shape], tcel, 5802, 16, -0.8); }
    cau.rays.forEach((ray, kk) => inkP(g, ray, mix(INK, FIN_S, 0.35), { w: 1.7, shadow: 0, taper: [0.05, 0.5], seed: 1100 + kk }, 0.72, part(tdt, kk, cau.rays.length)));
    const n = b.outline.length / 2, L = b.outline.slice(0, n), R = b.outline.slice(n).reverse(), cut = Math.round(n * 0.965);
    const open = [...L.slice(0, cut).reverse(), ...R.slice(0, cut)];
    inkP(g, open, INK, { w: 6.4, light: LIGHT, shadow: 0.95, seed: 1700, side: -1, taper: [0.06, 0.06], min: 0.3 }, undefined, bln);
    const tailEdge = cau.shape.slice(3, cau.shape.length - 3);
    inkP(g, tailEdge, INK, { w: 4.4, light: LIGHT, shadow: 0.85, seed: 1710, side: -1, taper: [0.04, 0.04], min: 0.3 }, undefined, tln);
  });

};

export const drawKoi = (ctx: Ctx, _frame: number, env: Env, clock?: KoiClock, live?: KoiLive) => {
  const g = new Gfx(ctx, env, 0, PENCIL), k = clock ?? ALL;
  ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);
  const b = koiBody(live);
  const fins = koiFins(b, live), cau = tail(b);
  if (clock) { // the process only: a bare sheet of marker paper, and the lay-in on it
    ctx.fillStyle = "#fbf9f3"; ctx.fillRect(0, 0, 1080, 1080);
    pencilLayIn(g, k, b, fins, cau, [padShape(905, 205, 168, 2.3, 3100), padShape(890, 905, 120, 3.6, 3300), padShape(120, 640, 88, 0.2, 3400)], [880, 195, 1.15]);
  }
  water(g, k);

  drawFish(g, k, b, fins, cau);

  // live: the pads ride the swell the fish leaves, each on its own phase; the rings drift out from the nose
  const bob = (i: number): P => (live ? [(live.amp ?? 1) * 3 * Math.sin((2 * Math.PI * live.t) / (2 * KOI_BEAT) + i * 2.1), (live.amp ?? 1) * 4 * Math.sin((2 * Math.PI * live.t) / (2 * KOI_BEAT) + i * 2.1 + 1.2)] : [0, 0]);
  if (live) { const nose = b.at(0, 0); ripples(g, nose[0], nose[1] - 26, 2100, k, (live.t / KOI_BEAT) % 1); }
  else ripples(g, 300, 196, 2100, k);
  const [p0, p1, p2] = [bob(0), bob(1), bob(2)];
  lilyPad(g, 905 + p0[0], 205 + p0[1], 168, 2.3, 3100, k, "pad0");
  waterLily(g, 880 + p0[0], 195 + p0[1], 1.15, 3200, k);
  lilyPad(g, 890 + p1[0], 905 + p1[1], 120, 3.6, 3300, k, "pad1");
  lilyPad(g, 120 + p2[0], 640 + p2[1], 88, 0.2, 3400, k, "pad2");
  g.paper("paper", 0.05);
};

export const koi: Film = {
  meta: { title: "Koi · marker comic", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 1 },
  assets: { images: {} },
  shots: [{ id: "koi", start: 0, end: 1, draw: drawKoi }],
};

// the koi, alive: a 4 s loop (two tail beats; the pads' swell is one period), for the launch film and loops
export const koiAlive: Film = {
  meta: { title: "Koi · marker comic, alive", W: 1080, H: 1080, fps: 30, bpm: 120, durationFrames: 120, kind: "loop" },
  assets: { images: {} },
  shots: [{ id: "swim", start: 0, end: 120, draw: (ctx, f, env) => drawKoi(ctx, f, env, undefined, { t: f / 30 }) }],
};
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall