The plasma effect drawing function uses a local buffer, lcd_getClip(), and lcd_drawBitmap() to keep the speed up:
static void drawPlasma(view_t * v) {
int x, y, i;
rect_t clip = lcd_getClip();
color_t buf[clip->right - clip->left];
(void)v;
for (y = clip.top; y < clip.bottom; ++y) {
for (i = 0, x = clip.left; x < clip.right; ++x, ++i) {
buf[i] = pal[0xFF & (
tab[0x1FF & ((pos1 >> 2) + 5 * x)]
+ tab[0x1FF & ((pos2 >> 2) + 3 * x)]
+ tab[0x1FF & ((pos3 >> 2) + 1 * y)]
+ tab[0x1FF & ((pos4 >> 2) + 3 * y)]
)];
}
lcd_drawBitmap((rect_t){ clip.left, y, clip.right, y + 1 }, buf);
}
}
tab is just a sine table, and pal is a color palette, both are placed in flash. I am using the palette from a demo effects collection i found.The plasma is animated:
static void animatePlasma(void) {
pos1 += 9; pos2 += 0; pos3 += 8; pos4 += 0;
}
The pos variables are just static integers starting at 0. Very simple stuff, but also very effective.
Ingen kommentarer:
Send en kommentar