1 /****************************************************************************
2 * Copyright (c) 1998-2017,2019 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.36 2019/12/14 23:26:09 tom Exp $
31 #include <test.priv.h>
35 static short my_bg = COLOR_BLACK;
44 onsig(int n GCC_UNUSED)
47 ExitProgram(EXIT_FAILURE);
55 if ((ch = getch()) != ERR) {
57 if (ch == KEY_RESIZE) {
63 ExitProgram(EXIT_SUCCESS);
64 } else if (ch == 's') {
65 nodelay(stdscr, FALSE);
66 } else if (ch == ' ') {
67 nodelay(stdscr, TRUE);
73 get_colour(chtype *bold)
76 attr = (rand() % 16) + 1;
83 return (short) (attr);
88 explode(int row, int col)
92 MvPrintw(row, col, "-");
95 init_pair(1, get_colour(&bold), my_bg);
96 (void) attrset(AttrArg(COLOR_PAIR(1), bold));
97 MvPrintw(row - 1, col - 1, " - ");
98 MvPrintw(row + 0, col - 1, "-+-");
99 MvPrintw(row + 1, col - 1, " - ");
102 init_pair(1, get_colour(&bold), my_bg);
103 (void) attrset(AttrArg(COLOR_PAIR(1), bold));
104 MvPrintw(row - 2, col - 2, " --- ");
105 MvPrintw(row - 1, col - 2, "-+++-");
106 MvPrintw(row + 0, col - 2, "-+#+-");
107 MvPrintw(row + 1, col - 2, "-+++-");
108 MvPrintw(row + 2, col - 2, " --- ");
111 init_pair(1, get_colour(&bold), my_bg);
112 (void) attrset(AttrArg(COLOR_PAIR(1), bold));
113 MvPrintw(row - 2, col - 2, " +++ ");
114 MvPrintw(row - 1, col - 2, "++#++");
115 MvPrintw(row + 0, col - 2, "+# #+");
116 MvPrintw(row + 1, col - 2, "++#++");
117 MvPrintw(row + 2, col - 2, " +++ ");
120 init_pair(1, get_colour(&bold), my_bg);
121 (void) attrset(AttrArg(COLOR_PAIR(1), bold));
122 MvPrintw(row - 2, col - 2, " # ");
123 MvPrintw(row - 1, col - 2, "## ##");
124 MvPrintw(row + 0, col - 2, "# #");
125 MvPrintw(row + 1, col - 2, "## ##");
126 MvPrintw(row + 2, col - 2, " # ");
129 init_pair(1, get_colour(&bold), my_bg);
130 (void) attrset(AttrArg(COLOR_PAIR(1), bold));
131 MvPrintw(row - 2, col - 2, " # # ");
132 MvPrintw(row - 1, col - 2, "# #");
133 MvPrintw(row + 0, col - 2, " ");
134 MvPrintw(row + 1, col - 2, "# #");
135 MvPrintw(row + 2, col - 2, " # # ");
142 static const char *msg[] =
144 "Usage: firework [options]"
147 #if HAVE_USE_DEFAULT_COLORS
148 ," -d invoke use_default_colors, repeat to use in init_pair"
153 for (n = 0; n < SIZEOF(msg); n++)
154 fprintf(stderr, "%s\n", msg[n]);
156 ExitProgram(EXIT_FAILURE);
160 main(int argc, char *argv[])
168 #if HAVE_USE_DEFAULT_COLORS
169 bool d_option = FALSE;
172 while ((ch = getopt(argc, argv, "d")) != -1) {
174 #if HAVE_USE_DEFAULT_COLORS
186 InitAndCatch(initscr(), onsig);
189 keypad(stdscr, TRUE);
190 nodelay(stdscr, TRUE);
194 #if HAVE_USE_DEFAULT_COLORS
195 if (d_option && (use_default_colors() == OK))
201 seed = (unsigned) time((time_t *) 0);
205 start = rand() % (COLS - 3);
206 end = rand() % (COLS - 3);
207 start = (start < 2) ? 2 : start;
208 end = (end < 2) ? 2 : end;
209 direction = (start > end) ? -1 : 1;
210 diff = abs(start - end);
211 } while (diff < 2 || diff >= LINES - 2);
212 (void) attrset(AttrArg(0, A_NORMAL));
213 for (row = 1; row < diff; row++) {
214 MvPrintw(LINES - row, start + (row * direction),
215 (direction < 0) ? "\\" : "/");
226 seed = (unsigned) time((time_t *) 0);
228 explode(LINES - row, start + (diff * direction));