Browse Source

* Optimised cacaballs a bit

tags/v0.99.beta14
Jean-Yves Lamoureux jylam 19 years ago
parent
commit
c32b620fb8
1 changed files with 31 additions and 11 deletions
  1. +31
    -11
      src/cacaball.c

+ 31
- 11
src/cacaball.c View File

@@ -49,6 +49,9 @@ int main(int argc, char **argv)
struct cucul_bitmap *cucul_bitmap;
float i = 10.0, j = 17.0, k = 11.0;
int p, frame = 0, pause = 0;
double frameOffset[360+80];
double frameOffset40[360];
double frameOffset80[360];

qq = cucul_init();
if(!qq)
@@ -80,6 +83,13 @@ int main(int argc, char **argv)
dk[p] = (float)cucul_rand(500, 4000) / 6000.0;
}

for(frame = 0; frame<360; frame++) {
frameOffset[frame] = frame * M_PI / 60;
frameOffset40[frame] = (frame + 40) * M_PI / 60;
frameOffset80[frame] = (frame + 80) * M_PI / 60;
}


/* Go ! */
for(;;)
{
@@ -93,26 +103,36 @@ int main(int argc, char **argv)
goto paused;

frame++;
if(frame>=360)
frame=0;

/* Crop the palette */
for(p = CROPBALL; p < 255; p++)
{
int t1, t2, t3;
t1 = p < 0x40 ? 0 : p < 0xc0 ? (p - 0x40) * 0x20 : 0xfff;
double c1 = 1.0 + sin((double)frameOffset[frame]);
double c2 = 1.0 + sin((double)frameOffset40[frame]);
double c3 = 1.0 + sin((double)frameOffset80[frame]);


t1 = p < 0x40 ? 0 : p < 0xc0 ? (p - 0x40) * 0x20 : 0xfff;
t2 = p < 0xe0 ? 0 : (p - 0xe0) * 0x80;
t3 = p < 0x40 ? p * 0x40 : 0xfff;

r[p] = (1.0 + sin((double)frame * M_PI / 60)) * t1 / 4
+ (1.0 + sin((double)(frame + 40) * M_PI / 60)) * t2 / 4
+ (1.0 + sin((double)(frame + 80) * M_PI / 60)) * t3 / 4;
g[p] = (1.0 + sin((double)frame * M_PI / 60)) * t2 / 4
+ (1.0 + sin((double)(frame + 40) * M_PI / 60)) * t3 / 4
+ (1.0 + sin((double)(frame + 80) * M_PI / 60)) * t1 / 4;
b[p] = (1.0 + sin((double)frame * M_PI / 60)) * t3 / 4
+ (1.0 + sin((double)(frame + 40) * M_PI / 60)) * t1 / 4
+ (1.0 + sin((double)(frame + 80) * M_PI / 60)) * t2 / 4;
t1/=4; t2/=4; t3/=4;


r[p] = c1 * t1
+ c2 * t2
+ c3 * t3;
g[p] = c1 * t2
+ c2 * t3
+ c3 * t1;
b[p] = c1 * t3
+ c2 * t1
+ c3 * t2;
}


/* Set the palette */
cucul_set_bitmap_palette(qq, cucul_bitmap, r, g, b, a);



Loading…
Cancel
Save