This blog is under construction

Friday 13 September 2013

linerel example in c

Header file:
    graphics.h

Synopsis:
      void linerel (int dx, int dy);
     
Description:
     linerel() draws a line to a point which is a relative distance away from current position(CP).

Current position : (x1, y1) => (100, 200)
Relative distance: (dx, dy) => (-50, 100)
Target position  : (x2, y2) => (x1 + dx, y1 + dy) => (50, 300);

And the line is drawn from (x1, y1) to (x2, y2)


linerel 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 err;
        char str[32];

        /* initialize graphics and local variables */
        initgraph(&graphicDriver, &graphicMode,
                                "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* error occurred */
                printf("Graphics Error: %s\n",
                                grapherrormsg(err));
                return 0;
        }

        /* move the C.P. to given location */
        moveto(getmaxx() / 2, getmaxy() / 2);

        /* store the current position in a string */
        sprintf(str, " (x, y) => (%d, %d)", getx(), gety());
        outtextxy(getmaxx() / 2, getmaxy() / 2, str);

        /* 
         * draw a line to a point a relative 
         * distance away from the current
         * value of C.P.
         */
        linerel(-100, 100);

        /* create and output a message at C.P. */
        sprintf(str, " (x, y) => (%d, %d)", getx(), gety());
        outtext(str);

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





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


No comments:

Post a Comment