9 #define A_POGRUBIONY (1 << 0)
12 #define KOLOR_CZARNY 0
13 #define KOLOR_CZERWONY 1
14 #define KOLOR_ZIELONY 2
15 #define KOLOR_BRAZOWY 3
16 #define KOLOR_NIEBIESKI 4
17 #define KOLOR_MAGENTA 5
26 static atrybut const bombki[] = {
27 {A_POGRUBIONY, KOLOR_CZERWONY},
28 {A_POGRUBIONY, KOLOR_NIEBIESKI},
29 {A_POGRUBIONY, KOLOR_BRAZOWY},
30 {A_POGRUBIONY, KOLOR_MAGENTA},
31 {A_POGRUBIONY, KOLOR_CYJAN},
32 {A_POGRUBIONY, KOLOR_BIALY},
34 static int const ile_b = sizeof bombki / sizeof *bombki;
36 static atrybut const spacja = {0, KOLOR_BRAK};
37 static atrybut const choinka = {0, KOLOR_ZIELONY};
38 static atrybut const podstawa = {0, KOLOR_BRAZOWY};
39 static atrybut const podpis = {A_POGRUBIONY, KOLOR_CZERWONY};
40 static atrybut const gwiazdka = {A_POGRUBIONY, KOLOR_BRAZOWY};
42 static void inicjuj_rng()
46 int f = open("/dev/urandom", O_RDONLY);
48 if (read(f, &ziarno, sizeof ziarno) == sizeof ziarno) {
59 static char const rysunek[] =
70 static void ustaw(atrybut const* attr)
72 static atrybut ostatni = {-1, -1};
73 if (ostatni.attr == attr->attr && ostatni.kolor == attr->kolor) return;
75 putp(exit_attribute_mode);
76 if ((attr->attr & A_POGRUBIONY) != 0) {
77 putp(enter_bold_mode);
79 if (attr->kolor != KOLOR_BRAK) {
80 putp(tparm(set_a_foreground, attr->kolor));
86 setvbuf(stdout, NULL, _IOFBF, BUFSIZ);
88 setupterm(NULL, 1, NULL);
89 atrybut const* kolor = &choinka;
90 for (int i = 0; rysunek[i] != '\0'; i++) {
92 if (c == '[') kolor = &podstawa;
93 atrybut const* akt = kolor;
94 if (c >= 'a' && c <= 'z') akt = &podpis;
95 if (c == '.') akt = &bombki[rand() % ile_b];
96 if (c == '*') akt = &gwiazdka;
97 if (c == ' ' || c == '\n') akt = &spacja;
98 if (c == ']') kolor = &choinka;
102 putp(exit_attribute_mode);