home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <signal.h>
- #include <curses.h>
- #include <ctype.h>
- #include <sys/types.h>
- #include <time.h>
- #define DELAYSIZE 100
-
- #ifdef PDCDEBUG
- char *rcsid_firework = "$Header: C:\CURSES\demos\RCS\firework.c 2.1 1993/06/18 20:24:05 MH Rel MH $";
- #endif
-
- main()
- {
- int start,end,row,diff,flag,direction,seed;
- int myrefresh();
- void explode();
-
- initscr();
- if (has_colors())
- start_color();
- seed = time((time_t *)0);
- srand(seed);
- nodelay(stdscr,TRUE);
- raw();
- while(getch() == ERR) /* loop until a key is hit */
- {
- do {
- start = rand() % (COLS -3);
- end = rand() % (COLS - 3);
- start = (start < 2) ? 2 : start;
- end = (end < 2) ? 2 : end;
- direction = (start > end) ? -1 : 1;
- diff = abs(start-end);
- } while (diff<2 || diff>=LINES-2);
- attrset(A_NORMAL);
- for (row=0;row<diff;row++)
- {
- mvprintw(LINES - row,start + (row * direction),
- (direction < 0) ? "\\" : "/");
- if (flag++)
- {
- myrefresh();
- clear();
- flag = 0;
- }
- }
- if (flag++)
- {
- myrefresh();
- flag = 0;
- }
- seed = time((time_t *)0);
- srand(seed);
- explode(LINES-row,start+(diff*direction));
- clear();
- myrefresh();
- }
- endwin();
- exit(0);
- }
- void explode(row,col)
- int row,col;
- {
- clear();
- mvprintw(row,col,"-");
- myrefresh();
-
- init_pair(1,get_colour(),COLOR_BLACK);
- attrset(COLOR_PAIR(1));
- mvprintw(row-1,col-1," - ");
- mvprintw(row,col-1,"-+-");
- mvprintw(row+1,col-1," - ");
- myrefresh();
-
- init_pair(1,get_colour(),COLOR_BLACK);
- attrset(COLOR_PAIR(1));
- mvprintw(row-2,col-2," --- ");
- mvprintw(row-1,col-2,"-+++-");
- mvprintw(row, col-2,"-+#+-");
- mvprintw(row+1,col-2,"-+++-");
- mvprintw(row+2,col-2," --- ");
- myrefresh();
-
- init_pair(1,get_colour(),COLOR_BLACK);
- attrset(COLOR_PAIR(1));
- mvprintw(row-2,col-2," +++ ");
- mvprintw(row-1,col-2,"++#++");
- mvprintw(row, col-2,"+# #+");
- mvprintw(row+1,col-2,"++#++");
- mvprintw(row+2,col-2," +++ ");
- myrefresh();
-
- init_pair(1,get_colour(),COLOR_BLACK);
- attrset(COLOR_PAIR(1));
- mvprintw(row-2,col-2," # ");
- mvprintw(row-1,col-2,"## ##");
- mvprintw(row, col-2,"# #");
- mvprintw(row+1,col-2,"## ##");
- mvprintw(row+2,col-2," # ");
- myrefresh();
-
- init_pair(1,get_colour(),COLOR_BLACK);
- attrset(COLOR_PAIR(1));
- mvprintw(row-2,col-2," # # ");
- mvprintw(row-1,col-2,"# #");
- mvprintw(row, col-2," ");
- mvprintw(row+1,col-2,"# #");
- mvprintw(row+2,col-2," # # ");
- myrefresh();
- return;
- }
- int myrefresh()
- {
- delay_output(DELAYSIZE);
- move(LINES-1,COLS-1);
- refresh();
- }
-
- int get_colour()
- {
- int attr;
- attr = (rand() % 16)+1;
- if (attr == 1 || attr == 9)
- attr = COLOR_RED;
- if (attr > 8)
- attr |= A_BOLD;
- return(attr);
- }
-