From 7969381e08dff8056e2a553e164f998d32e65a5d Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sun, 14 Mar 2021 00:37:49 -0800 Subject: [PATCH] Added "number of generations" as a command line flag to WolframAutomata. Also bumped default size of pixels from 1x1 to 2x2 given how many high DPI displays exist now. --- hacks/WolframAutomata/WolframAutomata.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hacks/WolframAutomata/WolframAutomata.c b/hacks/WolframAutomata/WolframAutomata.c index 1dac50e..1327532 100644 --- a/hacks/WolframAutomata/WolframAutomata.c +++ b/hacks/WolframAutomata/WolframAutomata.c @@ -14,7 +14,6 @@ /* TODO: Check manpage for all functions I use and ensure my includes are correct. I don't want to depend on picking up includes via screenhack.h. */ /* TODO: Verify everything in this file is C89. Get rid of things like '//' comments, pack all my declarations upfront, no stdint, etc. */ -/* TODO: Tabs -> Spaces before each commit. */ #include "screenhack.h" @@ -48,7 +47,6 @@ struct state { // TODO: Explain that this holds the whole evolution of the CA and the actual displayed visualization is simply a snapshot into this pixmap. Pixmap evolution_history; - size_t num_generations; // TODO: Explain all of these. unsigned long fg, bg; @@ -61,6 +59,7 @@ struct state { /* Misc Commandline Options */ int pixel_size; /* Size of CA cell in pixels (e.g. pixel_size=3 means 3x3 pixels per cell). */ int delay_microsec; /* Requested delay to screenhack framework before next call to WolframAutomata_draw(). */ + int num_generations; /* Number of generations of the CA to simulate before restarting. */ /* Expository Variables - Not strictly necessary, but makes some code easier to read. */ size_t number_of_cells; @@ -94,10 +93,18 @@ WolframAutomata_init(Display * dpy, Window win) state->number_of_cells = state->xlim / state->pixel_size; + /* + * The minimum number of generations is 2 since we must allocate enough + * space to hold the seed generation and at least one pass through + * WolframAutomata_draw(), which is where we check whether or not we've + * reached the end of the pixmap. + */ + state->num_generations = get_integer_resource(state->dpy, "num-generations", "Integer"); + if (state->num_generations < 0) state->num_generations = 2; + // TODO: These should be command-line options, but I need to learn how the get_integer_resource() and similar functions work first. state->display_info = True; state->ruleset = 30; - state->num_generations = 3000; // TODO: Enforce that this is >1 in order to hold the seed generation and at least one pass through WolframAutomata_draw(), which is where we check for a full pixmap. state->current_generation = calloc(1, (sizeof(*(state->current_generation))*state->number_of_cells)); // TODO: Check calloc() call TODO: Can't recall precedence; can I eliminate any parenthesis? // TODO: Make the starting state a user-configurable option. At least give the user some options like 'random', 'one-middle', 'one edge', etc. @@ -218,7 +225,9 @@ static const char * WolframAutomata_defaults[] = { ".background: black", ".foreground: white", "*delay-usec: 2500", - "*pixel-size: 1", // TODO: Difference between dot and asterisk? Presumably the asterisk matches all resouces of attribute "pixelsize"? + // TODO: Difference between dot and asterisk? Presumably the asterisk matches all resouces of attribute "pixelsize"? Apply answer to all new options. + "*pixel-size: 2", + "*num-generations: 5000", 0 }; @@ -226,6 +235,7 @@ static const char * WolframAutomata_defaults[] = { static XrmOptionDescRec WolframAutomata_options[] = { { "-delay-usec", ".delay-usec", XrmoptionSepArg, 0 }, { "-pixel-size", ".pixel-size", XrmoptionSepArg, 0 }, + { "-num-generations", ".num-generations", XrmoptionSepArg, 0 }, { 0, 0, 0, 0 } }; -- 2.20.1