This blog is under construction

Friday 13 September 2013

lineto example in c

Header file:
    graphics.h

Synopsis:
      void lineto (int x, int y);
     
Description:
     lineto() draws line from current point(CP) to given position(x, y) using the current drawing color.


lineto function in c graphic



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.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) {
                printf("Graphic Error: %s\n",
                                grapherrormsg(err));
                getch();
                return 0;
        }

        /* moves current position to given point */
        moveto(0, getmaxy());

        /* store the current position in a string */
        sprintf(str, " (%d, %d)", getx(), gety());
        outtextxy(50, getmaxy() - 50, str);

        /* moves the CP to given location */
        moveto(0, getmaxy());

        /* draws line from CP to given position */
        lineto(getmaxx() / 4, 0);

        /* store the current positon in a string */
        sprintf(str, " (x, y) => (%d, %d)", getx(), gety());
        outtextxy(getmaxx() / 4 + 5, 0, str);

        /* draw a line to given position */
        lineto(getmaxx() / 2, getmaxy());

        /* store the curren position in a string */
        sprintf(str, "(%d, %d)", getx(), gety());
        outtextxy(getmaxx() / 2 + 50, getmaxy() - 20, str);

        /* moving the current position to given point */
        moveto(getmaxx() / 2, getmaxy());
        lineto((3 * getmaxx()) / 4, 0);

        sprintf(str, " (x, y) => (%d, %d)", getx(), gety());
        outtextxy((3 * getmaxx()) / 4 + 5, 0, str);

        /* draws line from CP to given position */
        lineto(getmaxx(), getmaxy());

        sprintf(str, " (%d, %d)", getx(), gety());
        outtextxy(getmaxx() - 100, getmaxy() - 20, str);

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

  }





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


No comments:

Post a Comment