From: Michał Bartoszkiewicz Date: Mon, 7 Dec 2009 00:10:25 +0000 (+0100) Subject: Początkowy import. X-Git-Tag: v1.0~10 X-Git-Url: https://git.bzium.org/embe/choinka.git/commitdiff_plain/e6c419ea3d0fa00bd36f4a1a5c08dae6479489bf?ds=inline Początkowy import. --- e6c419ea3d0fa00bd36f4a1a5c08dae6479489bf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c2a472 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +CFLAGS := -W -Wall -std=gnu99 +LDLIBS := -lncurses + +all: choinka diff --git a/choinka.c b/choinka.c new file mode 100644 index 0000000..05dc299 --- /dev/null +++ b/choinka.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include + +typedef struct { + int attr; + int kolor; +} atrybut; + +atrybut 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 ile_b = sizeof bombki / sizeof *bombki; + +atrybut choinka = {0, COLOR_GREEN}; +atrybut podstawa = {0, COLOR_YELLOW}; +atrybut podpis = {A_BOLD, COLOR_RED}; +atrybut gwiazdka = {A_BOLD, COLOR_YELLOW}; + +char rysunek[] = +" *\n" +" /.\\\n" +" /..'\\\n" +" /'.'\\\n" +" /.''.'\\\n" +" /.'.'.\\\n" +" /'.''.'.\\\n" +" jgs ^^^[_]^^^\n" +; + +void ustaw(atrybut const* attr) +{ + if (attr->attr & A_BOLD) { + putp(enter_bold_mode); + } else { + putp(exit_attribute_mode); + } + putp(tparm(set_a_foreground, attr->kolor)); +} + +int main() +{ + srand(time(NULL)); + setupterm(NULL, 1, NULL); + atrybut* kolor = &choinka; + for (int i = 0; rysunek[i] != '\0'; i++) { + char c = rysunek[i]; + if (c == '[') kolor = &podstawa; + atrybut* 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; +}