• Have Any Question?
  • contact@eitworld.com

Drawpoly() Function





drawpoly() function is used to draw the polygons of three or more than three sides like triangle, rectangle, pentagone and hexagone etc..

void drawpoly( int num, int *polypoints );
  • drawpoly() function contains two parameters num and polypoints.
  • First parameter num specifies the number of points which are “n+1” whereas there are “n” vertices. Number of points are n+1 because first point coordinates should be equal to (n+1)th to draw a complete figure .
  • polypoints tell the sequence of (n*2) integers . Each pair of integers gives x and y coordinates of a point on the polygon.
  • For more clearance of the concept of the drawpoly() function go through its program.

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm,array[]={320,240,340,220,360,240,360,280,320,280,320,240);

initgraph(&gd,&gm,” “);

drawpoly(6,array);

getch();

closegraph();

}

Above program will draw a polygon of five sides or we can say a pentagon by using drawpoly() function, array[] contains the coordinates of the pentagon (320,240), (340,220), (360,240), (360,280) and (320,280). The last coordinates (320,240) is as same as the first one in order to maintain the cyclic behavior of the pentagon. In the above program drawpoly() function contains two arguments 6 and array. First argument shows the six coordinates of the pentagon which is one more than the number of sides. Second argument shows the array which is the collection of the coordinates.

Output

When you will execute the above program you will get the following output screen: poly



Real Time Web Analytics