I generate a rainbow palette at startup doing this:
Code:
for (int i = 0; i < copywrite_length; i++)
palette[i + sizeof_base_palette] = HsvToRgb(i * (255 / copywrite_length), 255, 255);
Then, in the main menu loop I have this code:
Code:
for (int i = 0; i < copywrite_length; i++)
{
int palette_index = (i + copywrite_shimmer) % copywrite_length;
gfx_SetTextFGColor(palette_index + sizeof_base_palette);
gfx_SetTextXY(GFX_LCD_WIDTH / 2 - w / 2 + 8 * i, 2);
gfx_PrintChar(copywrite[i]);
}
if (copywrite_shimmer < copywrite_length)
copywrite_shimmer++;
I also could've done something with palette cycling instead of changing which color I draw each letter as. This could have the advantage of not requiring a redraw each time. I'm not concerned with that right now though.
Also, for anyone interesting, the fade effect is really easy to do with the toolchain's gfx_Darken function:
Code:
void fade_out(uint16_t* base_palette, uint8_t start, uint8_t length)
{
for (int step = 255; step >= 0; step--)
{
for (int i = start; i < start + length; i++)
gfx_palette[i] = gfx_Darken(base_palette[i], step);
ticksleep(25);
}
}
void fade_in(uint16_t* base_palette, uint8_t start, uint8_t length)
{
for (int step = 0; step < 256; step++)
{
for (int i = start; i < start + length; i++)
gfx_palette[i] = gfx_Darken(base_palette[i], step);
ticksleep(25);
}
}