Skip to content

Commit d996bf2

Browse files
committed
Update textures_screen_buffer.c
1 parent f33823c commit d996bf2

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

examples/textures/textures_screen_buffer.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ int main(void)
5252
float hue = t*t;
5353
float saturation = t;
5454
float value = t;
55+
5556
palette[i] = ColorFromHSV(250.0f + 150.0f*hue, saturation, value);
5657
}
5758

@@ -68,7 +69,7 @@ int main(void)
6869
{
6970
int flame = (int)flameRootBuffer[x];
7071
flame += GetRandomValue(0, 2);
71-
flameRootBuffer[x] = (flameInc > 255)? 255: (unsigned char)flame;
72+
flameRootBuffer[x] = (flame > 255)? 255: (unsigned char)flame;
7273
}
7374

7475
// Transfer flameRoot to indexBuffer
@@ -81,8 +82,7 @@ int main(void)
8182
// Clear top row, because it can't move any higher
8283
for (int x = 0; x < imageWidth; x++)
8384
{
84-
if (indexBuffer[x] == 0) continue;
85-
indexBuffer[x] = 0;
85+
if (indexBuffer[x] != 0) indexBuffer[x] = 0;
8686
}
8787

8888
// Skip top row, it is already cleared
@@ -92,18 +92,22 @@ int main(void)
9292
{
9393
unsigned int i = x + y*imageWidth;
9494
unsigned char colorIndex = indexBuffer[i];
95-
if (colorIndex == 0) continue;
96-
97-
// Move pixel a row above
98-
indexBuffer[i] = 0;
99-
int moveX = GetRandomValue(0, 2) - 1;
100-
int newX = x + moveX;
101-
if (newX < 0 || newX >= imageWidth) continue;
102-
103-
unsigned int iabove = i - imageWidth + moveX;
104-
int decay = GetRandomValue(0, 3);
105-
colorIndex -= (decay < colorIndex)? decay : colorIndex;
106-
indexBuffer[iabove] = colorIndex;
95+
96+
if (colorIndex != 0)
97+
{
98+
// Move pixel a row above
99+
indexBuffer[i] = 0;
100+
int moveX = GetRandomValue(0, 2) - 1;
101+
int newX = x + moveX;
102+
103+
if ((newX > 0) && (newX < imageWidth))
104+
{
105+
unsigned int iabove = i - imageWidth + moveX;
106+
int decay = GetRandomValue(0, 3);
107+
colorIndex -= (decay < colorIndex)? decay : colorIndex;
108+
indexBuffer[iabove] = colorIndex;
109+
}
110+
}
107111
}
108112
}
109113

@@ -115,6 +119,7 @@ int main(void)
115119
unsigned int i = x + y*imageWidth;
116120
unsigned char colorIndex = indexBuffer[i];
117121
Color col = palette[colorIndex];
122+
118123
ImageDrawPixel(&screenImage, x, y, col);
119124
}
120125
}

0 commit comments

Comments
 (0)