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.

Graphics programming is an exciting avenue to unleash creativity, and creating visuals using Turbo C graphics is a classic and educational way to dive into this world. In this tutorial, we'll explore the process of drawing a hut on the screen using Turbo C graphics. By combining basic shapes and colors, we can bring a simple yet visually appealing hut to life.

We will use below mentioned graphics functions in this program.

Function Argument Description
initgraph initgraph is a vital function in Turbo C graphics that initializes the graphics system. It sets up the graphics mode, graphics driver, and the location of the BGI (Borland Graphics Interface) driver file. This function must be called before any graphics operation is performed.
setcolor The setcolor function is used to set the current drawing color in Turbo C graphics. It allows you to choose from a predefined set of colors for drawing lines, shapes, and other graphical elements.
setfillstyle setfillstyle is employed to set the fill pattern and color for shapes that support filling, such as rectangles, circles, and polygons. It determines how the interior of the shape will be filled.
rectangle The rectangle function is used to draw a rectangle on the screen. It takes two pairs of coordinates, representing the diagonally opposite corners of the rectangle, and draws the outline of the rectangle.
line The line function draws a straight line between two specified points. It is a fundamental function for creating various shapes, patterns, and outlines in Turbo C graphics.
floodfill floodfill is used to fill a closed area with a specified color. It starts from a given point (x, y) and continues filling until it encounters a boundary of a different color.
closegraph closegraph terminates the graphics mode and deallocates any system resources that were acquired during the initialization of the graphics system. It should be called before exiting a graphics program.

These functions collectively form the backbone of graphics programming in Turbo C, enabling users to create a wide range of graphical elements and designs. Understanding and utilizing these functions empower programmers to craft visually appealing applications and games.

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

Conclusion

In conclusion, this tutorial has guided you through the process of creating a visually appealing hut on the screen using Turbo C graphics. By leveraging fundamental graphics functions, you've not only drawn a hut but also explored the art of adding colors and creating a charming scene. Understanding the basics of Turbo C graphics provides a solid foundation for further exploration into the expansive field of graphics programming.

As you advance in your graphics programming journey, consider expanding your creations with more intricate designs, diverse shapes, and dynamic animations. Turbo C, though a classic environment, offers a nostalgic and educational platform to grasp essential concepts that are transferable to modern graphics libraries and frameworks.

Moreover, graphics programming is a gateway to unleashing creativity, enabling you to craft visually captivating applications, games, and simulations. The skills acquired in this tutorial lay the groundwork for more complex and engaging projects.

Remember, the joy of graphics programming lies in experimentation and exploration. Take the principles you've learned here and apply them to your unique ideas, fostering a deeper understanding of the visual elements that can be brought to life on a digital canvas. Embrace the endless possibilities, and let your imagination flourish in the vibrant world of graphics and design. Happy coding!


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