Skip to content
Snippets Groups Projects
Commit af318014 authored by Jan Grewe's avatar Jan Grewe
Browse files

dynamic color aging mode added

parent 50825214
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......@@ -44,19 +46,67 @@ void displayLoop()
for (int col = 0; col < SCREEN_WIDTH; col++)
{
if (currentGame[row][col] > 0)
{
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);
}
}
}
}
backgroundLayer.swapBuffers(false);
}
}
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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment