]> git.bzium.org - embe/choinka.git/commitdiff
Początkowy import.
authorMichał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
Mon, 7 Dec 2009 00:10:25 +0000 (01:10 +0100)
committerMichał Bartoszkiewicz <mbartoszkiewicz@gmail.com>
Mon, 7 Dec 2009 00:10:25 +0000 (01:10 +0100)
Makefile [new file with mode: 0644]
choinka.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..05dc299
--- /dev/null
+++ b/choinka.c
@@ -0,0 +1,66 @@
+#include <term.h>
+#include <ncurses.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+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;
+}