This blog is under construction

Wednesday 11 September 2013

getaspectratio example in c

Header file:
    graphics.h

Synopsis:
     void getaspectratio(int *xaspect, int *yaspect);
     xaspect - pointer to x's aspect factor
     yaspect - pointer to y's aspect factor

Description:
     getaspectratio() gets the aspect ratio of current graphic mode.



getaspectratio 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, midx, midy, x, y;
        char buf[256];

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

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

        /* get current aspect ratio settings */
        getaspectratio(&x, &y);
        sprintf(buf, "Aspect ratio=>%d : %d", x, y);
        outtextxy(0, 0, buf);

        /* draw normal circle */
        arc(midx, midy, 0, 360, 110);
        getch();

        /* clear the screen */
        cleardevice();

        /* adjust the aspect for a wide circle */
        setaspectratio(x / 2, y);
        sprintf(buf, "Aspect ratio=>%d : %d", x / 2, y);
        outtextxy(0, 0, buf);

        arc(midx, midy, 0, 360, 110);
        getch();

        /* adjust the aspect for a narrow circle */
        cleardevice();
        setaspectratio(x, y/2);
        sprintf(buf, "Aspect ratio=>%d : %d", x, y / 2);
        outtextxy(0, 0, buf);

        arc(midx, midy, 0, 360, 110);

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





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


No comments:

Post a Comment