drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / demos / firework.c
blob61fd65d54951220048fdff18aebd14d5a9c868e3
1 /* $Id: firework.c,v 1.25 2008/07/13 16:08:17 wmcbrine Exp $ */
3 #include <stdio.h>
4 #include <signal.h>
5 #include <curses.h>
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <sys/types.h>
9 #include <time.h>
11 #define DELAYSIZE 200
13 void myrefresh(void);
14 void get_color(void);
15 void explode(int, int);
17 short color_table[] =
19 COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
20 COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
23 int main(int argc, char **argv)
25 int i, start, end, row, diff, flag, direction, seed;
27 #ifdef XCURSES
28 Xinitscr(argc, argv);
29 #else
30 initscr();
31 #endif
32 nodelay(stdscr, TRUE);
33 noecho();
35 if (has_colors())
36 start_color();
38 for (i = 0; i < 8; i++)
39 init_pair(i, color_table[i], COLOR_BLACK);
41 seed = time((time_t *)0);
42 srand(seed);
43 flag = 0;
45 while (getch() == ERR) /* loop until a key is hit */
47 do {
48 start = rand() % (COLS - 3);
49 end = rand() % (COLS - 3);
50 start = (start < 2) ? 2 : start;
51 end = (end < 2) ? 2 : end;
52 direction = (start > end) ? -1 : 1;
53 diff = abs(start - end);
55 } while (diff < 2 || diff >= LINES - 2);
57 attrset(A_NORMAL);
59 for (row = 0; row < diff; row++)
61 mvaddstr(LINES - row, row * direction + start,
62 (direction < 0) ? "\\" : "/");
64 if (flag++)
66 myrefresh();
67 erase();
68 flag = 0;
72 if (flag++)
74 myrefresh();
75 flag = 0;
78 explode(LINES - row, diff * direction + start);
79 erase();
80 myrefresh();
83 endwin();
85 return 0;
88 void explode(int row, int col)
90 erase();
91 mvaddstr(row, col, "-");
92 myrefresh();
94 --col;
96 get_color();
97 mvaddstr(row - 1, col, " - ");
98 mvaddstr(row, col, "-+-");
99 mvaddstr(row + 1, col, " - ");
100 myrefresh();
102 --col;
104 get_color();
105 mvaddstr(row - 2, col, " --- ");
106 mvaddstr(row - 1, col, "-+++-");
107 mvaddstr(row, col, "-+#+-");
108 mvaddstr(row + 1, col, "-+++-");
109 mvaddstr(row + 2, col, " --- ");
110 myrefresh();
112 get_color();
113 mvaddstr(row - 2, col, " +++ ");
114 mvaddstr(row - 1, col, "++#++");
115 mvaddstr(row, col, "+# #+");
116 mvaddstr(row + 1, col, "++#++");
117 mvaddstr(row + 2, col, " +++ ");
118 myrefresh();
120 get_color();
121 mvaddstr(row - 2, col, " # ");
122 mvaddstr(row - 1, col, "## ##");
123 mvaddstr(row, col, "# #");
124 mvaddstr(row + 1, col, "## ##");
125 mvaddstr(row + 2, col, " # ");
126 myrefresh();
128 get_color();
129 mvaddstr(row - 2, col, " # # ");
130 mvaddstr(row - 1, col, "# #");
131 mvaddstr(row, col, " ");
132 mvaddstr(row + 1, col, "# #");
133 mvaddstr(row + 2, col, " # # ");
134 myrefresh();
137 void myrefresh(void)
139 napms(DELAYSIZE);
140 move(LINES - 1, COLS - 1);
141 refresh();
144 void get_color(void)
146 chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL;
147 attrset(COLOR_PAIR(rand() % 8) | bold);