From 90afc4a7b35dca2117bfa9f3e36c82424b0d3856 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sat, 12 Jun 2021 14:28:52 -0700 Subject: [PATCH] General proofreading and cleanup of WolframAutomata.c --- hacks/WolframAutomata/WolframAutomata.c | 39 ++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/hacks/WolframAutomata/WolframAutomata.c b/hacks/WolframAutomata/WolframAutomata.c index fff8a8a..3c7c573 100644 --- a/hacks/WolframAutomata/WolframAutomata.c +++ b/hacks/WolframAutomata/WolframAutomata.c @@ -70,6 +70,8 @@ struct curated_ruleset { enum seed_population seed; }; +/* The following array contains rule numbers and starting seeds which were */ +/* preselected as being visually interesting. */ static const struct curated_ruleset curated_ruleset_list[] = { { 18, middle_cell}, { 30, middle_cell}, @@ -131,6 +133,9 @@ struct color_pair { unsigned short bg_red, bg_green, bg_blue; }; +/* Since randomly selected colors would occasionally produce visually */ +/* indistinguishable foreground/background pairs, this array provides a */ +/* preselected list of complementary color pairs. */ static const struct color_pair color_list[] = { /* For mapping X11 color names to RGB values: */ /* https://www.ehdp.com/methods/x11-color-names-rgb-values.htm */ @@ -174,6 +179,9 @@ static const struct color_pair color_list[] = { /* Helper Functions */ /* -------------------------------------------------------------------------- */ +/* Some rules demonstrate behavior dominated by the starting seed. Thus, in */ +/* addition to a 50/50 random split of active/inactive cells, include other, */ +/* more biased random distributions in order to demonstrate such behavior. */ static void randomize_seed_density(struct state * state) { @@ -307,9 +315,6 @@ WolframAutomata_init(Display * dpy, Window win) bg.red = color_list[color_index].bg_red; bg.green = color_list[color_index].bg_green; bg.blue = color_list[color_index].bg_blue; - /* TODO: Since I 'alloc', presumably I must also 'free' these colors */ - /* at some point. Where/how? I don't want to eventually crash my */ - /* X server after months of use. */ XAllocColor(state->dpy, xgwa.colormap, &fg); XAllocColor(state->dpy, xgwa.colormap, &bg); state->fg = gcv.foreground = fg.pixel; @@ -520,6 +525,20 @@ WolframAutomata_draw(Display * dpy, Window win, void * closure) return state->delay_microsec; } +static void +WolframAutomata_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsigned int h) +{ + struct state * state = closure; + XWindowAttributes xgwa; + XGetWindowAttributes(state->dpy, state->win, &xgwa); + + /* Only restart the simulation if the window changed size. */ + if (state->dpy_width != xgwa.width || state->dpy_height != xgwa.height) { + WolframAutomata_free(dpy, win, closure); + closure = WolframAutomata_init(dpy, win); + } +} + static const char * WolframAutomata_defaults[] = { "*admiration-delay: 5", @@ -570,19 +589,5 @@ static XrmOptionDescRec WolframAutomata_options[] = { { 0, 0, 0, 0 } }; -static void -WolframAutomata_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsigned int h) -{ - struct state * state = closure; - XWindowAttributes xgwa; - XGetWindowAttributes(state->dpy, state->win, &xgwa); - - /* Only restart the simulation if the window changed size. */ - if (state->dpy_width != xgwa.width || state->dpy_height != xgwa.height) { - WolframAutomata_free(dpy, win, closure); - closure = WolframAutomata_init(dpy, win); - } -} - XSCREENSAVER_MODULE ("1D Nearest-Neighbor Cellular Automata", WolframAutomata) -- 2.20.1