-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.c
More file actions
95 lines (71 loc) · 2.08 KB
/
matrix.c
File metadata and controls
95 lines (71 loc) · 2.08 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
#include <stdlib.h>
#include <curses.h>
#include <term.h>
#include <signal.h>
#include <unistd.h>
#define countof(x) (sizeof(x) / sizeof(*(x)))
const int min_length = 7;
const int max_length = 21;
const int min_spacing = 5;
const int max_spacing = 10;
const char symbols[] = "0123456789qwertyuiopasdfghjkl"
"zxcvbnm,.[]!@#$^&*()-=_+";
const int colors[] = {22, 28, 34, 40, 46, 82, 76, 64, 58};
const int dark_colors[] = {233, 234, 232, 235};
typedef struct {
int length;
int offset;
bool shift;
} stripe_t;
volatile bool run = true;
void terminate(int sig)
{
run = false;
}
int gen_char()
{
return symbols[rand() % (sizeof(symbols) - 1)];
}
int main()
{
signal(SIGINT, terminate);
signal(SIGHUP, terminate);
signal(SIGTERM, terminate);
initscr();
int width = getmaxx(stdscr);
int count = width / 2 - 1;
stripe_t stripes[count];
for (int i = 0; i < count; i++) {
stripes[i].length = rand() % (max_length - min_length) + min_length;
stripes[i].offset = - (rand() % (max_spacing - min_spacing) + min_spacing);
stripes[i].shift = false;
}
while (run) {
for (int i = 0; i < count; i++) {
int color;
stripe_t *s = &stripes[i];
if (s->shift)
putchar(' ');
if (++s->offset > 0) {
color = colors[s->offset % countof(colors)];
} else {
color = dark_colors[s->offset % countof(dark_colors)];
}
tputs(tparm(tigetstr("setaf"), color), 1, putchar);
putchar(gen_char());
if (!s->shift)
putchar(' ');
if (s->offset > s->length) {
s->length = rand() % (max_length - min_length) + min_length;
s->offset = - (rand() % (max_spacing - min_spacing) + min_spacing);
s->shift = !s->shift;
}
}
tputs(tparm(tigetstr("sgr0")), 1, putchar);
putchar('\r');
putchar('\n');
usleep(100000);
}
endwin();
return EXIT_SUCCESS;
}