GRAPHIC PIE statement

Purpose | Draw a pie section on the selected graphic target.
Syntax | GRAPHIC PIE (x1!, y1!) - (x2!, y2!), arcStart!, arcEnd! [, [rgbColor&] [, [fillcolor&] [, [fillstyle&]]]]

Remarks

A pie section is an arc, with a line drawn from each end point to the center of the circle or ellipse. To specify a pie section, you would first define the full circle or ellipse of which it is a part, and then specify the points on the ellipse where the arc starts and stops.

The full circle or ellipse is defined by its bounding rectangle, which is the smallest rectangle which can be drawn around the circle or ellipse. For example, if the circle is centered at position (400,400), with a radius of 100 pixels, the upper left corner (x1,y1) of the bounding rectangle is (300,300), and the lower right corner (x2,y2) is (500,500).

The start point and end point of the arc are specified by their angle, which must be given in radians. A complete circle or ellipse is 2*pi radians. On a 12-hour clock-face, the values 0 and 2*pi both refer to the position of 3 o'clock, while the value 1*pi refers to the position of 9 o'clock. Other positions are specified by a radian value relative to these. In PowerBASIC, arcs are always drawn counter-clockwise from the starting point to the ending point.

Prior to any graphical operations, the graphic target must first be selected with GRAPHIC ATTACH. The Coordinates are specified in the same terms (pixels or dialog units) as the parent dialog (or world coordinates, if those were chosen with GRAPHIC SCALE). Line width can be set using GRAPHIC WIDTH. If line width is set to 1 (the default), the line style can be set with GRAPHIC STYLE. Because of the nature of a pie section, GRAPHIC PIE neither uses, nor updates, graphic POS (last point referenced).

x1!, y1! | The upper left corner of the bounding rectangle of the full circle or ellipse.
x2!, y2! | The lower right corner of the bounding rectangle of the full circle or ellipse.
ArcStart! | The starting angle of the arc, in radians, from 0 to 2*pi.
ArcEnd! | The ending angle of the arc, in radians, from 0 to 2*pi radians. Note that arcs are always drawn counter-clockwise from arcStart! to arcEnd!. Compared with a 12-hour clock-face, 0 or 2*pi radians is at 3 o'clock, and 1*pi radians is at 9 o'clock.
rgbColor& | Optional RGB color of the pie section edge. If omitted (or -1), the edge color defaults to the current foreground color.
fillcolor& | Optional RGB color of the pie section interior. If fillcolor& is omitted (or -2), the interior of the pie section is not filled, allowing the background to show through. If fillcolor& is -1, the interior is painted with the same color as the edge. Otherwise, fillcolor& specifies the RGB color to be used.

fillstyle&

Optional fill style (pattern) to be used. If fillstyle& is omitted, the default fill style is solid (0). If a hatch pattern is chosen (1 to 6), the foreground color is specified by the fillcolor&, while the background is specified by the default background color. The optional fillstyle& may be:

0 | Solid (default)
1 | Horizontal Lines
2 | Vertical Lines
3 | Upward Diagonal Lines
4 | Downward Diagonal Lines
5 | Crossed Lines
6 | Diagonal Crossed Lines

See also | Built In RGB Color Equates, GRAPHIC ARC, GRAPHIC ATTACH, GRAPHIC BOX, GRAPHIC COLOR, GRAPHIC ELLIPSE, GRAPHIC LINE, GRAPHIC SET OVERLAP, GRAPHIC STYLE, GRAPHIC WIDTH

Example

FUNCTION PBMAIN

LOCAL hWin AS DWORD

GRAPHIC WINDOW "Pie", 0, 0, 200, 200 TO hWin

GRAPHIC ATTACH hWin, 0

' A full circle is 2Pi radians (100%).

' To show a 25% Pie, use the formula 0.25 * 2Pi.

' The following divides a full circle into four 25% parts, each

' with its own colors, each slightly separated from the others.

' Note: 0 is at 3 O'clock, then it builds counter-clockwise.

LOCAL Pi2 AS DOUBLE

Pi2 = 8 * ATN(1) ' 2 * Pi can be useful here

GRAPHIC PIE (10, 9)-(110, 109), 0, Pi2 * 0.25, %BLUE, %LTGRAY, 3

GRAPHIC PIE (9, 9)-(109, 109), Pi2 * 0.25, Pi2 * 0.50, %RED, %LTGRAY, 4

GRAPHIC PIE (9, 10)-(109, 110), Pi2 * 0.5, Pi2 * 0.75, RGB(0,127,0), %LTGRAY, 3

GRAPHIC PIE (10, 10)-(110, 110), Pi2 * 0.75, 0, %GRAY, %LTGRAY, 4

SLEEP 10000

END FUNCTION