From 9a01e99eece729777750547e4f9e5c8d7e20d458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Sun, 31 Dec 2023 14:11:24 +0100 Subject: [PATCH] CountDownBars non-tick-pixels darker --- src/mode/CountDown/CountDown.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/mode/CountDown/CountDown.h b/src/mode/CountDown/CountDown.h index 67f2be4..fde17dd 100644 --- a/src/mode/CountDown/CountDown.h +++ b/src/mode/CountDown/CountDown.h @@ -114,24 +114,33 @@ private: } void drawCountdownBars(Display &display, uint8_t hours, uint8_t minutes, uint8_t seconds) { - drawBar(display, 0, 0, 24, 1, 0, 24, hours, RED); - drawBar(display, 0, 2, 30, 2, 0, 60, minutes, BLUE); - drawBar(display, 0, 5, 30, 2, 0, 60, seconds, GREEN); + drawBar(display, 0, 0, 24, 1, 0, 24, hours, RED, 6); + drawBar(display, 0, 2, 30, 2, 0, 60, minutes, BLUE, 5); + drawBar(display, 0, 5, 30, 2, 0, 60, seconds, GREEN, 10); } - void drawBar(Display &display, uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _h, uint8_t min, uint8_t max, uint8_t value, const Color &color) { - auto onCount = (uint8_t) round(((double) value - min) / (max - min) * _w * _h); + void drawBar(Display &display, uint8_t _x, uint8_t _y, uint8_t _w, uint8_t _h, uint8_t min, uint8_t max, uint8_t value, const Color &color, uint8_t ticks) { + auto totalOnCount = (uint8_t) round(((double) value - min) / (max - min) * _w * _h); + uint8_t doneOnCount = 0; for (uint8_t y = 0; y < _h; y++) { for (uint8_t x = 0; x < _w; x++) { - if (onCount <= 0) { + if (doneOnCount >= totalOnCount) { return; } - onCount--; - display.set(_x + x, _y + y, color); + doneOnCount++; + display.set(_x + x, _y + y, (doneOnCount % ticks) == 0 ? color : factor(color, 0.5)); } } } + static Color factor(Color color, double factor) { + return { + (uint8_t) round(color.r * factor), + (uint8_t) round(color.g * factor), + (uint8_t) round(color.b * factor), + }; + } + void drawCountdownNumbers(Display &display, uint8_t hours, uint8_t minutes, uint8_t seconds) const { uint8_t x = 0; if (days > 0) {