X-Git-Url: http://git.subgeniuskitty.com/screensavers/.git/blobdiff_plain/5216b8b29643018d4755189d7141052f80e835b0..90afc4a7b35dca2117bfa9f3e36c82424b0d3856:/hacks/WolframAutomata/WolframAutomata.c diff --git a/hacks/WolframAutomata/WolframAutomata.c b/hacks/WolframAutomata/WolframAutomata.c index 2decd95..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,55 +525,69 @@ 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[] = { - "*delay: 25000", "*admiration-delay: 5", - "*length: 5000", - "*cell-size: 2", + "*color-index: -1", - "*seed-density: -1", - "*seed-left: False", - "*seed-center: False", - "*seed-right: False", + + "*cell-size: 2", "*random-cell-size: False", + + "*delay: 25000", "*random-delay: False", + + "*length: 5000", "*random-length: False", - "*random-rule: False", + "*rule: -1", + "*random-rule: False", + + "*seed-density: -1", + "*seed-left: False", + "*seed-center: False", + "*seed-right: False", + 0 }; static XrmOptionDescRec WolframAutomata_options[] = { - { "-delay", ".delay", XrmoptionSepArg, 0 }, { "-admiration-delay", ".admiration-delay", XrmoptionSepArg, 0 }, - { "-length", ".length", XrmoptionSepArg, 0 }, - { "-cell-size", ".cell-size", XrmoptionSepArg, 0 }, + { "-color-index", ".color-index", XrmoptionSepArg, 0 }, - { "-seed-density", ".seed-density", XrmoptionSepArg, 0 }, - { "-seed-left", ".seed-left", XrmoptionNoArg, "True" }, - { "-seed-center", ".seed-center", XrmoptionNoArg, "True" }, - { "-seed-right", ".seed-right", XrmoptionNoArg, "True" }, + + { "-cell-size", ".cell-size", XrmoptionSepArg, 0 }, { "-random-cell-size", ".random-cell-size", XrmoptionNoArg, "True" }, + + { "-delay", ".delay", XrmoptionSepArg, 0 }, { "-random-delay", ".random-delay", XrmoptionNoArg, "True" }, + + { "-length", ".length", XrmoptionSepArg, 0 }, { "-random-length", ".random-length", XrmoptionNoArg, "True" }, - { "-random-rule", ".random-rule", XrmoptionNoArg, "True" }, + { "-rule", ".rule", XrmoptionSepArg, 0 }, - { 0, 0, 0, 0 } -}; + { "-random-rule", ".random-rule", XrmoptionNoArg, "True" }, -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); + { "-seed-density", ".seed-density", XrmoptionSepArg, 0 }, + { "-seed-left", ".seed-left", XrmoptionNoArg, "True" }, + { "-seed-center", ".seed-center", XrmoptionNoArg, "True" }, + { "-seed-right", ".seed-right", XrmoptionNoArg, "True" }, - /* 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); - } -} + { 0, 0, 0, 0 } +}; XSCREENSAVER_MODULE ("1D Nearest-Neighbor Cellular Automata", WolframAutomata)