drawing a circle-segment with gnomecanvas
- From: Joergen Scheibengruber <Joergen Scheibengruber informatik uni-ulm de>
- To: gtk-app-devel-list gnome org
- Subject: drawing a circle-segment with gnomecanvas
- Date: 17 Jan 2002 17:04:58 +0100
Hi!
I would like to know if there is a easy way to draw a circle/ecllipse
segment in gnome_canvas. As far as I see it is only possible to draw a
whole circle/ecllipse.
What I'm doing right now is drawing a polygon calcualting the points
with sin/cos (see below), but this doesn't look to good in my opinion
even in a antialiased canvas.
Is there a better way to do this?
Here is my code:
#define POINTS 100
void draw_circle_segment(GtkWidget* canvas,
double x,
double y,
double radius,
double percentage,
gchar* color)
{
double angel;
int i, xi, yi, p;
GnomeCanvasPoints *points;
angel = (1.0f - percentage)*PI;
if (percentage<1.0)
{
p = (int)(POINTS*percentage);
points = gnome_canvas_points_new (p+2);
points->coords[0] = (int)x;
points->coords[1] = (int)y;
}
else
{
p = POINTS;
points = gnome_canvas_points_new (p+2);
points->coords[0] = (int)x;
points->coords[1] = (int)y+radius;
}
for (i=0;i<=p;i++)
{
xi = (int)(sin((double)i*3.14*2/POINTS+angel)*radius+x);
points->coords[(i+1)*2] = xi;
yi = (int)(cos((double)i*3.14*2/POINTS+angel)*radius+y);
points->coords[(i+1)*2+1] = yi;
}
gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(canvas)),
gnome_canvas_polygon_get_type(),
"points", points,
"fill_color", color,
"outline_color", "black",
"width_units", (double)2,
NULL);
gnome_canvas_points_free(points);
}
--
There are two major products that come from Berkeley : LSD and UNIX. We
don't believe this to be a coincidence.
Jeremy S. Anderson
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]