]> git.bzium.org - embe/choinka.git/blob - choinka.c
Początkowy import.
[embe/choinka.git] / choinka.c
1 #include <term.h>
2 #include <ncurses.h>
3 #include <stdio.h>
4 #include <stdlib.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   if (attr->attr & A_BOLD) {
41     putp(enter_bold_mode);
42   } else {
43     putp(exit_attribute_mode);
44   }
45   putp(tparm(set_a_foreground, attr->kolor));
46 }
47
48 int main()
49 {
50   srand(time(NULL));
51   setupterm(NULL, 1, NULL);
52   atrybut* kolor = &choinka;
53   for (int i = 0; rysunek[i] != '\0'; i++) {
54     char c = rysunek[i];
55     if (c == '[') kolor = &podstawa;
56     atrybut* akt = kolor;
57     if (c >= 'a' && c <= 'z') akt = &podpis;
58     if (c == '.') akt = &bombki[rand() % ile_b];
59     if (c == '*') akt = &gwiazdka;
60     if (c == ']') kolor = &choinka;
61     ustaw(akt);
62     putchar(c);
63   }
64   putp(exit_attribute_mode);
65   return 0;
66 }