Skip to content

Isometric line figures that answer the pointer. For React and for anything with a DOM.

Skill: look no longer films the lap; the person judges the walk at handoff instead

Lucas Marques8904b8aaba70
diff --git a/packages/hairline/test/browser/look.spec.ts b/packages/hairline/test/browser/look.spec.ts
index 66eca27..542fad6 100644
--- a/packages/hairline/test/browser/look.spec.ts
+++ b/packages/hairline/test/browser/look.spec.ts
@@ -60,8 +60,7 @@ test.describe("look.mjs", () => {
/* 4 is information: a busy machine can say moving, so only its shape is held */
expect(run.out).toMatch(/^4 flicker: (still|moving)\. .* Information, not a check: look\.md, item 4\.$/m);
expect(run.out).toMatch(new RegExp(`^blind .*hairline-${name}-blind\\.png holds the small and small-answer pictures with the name and the read-out hidden`, "m"));
- expect(run.out).toMatch(new RegExp(`^motion .*hairline-${name}-motion\\.png is the stage while the tour plays its lap: \\d+ pictures`, "m"));
- expect(run.out).toMatch(/^14 tour: ok\. Every stop answers and holds still\./m);
+ expect(run.out).toMatch(new RegExp(`^motion .*hairline-${name}-motion\\.png is the stage while the answer plays: 16 pictures, rest first`, "m"));
for (const png of ["look", "answer", "blind", "motion"]) wrote(cwd, `hairline-${name}-${png}.png`);
});
}
@@ -78,7 +77,7 @@ test.describe("look.mjs", () => {
expect(run.out).not.toContain("no --answer");
expect(run.out).not.toContain("no --edge");
expect(run.out).toMatch(/^3 answer: ok\. /m);
- expect(run.out).toMatch(/^motion .*hairline-terrain-motion\.png is the stage while the tour plays its lap/m);
+ expect(run.out).toMatch(/^motion .*hairline-terrain-motion\.png /m);
wrote(cwd, "hairline-terrain-motion.png");
});
@@ -93,15 +92,14 @@ test.describe("look.mjs", () => {
expect(run.out).not.toContain("cell 2·6");
});
- test("says so when the figure's points are not points, and takes the answer from the tour's first stop", async () => {
+ test("says so when the figure's points are not points, and looks on at rest", async () => {
const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));
writeFileSync(join(cwd, "terrain.js"), declaring(' answer: ["a", 1],\n edge: [[1, 2, 3], [4, 5, 6], [7, 8, 9]],\n'));
const run = await look(cwd, "terrain.js");
expect(run.out).toMatch(/^the figure's hairline call gives answer a,1, which is not a point: two numbers for the viewBox, three for the world\. Give --answer x,y,z instead\.$/m);
expect(run.out).toMatch(/^the figure's hairline call gives edge \[\[1,2,3\],\[4,5,6\],\[7,8,9\]\], which is not one point or two\. Give --edge x,y,z instead\.$/m);
- expect(run.out).toMatch(/^answer 128,150 \(from the figure's tour\) -> at=128,150/m);
- expect(run.out).toMatch(/^3 answer: (ok|warn)\. /m);
- expect(run.out).toMatch(/^14 tour: ok\. /m);
+ expect(run.out).toMatch(/^no --answer: /m);
+ expect(run.out).toMatch(/^3 answer: not measured\. /m);
expect(run.code, run.out).toBe(0);
});
@@ -118,6 +116,19 @@ test.describe("look.mjs", () => {
expect(run.code, run.out).toBe(0);
});
+ test("without an answer point, writes the blind pair and no motion strip", async () => {
+ const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));
+ const run = await look(cwd, `${SKILL}examples/terrain.js`);
+ expect(run.code, run.out).toBe(0);
+ expect(run.out).toMatch(/^no --answer: /m);
+ expect(run.out).toMatch(/^3 answer: not measured\. No --answer\.$/m);
+ wrote(cwd, "hairline-terrain-look.png");
+ wrote(cwd, "hairline-terrain-blind.png");
+ expect(run.out).toMatch(/^blind .*hairline-terrain-blind\.png holds /m);
+ expect(existsSync(join(cwd, "hairline-terrain-motion.png"))).toBe(false);
+ expect(run.out).not.toMatch(/^motion /m);
+ });
+
test("fails a figure that throws when it mounts", async () => {
const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));
const src = readFileSync(SKILL + "examples/terrain.js", "utf8").replace(/^(function mount\(.*\{)$/m, '$1\n throw new Error("no drawing today");');
@@ -128,44 +139,4 @@ test.describe("look.mjs", () => {
expect(run.out).toMatch(/^12 console: fail/m);
expect(run.out).toContain("no drawing today");
});
-
- test("fails 14 tour when the figure ignores the pointer", async () => {
- const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));
- const terrain = readFileSync(SKILL + "examples/terrain.js", "utf8");
- const deaf = terrain.replace("move: (p) => { over = unproj(C, p[0], p[1], 0); retarget(); },", "move: () => {},");
- expect(deaf).not.toBe(terrain);
- writeFileSync(join(cwd, "terrain.js"), deaf);
- const { code, out } = await look(cwd, "terrain.js");
- expect(out).toMatch(/^14 tour: fail\. Stop 0 leaves the read-out at "rest"/m);
- expect(code).toBe(1);
- });
-
- test("fails 12 console, naming the lap, when the figure throws as the tour moves it", async () => {
- const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));
- const terrain = readFileSync(SKILL + "examples/terrain.js", "utf8");
- /* the shots each move the pointer once, so only the lap reaches the second move */
- const jumpy = terrain
- .replace(" bag.add(pointer(stage, {\n", " let moves = 0;\n bag.add(pointer(stage, {\n")
- .replace("move: (p) => { over = unproj(C, p[0], p[1], 0); retarget(); },", 'move: (p) => { if (++moves === 2) throw new Error("moved twice"); over = unproj(C, p[0], p[1], 0); retarget(); },');
- expect(jumpy).toContain("let moves = 0;");
- expect(jumpy).toContain("moved twice");
- writeFileSync(join(cwd, "terrain.js"), jumpy);
- const { code, out } = await look(cwd, "terrain.js");
- expect(out).toMatch(/^12 console: fail\. .*moved twice.* \(lap\)/m);
- expect(code).toBe(1);
- });
-
- test("says the tour never started when the figure throws as it mounts, without waiting out the lap", async () => {
- const cwd = mkdtempSync(join(tmpdir(), "hl-look-"));
- const src = readFileSync(SKILL + "examples/terrain.js", "utf8").replace(/^(function mount\(.*\{)$/m, '$1\n throw new Error("no drawing today");');
- expect(src).toContain("no drawing today");
- writeFileSync(join(cwd, "terrain.js"), src);
- const t0 = Date.now();
- const { code, out } = await look(cwd, "terrain.js");
- expect(out).toMatch(/^14 tour: fail\. The tour never started because the figure did not mount: .*no drawing today/m);
- expect(out).not.toContain("Does the figure call HL.pointer");
- expect(code).toBe(1);
- /* the lap alone could hold it 20 seconds */
- expect(Date.now() - t0).toBeLessThan(25_000);
- });
});
diff --git a/packages/hairline/test/skill/look.test.ts b/packages/hairline/test/skill/look.test.ts
index 40432ea..c487170 100644
--- a/packages/hairline/test/skill/look.test.ts
+++ b/packages/hairline/test/skill/look.test.ts
@@ -1,5 +1,5 @@
-import { describe, expect, it } from "vitest";
-import { moved, stops, tourLine } from "../../../../skills/hairline-create/look.mjs";
+import { expect, it } from "vitest";
+import { beats, moved } from "../../../../skills/hairline-create/look.mjs";
/** moved: the pixels inked in one picture and not the other, over the rest picture's ink. */
it("is nothing when the two pictures are the same", () => {
@@ -20,53 +20,13 @@ it("is nothing when only a stroke's colour changed: the ink is where it was", ()
expect(moved(sameInk, sameInk.slice())).toBe(0);
});
-const frame = (stop: number | null, read: string, svg: string) => ({ stop, read, svg });
-
-describe("stops", () => {
- it("groups the frames by the stop they follow, and reads whether the drawing held still before the next", () => {
- const got = stops([
- frame(0, "cell 2·6", "a"), frame(null, "cell 2·6", "b"), frame(null, "cell 2·6", "b"),
- frame(1, "cell 4·6", "c"), frame(null, "cell 4·6", "d"), frame(null, "cell 4·6", "e"),
- frame(2, "rest", "f"), frame(null, "rest", "f"),
- ]);
- expect(got).toEqual([
- { index: 0, read: "cell 2·6", held: true },
- { index: 1, read: "cell 4·6", held: false },
- { index: 2, read: "rest", held: true },
- ]);
- });
-
- it("a stop with a single frame counts as held", () => {
- expect(stops([frame(0, "x", "a")])).toEqual([{ index: 0, read: "x", held: true }]);
- });
+/** beats: when each frame of the motion strip is taken, in ms after the pointer arrives. */
+it("takes the first frame at rest, as the pointer arrives, and the others evenly after it", () => {
+ expect(beats(4, 40)).toEqual([0, 40, 80, 120]);
});
-describe("tourLine", () => {
- const tour = [[128, 150], [272, 150], [200, 206], null];
- it("passes when every point answers and holds, and names each stop's read-out", () => {
- const r = tourLine([
- { index: 0, read: "cell 2·6", held: true }, { index: 1, read: "cell 4·6", held: true },
- { index: 2, read: "cell 3·7", held: true }, { index: 3, read: "rest", held: true },
- ], tour);
- expect(r.ok).toBe(true);
- expect(r.line).toBe('14 tour: ok. Every stop answers and holds still. stop 0 "cell 2·6", stop 1 "cell 4·6", stop 2 "cell 3·7", stop 3 "rest".');
- });
- it("fails when no stop was reached", () => {
- const r = tourLine([], tour);
- expect(r.ok).toBe(false);
- expect(r.line).toMatch(/^14 tour: fail\. No stop was reached/);
- });
- it("fails when a point leaves the read-out at rest", () => {
- const r = tourLine([{ index: 0, read: "rest", held: true }, { index: 1, read: "cell 4·6", held: true }], tour);
- expect(r.ok).toBe(false);
- expect(r.line).toBe('14 tour: fail. Stop 0 leaves the read-out at "rest": the figure does not answer there.');
- });
- it("fails when the drawing never holds still at a stop", () => {
- const r = tourLine([{ index: 0, read: "cell 2·6", held: false }], tour);
- expect(r.ok).toBe(false);
- expect(r.line).toBe("14 tour: fail. The drawing never held still at stop 0 before the next stop began: it does not settle within the dwell.");
- });
- it("a null stop may read rest", () => {
- expect(tourLine([{ index: 3, read: "rest", held: true }], tour).ok).toBe(true);
- });
+it("by default reaches 600ms in sixteen frames, most of the way through the 700ms tween, in four rows of four", () => {
+ const b = beats();
+ expect(b).toHaveLength(16);
+ expect(b.at(-1)).toBe(600);
});
diff --git a/skills/hairline-create/look.mjs b/skills/hairline-create/look.mjs
index 733a8e2..49e9fc4 100644
--- a/skills/hairline-create/look.mjs
+++ b/skills/hairline-create/look.mjs
@@ -8,13 +8,11 @@
* look.md's eight addresses at once in one browser, and writes the eight
* pictures, labelled, on one sheet: hairline-<name>-look.png. Beside it go the
* two 240px pictures with the name and the read-out hidden, for a reader told
- * nothing, hairline-<name>-blind.png, and, when the figure declares a tour, the
- * stage every 300 ms through one lap of the tour under ?play=1, from the first
- * stop until it comes round again, each stop's picture labelled,
- * hairline-<name>-motion.png. Then it prints what can be measured, one line
- * each, under look.md's item numbers: 9 the frame, 8 the read-out, 12 the
- * console, 4 the flicker, 3 how much of the thumbnail's ink the pointer moves,
- * and 14 the tour, whether every stop answers and holds still. It exits 1 when the
+ * nothing, hairline-<name>-blind.png, and, when there is an answer point, the
+ * stage taken while the answer plays, rest to answer, hairline-<name>-motion.png.
+ * Then it prints what can be measured, one line each, under look.md's item
+ * numbers: 9 the frame, 8 the read-out, 12 the console, 4 the flicker, and 3
+ * how much of the thumbnail's ink the pointer moves. It exits 1 when the
* validator rejects the page or one of those fails, 2 when it cannot run, and
* 0 otherwise. Everything else is for eyes, on the three pictures.
*
@@ -51,8 +49,8 @@ const SMALL = 0.25;
const FAINT = 0.37;
/** A pixel this far from the ground on any channel is ink: the dim stroke on a white plate stands 31 from it. */
const INKED = 24;
-/** The motion strip: one picture every EVERY ms through a lap of the tour, four to a row, giving up after LAP_CAP ms. */
-const EVERY = 300, ACROSS = 4, LAP_CAP = 20000;
+/** The motion strip: 16 frames of the stage 40ms apart, four to a row. The last, at 600ms, is most of the way through a 700ms tween; the sheet's answer picture is where it ends. */
+const FRAMES = 16, EVERY = 40, ACROSS = 4;
/** The share of the rest picture's ink the answer moved: pixels inked in one and not the other, over the rest's ink. Each mask is a row of 0s and 1s. */
export function moved(rest, answer) {
@@ -61,6 +59,11 @@ export function moved(rest, answer) {
return ink ? changed / ink : 0;
}
+/** When each frame of the motion strip is taken, in ms after the pointer arrives: the first at rest, as it arrives, the others every `every` ms after. */
+export function beats(n = FRAMES, every = EVERY) {
+ return Array.from({ length: n }, (_, i) => i * every);
+}
+
/* A picture's ink, read in the page: 1 where a pixel stands INKED or more from the ground, the colour 14px inside the picture's top left corner, on the plate and clear of the drawing. The outer 12px, where the plate's own outline runs, are left out. */
const INK = async ([b64, INKED]) => {
const img = new Image();
@@ -120,10 +123,9 @@ function playwright(dir) {
/*
* Keeps the P the figure makes from its own camera, so a world point can be
- * turned into an ?at= point, the `answer` and `edge` points a figure may
- * give in its hairline({ … }) call and its `tour`, and, in window.__stops, each
- * stop the bench reports through window.hairline.onStop. The bench is not
- * touched: all of it is caught as the page sets it.
+ * turned into an ?at= point, and the `answer` and `edge` points a figure may
+ * give in its hairline({ … }) call. The bench is not touched: both are caught
+ * as the page sets them.
*/
const TRAP = () => {
let hl, call;
@@ -133,11 +135,8 @@ const TRAP = () => {
get: () => call,
set: (v) => {
call = (figure) => {
- window.declared = { answer: figure.answer ?? null, edge: figure.edge ?? null, tour: figure.tour ?? null };
- window.__stops = [];
- const out = v(figure);
- call.onStop = (i) => window.__stops.push(i);
- return out;
+ window.declared = { answer: figure.answer ?? null, edge: figure.edge ?? null };
+ return v(figure);
};
},
});
@@ -163,6 +162,15 @@ const STATE = () => {
};
};
+/* The pointer at a viewBox point x,y, put there as the bench's ?at= puts it: one pointermove on the stage. */
+const POINT = (at) => {
+ const [x, y] = at.split(",").map(Number), stage = document.getElementById("stage"), r = stage.getBoundingClientRect();
+ stage.dispatchEvent(new PointerEvent("pointermove", {
+ pointerType: "mouse", pointerId: 1, bubbles: true,
+ clientX: r.left + (x / 400) * r.width, clientY: r.top + (y / 320) * r.height,
+ }));
+};
+
/** A browser context with look.md's window: 800 × 900, so ?w=240 narrows the page and not the window. */
const window800 = (browser, scale = 1) => browser.newContext({ viewport: { width: 800, height: 900 }, deviceScaleFactor: scale, colorScheme: "light" });
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
@@ -214,8 +222,8 @@ function sheet(name, shots) {
<div class="row">${cell(by.low)}${cell(by.high)}</div>`;
}
-/** The motion strip: the stage's pictures through the lap, ACROSS to a row at their own size, each under its stop or its time since the first stop. */
-function strip(name, frames) {
+/** The motion strip: the stage's frames, ACROSS to a row at their own size, each under its time since the pointer arrived. */
+function strip(name, at, frames) {
return `<!doctype html><meta charset="utf-8"><style>
body { margin: 0; padding: 16px; width: max-content; background: #ececef; color: #18181b; font: 13px/1.3 ui-monospace, Menlo, Consolas, monospace; }
h1 { font: inherit; margin: 0 0 10px; color: #55555c; }
@@ -223,39 +231,10 @@ function strip(name, frames) {
figure { margin: 0; }
figcaption { margin: 0 0 6px; }
img { display: block; outline: 1px solid #c9c9ce; }
-</style><h1>hairline-${esc(name)} · the lap: ?play=1, one picture every ${EVERY}ms from the first stop until it comes round again</h1>
+</style><h1>hairline-${esc(name)} · the answer while it plays, the pointer to at=${esc(at)} after the first picture</h1>
<div class="grid">${frames.map((f) => `<figure><figcaption>${esc(f.label)}</figcaption><img src="data:image/png;base64,${f.png}"></figure>`).join("")}</div>`;
}
-/**
- * One entry per stop reached: its index, the read-out when it was reached, and
- * whether the drawing held still before the next stop: two pictures in a row
- * the same, EVERY ms apart, somewhere in the span. The span ends with the
- * travel to the next stop, so the still window is looked for anywhere in it.
- */
-export function stops(frames) {
- const out = [];
- for (let i = 0; i < frames.length; i++) {
- if (frames[i].stop === null) continue;
- let end = i + 1;
- while (end < frames.length && frames[end].stop === null) end++;
- const span = frames.slice(i, end);
- const held = span.length < 2 || span.some((f, k) => k > 0 && f.svg === span[k - 1].svg);
- out.push({ index: frames[i].stop, read: frames[i].read, held });
- }
- return out;
-}
-
-/** The 14 tour line: every point stop answers (its read-out is not "rest") and the stage holds still before the next stop. */
-export function tourLine(reached, tour) {
- if (!reached.length) return { ok: false, line: "14 tour: fail. No stop was reached within the lap. Does the figure call HL.pointer on its stage?" };
- for (const s of reached) {
- if (tour[s.index] !== null && s.read === "rest") return { ok: false, line: `14 tour: fail. Stop ${s.index} leaves the read-out at "rest": the figure does not answer there.` };
- if (!s.held) return { ok: false, line: `14 tour: fail. The drawing never held still at stop ${s.index} before the next stop began: it does not settle within the dwell.` };
- }
- return { ok: true, line: `14 tour: ok. Every stop answers and holds still. ${reached.map((s) => `stop ${s.index} "${s.read}"`).join(", ")}.` };
-}
-
/** Whether a box leaves the 400 × 320 viewBox. */
const outside = (b) => b.x < 0 || b.y < 0 || b.x + b.w > 400 || b.y + b.h > 320;
const n0 = (v) => Math.round(v);
@@ -306,7 +285,7 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {
const context = await window800(browser);
const rest = await open(context, url, true);
// the points the figure gives in its hairline({ … }) call, if any; a point on the command line wins over them
- const decl = (await rest.page.evaluate(() => window.declared ?? null)) ?? { answer: null, edge: null, tour: null }, theirs = new Set();
+ const decl = (await rest.page.evaluate(() => window.declared ?? null)) ?? { answer: null, edge: null }, theirs = new Set();
const isPoint = (p) => Array.isArray(p) && (p.length === 2 || p.length === 3) && p.every((v) => typeof v === "number" && Number.isFinite(v));
if (!answer && decl.answer) {
if (isPoint(decl.answer)) theirs.add((answer = decl.answer));
@@ -317,20 +296,17 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {
if (list.length <= 2 && list.every(isPoint)) for (const p of (edge = list)) theirs.add(p);
else console.log(`the figure's hairline call gives edge ${JSON.stringify(decl.edge)}, which is not one point or two. Give --edge x,y,z instead.`);
}
- /* with no answer of its own, the tour's first point is the answer: where the figure first takes its own pointer */
- const fromTour = new Set();
- const firstStop = Array.isArray(decl.tour) ? decl.tour.find((p) => p !== null) ?? null : null;
- if (!answer && isPoint(firstStop) && firstStop.length === 2) fromTour.add((answer = firstStop));
const given = { answer, low: edge[0] ?? answer, high: edge[1] ?? edge[0] ?? answer }, at = {}, said = [];
for (const [key, p] of Object.entries({ answer, edge0: edge[0], edge1: edge[1] })) {
if (!p) continue;
const v = p.length === 2 ? p : await rest.page.evaluate((q) => (window.P ? window.P(...q).map(Math.round) : null), p);
if (!v) { said.push(`${p} -> no P: the figure stopped before it called HL.proj`); continue; }
for (const use of Object.keys(given)) if (given[use] === p) at[use] = v.join(",");
- said.push(`${key === "answer" ? "answer" : "edge"} ${p}${theirs.has(p) ? " (from the figure's hairline call)" : fromTour.has(p) ? " (from the figure's tour)" : ""} -> at=${v.join(",")}`);
+ said.push(`${key === "answer" ? "answer" : "edge"} ${p}${theirs.has(p) ? " (from the figure's hairline call)" : ""} -> at=${v.join(",")}`);
}
if (said.length) console.log(said.join(" · "));
- if (answer && !edge.length) console.log(`no --edge: the slider's two ends are taken with the pointer at the ${theirs.has(answer) ? "answer" : fromTour.has(answer) ? "tour's first" : "--answer"} point.`);
+ if (!answer) console.log("no --answer: the answering shots are taken at rest. Give --answer x,y,z, a world point on the part that should answer.");
+ else if (!edge.length) console.log(`no --edge: the slider's two ends are taken with the pointer at the ${theirs.has(answer) ? "answer" : "--answer"} point.`);
// 3. the other seven, and the zoom, opened at once; each waits from its own load, so the waits overlap
const queryOf = (q, use) => [q, use && at[use] && `at=${at[use]}`].filter(Boolean).join("&");
@@ -373,37 +349,24 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {
await pair.locator("body").screenshot({ path: blindOut });
const share = moved(await pair.evaluate(INK, [blind[0], INKED]), await pair.evaluate(INK, [blind[1], INKED]));
- // the motion strip: the bench under ?play=1, a picture every EVERY ms from the first stop until stop 0 comes round again
+ // the motion strip: the rest page, held still, given the pointer at the answer point as ?at= gives it, and taken while it plays
const motion = [];
- let motionOut = null, reached = [], lap = null, started = false;
- if (decl.tour) {
- lap = await open(context, address("play=1"), true);
- await sleep(WAIT);
- const box = (await lap.page.evaluate(STATE)).stage;
- /* a figure that did not mount never wired the play button: there is no lap to wait for */
- started = await lap.page.evaluate(() => !!window.hairline?.playing);
+ let motionOut = null;
+ if (at.answer) {
+ const stage = shots[0], snap = async () => (await stage.page.screenshot({ clip: stage.stage })).toString("base64");
+ motion.push({ label: "rest", png: await snap() });
+ await stage.page.evaluate(POINT, at.answer);
const t0 = Date.now();
- let seen = 0, first = -1;
- while (started && Date.now() - t0 < LAP_CAP) {
- const s = await lap.page.evaluate(() => ({ stops: window.__stops.slice(), read: document.getElementById("read").textContent, svg: document.getElementById("stage").innerHTML }));
- const fresh = s.stops.slice(seen);
- seen = s.stops.length;
- if (first < 0 && fresh.length) first = Date.now();
- if (first >= 0) {
- if (motion.length && fresh.includes(0)) break; // round again
- const stop = fresh.length ? fresh[fresh.length - 1] : null;
- motion.push({ stop, read: s.read, svg: s.svg, label: stop !== null ? `stop ${stop}` : `${Date.now() - first}ms`, png: (await lap.page.screenshot({ clip: box })).toString("base64") });
- }
- await sleep(EVERY);
- }
- reached = stops(motion);
- if (motion.length) {
- motionOut = join(cwd, `hairline-${name}-motion.png`);
- const film = await (await browser.newContext({ viewport: { width: 1400, height: 800 } })).newPage();
- await film.setContent(strip(name, motion));
- await film.evaluate(() => Promise.all([...document.images].map((i) => i.decode())));
- await film.screenshot({ path: motionOut, fullPage: true });
+ for (const t of beats().slice(1)) {
+ await sleep(t0 + t - Date.now());
+ const ms = Date.now() - t0;
+ motion.push({ label: `${ms}ms`, png: await snap() });
}
+ motionOut = join(cwd, `hairline-${name}-motion.png`);
+ const film = await (await browser.newContext({ viewport: { width: 1400, height: 800 } })).newPage();
+ await film.setContent(strip(name, at.answer, motion));
+ await film.evaluate(() => Promise.all([...document.images].map((i) => i.decode())));
+ await film.screenshot({ path: motionOut, fullPage: true });
}
// 5. what can be measured
@@ -430,11 +393,8 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {
// each complaint once, with the shots that made it
const noise = new Map();
- for (const s of [...shots, ...(lap ? [{ name: "lap", bad: lap.bad }] : [])]) for (const b of [...s.bad, ...(s.error ? [`error line under the stage: ${s.error}`] : [])]) noise.set(b, [...(noise.get(b) ?? []), s.name]);
- const heard = [...noise].map(([b, where]) => {
- const shotsOnly = where.filter((n) => n !== "lap"), onLap = where.includes("lap");
- return `${b} (${shotsOnly.length === shots.length ? `every shot${onLap ? " and the lap" : ""}` : where.join(", ")})`;
- });
+ for (const s of shots) for (const b of [...s.bad, ...(s.error ? [`error line under the stage: ${s.error}`] : [])]) noise.set(b, [...(noise.get(b) ?? []), s.name]);
+ const heard = [...noise].map(([b, where]) => `${b} (${where.length === shots.length ? "every shot" : where.join(", ")})`);
if (heard.length) fail(`12 console: fail. ${heard.slice(0, 4).join("; ")}${heard.length > 4 ? `; and ${heard.length - 4} more` : ""}.`);
else console.log("12 console: ok. No console error or warning, no page error, no error line under the stage.");
@@ -446,25 +406,15 @@ export async function look(src, given0 = {}, cwd = process.cwd()) {
// how much of the thumbnail the answer moves: a warning, never a fail
- if (!answer) console.log("3 answer: not measured. The figure declares no tour and no --answer was given.");
+ if (!answer) console.log("3 answer: not measured. No --answer.");
else {
const faint = share < FAINT;
console.log(`3 answer: ${faint ? "warn" : "ok"}. At 240px the pointer moves ${n0(share * 100)}% of the ink, the pixels drawn in one small picture and not the other, over those drawn at rest${faint ? `; under ${n0(FAINT * 100)}% the answer is hard to see in a thumbnail. A change of colour moves no ink: make the answer move more, or say why a small one is right` : ""}.`);
}
- // the lap: every point stop answers and holds still
- if (!decl.tour) console.log("14 tour: not measured. The figure declares no tour.");
- else if (!started) {
- const why = lap.bad.find((b) => b.startsWith("page error")) ?? lap.bad[0];
- fail(`14 tour: fail. The tour never started because the figure did not mount: ${why ?? "the play button was never wired"}. Fix that first; 12 console has it.`);
- } else {
- const r = tourLine(reached, decl.tour);
- if (r.ok) console.log(r.line); else fail(r.line);
- }
-
console.log(`sheet ${out}`);
console.log(`blind ${blindOut} holds the small and small-answer pictures with the name and the read-out hidden, as someone who has not seen the figure would meet it: for item 1, look at it that way, or show it to such a reader.`);
- if (motionOut) console.log(`motion ${motionOut} is the stage while the tour plays its lap: ${motion.length} pictures, every ${EVERY} ms from the first stop, a stop's picture labelled stop i and the others with the ms since the first stop. The sheet shows only pictures that held still, so a part that folds, crosses another part, or jumps between two stops on the way is seen only here: look for one, and fix it in the figure.`);
+ if (motionOut) console.log(`motion ${motionOut} is the stage while the answer plays: ${motion.length} pictures, rest first, then each labelled with the ms since the pointer reached the answer point. The sheet shows only pictures that held still, so a part that folds, crosses another part, or jumps between two frames on the way is seen only here: look for one, and fix it in the figure.`);
if (zoomOut) console.log(`zoom ${zoomOut}`);
return failed ? 1 : 0;
} finally {