1999-08-24 01:06:48 +00:00
|
|
|
/*
|
2002-05-21 05:30:25 +00:00
|
|
|
* $Id: firework.c,v 1.20 2002/03/23 21:41:42 tom Exp $
|
1999-08-24 01:06:48 +00:00
|
|
|
*/
|
|
|
|
#include <time.h>
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
#include <test.priv.h>
|
|
|
|
|
1999-08-24 01:06:48 +00:00
|
|
|
static int my_bg = COLOR_BLACK;
|
|
|
|
|
2000-01-26 16:43:25 +00:00
|
|
|
static void
|
|
|
|
cleanup(void)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-01-26 16:43:25 +00:00
|
|
|
curs_set(1);
|
|
|
|
endwin();
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static RETSIGTYPE
|
|
|
|
onsig(int n GCC_UNUSED)
|
|
|
|
{
|
2000-01-26 16:43:25 +00:00
|
|
|
cleanup();
|
2002-05-21 05:30:25 +00:00
|
|
|
ExitProgram(EXIT_FAILURE);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 16:43:25 +00:00
|
|
|
static void
|
|
|
|
showit(void)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-01-26 16:43:25 +00:00
|
|
|
int ch;
|
|
|
|
napms(120);
|
|
|
|
if ((ch = getch()) != ERR) {
|
|
|
|
#ifdef KEY_RESIZE
|
|
|
|
if (ch == KEY_RESIZE) {
|
|
|
|
erase();
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (ch == 'q') {
|
|
|
|
cleanup();
|
2002-05-21 05:30:25 +00:00
|
|
|
ExitProgram(EXIT_SUCCESS);
|
2000-01-26 16:43:25 +00:00
|
|
|
} else if (ch == 's') {
|
|
|
|
nodelay(stdscr, FALSE);
|
|
|
|
} else if (ch == ' ') {
|
|
|
|
nodelay(stdscr, TRUE);
|
|
|
|
}
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2000-01-26 16:43:25 +00:00
|
|
|
int
|
|
|
|
get_colour(chtype * bold)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-01-26 16:43:25 +00:00
|
|
|
int attr;
|
|
|
|
attr = (rand() % 16) + 1;
|
|
|
|
|
|
|
|
*bold = A_NORMAL;
|
|
|
|
if (attr > 8) {
|
|
|
|
*bold = A_BOLD;
|
|
|
|
attr &= 7;
|
|
|
|
}
|
|
|
|
return (attr);
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-01-26 16:43:25 +00:00
|
|
|
static
|
|
|
|
void
|
|
|
|
explode(int row, int col)
|
|
|
|
{
|
|
|
|
chtype bold;
|
|
|
|
erase();
|
|
|
|
mvprintw(row, col, "-");
|
|
|
|
showit();
|
|
|
|
|
|
|
|
init_pair(1, get_colour(&bold), my_bg);
|
|
|
|
attrset(COLOR_PAIR(1) | bold);
|
|
|
|
mvprintw(row - 1, col - 1, " - ");
|
|
|
|
mvprintw(row + 0, col - 1, "-+-");
|
|
|
|
mvprintw(row + 1, col - 1, " - ");
|
|
|
|
showit();
|
|
|
|
|
|
|
|
init_pair(1, get_colour(&bold), my_bg);
|
|
|
|
attrset(COLOR_PAIR(1) | bold);
|
|
|
|
mvprintw(row - 2, col - 2, " --- ");
|
|
|
|
mvprintw(row - 1, col - 2, "-+++-");
|
|
|
|
mvprintw(row + 0, col - 2, "-+#+-");
|
|
|
|
mvprintw(row + 1, col - 2, "-+++-");
|
|
|
|
mvprintw(row + 2, col - 2, " --- ");
|
|
|
|
showit();
|
|
|
|
|
|
|
|
init_pair(1, get_colour(&bold), my_bg);
|
|
|
|
attrset(COLOR_PAIR(1) | bold);
|
|
|
|
mvprintw(row - 2, col - 2, " +++ ");
|
|
|
|
mvprintw(row - 1, col - 2, "++#++");
|
|
|
|
mvprintw(row + 0, col - 2, "+# #+");
|
|
|
|
mvprintw(row + 1, col - 2, "++#++");
|
|
|
|
mvprintw(row + 2, col - 2, " +++ ");
|
|
|
|
showit();
|
|
|
|
|
|
|
|
init_pair(1, get_colour(&bold), my_bg);
|
|
|
|
attrset(COLOR_PAIR(1) | bold);
|
|
|
|
mvprintw(row - 2, col - 2, " # ");
|
|
|
|
mvprintw(row - 1, col - 2, "## ##");
|
|
|
|
mvprintw(row + 0, col - 2, "# #");
|
|
|
|
mvprintw(row + 1, col - 2, "## ##");
|
|
|
|
mvprintw(row + 2, col - 2, " # ");
|
|
|
|
showit();
|
|
|
|
|
|
|
|
init_pair(1, get_colour(&bold), my_bg);
|
|
|
|
attrset(COLOR_PAIR(1) | bold);
|
|
|
|
mvprintw(row - 2, col - 2, " # # ");
|
|
|
|
mvprintw(row - 1, col - 2, "# #");
|
|
|
|
mvprintw(row + 0, col - 2, " ");
|
|
|
|
mvprintw(row + 1, col - 2, "# #");
|
|
|
|
mvprintw(row + 2, col - 2, " # # ");
|
|
|
|
showit();
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 16:43:25 +00:00
|
|
|
int
|
|
|
|
main(
|
2002-05-21 05:30:25 +00:00
|
|
|
int argc GCC_UNUSED,
|
|
|
|
char *argv[]GCC_UNUSED)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-01-26 16:43:25 +00:00
|
|
|
int j;
|
|
|
|
int start, end, row, diff, flag = 0, direction;
|
|
|
|
unsigned seed;
|
|
|
|
|
|
|
|
for (j = SIGHUP; j <= SIGTERM; j++)
|
|
|
|
if (signal(j, SIG_IGN) != SIG_IGN)
|
|
|
|
signal(j, onsig);
|
|
|
|
|
|
|
|
initscr();
|
|
|
|
noecho();
|
|
|
|
cbreak();
|
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
nodelay(stdscr, TRUE);
|
|
|
|
|
|
|
|
if (has_colors()) {
|
|
|
|
start_color();
|
2000-10-11 07:31:01 +00:00
|
|
|
#if HAVE_USE_DEFAULT_COLORS
|
2000-01-26 16:43:25 +00:00
|
|
|
if (use_default_colors() == OK)
|
|
|
|
my_bg = -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
curs_set(0);
|
|
|
|
|
|
|
|
seed = time((time_t *) 0);
|
|
|
|
srand(seed);
|
|
|
|
for (;;) {
|
|
|
|
do {
|
|
|
|
start = rand() % (COLS - 3);
|
|
|
|
end = rand() % (COLS - 3);
|
|
|
|
start = (start < 2) ? 2 : start;
|
|
|
|
end = (end < 2) ? 2 : end;
|
|
|
|
direction = (start > end) ? -1 : 1;
|
|
|
|
diff = abs(start - end);
|
|
|
|
} while (diff < 2 || diff >= LINES - 2);
|
|
|
|
attrset(A_NORMAL);
|
|
|
|
for (row = 0; row < diff; row++) {
|
|
|
|
mvprintw(LINES - row, start + (row * direction),
|
2002-05-21 05:30:25 +00:00
|
|
|
(direction < 0) ? "\\" : "/");
|
2000-01-26 16:43:25 +00:00
|
|
|
if (flag++) {
|
|
|
|
showit();
|
|
|
|
erase();
|
|
|
|
flag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flag++) {
|
|
|
|
showit();
|
|
|
|
flag = 0;
|
|
|
|
}
|
|
|
|
seed = time((time_t *) 0);
|
|
|
|
srand(seed);
|
|
|
|
explode(LINES - row, start + (diff * direction));
|
|
|
|
erase();
|
|
|
|
showit();
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|