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.

chore: resync Codex mirror

Alex Greenshpun8a46a0d77c3e
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/deadair.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/deadair.mjs
index ef3259c..d6ca965 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/deadair.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/deadair.mjs
@@ -20,13 +20,15 @@ const exempt = (arg("exempt", "") || "").split(",").filter(Boolean).map((s) => s
// decode small: 135x135 grey is plenty to see whether anything moved, and it keeps this honest
const W = SIZE, H = Math.max(2, Math.round(SIZE * stream.height / stream.width));
const changed = await changedArea(file, W, H, THRESH), n = changed.length;
+// the window floor is a change per 1/30 s: a 60 fps file is measured frame vs two back (the gate does the same)
+const STRIDE = Math.max(1, Math.round(fpsNum / fpsDen / 30)), per30 = STRIDE > 1 ? await changedArea(file, W, H, THRESH, STRIDE) : changed;
const probe = execFileSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=nb_frames,duration", "-of", "csv=p=0", file]).toString().trim();
console.log(`${file}\n ${n} frames decoded at ${W}x${H} grey, threshold ${THRESH}/255 (${probe})`);
const inExempt = (f) => exempt.some(([a, b]) => f >= a && f < b);
const still = [], windows = [];
for (let f = 1; f < n; f++) if (changed[f] === 0 && !inExempt(f)) still.push(f);
-for (let f = 1; f + WIN <= n; f++) { let m = 0; for (let k = f; k < f + WIN; k++) m = Math.max(m, changed[k]); if (m < MIN && !inExempt(f)) windows.push([f, f + WIN, m]); }
+for (let f = 1; f + WIN <= n; f++) { let m = 0; for (let k = f; k < f + WIN; k++) m = Math.max(m, per30[k]); if (m < MIN && !inExempt(f)) windows.push([f, f + WIN, m]); }
const merged = []; windows.forEach(([a, b, m]) => { const last = merged[merged.length - 1]; if (last && a <= last[1]) { last[1] = Math.max(last[1], b); last[2] = Math.max(last[2], m); } else merged.push([a, b, m]); });
const stat = (xs) => { const s = [...xs].sort((x, y) => x - y); return { med: s[s.length >> 1], min: s[0], max: s[s.length - 1] }; };
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/gate.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/gate.mjs
index 0250e20..68852b4 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/gate.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/gate.mjs
@@ -6,7 +6,7 @@
// 1 DETERMINISM the same sampled frames drawn twice, at two different worker counts, in two
// different orders. Byte-identical, or PSNR above 45 dB.
// 2 CONTRACT a static scan of every module the film draws through.
-// 3 DEAD AIR no identical consecutive frames, no 15-frame window under 0.5 % changed.
+// 3 DEAD AIR no identical consecutive frames, no half-second window under 0.5 % changed per 1/30 s.
//
// The gate NEVER writes to out/. It renders into .tmp/gate/ and it only ever READS the MP4 it is
// pointed at, so running it can never damage a finished film.
@@ -43,7 +43,9 @@ const FORBIDDEN = [
[/from\s+["']react["']/, "react import"], [/from\s+["']remotion["']/, "remotion import"], [/pencil\.tsx/, "pencil.tsx import"],
];
const stripComments = (s) => s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");
-const motionViolations = (changed, meta) => {
+// windowChanged: the change per 1/30 s (for a 60 fps film, each frame against the one two back). The
+// 0.5 % floor is a 30 fps measure: at 60 fps the same motion changes half the area per frame.
+const motionViolations = (changed, meta, windowChanged = changed) => {
const declared = (ranges, f) => ranges?.some(([from, to]) => f >= from && f < to) ?? false;
const step = meta.step ?? (meta.onTwos ? 2 : 1);
const explained = (f) => {
@@ -54,7 +56,7 @@ const motionViolations = (changed, meta) => {
let run = 0; const still = [];
for (let f = 1; f < changed.length; f++) { run = changed[f] === 0 ? run + 1 : 0; if (changed[f] === 0 && !explained(f) && run > pause) still.push(f); }
const windowSize = drawing ? Math.max(2, Math.round(meta.fps)) : Math.max(2, Math.round(meta.fps / 2));
- const windows = []; for (let f = 1; f + windowSize <= changed.length; f++) { let m = 0; for (let k = f; k < f + windowSize; k++) m = Math.max(m, changed[k]); if (m < floor && !Array.from({ length: windowSize }, (_, k) => f + k).every((i) => declared(meta.holds, i))) windows.push(f); }
+ const windows = []; for (let f = 1; f + windowSize <= changed.length; f++) { let m = 0; for (let k = f; k < f + windowSize; k++) m = Math.max(m, windowChanged[k]); if (m < floor && !Array.from({ length: windowSize }, (_, k) => f + k).every((i) => declared(meta.holds, i))) windows.push(f); }
return { still, windows, windowSize };
};
const walk = (dir, out = []) => { for (const e of execFileSync("find", [dir, "-name", "*.ts", "-type", "f"]).toString().trim().split("\n").filter(Boolean)) out.push(e); return out; };
@@ -80,7 +82,9 @@ const deadAir = async (mp4, meta) => {
let changed; try { changed = await changedArea(mp4, W, H); } catch (e) { say(false, "decode MP4", e.message); return; }
const n = changed.length;
say(n === meta.durationFrames, "MP4 frame count matches film", `${n}/${meta.durationFrames}`);
- const { still, windows: win, windowSize } = motionViolations(changed, meta);
+ const stride = Math.max(1, Math.round(meta.fps / 30));
+ let perThirtieth = changed; if (stride > 1) try { perThirtieth = await changedArea(mp4, W, H, 4, stride); } catch (e) { say(false, "decode MP4", e.message); return; }
+ const { still, windows: win, windowSize } = motionViolations(changed, meta, perThirtieth);
const merged = []; win.forEach((f) => { const l = merged[merged.length - 1]; if (l && f <= l[1]) l[1] = f + windowSize; else merged.push([f, f + windowSize]); });
for (const [from, to, reason] of meta.locked ?? []) console.log(` LOCKED ${from}-${to}: ${reason}; violations remain failures`);
for (const [from, to, reason] of meta.holds ?? []) if (reason) console.log(` HOLD ${from}-${to}: ${reason}`);
diff --git a/plugins/anidoodle/skills/anidoodle/engine/tools/motion.mjs b/plugins/anidoodle/skills/anidoodle/engine/tools/motion.mjs
index 01ab297..873453a 100644
--- a/plugins/anidoodle/skills/anidoodle/engine/tools/motion.mjs
+++ b/plugins/anidoodle/skills/anidoodle/engine/tools/motion.mjs
@@ -1,18 +1,20 @@
import { spawn } from "node:child_process";
// Read one small grayscale frame at a time. A ten-minute film must not need a gigabyte buffer.
-export const changedArea = async (file, width, height, threshold = 4) => {
+// stride: each frame is compared with the frame `stride` back (the first frames with frame 0), so a
+// 60 fps film can be measured over the same 1/30 s a 30 fps film is (the gate's motion floor).
+export const changedArea = async (file, width, height, threshold = 4, stride = 1) => {
const px = width * height, changed = [0];
const ff = spawn("ffmpeg", ["-v", "error", "-i", file, "-vf", `scale=${width}:${height}`, "-pix_fmt", "gray", "-f", "rawvideo", "-"]);
- let pending = Buffer.alloc(0), previous = null, error = "";
+ let pending = Buffer.alloc(0), error = ""; const back = [];
ff.stderr.on("data", (chunk) => { error += chunk.toString(); });
const closed = new Promise((resolve, reject) => { ff.on("error", reject); ff.on("close", (code) => code ? reject(new Error(error || `ffmpeg exited ${code}`)) : resolve()); });
for await (const chunk of ff.stdout) {
pending = pending.length ? Buffer.concat([pending, chunk]) : chunk;
while (pending.length >= px) {
const frame = pending.subarray(0, px);
- if (previous) { let count = 0; for (let i = 0; i < px; i++) if (Math.abs(frame[i] - previous[i]) > threshold) count++; changed.push(count / px); }
- previous = Buffer.from(frame);
+ if (back.length) { const previous = back[0]; let count = 0; for (let i = 0; i < px; i++) if (Math.abs(frame[i] - previous[i]) > threshold) count++; changed.push(count / px); }
+ back.push(Buffer.from(frame)); if (back.length > stride) back.shift();
pending = pending.subarray(px);
}
}