summaryrefslogtreecommitdiff
path: root/src/modules/pixbounce
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-07-20 21:49:37 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-07-20 22:29:36 -0700
commitc69917862a58cac01d9deca2b91255f0510b243c (patch)
tree7c99bd0b6eee2726e3033139860c451f8efab08b /src/modules/pixbounce
parent0aba23a14014d84a5ca1e3a2af45608cc9f23044 (diff)
modules/pixbounce: s/rand/rand_r/
Wire up seed via til_module_context.seed in the obvious manner, minimal change to the code, no functional difference besides giving pixbounces instances an isolated random seed state.
Diffstat (limited to 'src/modules/pixbounce')
-rw-r--r--src/modules/pixbounce/pixbounce.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c
index 206d8a2..d200ad6 100644
--- a/src/modules/pixbounce/pixbounce.c
+++ b/src/modules/pixbounce/pixbounce.c
@@ -235,9 +235,9 @@ typedef struct pixbounce_context_t {
int multiplier;
} pixbounce_context_t;
-static uint32_t pick_color()
+static uint32_t pick_color(unsigned *seedp)
{
- return makergb(rand()%256, rand()%256, rand()%256, 1);
+ return makergb(rand_r(seedp)%256, rand_r(seedp)%256, rand_r(seedp)%256, 1);
}
static til_module_context_t * pixbounce_create_context(unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup)
@@ -253,7 +253,7 @@ static til_module_context_t * pixbounce_create_context(unsigned seed, unsigned t
ctxt->x_dir = 0;
ctxt->y_dir = 0;
ctxt->pix = &pixbounce_pixmap[((pixbounce_setup_t *)setup)->pixmap];
- ctxt->color = pick_color();
+ ctxt->color = pick_color(&ctxt->til_module_context.seed);
ctxt->pixmap_size_factor = ((((pixbounce_setup_t *)setup)->pixmap_size)*55 + 22 )/ 100;
ctxt->multiplier = 1;
@@ -284,10 +284,10 @@ static void pixbounce_render_fragment(til_module_context_t *context, unsigned ti
}
/* randomly initialize location and direction of pixmap */
- ctxt->x = rand() % (width - ctxt->pix->width * ctxt->multiplier) + 1;
- ctxt->y = rand() % (height - ctxt->pix->height * ctxt->multiplier) + 1;
- ctxt->x_dir = (rand() % 7) - 3;
- ctxt->y_dir = (rand() % 7) - 3;
+ ctxt->x = rand_r(&ctxt->til_module_context.seed) % (width - ctxt->pix->width * ctxt->multiplier) + 1;
+ ctxt->y = rand_r(&ctxt->til_module_context.seed) % (height - ctxt->pix->height * ctxt->multiplier) + 1;
+ ctxt->x_dir = (rand_r(&ctxt->til_module_context.seed) % 7) - 3;
+ ctxt->y_dir = (rand_r(&ctxt->til_module_context.seed) % 7) - 3;
}
@@ -309,11 +309,11 @@ static void pixbounce_render_fragment(til_module_context_t *context, unsigned ti
/* update pixmap location */
if(ctxt->x+ctxt->x_dir < 0 || ctxt->x+ctxt->pix->width*ctxt->multiplier+ctxt->x_dir > width) {
ctxt->x_dir = ctxt->x_dir * -1;
- ctxt->color = pick_color();
+ ctxt->color = pick_color(&ctxt->til_module_context.seed);
}
if(ctxt->y+ctxt->y_dir < 0 || ctxt->y+ctxt->pix->height*ctxt->multiplier+ctxt->y_dir > height) {
ctxt->y_dir = ctxt->y_dir * -1;
- ctxt->color = pick_color();
+ ctxt->color = pick_color(&ctxt->til_module_context.seed);
}
ctxt->x = ctxt->x+ctxt->x_dir;
ctxt->y = ctxt->y+ctxt->y_dir;
© All Rights Reserved