ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Home » C programs » graphics.h header file functions

Draw lines from one co-ordinate to another using graphics.h in C

In this article, we are going to learn about the moveto() and lineto() function of graphics.h header file and use them to draw lines from one co-ordinate to another.
Submitted by Manu Jemini, on March 21, 2018

Every line is made of two endpoints. Making lines in c with graphics.h's function is very easy.

First thing is to initiate a graph. Then set the current position to a location by using the function moveto(). moveto() function takes up the x and y co-ordinate which define the location.

After setting up the current location, we can use the function lineto(). This lineto() function takes two parameters which define the end point of the line.

That’s all we have to do to make a line.

graphics.h - Draw lines from one co-ordinate to another in C



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

int main() 
{
	//initilizing graphic driver and 
	//graphic mode variable
	int graphicdriver=DETECT,graphicmode;

	//calling initgraph with parameters
	//(graphic mode and graphic driver)
	initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

	//Printing message for user
	outtextxy(10, 10 + 10, "Program to draw lines from one co-ordinate to another in C graphics");

	//line 1 move to and line to co-ordinate

	moveto(60,60);
	lineto(500, 60);

	//line 2 move to and line to co-ordinate

	moveto(80,80);
	lineto(480,80);

	//line 3 move to and line to co-ordinate

	moveto(100,100);
	lineto(460,100);
	
	getch();

	return 0;
}

Output

graphics.h - Draw lines from one co-ordinate to another in C

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.