graphics.h library is used to draw a line in computer graphics in c++. graphics.h library does have different Fonts, Shapes, colors and many more. With the help of computer graphics, we can draw a circle, rectangles, bars, lines, and many other geographical shapes.
Header file graphics.h contains line() function, which is used to draw a line in computer graphics.
Declaration: void line(int x1, int y1, int x2, int y2);
line() function does have 4 input parameters, which are coordinates of the line. To draw a line we need to point (x1,y1) and (x2,y2) to join the line. Based on coordinates entered in the line() function, we can draw horizontal, vertical or angle lines.
Write a program to draw a line in computer graphics in c++
#include <graphics.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
// Horizontal line
line(150, 150, 450, 150);
// Vertical line
line(150, 150, 150, 450);
getch();
closegraph();
}
Explanation:
gm is Graphics mode which is a computer display mode that generates an image using pixels. DETECT is a macro defined in "graphics.h" header file. initgraph initializes the graphics system by loading a graphics driver from disk. closegraph() function closes the graphics mode and deallocates all memory allocated by the graphics system.
Output:
Output:
Program to draw a line in computer graphics in c++ |
0 Comments