-
Notifications
You must be signed in to change notification settings - Fork 7
/
charsnow.c
64 lines (53 loc) · 1.14 KB
/
charsnow.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <curses.h>
#include <stdlib.h>
#include <time.h>
#include "delayms.h"
void dropchar(char ch, int column, int color, int *heights, int delay)
{
int lowest = heights[column];
int y; for (y=0; y<lowest; y++) {
if (y > 0) mvaddch(y-1, column, ' ');
attron(COLOR_PAIR(color));
mvaddch(y, column, ch);
attroff(COLOR_PAIR(color));
delayms(delay);
refresh();
}
heights[column] --;
}
int main(int argc, char *argv[])
{
int ymax, xmax;
int *heights;
int delay = 30;
if (argc >= 2)
delay = atoi(argv[1]);
initscr();
cbreak();
noecho();
curs_set(0);
srand((unsigned)time(NULL));
getmaxyx(stdscr, ymax, xmax);
heights = malloc(sizeof(int) * (xmax + 1));
int i; for (i=0; i<=xmax; i++) {
heights[i] = ymax;
}
clear();
printw("Press Ctrl+C to stop...");
refresh();
delayms(1000);
clear();
start_color();
for (i=1; i<=7; i++) {
init_pair(i, i, 0);
}
while (1) {
char ch = rand() % 94 + 33;
int x = rand() % (xmax + 1);
int color = rand() % 7 + 1;
if (rand() & 1) attron(A_BOLD);
dropchar(ch, x, color, heights, delay);
attroff(A_BOLD); /*if it wasn't set to begin with nothing will happen*/
}
return 0;
}