1 /****************************************************************************
2 * Copyright (c) 1998-2006,2008 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: rain.c,v 1.26 2008/03/09 00:17:09 tom Exp $
31 #include <test.priv.h>
33 /* rain 11/3/1980 EPS/CITHEP */
45 typedef void (*DrawPart) (struct DATA *);
57 onsig(int n GCC_UNUSED)
61 ExitProgram(EXIT_FAILURE);
67 long r = (rand() & 077777);
68 return ((float) r / 32768.);
74 return (((float) (COLS - 4) * ranf()) + 2);
80 return (((float) (LINES - 4) * ranf()) + 2);
91 int z = (int) (3 * ranf());
92 chtype color = COLOR_PAIR(z);
103 mvaddch(drop->y, drop->x, '.');
109 mvaddch(drop->y, drop->x, 'o');
115 mvaddch(drop->y, drop->x, 'O');
121 mvaddch(drop->y - 1, drop->x, '-');
122 mvaddstr(drop->y, drop->x - 1, "|.|");
123 mvaddch(drop->y + 1, drop->x, '-');
129 mvaddch(drop->y - 2, drop->x, '-');
130 mvaddstr(drop->y - 1, drop->x - 1, "/ \\");
131 mvaddstr(drop->y, drop->x - 2, "| O |");
132 mvaddstr(drop->y + 1, drop->x - 1, "\\ /");
133 mvaddch(drop->y + 2, drop->x, '-');
139 mvaddch(drop->y - 2, drop->x, ' ');
140 mvaddstr(drop->y - 1, drop->x - 1, " ");
141 mvaddstr(drop->y, drop->x - 2, " ");
142 mvaddstr(drop->y + 1, drop->x - 1, " ");
143 mvaddch(drop->y + 2, drop->x, ' ');
155 * This runs inside the mutex.
158 really_draw(WINDOW *win, void *arg)
160 DATA *data = (DATA *) arg;
169 draw_part(void (*func) (DATA *), int state, DATA * data)
173 use_window(stdscr, really_draw, (void *) data);
182 mydata = *(DATA *) arg; /* make a copy of caller's data */
184 draw_part(part1, 0, &mydata);
185 draw_part(part2, 1, &mydata);
186 draw_part(part3, 2, &mydata);
187 draw_part(part4, 3, &mydata);
188 draw_part(part5, 4, &mydata);
189 draw_part(part6, 0, &mydata);
199 ch = USING_WINDOW(stdscr, wgetch);
204 main(int argc GCC_UNUSED,
205 char *argv[]GCC_UNUSED)
212 setlocale(LC_ALL, "");
218 int bg = COLOR_BLACK;
220 #if HAVE_USE_DEFAULT_COLORS
221 if (use_default_colors() == OK)
224 init_pair(1, COLOR_BLUE, bg);
225 init_pair(2, COLOR_CYAN, bg);
232 for (j = MAX_DROP; --j >= 0;) {
233 last[j].x = random_x();
234 last[j].y = random_y();
242 if (pthread_create(&(drop.thread), NULL, draw_drop, &drop)) {
249 * The non-threaded code draws parts of each drop on each loop.
270 switch (get_input()) {
276 nodelay(stdscr, FALSE);
279 nodelay(stdscr, TRUE);
290 ExitProgram(EXIT_SUCCESS);