/* 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. */
+#include <X11/Intrinsic.h>
#include "screenhack.h"
+/*
+ * We do a few manual manipulations of X resources in this hack, like picking
+ * random colors. In order to ensure our manual manipulations always use the
+ * same X resource specification as Xscreensaver, we pass HACKNAME to
+ * Xscreensaver via the XSCREENSAVER_MODULE() line at the bottom of this file,
+ * and then always use HACKNAME or MAKE_STRING(HACKNAME) as the base of the
+ * resource specification when making manual manipulations.
+ */
+#define HACKNAME WolframAutomata
+#define MAKE_STRING_X(s) #s
+#define MAKE_STRING(s) MAKE_STRING_X(s)
+
// Command line options
// directory to output XBM files of each run (and call an external command to convert to PNGs?)
// -save-dir STRING
// delay time (speed of simulation)
// -delay-usec N
// foreground and background color
-// ??? (strings of some sort, but I need to look up what X resources to interact with)
+// -random-colors (highest precedence)
+// -foreground "COLORNAME"
+// -background "COLORNAME"
+// (default is black and white)
+// (mention sample color combinations in manpage, and link to: https://en.wikipedia.org/wiki/X11_color_names)
// display info overlay with CA number and start conditions?
// -overlay
// which ruleset number to use? Or random? Or random from small set of hand-selected interesting examples?
// TODO: Decorations
enum seed_population {
- left_only,
- middle_only,
- right_only,
- random_seed
+ random_cell,
+ middle_cell,
+ edge_cell
};
// TODO: Decorations
enum seed_population seed;
};
-// TODO: Check the full set of 256 CAs for visually interesting examples.
-// TODO: Add comments explaining why each ruleset is interesting.
+// TODO: Decorations
static const struct curated_ruleset curated_ruleset_list[] = {
- {110, random_seed}
+ {18, middle_cell},
+ {30, middle_cell},
+ {45, middle_cell},
+ {54, middle_cell},
+ {57, middle_cell},
+ {73, middle_cell},
+ {105, middle_cell},
+ {109, middle_cell},
+ {129, middle_cell},
+ {133, middle_cell},
+ {135, middle_cell},
+ {150, middle_cell},
+ {30, edge_cell},
+ {45, edge_cell},
+ {57, edge_cell},
+ {60, edge_cell},
+ {75, edge_cell},
+ {107, edge_cell},
+ {110, edge_cell},
+ {133, edge_cell},
+ {137, edge_cell},
+ {169, edge_cell},
+ {225, edge_cell},
+ {22, random_cell},
+ {30, random_cell},
+ {54, random_cell},
+ {62, random_cell},
+ {90, random_cell},
+ {105, random_cell},
+ {108, random_cell},
+ {110, random_cell},
+ {126, random_cell},
+ {146, random_cell},
+ {150, random_cell},
+ {182, random_cell},
+ {184, random_cell},
+ {225, random_cell},
+ {240, random_cell}
+};
+
+// TODO: Decorations
+struct color_pair {
+ char * fg;
+ char * bg;
+};
+
+// TODO: Decorations
+// TODO: Populate this table with more examples.
+static const struct color_pair color_list[] = {
+ {"white", "black"},
};
/* -------------------------------------------------------------------------- */
state->ylim = xgwa.height;
state->ypos = 0; // TODO: Explain why.
+ if (get_boolean_resource(state->dpy, "random-colors", "Boolean")) {
+ XrmDatabase db = XtDatabase(state->dpy);
+ size_t rand_i = random() % sizeof(color_list)/sizeof(color_list[0]);
+ XrmPutStringResource(&db, MAKE_STRING(HACKNAME) ".background", color_list[rand_i].bg);
+ XrmPutStringResource(&db, MAKE_STRING(HACKNAME) ".foreground", color_list[rand_i].fg);
+ }
+
state->fg = gcv.foreground = get_pixel_resource(state->dpy, xgwa.colormap, "foreground", "Foreground");
state->bg = gcv.background = get_pixel_resource(state->dpy, xgwa.colormap, "background", "Background");
state->gc = XCreateGC(state->dpy, state->win, GCForeground, &gcv);
/* setting the seed generation, instead drawing that information from */
/* the curated ruleset. */
switch (curated_ruleset->seed) {
- case random_seed: generate_random_seed(state); break;
- case left_only: state->current_generation[0] = True; break;
- case right_only: state->current_generation[state->number_of_cells-1] = True; break;
- case middle_only: state->current_generation[state->number_of_cells/2] = True; break;
+ case random_cell: generate_random_seed(state); break;
+ case middle_cell: state->current_generation[state->number_of_cells/2] = True; break;
+ case edge_cell : state->current_generation[0] = True; break;
}
} else {
/* If we're not using a curated ruleset, process any relevant flags */
static const char * WolframAutomata_defaults[] = {
".background: black",
".foreground: white",
+ "*random-colors: False",
"*delay-usec: 25000",
// TODO: Difference between dot and asterisk? Presumably the asterisk matches all resouces of attribute "pixelsize"? Apply answer to all new options.
"*pixel-size: 2",
// TODO: Fix formatting
static XrmOptionDescRec WolframAutomata_options[] = {
+ { "-background", ".background", XrmoptionSepArg, 0},
+ { "-foreground", ".foreground", XrmoptionSepArg, 0},
+ { "-random-colors", ".random-colors", XrmoptionNoArg, "True"},
{ "-delay-usec", ".delay-usec", XrmoptionSepArg, 0 },
{ "-pixel-size", ".pixel-size", XrmoptionSepArg, 0 },
{ "-num-generations", ".num-generations", XrmoptionSepArg, 0 },
closure = WolframAutomata_init(dpy, win);
}
-XSCREENSAVER_MODULE ("1D Nearest-Neighbor Cellular Automata", WolframAutomata)
+XSCREENSAVER_MODULE ("1D Nearest-Neighbor Cellular Automata", HACKNAME)