From 710a6c04244320f903195f6a82e0e3b82743937e 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:44:30 +0300 Subject: [PATCH 1/2] Animate score popup colors with contribution progress --- src/animation.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/animation.ts b/src/animation.ts index 48fe35a..dfe34d1 100644 --- a/src/animation.ts +++ b/src/animation.ts @@ -29,7 +29,44 @@ export interface ScorePopup extends ScoreEvent { const BACKGROUND = "#0d1117"; const CHARACTER = "#ffdf00"; const EYE = "#242424"; -const PALETTE: number[][] = [ + +const SCORE_COLOR_STOPS = [ + { progress: 0, color: "#FFDF00" }, // bright yellow + { progress: 0.15, color: "#FF9800" }, // orange + { progress: 0.28, color: "#F97316" }, // deeper orange + { progress: 0.38, color: "#7DD3FC" }, // light blue + { progress: 0.52, color: "#3B82F6" }, // medium blue + { progress: 0.65, color: "#1D4ED8" }, // dark blue + { progress: 0.76, color: "#86EFAC" }, // light green + { progress: 0.88, color: "#22C55E" }, // vivid green + { progress: 1, color: "#006D32" }, // deep green at completion +] as const; + +/** + * Map scoring progress to the requested color journey: + * yellow -> orange -> light/dark blue -> light/dark green. + */ +export function getScoreProgressColor(score: number, totalScores: number): string { + const progress = totalScores <= 0 + ? 0 + : Math.max(0, Math.min(1, score / totalScores)); + const upperIndex = SCORE_COLOR_STOPS.findIndex((stop) => stop.progress >= progress); + + if (upperIndex <= 0) return SCORE_COLOR_STOPS[0]!.color; + + const lower = SCORE_COLOR_STOPS[upperIndex - 1]!; + const upper = SCORE_COLOR_STOPS[upperIndex]!; + const ratio = (progress - lower.progress) / (upper.progress - lower.progress); + const lowerRgb = hexToRgb(lower.color); + const upperRgb = hexToRgb(upper.color); + const channels = lowerRgb.map((channel, index) => + Math.round(channel + ((upperRgb[index] ?? channel) - channel) * ratio), + ); + + return `#${channels.map((channel) => channel.toString(16).padStart(2, "0")).join("").toUpperCase()}`; +} + +const BASE_PALETTE: number[][] = [ [13, 17, 23], [22, 27, 34], [14, 68, 41], @@ -40,6 +77,14 @@ const PALETTE: number[][] = [ [36, 36, 36], ]; +// Include sampled colors from the score gradient so gifenc can preserve the +// changing popup colors instead of quantizing every score back to yellow. +const SCORE_PROGRESS_PALETTE = Array.from( + { length: 101 }, + (_, index) => hexToRgb(getScoreProgressColor(index, 100)), +); +const PALETTE: number[][] = [...BASE_PALETTE, ...SCORE_PROGRESS_PALETTE]; + const MOUTH_SEQUENCE = [0.06, 0.24, 0.48, 0.24]; const DEFAULT_FRAME_DELAY_MS = 70; @@ -456,6 +501,7 @@ export function renderCommitManGif( cellY, popup.score, popup.age, + getScoreProgressColor(popup.score, scoreEvents.length), ); } @@ -565,6 +611,7 @@ function drawScorePopup( cellTop: number, score: number, age: number, + scoreColor: string, ): void { const text = `+${score}`; const scale = score < 10 ? 2 : 1; @@ -575,7 +622,7 @@ function drawScorePopup( const rise = Math.min(age * SCORE_POPUP_RISE_PER_FRAME, SCORE_POPUP_MAX_RISE); const y = Math.max(0, Math.round(cellTop - textHeight - 2 - rise)); const shadow = hexToRgb(BACKGROUND); - const foreground = hexToRgb(CHARACTER); + const foreground = hexToRgb(scoreColor); drawBitmapText(pixels, width, height, text, x + 1, y + 1, shadow, scale); drawBitmapText(pixels, width, height, text, x, y, foreground, scale); From ae8ddead9c423a002b27a5325072926d230b23a0 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:44:32 +0300 Subject: [PATCH 2/2] Test score color progression endpoints --- tests/animation.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/animation.test.ts b/tests/animation.test.ts index 354e526..3b346ef 100644 --- a/tests/animation.test.ts +++ b/tests/animation.test.ts @@ -8,6 +8,7 @@ import { getCommitPauseFramesForFrame, getContributionLevelForFrame, getScorePopupsForFrame, + getScoreProgressColor, renderCommitManGif, } from "../src/animation.js"; @@ -152,6 +153,24 @@ test("adds a deterministic one- or two-frame pause before eating green cells onl assert.equal(getCommitPauseFramesForFrame([], 0), 0); }); +test("progresses score colors from yellow through orange and blues to deep green", () => { + assert.equal(getScoreProgressColor(0, 100), "#FFDF00"); + assert.equal(getScoreProgressColor(15, 100), "#FF9800"); + assert.equal(getScoreProgressColor(28, 100), "#F97316"); + assert.equal(getScoreProgressColor(38, 100), "#7DD3FC"); + assert.equal(getScoreProgressColor(52, 100), "#3B82F6"); + assert.equal(getScoreProgressColor(65, 100), "#1D4ED8"); + assert.equal(getScoreProgressColor(76, 100), "#86EFAC"); + assert.equal(getScoreProgressColor(88, 100), "#22C55E"); + assert.equal(getScoreProgressColor(100, 100), "#006D32"); +}); + +test("clamps score-color progress and defaults empty totals to bright yellow", () => { + assert.equal(getScoreProgressColor(-1, 100), "#FFDF00"); + assert.equal(getScoreProgressColor(120, 100), "#006D32"); + assert.equal(getScoreProgressColor(0, 0), "#FFDF00"); +}); + test("shows floating score popups briefly with an increasing score", () => { const events = [ { position: { column: 1, row: 0 }, score: 1, eatenAtFrame: 1 },