This blog is under construction

Saturday 14 September 2013

setfillpattern example in c

Header file:
    graphics.h

Synopsis:
      void setfillpattern(char *pattern);
     
Description:
     setfillpattern() sets user-defined fill pattern.


setfillpattern 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;
        int i, j, k = 14, err, midx, midy;
        char pattern[8] = {0xaa, 0x55, 0xaa, 0x55,
                                  0xaa, 0x55, 0xaa, 0x55};

        /* initialize graphics and 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));
                getch();
                return 0;
        }

        /* mid position in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        for (i = 0; i < 10; i++) {
                /* sets the current drawing color */
                setcolor(k);
                for (j = 0; j < 8; j++) {
                        /* user defined fill pattern */
                        if (j % 2 == 0) {
                                pattern[j] = pattern[j] - 1;
                        } else {
                                pattern[j] = pattern[j] - 2;
                        }
                }

                /* setting user defined fill pattern */
                setfillpattern(pattern, k--);

                /* draws pie slice using the current drawing color */
                pieslice(midx, midy, 0, 360, 150);

                /* sleep for 500 milli seconds */
                delay(500);

                /* clears graphic screen */
                cleardevice();
        }

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





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


No comments:

Post a Comment