From 8a65606559b017f8ab66c81ba870e79397b8af07 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Fri, 31 Mar 2017 20:24:38 +0200 Subject: cairo: split drawing into background and ball --- modules/cairo/cairo.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'modules') diff --git a/modules/cairo/cairo.c b/modules/cairo/cairo.c index 0b86304..9ebb571 100644 --- a/modules/cairo/cairo.c +++ b/modules/cairo/cairo.c @@ -69,18 +69,16 @@ static void destructor(void *arg) } -static void draw_gradient(cairo_t *cr, double step, int width, int height) +static void draw_background(cairo_t *cr, double color_step, + int width, int height) { cairo_pattern_t *pat; - double r, g, b; - double x, y; - - r = 0.1 + fabs(sin(5 * step)); - g = 0.0; - b = 0.1 + fabs(sin(3 * step)); + double grey, r, g, b; - x = width * (sin(10 * step) + 1)/2; - y = height * (1 - fabs(sin(30 * step))); + grey = 0.1 + fabs(sin(3 * color_step)); + r = grey; + g = grey; + b = grey; pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, height); cairo_pattern_add_color_stop_rgba (pat, 1, r, g, b, 1); @@ -89,21 +87,26 @@ static void draw_gradient(cairo_t *cr, double step, int width, int height) cairo_set_source (cr, pat); cairo_fill (cr); cairo_pattern_destroy (pat); +} + + +static void draw_ball(cairo_t *cr, double pos_step, int width, int height, + double r, double g, double b) +{ + cairo_pattern_t *pat; + double x, y; + + x = width * (sin(10 * pos_step) + 1)/2; + y = height * (1 - fabs(sin(30 * pos_step))); pat = cairo_pattern_create_radial (x-128, y-128, 25.6, x+128, y+128, 128.0); - cairo_pattern_add_color_stop_rgba (pat, 0, 0, 1, 0, 1); cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1); + cairo_pattern_add_color_stop_rgba (pat, 0, r, g, b, 1); cairo_set_source (cr, pat); cairo_arc (cr, x, y, 76.8, 0, 2 * M_PI); cairo_fill (cr); cairo_pattern_destroy (pat); - - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, 0, 0, 0); - cairo_set_line_width (cr, 0.1); - cairo_stroke (cr); } @@ -130,7 +133,10 @@ static void process(struct vidsrc_st *st) struct vidframe f; unsigned xoffs = 2, yoffs = 24; - draw_gradient(st->cr, st->step, st->size.w, st->size.h); + draw_background(st->cr, st->step, st->size.w, st->size.h); + + draw_ball(st->cr, st->step, st->size.w, st->size.h, + 0.0, 1.0, 0.0); draw_text(st, xoffs, yoffs + FONT_SIZE, "%H", fmt_gmtime, NULL); -- cgit v1.2.3