This blog is under construction

Friday, 13 September 2013

line example in c

Header file:
    graphics.h

Synopsis:
      void line (int x1, int y1, int x2, int y2);
     
Description:
     line() draws line from (x1, y1) to (x2, y2) using the current drawing color.


line function in c graphics



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

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

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

        x = 0;
        y = 0;

        /* setting the line style */
        setlinestyle(SOLID_LINE, 1, THICK_WIDTH);

        while (y <= getmaxy()) {
                /* draws line between two given points */
                line(x, y, getmaxx(), y);
                y = y + 25;

                /* sleep for 100 milliseconds */
                delay(100);
        }

        x = 0;
        y = 0;

        while (x <= getmaxx()) {
                /* draws line between two given points */
                line(x, y, x, getmaxy());
                x = x + 25;

                /* sleep for 100 milliseconds */
                delay(100);
        }

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





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


No comments:

Post a Comment