-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_rain.c
55 lines (43 loc) · 1.23 KB
/
matrix_rain.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
#include <ncurses.h>
#include <unistd.h> // For usleep function
#include <stdlib.h> // For rand()
#define DELAY 50000
#define COLOR_CYCLE 7
int main() {
int x, y;
int max_x, max_y;
int color_index = 1;
// Initialize ncurses
initscr();
noecho();
curs_set(FALSE);
start_color();
// Define color pairs
for (int i = 1; i <= COLOR_CYCLE; i++) {
init_pair(i, i, COLOR_BLACK);
}
// Get the screen size
getmaxyx(stdscr, max_y, max_x);
while (1) {
clear(); // Clear the screen
// Draw falling characters
for (x = 0; x < max_x; x++) {
for (y = 0; y < max_y; y++) {
if (rand() % 10 < 2) { // Randomly place characters
attron(COLOR_PAIR(color_index));
mvprintw(y, x, "%c", (rand() % 94) + 33); // Random ASCII character
attroff(COLOR_PAIR(color_index));
}
}
}
// Refresh the screen to show changes
refresh();
// Cycle through colors for each frame
color_index = (color_index % COLOR_CYCLE) + 1;
// Delay before next frame
usleep(DELAY);
}
// End ncurses mode
endwin();
return 0;
}