Index: cap.c =================================================================== --- cap.c (revision 7386) +++ cap.c (revision 7387) @@ -44,11 +44,46 @@ s->th = myrand(1, 20); } +pcb_t *default_new = NULL; + +pcb_t *load_str(char *fn) +{ + char line[256]; + FILE *f = fopen(fn, "r"); + pcb_t *p; + if (f == NULL) + return 0; + p = calloc(sizeof(pcb_t), 1); + while(fgets(line, sizeof(line), f) != NULL) { + char *s = line; + int x1, y1, x2, y2, th; + if (strncmp(s, "stroke", 6) == 0) + s+=6; + + if (sscanf(s, "%d %d %d %d %d", &x1, &y1, &x2, &y2, &th) == 5) { + stroke_t *s = &p->str[p->len]; + s->x1 = x1; + s->y1 = y1; + s->x2 = x2; + s->y2 = y2; + s->th = th; + p->len++; + } + } + fclose(f); + return p; +} + void *pcb_create(void) { pcb_t *p = malloc(sizeof(pcb_t)); int n; + if (default_new != NULL) { + memcpy(p, default_new, sizeof(pcb_t)); + return p; + } + p->len = myrand(1, max_strokes/2); for(n = 0; n < p->len; n++) rand_stroke(&p->str[n]); @@ -125,7 +160,7 @@ pcb_clear(canvas); pcb_draw(canvas, data); scr = pcb_diff(canvas, ref); - return scr + (p->len+1)*5.0; + return scr + (p->len+1)*50.0; } static inline void pcb_mutate_add(pcb_t *p) @@ -134,16 +169,16 @@ if (p->len >= MAX_STROKES) return; - loc = myrand(0, black_len); + loc = myrand(0, black_len-1); - x = image_x(ref, ref->pixmap+loc); - y = image_y(ref, ref->pixmap+loc); + x = image_x(ref, ref->pixmap+black[loc]); + y = image_y(ref, ref->pixmap+black[loc]); p->str[p->len].x1 = x; - p->str[p->len].x2 = y; - p->str[p->len].x2 = x + myrand(2, 30); - p->str[p->len].y2 = y + myrand(2, 30); - p->str[p->len].th = myrand(3, 20); + p->str[p->len].y1 = y; + p->str[p->len].x2 = x + myrand(2, 20) - 10; + p->str[p->len].y2 = y + myrand(2, 20) - 10; + p->str[p->len].th = myrand(3, 10); p->len++; } @@ -219,7 +254,6 @@ return s; } - gp_pop_t pop = { .len = 16, .weak_kill = 5, @@ -239,6 +273,9 @@ if (argv[1] != NULL) ref_fn = argv[1]; + if (argv[2] != NULL) + default_new = load_str(argv[2]); + srand(time(NULL)); ref = pnm_load(ref_fn);