- struct state * state = calloc(1, sizeof(*state));
+ struct state * state;
+ XGCValues gcv;
+ XWindowAttributes xgwa;
+ XColor fg, bg;
+ XColor blackx, blacks;
+ size_t color_index;
+ const struct curated_ruleset * curated_ruleset = NULL;
+
+ state = calloc(1, sizeof(*state));
/* Set foreground and background colors for active/inactive cells. Either */
/* the user provided an index into the pre-defined color_list[] or a */
/* random entry from that same array should be selected. */
/* Set foreground and background colors for active/inactive cells. Either */
/* the user provided an index into the pre-defined color_list[] or a */
/* random entry from that same array should be selected. */
if (color_index == -1) {
color_index = random() % sizeof(color_list)/sizeof(color_list[0]);
} else if (color_index >= sizeof(color_list)/sizeof(color_list[0])) {
fprintf(stderr, "WARNING: Color index out of range.\n");
color_index = 0;
}
if (color_index == -1) {
color_index = random() % sizeof(color_list)/sizeof(color_list[0]);
} else if (color_index >= sizeof(color_list)/sizeof(color_list[0])) {
fprintf(stderr, "WARNING: Color index out of range.\n");
color_index = 0;
}
fg.red = color_list[color_index].fg_red;
fg.green = color_list[color_index].fg_green;
fg.blue = color_list[color_index].fg_blue;
fg.red = color_list[color_index].fg_red;
fg.green = color_list[color_index].fg_green;
fg.blue = color_list[color_index].fg_blue;
state->evolution_history = XCreatePixmap(state->dpy, state->win, state->dpy_width, state->num_generations*state->cell_size, xgwa.depth);
/* Pixmap contents are undefined after creation. Explicitly set a black */
/* background by drawing a black rectangle over the entire pixmap. */
state->evolution_history = XCreatePixmap(state->dpy, state->win, state->dpy_width, state->num_generations*state->cell_size, xgwa.depth);
/* Pixmap contents are undefined after creation. Explicitly set a black */
/* background by drawing a black rectangle over the entire pixmap. */
XAllocNamedColor(state->dpy, DefaultColormapOfScreen(DefaultScreenOfDisplay(state->dpy)), "black", &blacks, &blackx);
XSetForeground(state->dpy, state->gc, blacks.pixel);
XFillRectangle(state->dpy, state->evolution_history, state->gc, 0, 0, state->dpy_width, state->num_generations*state->cell_size);
XAllocNamedColor(state->dpy, DefaultColormapOfScreen(DefaultScreenOfDisplay(state->dpy)), "black", &blacks, &blackx);
XSetForeground(state->dpy, state->gc, blacks.pixel);
XFillRectangle(state->dpy, state->evolution_history, state->gc, 0, 0, state->dpy_width, state->num_generations*state->cell_size);
- Bool new_generation[state->dpy_width];
+ Bool * new_generation = malloc(state->dpy_width * sizeof(Bool));
+ if (new_generation == NULL) {
+ fprintf(stderr, "ERROR: Failed to malloc() when calculating new generation.\n");
+ exit(EXIT_FAILURE);
+ }
for (xpos = 0; xpos < state->number_of_cells; xpos++) {
new_generation[xpos] = calculate_cell(state, xpos);
}
for (xpos = 0; xpos < state->number_of_cells; xpos++) {
state->current_generation[xpos] = new_generation[xpos];
}
for (xpos = 0; xpos < state->number_of_cells; xpos++) {
new_generation[xpos] = calculate_cell(state, xpos);
}
for (xpos = 0; xpos < state->number_of_cells; xpos++) {
state->current_generation[xpos] = new_generation[xpos];
}