This blog is under construction

Saturday, 14 September 2013

moverel example in c

Header file:
    graphics.h

Synopsis:
      void moverel (int dx, int dy);
     
Description:
     moverel() moves the current position(CP) by dx and dy pixels in x-direction and y-direction correspondingly.


moverel 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, x1, y1, x2, y2;
        char str[32];

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

        /* move the C.P. to location (50, 50) */
        moveto(50, 50);
        x1 = getx();
        y1 = gety();


        /* stores the current position in a string */
        sprintf(str, " (x1, y1) <=> (%d, %d)", x1, y1);
        outtextxy(x1, y1, str);

        /*
         * moves current position to a point which
         * is relative distance away from CP
         */
        moverel(150, 150);
        x2 = getx();
        y2 = gety();

        /* create and output a message at C.P. */
        sprintf(str, " (x2, y2) <=> (%d, %d)", x2, y2);
        outtext(str);

        /* plot a pixel at the (x2, y2) */
        putpixel(x2, y2, getmaxcolor());
        line(x1, y1, x2, y2);

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





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


No comments:

Post a Comment