-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzigzag.c
62 lines (49 loc) · 1.4 KB
/
zigzag.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
#include <ncurses.h>
#include <unistd.h> // For usleep function
#include <math.h> // For sin function
#define DELAY 30000 // Delay between frame updates (in microseconds)
#define COLOR_CYCLE 7
int main() {
int x, y;
int max_x, max_y;
float offset = 0.0;
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); // Text color on black background
}
// Get the screen size
getmaxyx(stdscr, max_y, max_x);
while (1) {
clear(); // Clear the screen
// Draw zig-zag pattern
for (y = 0; y < max_y; y++) {
for (x = 0; x < max_x; x++) {
if ((x + (int)offset) % 10 == 0) {
attron(COLOR_PAIR(color_index));
mvprintw(y, x, "#");
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;
// Shift pattern horizontally
offset += 0.3;
if (offset >= 10.0) {
offset = 0.0;
}
// Delay before next frame
usleep(DELAY);
}
// End ncurses mode
endwin();
return 0;
}