1 /****************************************************************************
2 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: firework.c,v 1.24 2006/05/20 15:36:08 tom Exp $
31 #include <test.priv.h>
35 static int my_bg = COLOR_BLACK;
45 onsig(int n GCC_UNUSED)
48 ExitProgram(EXIT_FAILURE);
56 if ((ch = getch()) != ERR) {
58 if (ch == KEY_RESIZE) {
64 ExitProgram(EXIT_SUCCESS);
65 } else if (ch == 's') {
66 nodelay(stdscr, FALSE);
67 } else if (ch == ' ') {
68 nodelay(stdscr, TRUE);
74 get_colour(chtype *bold)
77 attr = (rand() % 16) + 1;
89 explode(int row, int col)
93 mvprintw(row, col, "-");
96 init_pair(1, get_colour(&bold), my_bg);
97 attrset(COLOR_PAIR(1) | bold);
98 mvprintw(row - 1, col - 1, " - ");
99 mvprintw(row + 0, col - 1, "-+-");
100 mvprintw(row + 1, col - 1, " - ");
103 init_pair(1, get_colour(&bold), my_bg);
104 attrset(COLOR_PAIR(1) | bold);
105 mvprintw(row - 2, col - 2, " --- ");
106 mvprintw(row - 1, col - 2, "-+++-");
107 mvprintw(row + 0, col - 2, "-+#+-");
108 mvprintw(row + 1, col - 2, "-+++-");
109 mvprintw(row + 2, col - 2, " --- ");
112 init_pair(1, get_colour(&bold), my_bg);
113 attrset(COLOR_PAIR(1) | bold);
114 mvprintw(row - 2, col - 2, " +++ ");
115 mvprintw(row - 1, col - 2, "++#++");
116 mvprintw(row + 0, col - 2, "+# #+");
117 mvprintw(row + 1, col - 2, "++#++");
118 mvprintw(row + 2, col - 2, " +++ ");
121 init_pair(1, get_colour(&bold), my_bg);
122 attrset(COLOR_PAIR(1) | bold);
123 mvprintw(row - 2, col - 2, " # ");
124 mvprintw(row - 1, col - 2, "## ##");
125 mvprintw(row + 0, col - 2, "# #");
126 mvprintw(row + 1, col - 2, "## ##");
127 mvprintw(row + 2, col - 2, " # ");
130 init_pair(1, get_colour(&bold), my_bg);
131 attrset(COLOR_PAIR(1) | bold);
132 mvprintw(row - 2, col - 2, " # # ");
133 mvprintw(row - 1, col - 2, "# #");
134 mvprintw(row + 0, col - 2, " ");
135 mvprintw(row + 1, col - 2, "# #");
136 mvprintw(row + 2, col - 2, " # # ");
143 char *argv[]GCC_UNUSED)
145 int start, end, row, diff, flag = 0, direction;
153 keypad(stdscr, TRUE);
154 nodelay(stdscr, TRUE);
158 #if HAVE_USE_DEFAULT_COLORS
159 if (use_default_colors() == OK)
165 seed = time((time_t *) 0);
169 start = rand() % (COLS - 3);
170 end = rand() % (COLS - 3);
171 start = (start < 2) ? 2 : start;
172 end = (end < 2) ? 2 : end;
173 direction = (start > end) ? -1 : 1;
174 diff = abs(start - end);
175 } while (diff < 2 || diff >= LINES - 2);
177 for (row = 0; row < diff; row++) {
178 mvprintw(LINES - row, start + (row * direction),
179 (direction < 0) ? "\\" : "/");
190 seed = time((time_t *) 0);
192 explode(LINES - row, start + (diff * direction));