]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/rain.c
ncurses 4.1
[ncurses.git] / test / rain.c
1 /*
2  * $Id: rain.c,v 1.8 1997/05/03 18:38:27 tom Exp $
3  */
4 #include <test.priv.h>
5
6 #include <term.h>       /* for tparm() */
7
8 #include <signal.h>
9
10 /* rain 11/3/1980 EPS/CITHEP */
11
12 #define cursor(col,row) move(row,col)
13
14 static float ranf(void);
15 static void onsig(int sig);
16
17 int
18 main(
19         int argc GCC_UNUSED,
20         char *argv[] GCC_UNUSED)
21 {
22 int x, y, j;
23 static int xpos[5], ypos[5];
24 float r;
25 float c;
26
27     for (j=SIGHUP;j<=SIGTERM;j++)
28         if (signal(j,SIG_IGN)!=SIG_IGN) signal(j,onsig);
29
30     initscr();
31     nl();
32     noecho();
33     curs_set(0);
34
35     r = (float)(LINES - 4);
36     c = (float)(COLS - 4);
37     for (j=5;--j>=0;) {
38                 xpos[j]=(int)(c* ranf())+2;
39                 ypos[j]=(int)(r* ranf())+2;
40     }
41     for (j=0;;) {
42                 x=(int)(c*ranf())+2;
43                 y=(int)(r*ranf())+2;
44
45                 cursor(x,y); addch('.');
46
47                 cursor(xpos[j],ypos[j]); addch('o');
48
49                 if (j==0) j=4; else --j;
50                 cursor(xpos[j],ypos[j]); addch('O');
51
52                 if (j==0) j=4; else --j;
53                 cursor(xpos[j],ypos[j]-1);
54                 addch('-');
55                 cursor(xpos[j]-1,ypos[j]);
56                 addstr("|.|");
57                 cursor(xpos[j],ypos[j]+1);
58                 addch('-');
59
60                 if (j==0) j=4; else --j;
61                 cursor(xpos[j],ypos[j]-2);
62                 addch('-');
63                 cursor(xpos[j]-1,ypos[j]-1);
64                 addstr("/ \\");
65                 cursor(xpos[j]-2,ypos[j]);
66                 addstr("| O |");
67                 cursor(xpos[j]-1,ypos[j]+1);
68                 addstr("\\ /");
69                 cursor(xpos[j],ypos[j]+2);
70                 addch('-');
71
72                 if (j==0) j=4; else --j;
73                 cursor(xpos[j],ypos[j]-2);
74                 addch(' ');
75                 cursor(xpos[j]-1,ypos[j]-1);
76                 addstr("   ");
77                 cursor(xpos[j]-2,ypos[j]);
78                 addstr("     ");
79                 cursor(xpos[j]-1,ypos[j]+1);
80                 addstr("   ");
81                 cursor(xpos[j],ypos[j]+2);
82                 addch(' ');
83                 xpos[j]=x; ypos[j]=y;
84                 refresh();
85                 napms(50);
86     }
87 }
88
89 static void
90 onsig(int n GCC_UNUSED)
91 {
92     curs_set(1);
93     endwin();
94     exit(EXIT_FAILURE);
95 }
96
97 static float
98 ranf(void)
99 {
100     float rv;
101     long r = rand();
102
103     r &= 077777;
104     rv =((float)r/32767.);
105     return rv;
106 }