diff options
author | Philip J Freeman <elektron@halo.nu> | 2020-11-27 23:24:02 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-04-27 15:35:09 -0700 |
commit | 283d6fb431f04f643f48b1a79c7095219b42882a (patch) | |
tree | ce83065b9ef4b4c705d624d95e68f3646fe72575 /src/modules/pixbounce/pixbounce.c | |
parent | c881616cfbbd8c20d67f469d363254b2c56a12b7 (diff) |
modules/pixmap: randomize colors
Diffstat (limited to 'src/modules/pixbounce/pixbounce.c')
-rw-r--r-- | src/modules/pixbounce/pixbounce.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c index 310a509..5d7d674 100644 --- a/src/modules/pixbounce/pixbounce.c +++ b/src/modules/pixbounce/pixbounce.c @@ -95,6 +95,7 @@ typedef struct pixbounce_context_t { int x, y; int x_dir, y_dir; int pix_num; + uint32_t color; } pixbounce_context_t; @@ -109,6 +110,11 @@ static int pick_pix(int num_pics, int last_pic) return pix_num; } +static uint32_t pick_color() +{ + return makergb(rand()%256, rand()%256, rand()%256, 1); +} + static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup) { pixbounce_context_t *ctxt; @@ -123,6 +129,7 @@ static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, til_se ctxt->x_dir = 0; ctxt->y_dir = 0; ctxt->pix_num = rand() % num_pix; + ctxt->color = pick_color(); return ctxt; } @@ -172,7 +179,7 @@ static void pixbounce_render_fragment(void *context, unsigned ticks, unsigned cp if(pix_map[ctxt->pix_num][pix_offset] == 0) continue; til_fb_fragment_put_pixel_unchecked( fragment, ctxt->x+cursor_x, ctxt->y+cursor_y, - makergb(0xFF, 0xFF, 0xFF, 1) + ctxt->color ); } } @@ -181,18 +188,22 @@ static void pixbounce_render_fragment(void *context, unsigned ticks, unsigned cp if(ctxt->x+ctxt->x_dir < 0) { ctxt->x_dir = 1; ctxt->pix_num = pick_pix(num_pix, ctxt->pix_num); + ctxt->color = pick_color(); } if((ctxt->x+(pix_width*multiplier))+ctxt->x_dir > width) { ctxt->x_dir = -1; ctxt->pix_num = pick_pix(num_pix, ctxt->pix_num); + ctxt->color = pick_color(); } if(ctxt->y+ctxt->y_dir < 0) { ctxt->y_dir = 1; ctxt->pix_num = pick_pix(num_pix, ctxt->pix_num); + ctxt->color = pick_color(); } if((ctxt->y+(pix_height*multiplier))+ctxt->y_dir > height) { ctxt->y_dir = -1; ctxt->pix_num = pick_pix(num_pix, ctxt->pix_num); + ctxt->color = pick_color(); } ctxt->x = ctxt->x+ctxt->x_dir; ctxt->y = ctxt->y+ctxt->y_dir; |