How to draw linesAnd basic maths to draw lines in graphics programming with c graphics.

To understand the graphics program you must need to understand the simple math behind graphics programming.

 To draw lines in c, especially we need graphics.h header file,line( ), and some graphic driver codes to initialize the graph .

#include<conio.h>
#include<graphics.h>
void main( )
{
clrscr( );
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
line(100,200,400,300);
getch( );
closegraph( );
}

Here in this code you can see  line function, there are four arguments are present within line( ), so now here you have to pass four arguments within line( );

line(100,200,400,300);

to understand the line( ) and arguments of line( ),we will consider the line( ) like this.

void line(int x1,int y1,int x2,int y2);  or   line(x1,y1,x2,y2);

here you can see four int type arguments are present within line function. These arguments are the coordinates of two point x1,y1 and x2,y2As we know that according to coordinate geometry, to draw a line on the graph we need coordinates of two points. First, two arguments (100,200) are x1 and y1 which is the initial point and first coordinate of the line, and last two arguments are (400,300) are x2  and y2, are the endpoint of the line.

                         graph of line,where coordinate of line is line(100,200,400,300);

This graph is correct according to mathematics but, if we write the same coordinates of lines which is shown in the graph, and compile it with c++ compiler .it will give output like this

                         output screen of line,where coordinate of line is line(100,200,400,300);


So in order to work on the graphic with c/c++ you have to consider the graph like this.

                                                                                      line(100,200,400,300)

One another simple way to predict about the coordinates is.

Here x1 or 100 is a distance from the left of the computer screen.
And y1 or 200 is a distance from the top of the computer screen.


If this article is helpful for you then please do comment and share it with friends. It will motivate me to write such a learning article for you.

If you wanna give any suggestion and correction regarding to this article, you are always welcome

Thank you........... 


Comments

Popular posts from this blog

Graphics with c/c++