This blog is under construction

Saturday, 14 September 2013

sector example in c

Header file:
    graphics.h

Synopsis:
      void sector(int xc, int yc, int stangle, int endangle, int xradius, int yradius);
     (xc, yc) - center of the ellipse(sector)
     stangle -starting angle
     endangle - ending angle
     xradius - radius along x-axis
     yradius - radius along y-axis
     
Description:
     sector() draws an elliptical pie slice using the current drawing color and fill it using the same color.


sector 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, err, midx, midy, xradius = 300, yradius = 150;
        int startangle = 30, endangle = 150;

        /* 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 positions in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

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

                /* draw the sector slice */
                sector(midx, midy, startangle,
                                endangle, xradius, yradius);
                xradius = xradius - 20;
                yradius = yradius - 10;

                /* sleep for 500 milliseconds */
                delay(500);
        }

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





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


No comments:

Post a Comment