User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:graphics.h:drawpoly

drawpoly

Syntax of drawpoly

#include <graphics.h>
void drawpoly(int numpoints, int *polypoints);
 

Description of drawpoly

drawpoly draws a polygon with numpoints points, using the current line
style and color.
*polypoints points to a sequence of (numpoints * 2) integers. Each pair
of integers gives the x- and y-coordinates of a point on the polygon.
In order to draw a closed figure with n vertices, you must pass n + 1
coordinates to drawpoly where the nth coordinate is equal to the 0th.

Example of drawpoly

/* drawpoly example */
 
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
 
int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;
   int maxx, maxy;
 
   int poly[10];   /* our polygon array */
 
   /* initialize graphics and 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;     /* first vertex */
   poly[1] = maxy / 2;
   poly[2] = maxx - 20;    /* second vertex */
   poly[3] = 20;
   poly[4] = maxx - 50;    /* third vertex */
   poly[5] = maxy - 20;
   poly[6] = maxx / 2;     /* fourth vertex */
   poly[7] = maxy / 2;
   poly[8] = poly[0];/* drawpoly doesn't automatically close */
 
   poly[9] = poly[1];/* the polygon, so we close it */
 
   drawpoly(5, poly);   /* draw the polygon */
 
   /* clean up */
   getch();
   closegraph();
   return 0;
}

See also

output of drawpoly example

  no output of example at the moment
  do not hesitate and add it...  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/graphics.h/drawpoly.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz