Build Home


Explanation

The graphics.h library allows us to create simple graphical drawings using basic shapes. In this program, circles, rectangles, and lines are combined to draw a simple house. The circles represent the sun and a window, rectangles form the walls and door, and lines create the roof.

How It Works?

  • Step 1: Include the graphics.h header file.
  • Step 2: Initialize graphics mode using initgraph().
  • Step 3: Set the drawing color using setcolor().
  • Step 4: Draw circles using the circle() function.
  • Step 5: Draw the house body and door using the rectangle() function.
  • Step 6: Draw the roof using the line() function.
  • Step 7: Wait for a key press using getch().

Example Program


#include <stdio.h>
#include <conio.h>
#include <graphics.h>

main()
{

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "c:\\turboc3\\bgi");

    setcolor(7);

    circle(20, 40, 50);
    circle(200, 155, 20);

    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);

    getch();

}

Output

Build Home Graphics Output