Browse Source

* examples/:

+ Use Space to pause demos, Esc to quit.
tags/v0.99.beta14
Sam Hocevar sam 20 years ago
parent
commit
5ef8b56c5e
4 changed files with 57 additions and 16 deletions
  1. +16
    -1
      examples/aafire.c
  2. +14
    -2
      examples/cacaball.c
  3. +15
    -2
      examples/cacamoir.c
  4. +12
    -11
      examples/cacaplas.c

+ 16
- 1
examples/aafire.c View File

@@ -40,6 +40,7 @@
static int XSIZ, YSIZ;
static struct caca_bitmap *caca_bitmap;
static char *bitmap;
static int pause = 0;
#else
static aa_context *context;
static aa_renderparams *params;
@@ -193,6 +194,9 @@ drawfire (void)
register unsigned char *p;
#ifndef LIBCACA
char *bitmap = aa_image (context);
#else
if(pause)
goto paused;
#endif

height++;
@@ -216,6 +220,7 @@ drawfire (void)
i = 0;
firemain ();
#ifdef LIBCACA
paused:
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
caca_bitmap, bitmap);
caca_refresh();
@@ -230,14 +235,24 @@ drawfire (void)
static void
game (void)
{
#ifndef LIBCACA
int event;
#endif
gentable ();
#ifdef LIBCACA
while (!(event = caca_get_event(CACA_EVENT_KEY_PRESS)))
for(;;)
#else
while (!(event = aa_getevent (context, 0)) || event == AA_RESIZE)
#endif
{
#ifdef LIBCACA
switch (caca_get_event(CACA_EVENT_KEY_PRESS))
{
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: return;
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause;
}

#endif
drawfire ();
}
}


+ 14
- 2
examples/cacaball.c View File

@@ -57,7 +57,7 @@ int main(int argc, char **argv)
unsigned int x[METABALLS], y[METABALLS];
struct caca_bitmap *caca_bitmap;
float i = 10.0, j = 17.0, k = 11.0;
int p, frame = 0;
int p, frame = 0, pause = 0;

if(caca_init())
return 1;
@@ -86,8 +86,17 @@ int main(int argc, char **argv)
}

/* Go ! */
while(!caca_get_event(CACA_EVENT_KEY_PRESS))
for(;;)
{
switch(caca_get_event(CACA_EVENT_KEY_PRESS))
{
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end;
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause;
}

if(pause)
goto paused;

frame++;

/* Crop the palette */
@@ -134,6 +143,7 @@ int main(int argc, char **argv)
for(p = 0; p < METABALLS; p++)
draw_ball(x[p], y[p]);

paused:
/* Draw our virtual buffer to screen, letting libcaca resize it */
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
caca_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ));
@@ -141,6 +151,8 @@ int main(int argc, char **argv)
}

/* End, bye folks */
end:
caca_free_bitmap(caca_bitmap);
caca_end();

return 0;


+ 15
- 2
examples/cacamoir.c View File

@@ -46,7 +46,7 @@ int main (int argc, char **argv)
{
int red[256], green[256], blue[256], alpha[256];
struct caca_bitmap *bitmap;
int i, x, y, frame;
int i, x, y, frame = 0, pause = 0;

if(caca_init() < 0)
return 1;
@@ -68,8 +68,17 @@ int main (int argc, char **argv)
bitmap = caca_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);

/* Main loop */
for(frame = 0; !caca_get_event(CACA_EVENT_KEY_PRESS); frame++)
for(;;)
{
switch(caca_get_event(CACA_EVENT_KEY_PRESS))
{
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end;
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause;
}

if(pause)
goto paused;

memset(screen, 0, XSIZ * YSIZ);

/* Set the palette */
@@ -92,11 +101,15 @@ int main (int argc, char **argv)
y = sin(0.09 * frame + 1.0) * 64.0 + (YSIZ / 2);
put_disc(x, y);

frame++;

paused:
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
bitmap, screen);
caca_refresh();
}

end:
caca_free_bitmap(bitmap);
caca_end();



+ 12
- 11
examples/cacaplas.c View File

@@ -89,6 +89,9 @@ int main (int argc, char **argv)
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause;
}

if(pause)
goto paused;

for(i = 0 ; i < 256; i++)
{
double z = ((double)i) / 256 * 6 * M_PI;
@@ -101,18 +104,16 @@ int main (int argc, char **argv)
/* Set the palette */
caca_set_bitmap_palette(bitmap, red, green, blue, alpha);

if(!pause)
{
do_plasma(screen,
(1.0 + sin(((double)frame) * R[0])) / 2,
(1.0 + sin(((double)frame) * R[1])) / 2,
(1.0 + sin(((double)frame) * R[2])) / 2,
(1.0 + sin(((double)frame) * R[3])) / 2,
(1.0 + sin(((double)frame) * R[4])) / 2,
(1.0 + sin(((double)frame) * R[5])) / 2);
frame++;
}
do_plasma(screen,
(1.0 + sin(((double)frame) * R[0])) / 2,
(1.0 + sin(((double)frame) * R[1])) / 2,
(1.0 + sin(((double)frame) * R[2])) / 2,
(1.0 + sin(((double)frame) * R[3])) / 2,
(1.0 + sin(((double)frame) * R[4])) / 2,
(1.0 + sin(((double)frame) * R[5])) / 2);
frame++;

paused:
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
bitmap, screen);
caca_refresh();


Loading…
Cancel
Save