aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-30 21:16:39 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-30 21:16:39 +0000
commit4711fcec5bc1af344bc3be0239df964046c54104 (patch)
tree3ec21a9d34509db422f4deb9f0aba654f8899b6b
parent436c01d5e722dadaa459ae2ec13fb82e72c0784a (diff)
dynamic colors
-rw-r--r--weasel.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/weasel.c b/weasel.c
index 6784c1c..0f2b1f0 100644
--- a/weasel.c
+++ b/weasel.c
@@ -26,13 +26,12 @@
#include <time.h>
#include <unistd.h>
-enum { Red = 1, Green, Cyan, Blue };
-
pthread_mutex_t mutexsum;
pthread_attr_t attr;
int population = 1000;
int mutationrate = 100; /* 1/n */
+int bad;
#if 0
const char defaim[] = "METHINKS IT IS LIKE A WEASEL";
@@ -114,18 +113,19 @@ initpopulation(int length)
void
printcreature(struct creature *c)
{
- if (c->locked)
- attron(COLOR_PAIR(Red));
- else if (c->fitness > 0.95)
- ;
- else if (c->fitness > 0.85)
- attron(COLOR_PAIR(Green));
- else if (c->fitness > 0.70)
- attron(COLOR_PAIR(Cyan));
- else if (c->fitness > 0.47)
- attron(COLOR_PAIR(Blue));
+ //double lg[] = { 0.30, 0.48, 0.60, 0.70, 0.78, 0.85, 0.90, 0.95 };
+ double lg[] = { 0.30, 0.60, 0.80, 0.90 };
+ int i, n;
+
+ for (i = 0, n = 1; i < sizeof(lg)/sizeof(lg[0]); i++)
+ if (c->fitness > lg[i])
+ n++;
+
+ attron(COLOR_PAIR(c->locked ? bad : n));
+
printw("%1.3f\t%s\n", c->fitness, c->genom);
- attroff(COLOR_PAIR(Red)|COLOR_PAIR(Blue)|COLOR_PAIR(Cyan)|COLOR_PAIR(Green));
+
+ attroff(COLOR_PAIR(c->locked ? bad : n));
}
void
@@ -238,6 +238,19 @@ usage(void)
exit(1);
}
+int
+initcolors(void)
+{
+ short c[] = { COLOR_WHITE, COLOR_CYAN, COLOR_YELLOW, COLOR_GREEN, COLOR_WHITE };
+ int i;
+
+ for (i = 0; i < sizeof(c)/sizeof(c[0]); i++)
+ init_pair(i + 1, c[i], COLOR_BLACK);
+
+ init_pair(++i, COLOR_BLACK, COLOR_RED);
+
+ return i;
+}
int
main(int argc, char **argv)
@@ -295,10 +308,7 @@ main(int argc, char **argv)
if (has_colors())
start_color();
- init_pair(Red, COLOR_RED, COLOR_BLACK);
- init_pair(Green, COLOR_GREEN, COLOR_BLACK);
- init_pair(Cyan, COLOR_CYAN, COLOR_BLACK);
- init_pair(Blue, COLOR_BLUE, COLOR_BLACK);
+ bad = initcolors();
pthread_mutex_init(&mutexsum, NULL);
pthread_attr_init(&attr);