home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ncurses-1.9.9e-src.tgz / tar.out / fsf / ncurses / test / rain.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  98 lines

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