Merge branch 'vendor/GCC44'
[dragonfly.git] / contrib / ncurses-5.4 / test / firework.c
blob3d84c4399139d3c9c7839d7a3f668ef17cb41f70
1 /*
2 * $Id: firework.c,v 1.20 2002/03/23 21:41:42 tom Exp $
3 */
4 #include <time.h>
6 #include <test.priv.h>
8 static int my_bg = COLOR_BLACK;
10 static void
11 cleanup(void)
13 curs_set(1);
14 endwin();
17 static RETSIGTYPE
18 onsig(int n GCC_UNUSED)
20 cleanup();
21 ExitProgram(EXIT_FAILURE);
24 static void
25 showit(void)
27 int ch;
28 napms(120);
29 if ((ch = getch()) != ERR) {
30 #ifdef KEY_RESIZE
31 if (ch == KEY_RESIZE) {
32 erase();
33 } else
34 #endif
35 if (ch == 'q') {
36 cleanup();
37 ExitProgram(EXIT_SUCCESS);
38 } else if (ch == 's') {
39 nodelay(stdscr, FALSE);
40 } else if (ch == ' ') {
41 nodelay(stdscr, TRUE);
46 static
47 int
48 get_colour(chtype * bold)
50 int attr;
51 attr = (rand() % 16) + 1;
53 *bold = A_NORMAL;
54 if (attr > 8) {
55 *bold = A_BOLD;
56 attr &= 7;
58 return (attr);
61 static
62 void
63 explode(int row, int col)
65 chtype bold;
66 erase();
67 mvprintw(row, col, "-");
68 showit();
70 init_pair(1, get_colour(&bold), my_bg);
71 attrset(COLOR_PAIR(1) | bold);
72 mvprintw(row - 1, col - 1, " - ");
73 mvprintw(row + 0, col - 1, "-+-");
74 mvprintw(row + 1, col - 1, " - ");
75 showit();
77 init_pair(1, get_colour(&bold), my_bg);
78 attrset(COLOR_PAIR(1) | bold);
79 mvprintw(row - 2, col - 2, " --- ");
80 mvprintw(row - 1, col - 2, "-+++-");
81 mvprintw(row + 0, col - 2, "-+#+-");
82 mvprintw(row + 1, col - 2, "-+++-");
83 mvprintw(row + 2, col - 2, " --- ");
84 showit();
86 init_pair(1, get_colour(&bold), my_bg);
87 attrset(COLOR_PAIR(1) | bold);
88 mvprintw(row - 2, col - 2, " +++ ");
89 mvprintw(row - 1, col - 2, "++#++");
90 mvprintw(row + 0, col - 2, "+# #+");
91 mvprintw(row + 1, col - 2, "++#++");
92 mvprintw(row + 2, col - 2, " +++ ");
93 showit();
95 init_pair(1, get_colour(&bold), my_bg);
96 attrset(COLOR_PAIR(1) | bold);
97 mvprintw(row - 2, col - 2, " # ");
98 mvprintw(row - 1, col - 2, "## ##");
99 mvprintw(row + 0, col - 2, "# #");
100 mvprintw(row + 1, col - 2, "## ##");
101 mvprintw(row + 2, col - 2, " # ");
102 showit();
104 init_pair(1, get_colour(&bold), my_bg);
105 attrset(COLOR_PAIR(1) | bold);
106 mvprintw(row - 2, col - 2, " # # ");
107 mvprintw(row - 1, col - 2, "# #");
108 mvprintw(row + 0, col - 2, " ");
109 mvprintw(row + 1, col - 2, "# #");
110 mvprintw(row + 2, col - 2, " # # ");
111 showit();
115 main(
116 int argc GCC_UNUSED,
117 char *argv[]GCC_UNUSED)
119 int j;
120 int start, end, row, diff, flag = 0, direction;
121 unsigned seed;
123 for (j = SIGHUP; j <= SIGTERM; j++)
124 if (signal(j, SIG_IGN) != SIG_IGN)
125 signal(j, onsig);
127 initscr();
128 noecho();
129 cbreak();
130 keypad(stdscr, TRUE);
131 nodelay(stdscr, TRUE);
133 if (has_colors()) {
134 start_color();
135 #if HAVE_USE_DEFAULT_COLORS
136 if (use_default_colors() == OK)
137 my_bg = -1;
138 #endif
140 curs_set(0);
142 seed = time((time_t *) 0);
143 srand(seed);
144 for (;;) {
145 do {
146 start = rand() % (COLS - 3);
147 end = rand() % (COLS - 3);
148 start = (start < 2) ? 2 : start;
149 end = (end < 2) ? 2 : end;
150 direction = (start > end) ? -1 : 1;
151 diff = abs(start - end);
152 } while (diff < 2 || diff >= LINES - 2);
153 attrset(A_NORMAL);
154 for (row = 0; row < diff; row++) {
155 mvprintw(LINES - row, start + (row * direction),
156 (direction < 0) ? "\\" : "/");
157 if (flag++) {
158 showit();
159 erase();
160 flag = 0;
163 if (flag++) {
164 showit();
165 flag = 0;
167 seed = time((time_t *) 0);
168 srand(seed);
169 explode(LINES - row, start + (diff * direction));
170 erase();
171 showit();