Upload files to "/"
This commit is contained in:
parent
c43379f454
commit
cbfd860935
74
xmas.c
74
xmas.c
@ -16,7 +16,7 @@ typedef struct {
|
|||||||
size_t mx;
|
size_t mx;
|
||||||
size_t my;
|
size_t my;
|
||||||
} SCREEN_SIZE;
|
} SCREEN_SIZE;
|
||||||
SCREEN_SIZE ss;
|
static SCREEN_SIZE ss;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *str;
|
char *str;
|
||||||
@ -24,7 +24,8 @@ typedef struct {
|
|||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
} ENTITY;
|
} ENTITY;
|
||||||
ENTITY names[10];
|
static ENTITY names[10];
|
||||||
|
static ENTITY stars[25];
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
COL_RED = 1,
|
COL_RED = 1,
|
||||||
@ -33,6 +34,7 @@ enum {
|
|||||||
COL_YELLOW,
|
COL_YELLOW,
|
||||||
COL_CYAN,
|
COL_CYAN,
|
||||||
COL_MAGENTA,
|
COL_MAGENTA,
|
||||||
|
COL_WHITE,
|
||||||
COL_COUNT
|
COL_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,32 +57,26 @@ char *persons[] = {
|
|||||||
"Timukra",
|
"Timukra",
|
||||||
"mnnwwn",
|
"mnnwwn",
|
||||||
"dlmk",
|
"dlmk",
|
||||||
"vlnst"
|
"vlnst",
|
||||||
|
"KindFoxie",
|
||||||
|
"leca",
|
||||||
|
"kurator88",
|
||||||
|
"SiberiaBread"
|
||||||
};
|
};
|
||||||
|
|
||||||
void color_print(const int y, const int x, const char *str, const int color) {
|
void add_entity(ENTITY *ent, int y, int x, char *str, int color) {
|
||||||
attron(COLOR_PAIR(color));
|
ent->y = y;
|
||||||
mvprintw(y, x, "%s", str);
|
ent->x = x;
|
||||||
attroff(COLOR_PAIR(color));
|
ent->color = color;
|
||||||
}
|
ent->str = str;
|
||||||
|
|
||||||
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 init_names(int i, int y) {
|
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;
|
int color = rand() % COL_COUNT;
|
||||||
while (color == COL_GREEN)
|
while (color == COL_GREEN)
|
||||||
color = rand() % COL_COUNT;
|
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) {
|
void update_names(void) {
|
||||||
@ -89,7 +85,27 @@ void update_names(void) {
|
|||||||
names[i].y++;
|
names[i].y++;
|
||||||
|
|
||||||
if (names[i].y >= ss.ws.ws_row)
|
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) {
|
int main(void) {
|
||||||
srand(getpid());
|
srand(getpid());
|
||||||
|
|
||||||
/* Fill SCREEN_SIZE structure */
|
/* Fill SCREEN_SIZE struct */
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ss.ws) < 0) {
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ss.ws) < 0) {
|
||||||
fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
|
fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
@ -126,11 +142,12 @@ int main(void) {
|
|||||||
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
|
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
|
||||||
init_pair(5, COLOR_CYAN, COLOR_BLACK);
|
init_pair(5, COLOR_CYAN, COLOR_BLACK);
|
||||||
init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
|
init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
|
||||||
|
init_pair(7, COLOR_WHITE, COLOR_BLACK);
|
||||||
|
|
||||||
if (!has_colors()) {
|
if (!has_colors()) {
|
||||||
endwin();
|
endwin();
|
||||||
|
|
||||||
fputs("colors not supported by your terminal", stderr);
|
fputs("colors are not supported by the terminal", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,20 +159,31 @@ int main(void) {
|
|||||||
for (size_t i = 0; i < ARRAY_SIZE(names); i++)
|
for (size_t i = 0; i < ARRAY_SIZE(names); i++)
|
||||||
init_names(i, 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 */
|
/* Main */
|
||||||
while (1) {
|
while (1) {
|
||||||
clear();
|
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!";
|
char *msg = "HAPPY NEW YEAR!";
|
||||||
mvprintw(0, ss.mx - strlen(msg) / 2, "%s", msg);
|
mvprintw(0, ss.mx - strlen(msg) / 2, "%s", msg);
|
||||||
|
|
||||||
|
/* Tree */
|
||||||
draw_tree();
|
draw_tree();
|
||||||
|
|
||||||
|
/* Names */
|
||||||
update_names();
|
update_names();
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(names); i++)
|
for (size_t i = 0; i < ARRAY_SIZE(names); i++)
|
||||||
color_print(names[i].y, names[i].x, names[i].str, names[i].color);
|
color_print(names[i].y, names[i].x, names[i].str, names[i].color);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
usleep(700000);
|
usleep(600000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user