From af318014566fbe0bf58363f51eb55ba9dc34f927 Mon Sep 17 00:00:00 2001 From: Jan Grewe <jan@faked.org> Date: Tue, 6 Jun 2023 22:57:50 +0200 Subject: [PATCH] dynamic color aging mode added --- src/display.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++----- src/display.h | 1 + 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index b4fd813..d36ccf9 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -18,6 +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 + SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions); SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions); SMARTMATRIX_ALLOCATE_INDEXED_LAYER(indexedLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kIndexedLayerOptions); @@ -45,11 +47,25 @@ void displayLoop() { if (currentGame[row][col] > 0) { - int age = colorMap[row][col]; - pixelColor.red = (uint8_t)(age == 1 ? 255 : 0); - pixelColor.green = (uint8_t)(age == 2 ? 255 : 0); - pixelColor.blue = (uint8_t)(age > 2 ? 255 : 0); - backgroundLayer.drawPixel(row, col, pixelColor); + if (colorMode > 0) + { + int age = colorMap[row][col]; + if (colorMode == 1) + { + pixelColor.red = (uint8_t)(age == 1 ? 255 : 0); + pixelColor.green = (uint8_t)(age == 2 ? 255 : 0); + pixelColor.blue = (uint8_t)(age > 2 ? 255 : 0); + } + else if (colorMode == 2) + { + ageColor(age); + } + backgroundLayer.drawPixel(row, col, pixelColor); + } + else + { + backgroundLayer.drawPixel(row, col, gameColor); + } } } } @@ -57,6 +73,40 @@ void displayLoop() } } +void ageColor(int age) +{ + if (age <= 10) + { + pixelColor.red = 255; + pixelColor.green = (uint8_t)map(age, 1, 10, 0, 255); // 1 -> 10 = 0 -> 255 + pixelColor.blue = 0; + } + else if (age <= 20) + { + pixelColor.red = (uint8_t)map(age, 11, 20, 255, 0); // 11 -> 20 = 255 -> 0 + pixelColor.green = 255; + pixelColor.blue = 0; + } + else if (age <= 30) + { + pixelColor.red = 0; + pixelColor.green = 255; + pixelColor.blue = (uint8_t)map(age, 21, 30, 0, 255); // 21 -> 31 = 0 -> 255 + } + else if (age <= 40) + { + pixelColor.red = 0; + pixelColor.green = (uint8_t)map(age, 31, 40, 0, 255); // 31 -> 41 = 255 -> 0 + pixelColor.blue = 255; + } + else + { + pixelColor.red = 0; + pixelColor.green = 0; + pixelColor.blue = 255; + } +} + void showMessage(char *msg) { indexedLayer.fillScreen(0); diff --git a/src/display.h b/src/display.h index a0a17cd..6180d48 100644 --- a/src/display.h +++ b/src/display.h @@ -14,6 +14,7 @@ extern uint8_t colorB; void setupDisplay(); void displayLoop(); +void ageColor(int age); void showEndScreen(int ticks); void showMessage(char* msg); void displayBrightness(int brightness); -- GitLab