Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ export const sampleTimes = (from, duration, frames) =>

export const frameName = (index, at) => `${String(index).padStart(2, '0')}-t${at.toFixed(1)}s.jpg`;

/** Columns from the frame count, so a 4-frame sheet is 2x2 instead of 3x2 with two black cells
* that read like failed frames. */
export function tileGrid(count) {
const columns = Math.min(3, Math.max(1, count));
const columns = Math.min(3, Math.max(1, Math.ceil(Math.sqrt(count))));
return { columns, rows: Math.ceil(count / columns) };
}

Expand Down
5 changes: 4 additions & 1 deletion tests/watch.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ test('sampleTimes centres one frame in each cell and spans the segment', () => {
assert.ok(sampleTimes(10, 90, 12).every(at => at > 10 && at < 100));
});

test('tileGrid never leaves an empty trailing cell row', () => {
test('tileGrid keeps at most one blank cell, so a blank reads as padding not a lost frame', () => {
assert.deepEqual(tileGrid(1), { columns: 1, rows: 1 });
assert.deepEqual(tileGrid(2), { columns: 2, rows: 1 });
assert.deepEqual(tileGrid(4), { columns: 2, rows: 2 });
assert.deepEqual(tileGrid(5), { columns: 3, rows: 2 });
assert.deepEqual(tileGrid(6), { columns: 3, rows: 2 });
assert.deepEqual(tileGrid(12), { columns: 3, rows: 4 });
});

Expand Down
Loading