diff options
author | Philip J Freeman <elektron@halo.nu> | 2022-04-25 15:10:36 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-04-25 15:45:34 -0700 |
commit | e9adbf5a5788326a9e376da77276d9a96e31c548 (patch) | |
tree | c8b236751891ce1db29dcd03f6331c2cdbc017b5 | |
parent | 7db08a73d497862ebd5c5cc5b209ff4e178fe805 (diff) |
modules/pixbounce: rand start pos and dir
-rw-r--r-- | src/modules/pixbounce/pixbounce.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c index c26eb88..310a509 100644 --- a/src/modules/pixbounce/pixbounce.c +++ b/src/modules/pixbounce/pixbounce.c @@ -118,10 +118,10 @@ static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, til_se return NULL; ctxt->n_cpus = num_cpus; - ctxt->x = 0; - ctxt->y = 8; - ctxt->x_dir = 1; - ctxt->y_dir = 1; + ctxt->x = -1; + ctxt->y = -1; + ctxt->x_dir = 0; + ctxt->y_dir = 0; ctxt->pix_num = rand() % num_pix; return ctxt; @@ -140,9 +140,6 @@ static void pixbounce_render_fragment(void *context, unsigned ticks, unsigned cp int multiplier_x, multiplier_y, multiplier; int width = fragment->width, height = fragment->height; - /* blank the frame */ - til_fb_fragment_clear(fragment); - /* check for very small fragment */ if(pix_width*2>width||pix_height*2>height) return; @@ -157,6 +154,17 @@ static void pixbounce_render_fragment(void *context, unsigned ticks, unsigned cp multiplier = multiplier_x * 77 / 100; } + /* randomly initialize location and direction of pixmap */ + if(ctxt->x == -1) { + ctxt->x = rand() % (width - pix_width * multiplier) + 1; + ctxt->y = rand() % (height - pix_height * multiplier) + 1; + ctxt->x_dir = (rand() % 3) - 1; + ctxt->y_dir = (rand() % 3) - 1; + } + + /* blank the frame */ + til_fb_fragment_clear(fragment); + /* translate pixmap to multiplier size and draw it to the fragment */ for(int cursor_y=0; cursor_y < pix_height*multiplier; cursor_y++) { for(int cursor_x=0; cursor_x < pix_width*multiplier; cursor_x++) { |