Upload files to "/"

This commit is contained in:
8nl 2024-12-27 15:05:29 +00:00
parent c43379f454
commit cbfd860935

74
xmas.c
View File

@ -16,7 +16,7 @@ typedef struct {
size_t mx;
size_t my;
} SCREEN_SIZE;
SCREEN_SIZE ss;
static SCREEN_SIZE ss;
typedef struct {
char *str;
@ -24,7 +24,8 @@ typedef struct {
int x;
int y;
} ENTITY;
ENTITY names[10];
static ENTITY names[10];
static ENTITY stars[25];
enum {
COL_RED = 1,
@ -33,6 +34,7 @@ enum {
COL_YELLOW,
COL_CYAN,
COL_MAGENTA,
COL_WHITE,
COL_COUNT
};
@ -55,32 +57,26 @@ char *persons[] = {
"Timukra",
"mnnwwn",
"dlmk",
"vlnst"
"vlnst",
"KindFoxie",
"leca",
"kurator88",
"SiberiaBread"
};
void color_print(const int y, const int x, const char *str, const int color) {
attron(COLOR_PAIR(color));
mvprintw(y, x, "%s", str);
attroff(COLOR_PAIR(color));
}
void draw_tree(void) {
mvprintw(ss.ws.ws_row - 1, ss.mx - 2, "|___|");
for (unsigned int i = ss.ws.ws_row - 2; i > 0; i--)
for (unsigned int j = 0; j < i * 2; j++)
color_print(i, (int)(ss.mx - i + j), "#", COL_GREEN);
void add_entity(ENTITY *ent, int y, int x, char *str, int color) {
ent->y = y;
ent->x = x;
ent->color = color;
ent->str = str;
}
void init_names(int i, int y) {
names[i].y = y;
names[i].x = ss.mx + (-6 + rand() % 12);
names[i].str = persons[rand() % (sizeof(persons) / sizeof(char *))];
int color = rand() % COL_COUNT;
while (color == COL_GREEN)
color = rand() % COL_COUNT;
names[i].color = color;
add_entity(&names[i], y, ss.mx + (-6 + rand() % 12), persons[rand() % ARRAY_SIZE(persons)], color);
}
void update_names(void) {
@ -89,7 +85,27 @@ void update_names(void) {
names[i].y++;
if (names[i].y >= ss.ws.ws_row)
init_names(i, 0);
init_names(i, 1);
}
}
void color_print(const int y, const int x, const char *str, const int color) {
attron(COLOR_PAIR(color));
mvprintw(y, x, "%s", str);
attroff(COLOR_PAIR(color));
}
void draw_tree(void) {
mvprintw(ss.ws.ws_row - 1, ss.mx - 3, "|_____|");
for (size_t i = ss.ws.ws_row - 2; i > 0; i--) {
for (size_t j = 0; j < i; j++) {
color_print(i, (int)(ss.mx + j), "-", COL_GREEN);
color_print(i, (int)(ss.mx - j), "-", COL_GREEN);
}
if (i == 1)
color_print(i, ss.mx, "@", COL_YELLOW);
}
}
@ -103,7 +119,7 @@ void sig_handler(int sig) {
int main(void) {
srand(getpid());
/* Fill SCREEN_SIZE structure */
/* Fill SCREEN_SIZE struct */
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ss.ws) < 0) {
fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
return 1;
@ -126,11 +142,12 @@ int main(void) {
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
init_pair(5, COLOR_CYAN, COLOR_BLACK);
init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
init_pair(7, COLOR_WHITE, COLOR_BLACK);
if (!has_colors()) {
endwin();
fputs("colors not supported by your terminal", stderr);
fputs("colors are not supported by the terminal", stderr);
return 1;
}
@ -142,20 +159,31 @@ int main(void) {
for (size_t i = 0; i < ARRAY_SIZE(names); i++)
init_names(i, i);
/* Add stars */
for (size_t i = 0; i < ARRAY_SIZE(stars); i++)
add_entity(&stars[i], rand() % ss.my, rand() % ss.ws.ws_col, ".", COLOR_WHITE);
/* Main */
while (1) {
clear();
/* Stars */
for (size_t i = 0; i < ARRAY_SIZE(stars); i++)
color_print(stars[i].y, stars[i].x, stars[i].str, stars[i].color);
/* Title */
char *msg = "HAPPY NEW YEAR!";
mvprintw(0, ss.mx - strlen(msg) / 2, "%s", msg);
/* Tree */
draw_tree();
/* Names */
update_names();
for (size_t i = 0; i < ARRAY_SIZE(names); i++)
color_print(names[i].y, names[i].x, names[i].str, names[i].color);
refresh();
usleep(700000);
usleep(600000);
}
}