Circles, Ellipses, and Arcs

Fastgraph includes functions for drawing filled and unfilled circles and ellipses, plus unfilled circular arcs. Both screen space and world space versions of these functions are available, and all of them observe the clipping limits.

The fg_circle() function draws an unfilled circle in screen space, centered at the graphics cursor position, using the current color. Its only parameter specifies the circle's radius in horizontal screen space units. Another function, fg_circlew(), draws an unfilled circle where the radius is measured in horizontal world space units. The analogous functions for drawing filled circles are fg_circlef() and fg_circlefw(). All four circle drawing functions leave the graphics cursor position unchanged.

The fg_ellipse() function draws an unfilled ellipse in screen space, centered at the graphics cursor position, using the current color. The function requires two parameters that respectively specify the length of its horizontal and vertical semi-axes. In other words, the first parameter is the absolute distance from the center of the ellipse to its horizontal extremity, and the second parameter is the absolute distance from the center to the vertical extremity. Another function, fg_ellipsew(), draws an unfilled ellipse in world space. The analogous functions for drawing filled ellipses are fg_ellipsef() and fg_ellipsfw(). All four ellipse drawing functions leave the graphics cursor position unchanged.

The following code snippet illustrates the use of fg_circlew() and fg_ellipsew() in a 200x200 world space coordinate system.

C/C++ and Delphi:

fg_setworld(-100.0,100.0,-100.0,100.0);
fg_movew(0.0,0.0);
fg_ellipsew(12.5,12.5);
fg_circlew(12.5);

Visual Basic:

Call fg_setworld(-100.0, 100.0, -100.0, 100.0)
Call fg_movew(0.0, 0.0)
Call fg_ellipsew(12.5, 12.5)
Call fg_circlew(12.5)

We first draw an ellipse and then draw a circle, both centered at the middle of the virtual buffer (which is the origin of our world space coordinate system). The circle has a radius of 1/16 the width of the virtual buffer (in this case, 12.5 horizontal world space units), and the ellipse is horizontally inscribed within the circle.

We can do the same thing in screen space with fg_circle() and fg_ellipse(), as shown here:

C/C++:

mid_x = fg_getmaxx() / 2;
mid_y = fg_getmaxy() / 2;
x = mid_x / 8;
y = mid_y / 8;
fg_move(mid_x,mid_y);
fg_ellipse(x,y);
fg_circle(x);

Delphi:

mid_x := fg_getmaxx div 2;
mid_y := fg_getmaxy div 2;
x := mid_x div 8;
y := mid_y div 8;
fg_move(mid_x,mid_y);
fg_ellipse(x,y);
fg_circle(x);

Visual Basic:

mid_x = fg_getmaxx() / 2
mid_y = fg_getmaxy() / 2
x = mid_x / 8
y = mid_y / 8
Call fg_move(mid_x, mid_y)
Call fg_ellipse(x, y)
Call fg_circle(x)

Note that in this case, the fg_circle() and fg_ellipse() parameters are dependent on the maximum x and y coordinates of the active virtual buffer. If we didn't compute these quantities in this manner, the actual size of the circle and ellipse would be proportional to the virtual buffer resolution. No such dependency exists when using world space, but we pay a price for this feature in slightly slower execution speed.

The fg_arc() function draws an unfilled circular arc in screen space, centered at the graphics cursor position, using the current color. Its first parameter specifies the arc's radius in horizontal screen space units (that is, the arc's horizontal distance at zero degrees from the current graphics position). The two remaining parameters define the starting and ending points of the arc, expressed in tenths of degrees counterclockwise from the horizontal. For example, we could construct a circle with a 30-pixel radius from four 90º arcs, each in a different color, as shown here:

C/C++ and Delphi:

fg_move(x,y);
fg_setcolor(9);
fg_arc(30,0,90*10);
fg_setcolor(10);
fg_arc(30,90*10,180*10);
fg_setcolor(11);
fg_arc(30,180*10,270*10);
fg_setcolor(12);
fg_arc(30,270*10,360*10);

Visual Basic:

Call fg_move(x, y)
Call fg_setcolor(9)
Call fg_arc(30, 0, 90 * 10)
Call fg_setcolor(10)
Call fg_arc(30, 90 * 10, 180 * 10)
Call fg_setcolor(11)
Call fg_arc(30, 180 * 10, 270 * 10)
Call fg_setcolor(12)
Call fg_arc(30, 270 * 10, 360 * 10)

Another function, fg_arcw(), draws an arc where the radius is measured in horizontal world space units. Both arc functions draw the arc counterclockwise from the starting angle to the ending angle and leave the graphics cursor position unchanged.

It's important to note that the circle, ellipse, and arc functions draw these shapes with aspect ratios for the active virtual buffer. For example, a circle will appear circular in the virtual buffer, but it will be transformed into an ellipse if you scale the virtual buffer contents in the client area with fg_vbscale() unless the client has the same aspect ratio as the virtual buffer. Similarly, the aspect ratio of an ellipse or arc may become distorted under these same circumstances. You can avoid these problems by using fg_vbpaste(), or by making sure the size of the client area can only change in increments that maintain the same aspect ratio as the active virtual buffer.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.