From c9e0a015de60f35213dbb7fbaf1a7ff8a1eb249e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Crem=20Sancaktutan?= <36550960+codelovingcat@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:06:34 +0300 Subject: [PATCH 1/2] Make zigzag runs longer and distribute band widths --- src/animation.ts | 63 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/src/animation.ts b/src/animation.ts index 23ab30f..b6a54cd 100644 --- a/src/animation.ts +++ b/src/animation.ts @@ -35,14 +35,13 @@ const DEFAULT_FRAME_DELAY_MS = 70; const DEFAULT_ZIGZAG_SEED = 0xC0FFEE; const CONTRIBUTION_ROWS = 7; -const MIN_ZIGZAG_RUN = 2; -const MAX_ZIGZAG_RUN = 5; +const MIN_ZIGZAG_RUN = 8; +const MAX_ZIGZAG_RUN = 14; /** * Build a deterministic, connected path through every contribution cell. - * The route snakes through short column bands of varying widths instead of - * crossing the entire garden before changing rows. Odd/even bands alternate - * between descending and ascending through the seven rows. + * Long, varied column bands reduce the rapid back-and-forth movement while + * retaining a continuous serpentine route through the full grid. */ export function buildZigzagPath( columns: number, @@ -56,15 +55,11 @@ export function buildZigzagPath( } const random = createSeededRandom(seed); + const bandWidths = createZigzagBandWidths(columns, random); const bands: Array<{ startColumn: number; width: number }> = []; let nextColumn = 0; - while (nextColumn < columns) { - const remaining = columns - nextColumn; - const width = remaining <= MAX_ZIGZAG_RUN - ? remaining - : MIN_ZIGZAG_RUN + Math.floor(random() * (MAX_ZIGZAG_RUN - MIN_ZIGZAG_RUN + 1)); - + for (const width of bandWidths) { bands.push({ startColumn: nextColumn, width }); nextColumn += width; } @@ -95,6 +90,52 @@ export function buildZigzagPath( return path; } +/** + * Choose varied band widths while avoiding a very short final band on normal + * contribution grids. Small grids can be narrower than the preferred range. + */ +function createZigzagBandWidths( + columns: number, + random: () => number, +): number[] { + const minimumBandCount = Math.ceil(columns / MAX_ZIGZAG_RUN); + const maximumBandCount = Math.max(1, Math.floor(columns / MIN_ZIGZAG_RUN)); + const preferredBandCount = Math.max(1, Math.round(columns / 11)); + const bandCount = minimumBandCount <= maximumBandCount + ? Math.max(minimumBandCount, Math.min(maximumBandCount, preferredBandCount)) + : minimumBandCount; + + const widths: number[] = []; + let remaining = columns; + + for (let index = 0; index < bandCount; index += 1) { + const bandsLeft = bandCount - index - 1; + if (bandsLeft === 0) { + widths.push(remaining); + break; + } + + const minimumWidth = Math.max( + MIN_ZIGZAG_RUN, + remaining - bandsLeft * MAX_ZIGZAG_RUN, + ); + const maximumWidth = Math.min( + MAX_ZIGZAG_RUN, + remaining - bandsLeft * MIN_ZIGZAG_RUN, + ); + + const width = minimumWidth <= maximumWidth + ? minimumWidth + Math.floor(random() * (maximumWidth - minimumWidth + 1)) + : Math.floor(remaining / (bandsLeft + 1)) + + (index < remaining % (bandsLeft + 1) ? 1 : 0); + + widths.push(width); + remaining -= width; + } + + return widths; +} + function createSeededRandom(seed: number): () => number { let state = seed >>> 0; From 9d46009543e537a5fcad598b050c89e6511fb4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Crem=20Sancaktutan?= <36550960+codelovingcat@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:06:37 +0300 Subject: [PATCH 2/2] Test longer varied zigzag runs --- tests/animation.test.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/animation.test.ts b/tests/animation.test.ts index fbb0b16..c5b3413 100644 --- a/tests/animation.test.ts +++ b/tests/animation.test.ts @@ -62,8 +62,30 @@ test("builds a deterministic zigzag with varied run lengths", () => { } const firstHorizontalRunLength = path.findIndex((position) => position.row !== 0); - assert.ok(firstHorizontalRunLength >= 2 && firstHorizontalRunLength <= 5); + assert.ok(firstHorizontalRunLength >= 8 && firstHorizontalRunLength <= 14); assert.ok(firstHorizontalRunLength < columns, "the first run should end before crossing the entire garden"); + + const normalGridPath = buildZigzagPath(53, seed); + const horizontalRunLengths: number[] = []; + let horizontalRunLength = 1; + + for (let index = 1; index < normalGridPath.length; index += 1) { + const previous = normalGridPath[index - 1]!; + const current = normalGridPath[index]!; + + if (previous.row === current.row) { + horizontalRunLength += 1; + } else { + horizontalRunLengths.push(horizontalRunLength); + horizontalRunLength = 1; + } + } + horizontalRunLengths.push(horizontalRunLength); + + assert.ok( + horizontalRunLengths.every((length) => length >= 8), + `normal-grid path contains a short horizontal run: ${horizontalRunLengths.join(", ")}`, + ); }); test("keeps empty contribution cells gray throughout the animation", () => {