Draw a triangle in C++ graphics
Prerequisite: graphics.h, How to include graphics.h in CodeBlocks?
The task is to write a C program to make a triangle with the line function of graphics.
To run the program we have to include the below header file:
Approach: The idea is to create a triangle with the help of several lines. We will draw a line in graphics by passing 4 numbers to line() function as:
line(a, b, c, d)
The above function will draw a line from coordinates (a, b) to (c, d) in the output window.
Below is the implementation of the above approach:
gd = DETECT, gm;
line(150, 150, 450, 150);
line(150, 150, 300, 300);
line(450, 150, 300, 300);
Below is the output of the above program: