C Program to Draw a Hut on Screen Using C Graphics

Write a program in C to draw a hut and color it using graphics.h header file

In this program, we will draw a hut on screen using line and rectangle function and then fill it with different patterns and colors. We will use below mentioned graphics functions in this program.

Function Argument Description
initgraph It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode.
setcolor It changes the current drawing colour. Default colour is white. Each color is assigned a number, like BLACK is 0 and RED is 4. Here we are using colour constants defined inside graphics.h header file.
setfillstyle It sets the current fill pattern and fill color.
rectangle It draws a rectangle on screen. It takes the coordinates of top left and bottom right corners.
line It draws a straight line between two points on screen.
floodfill It is used to fill a closed area with current fill pattern and fill color. It takes any point inside closed area and color of the boundary as input.
closegraph It unloads the graphics drivers and sets the screen back to text mode.

C program to draw a hut and color it using graphics


int main(){
 int gd = DETECT,gm;
    initgraph(&gd, &gm, "X:\\TC\\BGI");
    /* Draw Hut */


    /* Fill colours */
    setfillstyle(SOLID_FILL, BROWN);
    floodfill(152, 182, WHITE);
    floodfill(252, 182, WHITE);
    setfillstyle(SLASH_FILL, BLUE);
    floodfill(182, 252, WHITE);
    setfillstyle(HATCH_FILL, GREEN);
    floodfill(200, 105, WHITE);
    floodfill(210, 105, WHITE);
    return 0;
Program Output C graphics program to draw a a hut
Related Topics
C Program for bouncing ball animation
C graphics program to draw concentric circles
C program to draw sine wave graph on screen
C program to draw pie chart using graphics
C graphics program to draw digital clock
C Program to draw a circle on screen
C graphics program for moving car animation
List of all C Graphics Programs