C Program to Draw Line in Graphics Mode

C Program to Draw Line in Graphics Mode.


C Program to Draw Line in Graphics Mode Images-Pics-Pictures-Photos-Basic C Programs-C Language Programs-C Program to draw a Line in Graphics Mode-General C Programs-Program for Line-Line Program-Graphics Programs.

InitGraph initializes the graphics system by loading a graphics driver from disk then putting the system into graphics mode

The syntax for line function is as follows:
                 
line(x1,y1,x2,y2);
          x1 - X Co-ordinate of first point.
          y1 - Y Co-ordinate of first point.
          x2 - X Co-ordinate of second point.
          y2 - Y Co-ordinate of second point.

closegraph( ) function switches back the screen from graphics mode to text mode.


--------------------------------------------------------------------------------------------------------------------------

#include<graphics.h>
#include<stdio.h>
int main(void)
{
    int gdriver = DETECT, gmode;
    int x1 = 200, y1 = 200;
    int x2 = 300,y2 = 300;
    initgraph(&gdriver, &gmode,"c:\\tc\\bgi");
    line(x1,y1,x2,y2);
    closegraph( );
}

--------------------------------------------------------------------------------------------------------------------------

Explanation

--------------------------------------------------------------------------------------------------------------------------

int x1=200, y1=200;
int x2=300, y2=300;

Using these variables we can keep track of starting and ending point.
line(x1,y1,x2,y2);

We need to pass 4 parameters to the line( ) function.

Line function draws line from (x1,y1) to (x2,y2)


EmoticonEmoticon