Hey, I've got freaking needles now

This commit is contained in:
XANTRONIX Development 2019-05-25 22:08:26 -05:00
parent e5b2b11ec0
commit 4900d59328

View file

@ -8,6 +8,24 @@
#include <stdlib.h>
#include <math.h>
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);