]> git.bzium.org - embe/choinka.git/blob - choinka.c
Uporządkowanie kolejności include’ów.
[embe/choinka.git] / choinka.c
1 #include <ncurses.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <term.h>
5 #include <time.h>
6
7 typedef struct {
8   int attr;
9   int kolor;
10 } atrybut;
11
12 atrybut bombki[] = {
13   {A_BOLD, COLOR_RED},
14   {A_BOLD, COLOR_BLUE},
15   {A_BOLD, COLOR_YELLOW},
16   {A_BOLD, COLOR_MAGENTA},
17   {A_BOLD, COLOR_CYAN},
18   {A_BOLD, COLOR_WHITE},
19 };
20 int ile_b = sizeof bombki / sizeof *bombki;
21
22 atrybut choinka = {0, COLOR_GREEN};
23 atrybut podstawa = {0, COLOR_YELLOW};
24 atrybut podpis = {A_BOLD, COLOR_RED};
25 atrybut gwiazdka = {A_BOLD, COLOR_YELLOW};
26
27 char rysunek[] = 
28 "           *\n"
29 "          /.\\\n"
30 "         /..'\\\n"
31 "         /'.'\\\n"
32 "        /.''.'\\\n"
33 "        /.'.'.\\\n"
34 "       /'.''.'.\\\n"
35 "  jgs  ^^^[_]^^^\n"
36 ;
37
38 void ustaw(atrybut const* attr)
39 {
40   static atrybut ostatni = {-1, -1};
41   if (ostatni.attr == attr->attr && ostatni.kolor == attr->kolor) return;
42   ostatni = *attr;
43   if (attr->attr & A_BOLD) {
44     putp(enter_bold_mode);
45   } else {
46     putp(exit_attribute_mode);
47   }
48   putp(tparm(set_a_foreground, attr->kolor));
49 }
50
51 int main()
52 {
53   srand(time(NULL));
54   setupterm(NULL, 1, NULL);
55   atrybut* kolor = &choinka;
56   for (int i = 0; rysunek[i] != '\0'; i++) {
57     char c = rysunek[i];
58     if (c == '[') kolor = &podstawa;
59     atrybut* akt = kolor;
60     if (c >= 'a' && c <= 'z') akt = &podpis;
61     if (c == '.') akt = &bombki[rand() % ile_b];
62     if (c == '*') akt = &gwiazdka;
63     if (c == ']') kolor = &choinka;
64     ustaw(akt);
65     putchar(c);
66   }
67   putp(exit_attribute_mode);
68   return 0;
69 }