home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / linux / old-src / ncurses-1.8.5 / rain.c < prev    next >
C/C++ Source or Header  |  1993-11-27  |  2KB  |  97 lines

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