This blog is under construction

Wednesday 11 September 2013

fillpoly example in c

Header file:
    graphics.h

Synopsis:
     void fillpoly(int num, int *points);
     num - number of points
     *points - pointer to an array of intergers(num X 2) and each 
                    pair of points gives a coordinate(x,y) of polygon

Description:
      fillpoly() draws a polygon using the current drawing color, then fill it with current fill style and fill color.


fillpoly function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>
  #include <dos.h>

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;

        /* our polygon array */
        int err, i, polygon[10];

        /* initialize graphics, local variables */
        initgraph(&graphicDriver, &graphicMode,
                                "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* an error occurred */
                printf("Graphic Error: %s\n",
                                grapherrormsg(err));
                return 0;
        }

        polygon[0] = 0;
        polygon[1] = getmaxy() / 2;

        polygon[2] = getmaxx() / 4;
        polygon[3] = getmaxy();

        polygon[4] = getmaxx();
        polygon[5] = 0;

        polygon[6] = getmaxx() / 4;
        polygon[7] = getmaxy() - 80;

        polygon[8] = 0;
        polygon[9] = getmaxy() / 2;

        /* loop through the fill patterns */
        for (i=EMPTY_FILL; i<USER_FILL; i++) {
                /* set fill pattern */
                setcolor(i % 12);
                setfillstyle(i, i % 12);

                /* draw a filled polygon */
                fillpoly(5, polygon);
                delay(400);
        }

        /* clean up */
        closegraph();
        return 0;
  }




Output: (fillpoly built-in function in c graphics.h)


No comments:

Post a Comment