summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2012-11-08 18:23:43 +0000
committerJon TURNEY <jon.turney@dronecode.org.uk>2012-11-19 21:18:38 +0000
commit5c76a54a0eb8d11b83cfe54f54cbf378ea5819b9 (patch)
treef6439af8aca55fb437cb093ea0d47879204afa54
parent3e9135051334624d157ffdbfb79d591859059a26 (diff)
Draw a circle with a gradient fill
-rw-r--r--alphademo.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/alphademo.c b/alphademo.c
index 49cc616..36c0c68 100644
--- a/alphademo.c
+++ b/alphademo.c
@@ -112,19 +112,18 @@ static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer userda
int width, height;
gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
+ /* draw a circle with a gradient fill */
int radius = (width < height ? width : height);
-
- /* draw a circle */
- cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.5);
- cairo_arc(cr, width / 2, height / 2, radius / 2 - 8 , 0, 2 * 3.14);
- cairo_fill(cr);
-
- cairo_set_source_rgba(cr, 0.2, 1, 0.2, 0.75);
- cairo_arc(cr, width / 2, height / 2, radius *3/8 - 8 , 0, 2 * 3.14);
- cairo_fill(cr);
-
- cairo_set_source_rgba(cr, 0.2, 0.2, 1.0, 1.0);
- cairo_arc(cr, width / 2, height / 2, radius / 4 - 8 , 0, 2 * 3.14);
+ int cx = width / 2;
+ int cy = height / 2;
+
+ cairo_pattern_t *pat;
+ pat = cairo_pattern_create_radial(cx, cy, 0, cx, cy, radius/2 - 8);
+ cairo_pattern_add_color_stop_rgba(pat, 1.0, 1.0, 0.2, 0.2, 0.1);
+ cairo_pattern_add_color_stop_rgba(pat, 0.5, 0.2, 1.0, 0.6, 0.5);
+ cairo_pattern_add_color_stop_rgba(pat, 0.0, 0.2, 0.2, 1.0, 1.0);
+ cairo_arc(cr, cx, cy, radius / 2 - 8 , 0, 2 * 3.14);
+ cairo_set_source(cr, pat);
cairo_fill(cr);
cairo_destroy(cr);