+/* -------------------------------------------------------------------------- */
+/* Helper Functions */
+/* -------------------------------------------------------------------------- */
+
+// TODO: decorations? inline?
+void
+generate_random_seed(struct state * state)
+{
+ int i;
+ for (i = 0; i < state->number_of_cells; i++) {
+ state->current_generation[i] = ((random() % 100) < state->population_density) ? True : False;
+ }
+}
+
+// TODO: function decorations?
+// TODO: Explain why this santizes the index for accessing current_generation (i.e. it creates a circular topology).
+size_t
+sindex(struct state * state, int index)
+{
+ while (index < 0) {
+ index += state->number_of_cells;
+ }
+ while (index >= state->number_of_cells) {
+ index -= state->number_of_cells;
+ }
+ return (size_t) index;
+}
+
+// TODO: function decorations?
+// TODO: At least give a one-sentence explanation of the algorithm since this function is the core of the simulation.
+Bool
+calculate_cell(struct state * state, int cell_id)
+{
+ uint8_t cell_pattern = 0;
+ int i;
+ for (i = -1; i < 2; i++) {
+ cell_pattern = cell_pattern << 1;
+ if (state->current_generation[sindex(state, cell_id+i)] == True) {
+ cell_pattern |= 1;
+ }
+ }
+ if ((state->rule_number >> cell_pattern) & 1) {
+ return True;
+ } else {
+ return False;
+ }
+}
+
+// TODO: function decorations?
+void
+render_current_generation(struct state * state)
+{
+ size_t xpos;
+ for (xpos = 0; xpos < state->number_of_cells; xpos++) {
+ if (state->current_generation[xpos] == True) {
+ XFillRectangle(state->dpy, state->evolution_history, state->gc, xpos*state->pixel_size, state->ypos, state->pixel_size, state->pixel_size);
+ }
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+/* Screenhack API Functions */
+/* -------------------------------------------------------------------------- */
+