diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-04-29 23:47:09 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-05-02 09:08:47 -0700 |
commit | d1199af772011338f7419666911196bcb8d8d6a6 (patch) | |
tree | d91aadc1fdd1d663bfe7d760073ce01e3b0ee602 | |
parent | 8292d95533801b41ee4b05edc0bf296394085528 (diff) |
modules/checkers: add dynamics=sonar radiating wave
just another dynamic illumination pattern
could use some more work like controlling the rate and thickness
-rw-r--r-- | src/modules/checkers/checkers.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c index 27da42b..c4e02c1 100644 --- a/src/modules/checkers/checkers.c +++ b/src/modules/checkers/checkers.c @@ -38,6 +38,7 @@ typedef enum checkers_dynamics_t { CHECKERS_DYNAMICS_EVEN, CHECKERS_DYNAMICS_ALTERNATING, CHECKERS_DYNAMICS_RANDOM, + CHECKERS_DYNAMICS_SONAR, } checkers_dynamics_t; typedef struct checkers_setup_t { @@ -49,6 +50,7 @@ typedef struct checkers_setup_t { } checkers_setup_t; typedef struct checkers_context_t { + unsigned tickoff; checkers_setup_t setup; } checkers_context_t; @@ -73,6 +75,7 @@ static void * checkers_create_context(unsigned ticks, unsigned n_cpus, til_setup return NULL; ctxt->setup = *(checkers_setup_t *)setup; + ctxt->tickoff = ticks; return ctxt; } @@ -142,6 +145,22 @@ static void checkers_render_fragment(void *context, unsigned ticks, unsigned cpu case CHECKERS_DYNAMICS_RANDOM: /* note: the big multiply here is just to get up out of the low bits */ state &= hash(fragment->number * 0x61C88647 + (unsigned)((float)ticks * ctxt->setup.rate)) & 0x1; break; + case CHECKERS_DYNAMICS_SONAR: { + float t = (float)((ticks - ctxt->tickoff) % 1000) * .001f * 2; + float dist_sq, x, y; + + x = fragment->x + (fragment->width >> 1); + y = fragment->y + (fragment->height >> 1); + x = x / (float)fragment->frame_width * 2.f - 1.f; + y = y / (float)fragment->frame_height * 2.f - 1.f; + + dist_sq = x * x + y * y; + + t *= t; + + state &= (dist_sq > (t - .1f) && dist_sq < (t + .1f)); + break; + } } if (!state) @@ -176,6 +195,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se "even", "alternating", "random", + "sonar", NULL }; const char *dynamics_rate_values[] = { @@ -276,6 +296,8 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se setup->dynamics = CHECKERS_DYNAMICS_ALTERNATING; else if (!strcmp(dynamics, "random")) setup->dynamics = CHECKERS_DYNAMICS_RANDOM; + else if (!strcmp(dynamics, "sonar")) + setup->dynamics = CHECKERS_DYNAMICS_SONAR; else { free(setup); return -EINVAL; |