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.

kineticDemo: slow push-ins end its dead air (gate PASS); grain as soft 2x2 clumps at a lower default (8 s 1080p: 69 MB to 21 MB)

Alex Greenshpuna2f031f4cdfe
diff --git a/skills/anidoodle/engine/src/canvas-core/kineticDemo.ts b/skills/anidoodle/engine/src/canvas-core/kineticDemo.ts
index 68abe1e..eac87ab 100644
--- a/skills/anidoodle/engine/src/canvas-core/kineticDemo.ts
+++ b/skills/anidoodle/engine/src/canvas-core/kineticDemo.ts
@@ -10,10 +10,14 @@ const W = 1920, H = 1080, PAPER = "#f4efe6";
const ground = (ctx: Ctx, env: Env) => { ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0); ctx.fillStyle = PAPER; ctx.fillRect(0, 0, W, H); };
const ease = (t: number) => { const c = Math.max(0, Math.min(1, t)); return c * c * (3 - 2 * c); };
const bug = (ctx: Ctx, env: Env, f: number) => logoBug(ctx, env, f, 1640, 1030, 1, { t0: 40 });
+// a slow, constant push-in about the frame centre, drawn as vector (positions and sizes scale, no raster
+// resample): once a shot's words are down the camera keeps leaning in, so the frame never goes still.
+// The corner bug is screen furniture and stays put.
+const push = (f: number, len: number, amt: number) => { const z = 1 + (amt * f) / len; return { z, x: (x: number) => W / 2 + (x - W / 2) * z, y: (y: number) => H / 2 + (y - H / 2) * z }; };
const opening = (ctx: Ctx, f: number, env: Env) => {
ground(ctx, env);
- logoCentred(ctx, env, W / 2, H / 2, 150, ease(f / 44));
+ logoCentred(ctx, env, W / 2, H / 2, 150 * push(f, 60, 0.04).z, ease(f / 44));
bug(ctx, env, f);
};
// two rows of three, each row laid out by measured width and centred
@@ -21,15 +25,17 @@ const SZ = 100, ROWS: [string, KStyle][][] = [[["INK", "ink"], ["CRAYON", "crayo
const WORDS: [string, KStyle, number, number][] = ROWS.flatMap((row, r) => { const gap = 90, tot = row.reduce((a, [t]) => a + measure(t, SZ), 0) + gap * (row.length - 1); let x = W / 2 - tot / 2; return row.map(([t, st]) => { const o: [string, KStyle, number, number] = [t, st, x, r ? 700 : 360]; x += measure(t, SZ, st === "brick" ? { track: 2.6, slant: 0 } : {}) + gap; return o; }); });
const styles = (ctx: Ctx, f: number, env: Env) => {
ground(ctx, env);
- const [, , cx, cy] = WORDS[3], cw = measure("CHALK", SZ); // the chalkboard behind the chalk word
- ctx.fillStyle = "#2c3a33"; ctx.fillRect(cx - 50, cy - SZ - 55, cw + 100, SZ + 110); ctx.strokeStyle = "#6b4a2b"; ctx.lineWidth = 14; ctx.strokeRect(cx - 50, cy - SZ - 55, cw + 100, SZ + 110);
- WORDS.forEach(([t, st, x, y], i) => writeOn(ctx, env, t, x, y, SZ, ease((f - i * 10) / 38), st, { seed: 3 + i }));
- caption(ctx, env, "drawn live, no fonts", W / 2 + 180, 960, 40, ease((f - 60) / 30), "arrow", { to: [WORDS[5][2] + 60, 790] });
+ const P = push(f, 100, 0.02), z = P.z, sz = SZ * z, [, , cx, cy] = WORDS[3], cw = measure("CHALK", sz); // the chalkboard behind the chalk word
+ const bx = P.x(cx - 50), by = P.y(cy - SZ - 55);
+ ctx.fillStyle = "#2c3a33"; ctx.fillRect(bx, by, cw + 100 * z, sz + 110 * z); ctx.strokeStyle = "#6b4a2b"; ctx.lineWidth = 14 * z; ctx.strokeRect(bx, by, cw + 100 * z, sz + 110 * z);
+ WORDS.forEach(([t, st, x, y], i) => writeOn(ctx, env, t, P.x(x), P.y(y), sz, ease((f - i * 10) / 38), st, { seed: 3 + i }));
+ caption(ctx, env, "drawn live, no fonts", P.x(W / 2 + 180), P.y(960), 40 * z, ease((f - 60) / 30), "arrow", { to: [P.x(WORDS[5][2] + 60), P.y(790)] });
bug(ctx, env, f + 60);
};
const finale = (ctx: Ctx, f: number, env: Env) => {
ground(ctx, env);
- sentence(ctx, env, ["Images", "Illustrations", "Loops", "Animations", "Films"], f, 0, { beat: 14 });
+ const P = push(f, 120, 0.03);
+ sentence(ctx, env, ["Images", "Illustrations", "Loops", "Animations", "Films"], f, 0, { beat: 14, size: 74 * P.z, claimSize: 118 * P.z, top: P.y(H * 0.3) });
bug(ctx, env, f + 160);
};
diff --git a/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts b/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts
index 799c5c7..282ef43 100644
--- a/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts
+++ b/skills/anidoodle/engine/src/canvas-core/threeTypeDemo.ts
@@ -133,7 +133,7 @@ const sceneC = (ctx: Ctx, env: Env, f: number) => {
};
// ---------------------------------------------------------------- finish and shots
-const finish = (ctx: Ctx, env: Env, f: number, dark = false) => { vignette(ctx, env, dark ? 0.32 : 0.22, dark ? "#0b0f2a" : "#3a2420"); grain(ctx, env, f, 0.05); };
+const finish = (ctx: Ctx, env: Env, f: number, dark = false) => { vignette(ctx, env, dark ? 0.32 : 0.22, dark ? "#0b0f2a" : "#3a2420"); grain(ctx, env, f); };
const shotA = (ctx: Ctx, f: number, env: Env) => { sceneA(ctx, env, f); finish(ctx, env, f); };
const shotWipe = (ctx: Ctx, f: number, env: Env) => {
const F = WIPE[0] + f;
diff --git a/skills/anidoodle/engine/src/three-core/look.ts b/skills/anidoodle/engine/src/three-core/look.ts
index c326873..032e323 100644
--- a/skills/anidoodle/engine/src/three-core/look.ts
+++ b/skills/anidoodle/engine/src/three-core/look.ts
@@ -15,7 +15,7 @@
// ink: outline(mesh, width, color, o) -> inverted hull, animatable width
// ground: contactShadow(size, softness, o) -> a soft shadow plane, no shadow map
// shadows: softShadows(light, o) -> acne-free cast shadows when wanted
-// post (2D): grain(ctx, env, frame, amount) vignette(ctx, env, amount) after draw3d
+// post (2D): grain(ctx, env, frame, amount, seed, cell) vignette(ctx, env, amount) after draw3d
import * as THREE from "three";
import type { Ctx, Env, Layer } from "../canvas-core/core";
import { rand } from "./stage";
@@ -240,19 +240,22 @@ export const grainTile = (seed: number, frame: number, size = 256): Uint8Clamped
};
/**
* Film grain over the whole frame, new every frame, seeded by the frame (so frame 40 drawn first
- * or last is the same). amount 0-1: 0.06-0.1 is felt, not seen. Call after draw3d and any 2D
+ * or last is the same). amount 0-1: 0.03-0.06 is felt, not seen. Call after draw3d and any 2D
* layers; overlay blending keeps mid-tones and leaves pure black and white alone.
+ * cell: logical pixels per grain value (default 2). The tile is stretched with smoothing, so each
+ * grain is a soft clump rather than a one-pixel speck: it still reads as film at 1x, and the encoder
+ * no longer spends its bits on per-pixel noise (an 8 s 1080p film went from 69 MB to well under 25).
*/
-export const grain = (ctx: Ctx, env: Env, frame: number, amount = 0.08, seed = 7) => {
+export const grain = (ctx: Ctx, env: Env, frame: number, amount = 0.035, seed = 7, cell = 2) => {
if (amount <= 0) return;
- const T = 256, key = `three:grain:${T}`;
+ const T = 256, key = `three:grain:${T}`, k = Math.max(1, cell);
let layer = env.cache.get(key) as Layer | undefined;
if (!layer) { layer = env.canvas(T, T); env.cache.set(key, layer); }
const img = layer.ctx.createImageData(T, T); img.data.set(grainTile(seed, frame, T)); layer.ctx.putImageData(img, 0, 0);
const pat = ctx.createPattern(layer.canvas as CanvasImageSource, "repeat"); if (!pat) return;
- ctx.save(); ctx.setTransform(env.scale, 0, 0, env.scale, 0, 0);
+ ctx.save(); ctx.setTransform(env.scale * k, 0, 0, env.scale * k, 0, 0);
ctx.globalCompositeOperation = "overlay"; ctx.globalAlpha = Math.min(1, amount * 3); ctx.imageSmoothingEnabled = true;
- ctx.fillStyle = pat; ctx.fillRect(0, 0, env.W, env.H);
+ ctx.fillStyle = pat; ctx.fillRect(0, 0, env.W / k, env.H / k);
ctx.restore();
};
/** darken the corners toward a tinted dark (not black: lesson 8, black crush). amount 0-1, 0.3 is gentle */