C Program to Draw a Hut on Screen Using C Graphics

Here is a C graphics program 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

#include<graphics.h>

int main(){
 int gd = DETECT,gm;
    initgraph(&gd, &gm, "X:\\TC\\BGI");
    /* Draw Hut */
    setcolor(WHITE);
    rectangle(150,180,250,300);
    rectangle(250,180,420,300);
    rectangle(180,250,220,300);

    line(200,100,150,180);
    line(200,100,250,180);
    line(200,100,370,100);
    line(370,100,420,180);

    /* 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);
    
    closegraph();
    return 0;
} 
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