From 5ba97e9edf82b782a7dba9e008360865eaf67ed2 Mon Sep 17 00:00:00 2001 From: Antonio Carzaniga Date: Mon, 7 Jun 2021 13:38:13 +0200 Subject: [PATCH] shaded ball pattern. --- balls.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/balls.c b/balls.c index a41cbd3..d8cbee6 100644 --- a/balls.c +++ b/balls.c @@ -465,6 +465,10 @@ struct ball_face { cairo_surface_t ** c_faces; }; +static double random_color_component() { + return 1.0*(rand() % 200 + 56)/255; +}; + struct ball_face * new_ball_face(unsigned int radius, cairo_surface_t * face, int rotation) { struct ball_face * f = malloc(sizeof(struct ball_face)); if (!f) @@ -497,8 +501,17 @@ struct ball_face * new_ball_face(unsigned int radius, cairo_surface_t * face, in cairo_set_source_surface(ball_cr, face, -face_x_offset, -face_y_offset); cairo_paint(ball_cr); } else { - cairo_set_source_rgb(ball_cr, 1.0*(rand() % 256)/255, 1.0*(rand() % 256)/255, 1.0*(rand() % 256)/255); - cairo_paint(ball_cr); + cairo_pattern_t *pat; + pat = cairo_pattern_create_radial (-0.2*radius, -0.2*radius, 0.2*radius, + -0.2*radius, -0.2*radius, 1.2*radius); + double col_r = random_color_component(); + double col_g = random_color_component(); + double col_b = random_color_component(); + cairo_pattern_add_color_stop_rgba (pat, 0, col_r, col_g, col_b, 1); + cairo_pattern_add_color_stop_rgba (pat, 1, col_r/3, col_g/3, col_b/3, 1); + cairo_set_source (ball_cr, pat); + cairo_arc (ball_cr, 0.0, 0.0, radius, 0, 2 * M_PI); + cairo_fill (ball_cr); } cairo_surface_flush(f->c_faces[i]); cairo_destroy(ball_cr);