summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-03-31 20:24:38 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-03-31 20:24:38 +0200
commit8a65606559b017f8ab66c81ba870e79397b8af07 (patch)
treedd29c201578bf6fd445134b337b052321a276e70
parent456f263445770616a424022780e7feebd881a061 (diff)
cairo: split drawing into background and ball
-rw-r--r--modules/cairo/cairo.c40
1 files changed, 23 insertions, 17 deletions
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);