Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Program to draw a line in computer graphics in c++

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  

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:
Program to draw a line in computer graphics in c++




This post first appeared on Ask For Program, please read the originial post: here

Share the post

Program to draw a line in computer graphics in c++

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×