This blog is under construction

Saturday, 14 September 2013

setaspectratio example in c

Header file:
    graphics.h

Synopsis:
      void setaspectratio(int xasp, int yasp);
     
Description:
     setaspectratio() sets aspect ratio for the current graphics system.


setaspectratio function in c graphics


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

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, x, y, midx, midy;

        /* 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;
        }

        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        /* set a drawing color and draw an pie slice */
        setcolor(10);
        setfillstyle(SOLID_FILL, 10);

        /* get current aspect ratio settings */
        getaspectratio(&x, &y);

        /* draw normal circle */
        pieslice(midx, midy, 0, 360, 75);

        getch();

        /* clear the screen */
        cleardevice();

        /* adjust the aspect for a wide circle */
        setaspectratio(x/2, y);
        pieslice(midx, midy, 0, 360, 75);
        getch();

        /* adjust the aspect for a narrow circle */
        cleardevice();
        setaspectratio(x, y/2);
        pieslice(midx, midy, 0, 360, 75);

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





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


No comments:

Post a Comment