C Program to create a House using Graphics
To run the program we have the include the below header file:
Setting Up the Environment:
- Download the WinBGlm zip file from this link.
- Extract the WinBGlm zip at any desired directory as shown below:
- Copy the header file graphic.h and winbgim.h and paste these file inside the folder Program Files->CodeBlock->MinGW->Include_folder.
- Also copy the libbgi.a and paste inside the folder Program Files->CodeBlock->MinGW-> lib_folder.
- After this open your Code::Blocks and goto the Setting->Compiler->Linker Settings as shown below:
- Add New and Browse the file where the libbgi.a is available which is lib folder.
- And in other linker option paste this: “lbgi lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32“, Click on OK and Exit from Code::Blocks.
Approach: We will create a house with the help of several lines and rectangles. Below are the steps:
- 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.
- IWe will draw a rectangle in graphics by passing 4 numbers to rectangle() function as:
line(left, top, right, bottom)
The above function will draw a rectangle with coordinates of left, right, top and bottom.
- The setfillstyle() function which sets any fill pattern in any shape created in C program using graphics.
- The floodfill() function is used to fill an enclosed area with any color.
Below is the implementation of the above approach: