Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
Draw a Chess Board using Graphics Programming in C
Next article icon

C Program to create a House using Graphics

Last Updated : 14 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Prerequisite: graphics.h, How to include graphics.h in CodeBlocks?

The task is to write C program to create a house using graphics.

To run the program we have the include the below header file:

  #include <graphic.h>  

Setting Up the Environment:

  1. Download the WinBGlm zip file from this link.
  2. Extract the WinBGlm zip at any desired directory as shown below:
  3. Copy the header file graphic.h and winbgim.h and paste these file inside the folder Program Files->CodeBlock->MinGW->Include_folder.
  4. Also copy the libbgi.a and paste inside the folder Program Files->CodeBlock->MinGW-> lib_folder.
  5. After this open your Code::Blocks and goto the Setting->Compiler->Linker Settings as shown below:
  6. Add New and Browse the file where the libbgi.a is available which is lib folder.
  7. 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:

  1. 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.

  2. 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.

  3. The setfillstyle() function which sets any fill pattern in any shape created in C program using graphics.
  4. The floodfill() function is used to fill an enclosed area with any color.

Below is the implementation of the above approach:




// C program to draw a house using
// graphics.h library
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
  
// Driver Code
void main()
{
    // Initialize of gdriver with
    // DETECT macros
    int gdriver = DETECT, gmode;
  
    // Initialize structure of
    // the house
    initgraph(&gdriver, &gmode, "");
  
    // Create lines for structure
    // of the House
    line(100, 100, 150, 50);
  
    line(150, 50, 200, 100);
  
    line(150, 50, 350, 50);
    line(350, 50, 400, 100);
  
    // Draw rectangle to give proper
    // shape to the house
    rectangle(100, 100, 200, 200);
    rectangle(200, 100, 400, 200);
    rectangle(130, 130, 170, 200);
    rectangle(250, 120, 350, 180);
  
    // Set color using setfillstyle()
    // which take style and color as
    // an argument
    setfillstyle(2, 3);
  
    // Fill the shapes with colors white
    floodfill(131, 131, WHITE);
    floodfill(201, 101, WHITE);
  
    // Change the filling color
    setfillstyle(11, 7);
  
    // Fill the shapes with changed colors
    floodfill(101, 101, WHITE);
    floodfill(150, 52, WHITE);
    floodfill(163, 55, WHITE);
    floodfill(251, 121, WHITE);
  
    // Close the initialized gdriver
    closegraph();
}
 
 

Output:
Below is the output of the above program:



Next Article
Draw a Chess Board using Graphics Programming in C

V

Vishesh__Jha
Improve
Article Tags :
  • C Language
  • c-graphics
  • computer-graphics

Similar Reads

  • Creating a Rainbow using Graphics Programming in C
    In Turbo C graphics we use graphics.h functions to draw different shapes(like circle, rectangle etc), display text(any message) in different format(different fonts and colors). By using graphics.h we can make programs, animations and also games. These can be useful for beginners. Functions Used : de
    2 min read
  • Draw a Chess Board using Graphics Programming in C
    Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? In Computer Graphics, we use graphics.h which provide direct functions to draw different coordinate shapes(like circle, rectangle etc). By using these functions we can draw different objects like car, hut, trees etc. In this program,
    4 min read
  • Basic Graphic Programming in C++
    Introduction So far we have been using C language for simple console output only.  Most of us are unaware that using C++, low level graphics program can also be made. This means we can incorporate shapes,colors and designer fonts in our program. This article deals with the steps to enable the DevC++
    2 min read
  • How to create GUI in C programming using GTK Toolkit
    Introduction to GTK Many programming languages bolster GUI improvement as one of the centrepieces of its language highlights. C has no such library connected to it like the string library, IO library, etc, that we every now and again use. This weakness opened the skyline for engineers to pick from a
    7 min read
  • Draw a smiley face using Graphics in C language
    Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? The task is to write a C program to draw a smiley face using graphics in C.To run the program we have the include the below header file: #include <graphic.h> Approach: We will create a Smiley Face with the help below functions:
    2 min read
  • Draw a triangle in C++ graphics
    Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? The task is to write a C program to make a triangle with the line function of graphics. To run the program we have to include the below header file: #include <graphic.h> Approach: The idea is to create a triangle with the help
    2 min read
  • Draw a line in C++ graphics
    graphics.h library is used to include and facilitate graphical operations in program. graphics.h functions can be used to draw different shapes, display text in different fonts, change colors and many more. Using functions of graphics.h you can make graphics programs, animations, projects and games.
    2 min read
  • Create Bingo Game Using C
    In this article, we will learn the process of creating a Bingo Game using the C programming language. What is a Bingo Game?Bingo is a social game where players are given cards with grids of numbers. The goal is to mark off a specific pattern of numbers on the card, usually five in a row, column, or
    12 min read
  • Segments in Computer Graphics
    Introduction : Introduction segments are a fundamental concept in computer graphics, used to represent the basic building blocks of a graphical scene. They are commonly used in 2D graphics to represent lines or curves that connect two or more points. An introduction segment is defined by two endpoin
    8 min read
  • Draw circle in C graphics
    The header file graphics.h contains circle() function which draws a circle with center at (x, y) and given radius. Syntax : circle(x, y, radius); where, (x, y) is center of the circle. 'radius' is the Radius of the circle. Examples : Input : x = 250, y = 200, radius = 50 Output : Input : x = 300, y
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences