Create different styles of lines of graphics.h in C

In this article, we are going to learn about the use of setlinestyle() and line() functions of graphics header file and try to create different styles of lines in graphics.h of C.
Submitted by Manu Jemini, on March 24, 2018

Setting the style of the line can be useful to show the different boundaries of a figure or any shape. This gives us the advantage to show shapes inside a shape, which will be very clear to see, because of the different borders.

How to set a style for the line is very simple, all you need to do is to call the setlinestyle() function before drawing the line itself. The Example, below shows us how it will be after execution.

To Create a line after the setting the style, we need to call a function called line() with four parameters, which defines the (x, y) coordinate of the end-points of the line.

You can make a loop and pass the integrator’s index to the function.

graphics.h - Create different styles of lines in C

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

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

	//calling initgraph
	initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

	//Printing message for user
	outtextxy(20, 20 + 20, "Program to set different styles of lines in C graphics");

	//initilizing the variables
	int c , x = 120, y = 80;

	//for loop to set different styles of line
	for ( c = 4 ; c >= 0 ; c-- )
	{
		setlinestyle(c, 0, 3);
		line(x, y, x+150, y);
		y = y + 20;
	}

	getch();

	return 0;
}

Output

Create different styles of lines of graphics.h in C




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.