home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / languages / progs / curses / examples / c / rain < prev    next >
Encoding:
Text File  |  1992-02-28  |  1.7 KB  |  104 lines

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