-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.c
More file actions
114 lines (86 loc) · 2.03 KB
/
Copy pathmatrix.c
File metadata and controls
114 lines (86 loc) · 2.03 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Falling "matrix" code.
// A simple implementation of ncurses.
//
// vim README for help.
//
// mindfuzz.net
#include <sys/ioctl.h>
#include <stdio.h>
#include <ncurses.h>
#include <time.h>
#include <unistd.h>
#define MAX_CHARS 50
typedef struct coords {
unsigned short int x;
unsigned short int y;
unsigned short int len;
unsigned short int colour;
} point ;
bool mv(int x,int y);
int main(int argc, char *argv[])
{
unsigned short int i, x, y, tmp, swidth, sheight, max_chars;
bool red = false, green = false, blue = false, grey = false;
srand(time(NULL));
if ( argc > 1 ) {
if (strcmp(argv[1], "red") == 0) red = true;
if (strcmp(argv[1], "blue") == 0 ) blue = true;
if (strcmp(argv[1], "green") == 0 ) green = true;
if (strcmp(argv[1], "grey") == 0 ) grey = true;
} else {
green = true;
}
initscr();
getmaxyx(stdscr,sheight,swidth);
sheight--;
swidth--;
point pts[MAX_CHARS];
for(i=0;i<MAX_CHARS; i++) {
pts[i].x=rand() % sheight - (sheight/2);
pts[i].y=rand() % swidth;
pts[i].len=rand() % 13 + 1;
pts[i].colour = rand() % 6 + 1;
};
start_color();
for(tmp = 1; tmp < 8; tmp++) {
init_pair(tmp, tmp, 0);
if (red) init_color(tmp, 100+(tmp*100), 0, 0);
if (green) init_color(tmp, 0, 100+(tmp*100), 0);
if (blue) init_color(tmp, 0, 0, 100+(tmp*100));
if (grey) init_color(tmp, 100+(tmp*100), 100+(tmp*100), 100+(tmp*100));
}
init_color(7, 1000,1000,1000);
while(true)
{
for (i=0;i<MAX_CHARS; i++) {
x = pts[i].x;
y = pts[i].y;
attron(COLOR_PAIR(pts[i].colour));
if (mv(pts[i].x,pts[i].y))
printw("%c", rand() % 93 + 33 );
if (pts[i].x < sheight) {
if (mv(pts[i].x+1,pts[i].y)) {
attron(COLOR_PAIR(7));
printw("%c", rand() % 93 + 33 );
}
}
pts[i].x = pts[i].x + 1;
if (pts[i].x > sheight) {
pts[i].x = rand() % 20;
pts[i].y = rand() % swidth;
}
}
refresh();
usleep(100000/2);
}
getch();
endwin();
return 0;
}
bool mv(int x, int y)
{
if (x < 0) return false;
if (y < 0) return false;
move(x,y);
return true;
}