**c graphic program to draw polygon.**

**drawpoly function is used to draw polygon it may be triangle, rectangle, hexagon, etc. In drawpoly function it will takes two argument first argument is num i.e number if points or vertices and that is ( num + 1 ). And another is an array of points which gives the x and y coordinates of the point or vertices of the polygon. In which array of polypoint is ( num * 2 ) where num is number of points or vertices.**

**General syntax of polygon :**

**drawpoly( int num, int *polypoint);**

**For example we need to draw rectangle using drawpoly function than the first argument num is number of vertices + 1 that is 5 and the array of polypoints contain num * 2 elements so in rectangle num is 5 and polypoint are 5 * 2 = 10.**

fillpoly is also used to draw and fill polygon. setfillstyle is used to apply different style to fill color and pattern in polygon.

**C graphic program to demonstrate drawpoly function**

#include <graphics.h>

#include <stdio.h>

int main( )

{

int gd=DETECT, gm;

int points[]={150,130,350,130,350,400,250,400,150,130};

initgraph(&gd,&gm,"C:\\tc\\bgi");

drawpoly(5,points);

getch();

closegraph();

return 0;

}

Download |
---|

nice leart quite alot

ReplyDelete