diff --git a/examples/cluster.c b/examples/cluster.c index 83baf21..4ac3e6a 100644 --- a/examples/cluster.c +++ b/examples/cluster.c @@ -8,6 +8,24 @@ #include #include +static void draw_needle(cairo_t *cr, + double x, + double y, + double r, + double min_angle, + double max_angle, + double value) { + double angle = min_angle + ((max_angle - min_angle) * value) - 90.0; + + cairo_move_to(cr, x, y); + + cairo_line_to(cr, + x + r * cos((M_PI/180.0) * angle), + y + r * sin((M_PI/180.0) * angle)); + + cairo_stroke(cr); +} + static void redraw(cairo_t *ctx) { /* * Paint canvas black @@ -22,6 +40,14 @@ static void redraw(cairo_t *ctx) { cairo_arc(ctx, 208, 240, 192, 0, 360); cairo_stroke(ctx); + /* + * Draw a gauge needle + */ + draw_needle(ctx, 208, 240, 176, 240, 480, 0.0); + + /* + * Draw another circle + */ cairo_arc(ctx, 816, 240, 192, 0, 360); cairo_stroke(ctx);