C Program to Draw a Hut on Screen Using C Graphics

In this article, we will write a C Program to draw a Hut on screen using C Graphics. It is a very common example and question for computer science students learning Computer Graphics with C programming language.

We will first understand the concepts used in this program and then write the C Program to Draw a Hut on Screen Using C Graphics. Let’s understand the concept of C Programming and C graphics we are going to use here.

C Program to Draw a Hut on Screen Using C Graphics

To begin with, let’s understand the C programming and graphics concepts and then write the C Program.

1. Concepts

We will be using the following concepts in this C Program to draw a hut. You must have the knowledge of these concepts to write this C Program.

  • initgraph
  • setcolor
  • setfillstyle
  • rectangle
  • line
  • floodfill
  • closegraph

After learning these concepts, you’ll be able to understand the following C program easily.

2. C Program to Draw a Hut on Screen Using C Graphics

Here’s the C Program to Draw a Hut on Screen Using C Graphics:

#include<graphics.h>
#include<conio.h>
  
int main(){
 int gd = DETECT,gm;
    initgraph(&gd, &gm, "X:\\TC\\BGI");
    /* Start Drawing the Structure of 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);
  
    /* Now, Fill the colors in the structure of our Hut */
    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);
      
    getch();
    closegraph(); /* Closing the graph */
    return 0;
} 

3. Output

C Program to Draw a Hut on Screen Using C Graphics
groot
groot

Leave a Reply

Your email address will not be published. Required fields are marked *