/* 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?
{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"},
+};
+
/* -------------------------------------------------------------------------- */
/* Helper Functions */
/* -------------------------------------------------------------------------- */
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);
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)