1 /****************************************************************************
2 * Copyright (c) 1998-2013,2014 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.30 2014/08/02 17:24:07 tom Exp $
31 #include <test.priv.h>
35 static short 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;
84 return (short) (attr);
89 explode(int row, int col)
93 MvPrintw(row, col, "-");
96 init_pair(1, get_colour(&bold), my_bg);
97 (void) attrset(AttrArg(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 (void) attrset(AttrArg(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 (void) attrset(AttrArg(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 (void) attrset(AttrArg(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 (void) attrset(AttrArg(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 = (unsigned) 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);
176 (void) attrset(AttrArg(0, A_NORMAL));
177 for (row = 0; row < diff; row++) {
178 MvPrintw(LINES - row, start + (row * direction),
179 (direction < 0) ? "\\" : "/");
190 seed = (unsigned) time((time_t *) 0);
192 explode(LINES - row, start + (diff * direction));