drawpoly() function in C
The header file graphics.h contains drawpoly() function which is used to draw polygons i.e. triangle, rectangle, pentagon, hexagon etc.
Syntax :
void drawpoly( int number, int *polypoints ); where, number indicates (n + 1) number of points where n is the number of vertices in a polygon. polypoints points to a sequence of (n*2) integers.
Examples :
Input : arr[] = {320, 150, 400, 250,
250, 350, 320, 150};
Output :
Input : arr[] = {120, 250, 400, 250, 400,
350, 450, 200, 120, 250};
Output :
Explanation : The declaration of drawpoly() contains two arguments. number indicates (n + 1) number of points where n is the number of vertices in a polygon.The second argument, i.e, polypoints points to a sequence of (n * 2) integers . Each pair of integers gives x and y coordinates of a point on the polygon. We specify (n + 1) points because first point coordinates should be equal to (n + 1)th to draw a complete figure.
Example 1 : Drawing a triangle using drawpoly.
int arr[] = {320, 150, 400, 250, 250, 350, 320, 150};
Array arr contains coordinates of triangle which are (320, 150), (400, 250) and (250, 350). Note that last point(320, 150) in array is same as first.
Below is the implementation of drawpoly() function.
// C Implementation for drawpoly() #include <graphics.h> // driver code int main() { // gm is Graphics mode which is // a computer display mode that // generates image using pixels. // DETECT is a macro defined in // "graphics.h" header file int gd = DETECT, gm; // coordinates of polygon int arr[] = {320, 150, 400, 250, 250, 350, 320, 150}; // initgraph initializes the // graphics system by loading a // graphics driver from disk initgraph(&gd;, &gm;, ""); // drawpoly function drawpoly(4, arr); getch(); // closegraph function closes the // graphics mode and deallocates // all memory allocated by // graphics system . closegraph(); return 0; } |
Output :
Recommended Posts:
- arc function in C
- iswctype() function in C/C++
- strrev() function in C
- iswxdigit() function in C/C++
- wcstol() function in C/C++
- wcsncmp() function in C/C++
- strcspn() function in C/C++
- wcsncat() function in C/C++
- wcsrtombs() function in C/C++
- wcstod() function in C/C++
- atexit() function in C/C++
- strrchr() function in C/C++
- mbsrtowcs() function in C/C++
- strcmpi() function in C
- wctype() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




