-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfire.c
61 lines (53 loc) · 1.32 KB
/
fire.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
// Originally written by Matthew Simpson in Python: https://gist.github.com/msimpson/1096950
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
static int *b = NULL;
static int width;
static int height;
static int size;
static void sizechanged()
{
getmaxyx(stdscr, height, width);
size = width * height;
b = (int *)realloc(b, (size + width + 1) * sizeof(int));
memset(b, 0, (size + width + 1) * sizeof(int));
clear();
}
int main()
{
initscr();
const char *charz[] = {" ", ".", ":", "^", "*", "x", "s", "S", "#", "$"};
curs_set(0);
start_color();
init_pair(1, COLOR_BLACK, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_BLACK);
init_pair(4, COLOR_BLUE, COLOR_BLACK);
sizechanged();
while (1)
{
for (int i = 0; i < width / 9; i++)
b[(rand() % width) + width * (height - 1)] = 65;
for (int i = 0; i < size; i++)
{
b[i] = (b[i] + b[i + 1] + b[i + width] + b[i + width + 1]) / 4;
int color = ((b[i] > 15) ? 4 : ((b[i] > 9) ? 3 : ((b[i] > 4) ? 2 : 1)));
if (i < size - 1)
{
attrset(COLOR_PAIR(color) | A_BOLD);
move(i / width, i % width);
addstr(charz[((b[i] > 9) ? 9 : b[i])]);
}
}
refresh();
timeout(30);
int ch = getch();
if ((ch != -1) && (ch != KEY_RESIZE))
break;
if (ch == KEY_RESIZE)
sizechanged();
}
endwin();
return 0;
}