-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpanding_circles.c
More file actions
65 lines (51 loc) · 1.53 KB
/
expanding_circles.c
File metadata and controls
65 lines (51 loc) · 1.53 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
#include <ncurses.h>
#include <unistd.h> // For usleep function
#include <math.h> // For sin, cos functions
#define DELAY 50000
#define COLOR_CYCLE 7
int main() {
int x, y;
int max_x, max_y;
float radius = 1.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);
int center_x = max_x / 2;
int center_y = max_y / 2;
while (1) {
clear(); // Clear the screen
// Draw expanding circles
for (float angle = 0; angle < 360; angle += 10) {
float rad = angle * M_PI / 180;
x = center_x + (int)(radius * cos(rad));
y = center_y + (int)(radius * sin(rad));
// Set color and draw circle points
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;
// Increase radius for expansion
radius += 0.5;
if (radius > max_x / 2) {
radius = 1.0; // Reset radius after a certain size
}
// Delay before next frame
usleep(DELAY);
}
// End ncurses mode
endwin();
return 0;
}