home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / contrib / ncurses-.8 / ncurses-.002 / ncurses- / ncurses-1.8.5 / test / firework.c < prev    next >
C/C++ Source or Header  |  1994-01-31  |  3KB  |  114 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <ncurses.h>
  4. #include <ctype.h>
  5. #include <sys/types.h>
  6. #include <time.h>
  7.  
  8. void explode();
  9.  
  10. int main()
  11. {
  12. int start,end,row,diff,flag,direction,seed;
  13.  
  14.        initscr();
  15.        if (has_colors())
  16.           start_color();
  17.        seed = time((time_t *)0);
  18.        srand(seed);
  19.        cbreak();
  20.        for (;;) {
  21.             do {
  22.                 start = rand() % (COLS -3);
  23.                 end = rand() % (COLS - 3);
  24.                 start = (start < 2) ? 2 : start;
  25.                 end = (end < 2) ? 2 : end;
  26.                 direction = (start > end) ? -1 : 1;
  27.                 diff = abs(start-end);
  28.             } while (diff<2 || diff>=LINES-2);
  29.             attrset(A_NORMAL);
  30.             for (row=0;row<diff;row++) {
  31.                 mvprintw(LINES - row,start + (row * direction),
  32.                     (direction < 0) ? "\\" : "/");
  33.                 if (flag++) {
  34.                     refresh();
  35.                     erase();
  36.                     flag = 0;
  37.                 }
  38.             }
  39.             if (flag++) {
  40.                 refresh();
  41.                 flag = 0;
  42.             }
  43.             seed = time((time_t *)0);
  44.             srand(seed);
  45.             explode(LINES-row,start+(diff*direction));
  46.             erase();
  47.             refresh();
  48.        }
  49.        endwin();
  50.        exit(0);
  51. }
  52.  
  53. void explode(int row, int col)
  54. {
  55.        erase();
  56.        mvprintw(row,col,"-");
  57.        refresh();
  58.  
  59.        init_pair(1,get_colour(),COLOR_BLACK);
  60.        attrset(COLOR_PAIR(1));
  61.        mvprintw(row-1,col-1," - ");
  62.        mvprintw(row,col-1,"-+-");
  63.        mvprintw(row+1,col-1," - ");
  64.        refresh();
  65.  
  66.        init_pair(1,get_colour(),COLOR_BLACK);
  67.        attrset(COLOR_PAIR(1));
  68.        mvprintw(row-2,col-2," --- ");
  69.        mvprintw(row-1,col-2,"-+++-");
  70.        mvprintw(row,  col-2,"-+#+-");
  71.        mvprintw(row+1,col-2,"-+++-");
  72.        mvprintw(row+2,col-2," --- ");
  73.        refresh();
  74.  
  75.        init_pair(1,get_colour(),COLOR_BLACK);
  76.        attrset(COLOR_PAIR(1));
  77.        mvprintw(row-2,col-2," +++ ");
  78.        mvprintw(row-1,col-2,"++#++");
  79.        mvprintw(row,  col-2,"+# #+");
  80.        mvprintw(row+1,col-2,"++#++");
  81.        mvprintw(row+2,col-2," +++ ");
  82.        refresh();
  83.  
  84.        init_pair(1,get_colour(),COLOR_BLACK);
  85.        attrset(COLOR_PAIR(1));
  86.        mvprintw(row-2,col-2,"  #  ");
  87.        mvprintw(row-1,col-2,"## ##");
  88.        mvprintw(row,  col-2,"#   #");
  89.        mvprintw(row+1,col-2,"## ##");
  90.        mvprintw(row+2,col-2,"  #  ");
  91.        refresh();
  92.  
  93.        init_pair(1,get_colour(),COLOR_BLACK);
  94.        attrset(COLOR_PAIR(1));
  95.        mvprintw(row-2,col-2," # # ");
  96.        mvprintw(row-1,col-2,"#   #");
  97.        mvprintw(row,  col-2,"     ");
  98.        mvprintw(row+1,col-2,"#   #");
  99.        mvprintw(row+2,col-2," # # ");
  100.        refresh();
  101.        return;
  102. }
  103.  
  104. int get_colour()
  105. {
  106.  int attr;
  107.        attr = (rand() % 16)+1;
  108.        if (attr == 1 || attr == 9)
  109.           attr = COLOR_RED;
  110.        if (attr > 8)
  111.           attr |= A_BOLD;
  112.        return(attr);
  113. }
  114.