From 318bdfb9c0cfdaf83465720f0e34a9acc6a66ce1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 18 Mar 2019 16:48:54 -0700 Subject: [PATCH] Added zero-filled option for blank canvas. --- README.md | 6 +++++- conway.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 358a529..82c8237 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Conway A termbox program for running Conway's Game of Life. -Different rulesets can be used with `conway -S23 -B3` syntax. + +# Usage +Different rulesets can be provided with the `conway -S23 -B3` flags. To start +with a blank canvas instead of a randomized canvas, use `-Z`. + diff --git a/conway.c b/conway.c index 6b05a2b..4f8335c 100644 --- a/conway.c +++ b/conway.c @@ -29,9 +29,10 @@ static void update(const char *cells, char *future_cells) } int main(int argc, char **argv) { + int randomize = 1; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--help") == 0) { - printf("Conway's Game of Life Viewer\nUsage: conway [-S012345678] [-B012345678]\n"); + printf("Conway's Game of Life Viewer\nUsage: conway [-Z] [-S012345678] [-B012345678]\n"); return 0; } else if (strncmp(argv[i], "-B", 2) == 0) { memset(rules[0], 0, sizeof(rules[0])); @@ -45,6 +46,8 @@ int main(int argc, char **argv) { if ('0' <= *p && *p <= '8') rules[1][*p - '0'] = 1; } + } else if (strcmp(argv[i], "-Z") == 0) { + randomize = 0; } } @@ -62,9 +65,10 @@ int main(int argc, char **argv) { W = tb_width()/2, H = tb_height(); buffers[0] = calloc(W*H, sizeof(char)); buffers[1] = calloc(W*H, sizeof(char)); - for (int x = 0; x < W; x++) - for (int y = 0; y < H; y++) - CELL(buffers[flipflop], x, y) = random() % 2; + if (randomize) + for (int x = 0; x < W; x++) + for (int y = 0; y < H; y++) + CELL(buffers[flipflop], x, y) = random() % 2; int draw_mode = 1; tb_clear();