_polygon Functions

Description

Draw polygon shapes.

#include <graph.h>

short __far _polygon( short control, const struct _xycoord __far *points,
short numpoints );

short __far _polygon_w( short control, const double __far *points,
short numpoints);

short __far _polygon_wxy( short control,
const struct _wxycoord __far *points, short numpoints );

control Fill flag  
points Pointer to an array of structures or doubles defining the polygon  
numpoints Number of points  

Remarks

The _polygon functions draw polygons. The border of the polygon is drawn in the current color and line style. The _polygon routine uses the view coordinate system (expressed in _xycoord structures), and the _polygon_wxy and _polygon_w routines use real-valued window coordinates (expressed in _wxycoord structures and in pairs of double-precision floating-point values, respectively).

The argument points is an array of _xycoord or _wxycoord structures or pairs of doubles, each of which specifies one of the polygon's vertices. (For _polygon_w, points[0] and points[1] specify the x and y coordinates, respectively, of the first point.) If the first point does not equal the last point, the _polygon functions use them to provide a closing edge.

The argument numpoints indicates the number of elements (the number of vertices) in the points array. The minimum number of points is 3, the maximum is 16,381.

The control argument can be one of the following manifest constants:

Constant Action

_GFILLINTERIOR Fills the polygon with the current fill mask using a scan fill
_GBORDER Does not fill the polygon

The _setwritemode, _setlinestyle, and _setfillmask functions all affect the output from the_polygon functions.

If you try to fill the polgon with the _floodfill function, the polygon must be bordered by a solid line-style pattern.

Return Value

The _polygon functions return a nonzero value if the arc is successfully drawn; otherwise, they return 0.

Compatibility

Standards:None

16-Bit:DOS

32-Bit:None

See Also

_ellipse functions, _floodfill, _lineto functions, _pie functions, _rectangle functions, _setcolor, _setfillmask, _setlinestyle, _setwritemode

Example

/* POLYGON.C: This program draws a star-shaped polygon. */

#include <conio.h>

#include <stdlib.h>

#include <graph.h>

#include <math.h>

#include <stdlib.h>

#define PI 3.1415

void main( void )

{

short side, radius = 90, x = 0, y = 0;

double radians;

struct _xycoord polyside[5];

struct _videoconfig vc;

/* Find a valid graphics mode. */

if( !_setvideomode( _MAXRESMODE ) )

exit( 1 );

_getvideoconfig( &vc );

_setvieworg( vc.numxpixels / 2, vc. numypixels / 2 );

/* Calculate points of star every 144 degrees, then connect them. */

for( side = 0; side < 5; side++ )

{

radians = 144 * PI / 180;

polyside[side].xcoord = x + (short)(cos( side * radians ) * radius);

polyside[side].ycoord = y + (short)(sin( side * radians ) * radius);

}

_polygon( _GFILLINTERIOR, polyside, 5 );

_getch();

_setvideomode( _DEFAULTMODE );

exit( 0 );

}