From e6c419ea3d0fa00bd36f4a1a5c08dae6479489bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Bartoszkiewicz?= Date: Mon, 7 Dec 2009 01:10:25 +0100 Subject: [PATCH] =?utf8?q?Pocz=C4=85tkowy=20import.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++++ choinka.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Makefile create mode 100644 choinka.c 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; +} -- 2.43.2