HAMMER Utilities: Sync with 60F
[dragonfly.git] / contrib / ncurses-5.4 / test / rain.c
blob19e7f9000c29ba639a8bca2d0b81ba7589b1bd2d
1 /*
2 * $Id: rain.c,v 1.20 2002/06/29 23:32:18 tom Exp $
3 */
4 #include <test.priv.h>
6 /* rain 11/3/1980 EPS/CITHEP */
8 static float ranf(void);
9 static void onsig(int sig);
11 static int
12 next_j(int j)
14 if (j == 0)
15 j = 4;
16 else
17 --j;
18 if (has_colors()) {
19 int z = (int) (3 * ranf());
20 chtype color = COLOR_PAIR(z);
21 if (z)
22 color |= A_BOLD;
23 attrset(color);
25 return j;
28 int
29 main(
30 int argc GCC_UNUSED,
31 char *argv[]GCC_UNUSED)
33 int x, y, j;
34 static int xpos[5], ypos[5];
35 float r;
36 float c;
38 setlocale(LC_ALL, "");
40 for (j = SIGHUP; j <= SIGTERM; j++)
41 if (signal(j, SIG_IGN) != SIG_IGN)
42 signal(j, onsig);
44 initscr();
45 if (has_colors()) {
46 int bg = COLOR_BLACK;
47 start_color();
48 #if HAVE_USE_DEFAULT_COLORS
49 if (use_default_colors() == OK)
50 bg = -1;
51 #endif
52 init_pair(1, COLOR_BLUE, bg);
53 init_pair(2, COLOR_CYAN, bg);
55 nl();
56 noecho();
57 curs_set(0);
58 timeout(0);
60 r = (float) (LINES - 4);
61 c = (float) (COLS - 4);
62 for (j = 5; --j >= 0;) {
63 xpos[j] = (int) (c * ranf()) + 2;
64 ypos[j] = (int) (r * ranf()) + 2;
67 for (j = 0;;) {
68 x = (int) (c * ranf()) + 2;
69 y = (int) (r * ranf()) + 2;
71 mvaddch(y, x, '.');
73 mvaddch(ypos[j], xpos[j], 'o');
75 j = next_j(j);
76 mvaddch(ypos[j], xpos[j], 'O');
78 j = next_j(j);
79 mvaddch(ypos[j] - 1, xpos[j], '-');
80 mvaddstr(ypos[j], xpos[j] - 1, "|.|");
81 mvaddch(ypos[j] + 1, xpos[j], '-');
83 j = next_j(j);
84 mvaddch(ypos[j] - 2, xpos[j], '-');
85 mvaddstr(ypos[j] - 1, xpos[j] - 1, "/ \\");
86 mvaddstr(ypos[j], xpos[j] - 2, "| O |");
87 mvaddstr(ypos[j] + 1, xpos[j] - 1, "\\ /");
88 mvaddch(ypos[j] + 2, xpos[j], '-');
90 j = next_j(j);
91 mvaddch(ypos[j] - 2, xpos[j], ' ');
92 mvaddstr(ypos[j] - 1, xpos[j] - 1, " ");
93 mvaddstr(ypos[j], xpos[j] - 2, " ");
94 mvaddstr(ypos[j] + 1, xpos[j] - 1, " ");
95 mvaddch(ypos[j] + 2, xpos[j], ' ');
97 xpos[j] = x;
98 ypos[j] = y;
100 switch (getch()) {
101 case ('q'):
102 case ('Q'):
103 curs_set(1);
104 endwin();
105 ExitProgram(EXIT_SUCCESS);
106 case 's':
107 nodelay(stdscr, FALSE);
108 break;
109 case ' ':
110 nodelay(stdscr, TRUE);
111 break;
112 #ifdef KEY_RESIZE
113 case (KEY_RESIZE):
114 r = (float) (LINES - 4);
115 c = (float) (COLS - 4);
116 break;
117 #endif
119 napms(50);
123 static void
124 onsig(int n GCC_UNUSED)
126 curs_set(1);
127 endwin();
128 ExitProgram(EXIT_FAILURE);
131 static float
132 ranf(void)
134 long r = (rand() & 077777);
135 return ((float) r / 32768.);