Home>

In C, the function of the fillpoly function is to draw a polygon.And fill the polygon.Fill the inside of the polygon defined by the border.Fillpoly function usage:void far fillpoly (int numpoints, int far * polypoints) ;.

In C, the function of the fillpoly function is to draw a polygon.Let's learn today.

C language fillpoly function:Fill a polygon

Function name:fillpoly

Features:Draw and fill a polygon

head File:#include<graphics.h>

Prototype:fillpoly (int numpoints, int far * polypoints);

Parameter Description:numpoints is the number of sides of the polygon;far * polypoints is an array that stores the coordinates of each vertex,Each set of two represents the x and y coordinates of a vertex.

Example code:

#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
int main (void)
{
 /* request auto detection * /
 int gdriver=detect, gmode, errorcode;
 int i, maxx, maxy;
 /* our polygon array * /
 int poly [8];
 /* initialize graphics, local variables * /
 initgraph (&gdriver,&gmode, "");
 /* read result of initialization * /
 errorcode=graphresult ();
 if (errorcode!=grok)
 /* an error occurred * /
 {
 printf ("graphics error:%s \ n", grapherrormsg (errorcode));
 printf ("press any key to halt:");
 getch ();
 exit (1);
 /* terminate with an error code * /
 }
 maxx=getmaxx ();
 maxy=getmaxy ();
 poly [0]=20;/* 1st vertext * /
 poly [1]=maxy/2;
 poly [2]=maxx-20;/* 2nd * /
 poly [3]=20;
 poly [4]=maxx-50;/* 3rd * /
 poly [5]=maxy-20;
 /*
 4th vertex. Fillpoly automatically
 closes the polygon.
 * /
 poly [6]=maxx/2;
 poly [7]=maxy/2;
 /* loop through the fill patterns * /
 for (i=empty_fill;i<user_fill;i ++)
 {
 /* set fill pattern * /
 setfillstyle (i, getmaxcolor ());
 /* draw a filled polygon * /
 fillpoly (4, poly);
 getch ();
 }
 /* clean up * /
 closegraph ();
 return 0;
}

Note:The fillpoly function is a function under the tc compilation environment.Not available in vc.

c
  • Previous Android get the current view's coordinates on the screen
  • Next Java method to determine the number of days difference between two dates