C Program to Draw Line in Graphics Mode : Line Function
Live Program : Drawing Line in Graphics Mode Using Graphics Function
1 2 3 4 5 6 7 8 9 10 11 12 | #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 of Code :
1 2 | int x1=200, y1=200; int x2=300, y2=300; |
We have declared above variables so that we can keep track of starting and ending point.
1 | line(x1,y1,x2,y2); |
We need to pass just 4 parameters to the line() function.
- Line Function Draws Line From (x1,y1) to (x2,y2) .
Syntax :
1 | line(x1,y1,x2,y2); |
Parameter | Explanation |
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 |