From d996bf2bbd48ff21ccfbd68b87b06ca11eed29e0 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 20 Feb 2026 16:06:59 +0100 Subject: [PATCH] Update textures_screen_buffer.c --- examples/textures/textures_screen_buffer.c | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/textures/textures_screen_buffer.c b/examples/textures/textures_screen_buffer.c index 9f40f180b..9c0f25031 100644 --- a/examples/textures/textures_screen_buffer.c +++ b/examples/textures/textures_screen_buffer.c @@ -52,6 +52,7 @@ int main(void) float hue = t*t; float saturation = t; float value = t; + palette[i] = ColorFromHSV(250.0f + 150.0f*hue, saturation, value); } @@ -68,7 +69,7 @@ int main(void) { int flame = (int)flameRootBuffer[x]; flame += GetRandomValue(0, 2); - flameRootBuffer[x] = (flameInc > 255)? 255: (unsigned char)flame; + flameRootBuffer[x] = (flame > 255)? 255: (unsigned char)flame; } // Transfer flameRoot to indexBuffer @@ -81,8 +82,7 @@ int main(void) // Clear top row, because it can't move any higher for (int x = 0; x < imageWidth; x++) { - if (indexBuffer[x] == 0) continue; - indexBuffer[x] = 0; + if (indexBuffer[x] != 0) indexBuffer[x] = 0; } // Skip top row, it is already cleared @@ -92,18 +92,22 @@ int main(void) { unsigned int i = x + y*imageWidth; unsigned char colorIndex = indexBuffer[i]; - if (colorIndex == 0) continue; - - // Move pixel a row above - indexBuffer[i] = 0; - int moveX = GetRandomValue(0, 2) - 1; - int newX = x + moveX; - if (newX < 0 || newX >= imageWidth) continue; - - unsigned int iabove = i - imageWidth + moveX; - int decay = GetRandomValue(0, 3); - colorIndex -= (decay < colorIndex)? decay : colorIndex; - indexBuffer[iabove] = colorIndex; + + if (colorIndex != 0) + { + // Move pixel a row above + indexBuffer[i] = 0; + int moveX = GetRandomValue(0, 2) - 1; + int newX = x + moveX; + + if ((newX > 0) && (newX < imageWidth)) + { + unsigned int iabove = i - imageWidth + moveX; + int decay = GetRandomValue(0, 3); + colorIndex -= (decay < colorIndex)? decay : colorIndex; + indexBuffer[iabove] = colorIndex; + } + } } } @@ -115,6 +119,7 @@ int main(void) unsigned int i = x + y*imageWidth; unsigned char colorIndex = indexBuffer[i]; Color col = palette[colorIndex]; + ImageDrawPixel(&screenImage, x, y, col); } }