#include #include #include #include #include typedef struct { int attr; int kolor; } atrybut; atrybut const bombki[] = { {A_BOLD, COLOR_RED}, {A_BOLD, COLOR_BLUE}, {A_BOLD, COLOR_YELLOW}, {A_BOLD, COLOR_MAGENTA}, {A_BOLD, COLOR_CYAN}, {A_BOLD, COLOR_WHITE}, }; int const ile_b = sizeof bombki / sizeof *bombki; atrybut const choinka = {0, COLOR_GREEN}; atrybut const podstawa = {0, COLOR_YELLOW}; atrybut const podpis = {A_BOLD, COLOR_RED}; atrybut const gwiazdka = {A_BOLD, COLOR_YELLOW}; void inicjuj_rng() { unsigned ziarno = 0; FILE* f = fopen("/dev/urandom", "rb"); if (f != NULL) { unsigned nowe_ziarno; if (fread(&nowe_ziarno, sizeof nowe_ziarno, 1, f) == 1) { ziarno = nowe_ziarno; } fclose(f); } if (ziarno == 0) { ziarno = time(NULL); } srand(ziarno); } char const rysunek[] = " *\n" " /.\\\n" " /..'\\\n" " /'.'\\\n" " /.''.'\\\n" " /.'.'.\\\n" " /'.''.'.\\\n" " jgs ^^^[_]^^^\n" ; void ustaw(atrybut const* attr) { static atrybut ostatni = {-1, -1}; if (ostatni.attr == attr->attr && ostatni.kolor == attr->kolor) return; ostatni = *attr; if (attr->attr & A_BOLD) { putp(enter_bold_mode); } else { putp(exit_attribute_mode); } putp(tparm(set_a_foreground, attr->kolor)); } int main() { inicjuj_rng(); setupterm(NULL, 1, NULL); atrybut const* kolor = &choinka; for (int i = 0; rysunek[i] != '\0'; i++) { char c = rysunek[i]; if (c == '[') kolor = &podstawa; atrybut const* akt = kolor; if (c >= 'a' && c <= 'z') akt = &podpis; if (c == '.') akt = &bombki[rand() % ile_b]; if (c == '*') akt = &gwiazdka; if (c == ']') kolor = &choinka; ustaw(akt); putchar(c); } putp(exit_attribute_mode); return 0; }