From 27e014c39b08e7cd674de73a224e4311a751f325 Mon Sep 17 00:00:00 2001
From: Jan Grewe <jan@faked.org>
Date: Tue, 6 Jun 2023 23:10:15 +0200
Subject: [PATCH] add color aging decay

---
 src/display.cpp | 17 +++++++++--------
 src/display.h   |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/display.cpp b/src/display.cpp
index d36ccf9..df29ca1 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -18,7 +18,8 @@ rgb24 gameColor = {colorR, colorG, colorB};
 rgb24 textColor = {255, 255, 255};
 rgb24 pixelColor = {255, 255, 255};
 
-int colorMode = 2; // 0 = static, 1 = RGB, 2 = dynamic
+int colorMode = 2; // 0 = static, 1 = simple RGB, 2 = dynamic aging (decay)
+int colorDecay = 5;
 
 SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
 SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
@@ -58,7 +59,7 @@ void displayLoop()
             }
             else if (colorMode == 2)
             {
-              ageColor(age);
+              ageColor(age, colorDecay);
             }
             backgroundLayer.drawPixel(row, col, pixelColor);
           }
@@ -73,27 +74,27 @@ void displayLoop()
   }
 }
 
-void ageColor(int age)
+void ageColor(int age, int decay)
 {
-  if (age <= 10)
+  if (age <= 2 * decay)
   {
     pixelColor.red = 255;
-    pixelColor.green = (uint8_t)map(age, 1, 10, 0, 255); // 1 -> 10 = 0 -> 255
+    pixelColor.green = (uint8_t)map(age, 1, 2 * decay, 0, 255); // 1 -> 10 = 0 -> 255
     pixelColor.blue = 0;
   }
-  else if (age <= 20)
+  else if (age <= (2 * decay) * 2)
   {
     pixelColor.red = (uint8_t)map(age, 11, 20, 255, 0); // 11 -> 20 = 255 -> 0
     pixelColor.green = 255;
     pixelColor.blue = 0;
   }
-  else if (age <= 30)
+  else if (age <= (2 * decay) * 3)
   {
     pixelColor.red = 0;
     pixelColor.green = 255;
     pixelColor.blue = (uint8_t)map(age, 21, 30, 0, 255); // 21 -> 31 = 0 -> 255
   }
-  else if (age <= 40)
+  else if (age <= (2 * decay) * 4)
   {
     pixelColor.red = 0;
     pixelColor.green = (uint8_t)map(age, 31, 40, 0, 255); // 31 -> 41 = 255 -> 0
diff --git a/src/display.h b/src/display.h
index 6180d48..793cf83 100644
--- a/src/display.h
+++ b/src/display.h
@@ -14,7 +14,7 @@ extern uint8_t colorB;
 
 void setupDisplay();
 void displayLoop();
-void ageColor(int age);
+void ageColor(int age, int decay);
 void showEndScreen(int ticks);
 void showMessage(char* msg);
 void displayBrightness(int brightness);
-- 
GitLab