Added zero-filled option for blank canvas.
This commit is contained in:
parent
ce3ff4797e
commit
318bdfb9c0
@ -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`.
|
||||
|
||||
|
12
conway.c
12
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();
|
||||
|
Loading…
Reference in New Issue
Block a user