How to draw Man Walking by C Graphics with Source Code

man walking using C or C++ graphics programing language

Introduction :

Computer graphics allow a wide range of tools and functions by which you create an attractive and dynamic animation on the screen. Creating animations using graphics programing is a interesting way to bring your imagination to life on the screen.

In this article, I shall explore you how to create a simple animation of a man walking using C or C++ graphics programing language with source code. By basic geometric shapes of graphics.h library, I show you how draw the body, head, arms, legs of a man and animating walking motion effect to create the man to life on the screen.

About the program :

In this program, I draw a man with the head, ear, nose, eye, mouth, body, arms and legs. When the man is walking, his hands and legs also moving same as a real man walking. When left hand and right leg move forward, at the same time right hand and left leg move backward. This process run continues until the program end.

Explanation of the program :

Here, I discuss about the Explanation of how to create a man walking or moving by C or C++ graphics programming language. At the beginning of the program, you have to include graphics.h, conio.h and dos.h library. In the main function, initialize the graphics mode using the initgraph() function. The initgraph() function takes the graphics driver, graphics mode and BGI path as parameters. Next, set the background of the screen by setbkcolor() function. Then set the color of the man by setcolor() function.

After that, in the for loop I create the man who can walk or move like a real man. Using circle(), arc() and line() function, I create a man with the head, ear, nose, eye, mouth, body, arms and legs. By changing the position of circle, arc and line, you can create walking motion with the movement of hands and legs back and forth. Next, using delay() function controls the speed of the movement of the man. Here I also use cleardevice() function for clear the screen after the movement. Lastly, you can use the getch() function to wait for a key press and the closegraph() function to close the graphics mode.

How run the program :

To run the walking man program using the C or C++ graphics programming language you have to install Turbo C++ on your pc. Here, I use the graphics.h library of the Turbo C++ IDE. After installing Turbo C++, create a C or C++ file in Turbo C ++ IDE. Now copy the following source code and paste in your C or C++ file in the Turbo C++ IDE. Then save the file and run the code. Now you will be seen that a man is walking on the screen. If You do not know how to use graphics.h library in turbo C++ IDE click here.

Source code :

You can copy the below source code for creating a man walking or moving using C or C++ graphics programing language.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
    int x, y, i = 0, j = 0;
    int graphic_driver = DETECT, graphic_mode;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    setbkcolor(4);
    setcolor(15);
    for (i = 0; i <= 2; i++)
    {
        for (j = 0; j <= 70; j++)
        {
            circle(x, y, 20);
            circle(x + 10, y - 10, 5);
            arc(x + 20, y, 90, 270, 5);
            arc(x + 10, y + 15, 30, 120, 5);
            arc(x + 10, y + 10, 210, 330, 5);
            arc(x + 20, y + 10, 117, 180, 35);
            arc(x - 15, y - 5, 280, 45l, 10);
            line(x - 2, y + 20, x - 2, y + 30);
            line(x + 2, y + 20, x + 2, y + 30);
            line(x - 15, y + 36, x + 21, y + 25);
            line(x - 15, y + 36, x - 15, y + 96);
            line(x + 21, y + 25, x + 21, y + 85);
            line(x - 15, y + 96, x + 21, y + 85);
            if (j < 41)
            {
                line(x - 15, y + 36, x - 30 + j, y + 85 - j / 8);
                delay(25);
            }
            else
            {
                line(x - 15, y + 36, x + 40 - j, y + 75 + j / 8);
                delay(25);
            }
            if (j < 41)
            {
                line(x + 21, y + 85, x + 5 + j, y + 135 - j / 8);
                delay(25);
            }
            else
            {
                line(x + 21, y + 85, x + 75 - j, y + 125 + j / 8);
                delay(25);
            }
            if (j < 41)
            {
                line(x + 21, y + 25, x + 36 - j, y + 70 + j / 8);
                delay(25);
            }
            else
            {
                line(x + 21, y + 25, x - 34 + j, y + 80 - j / 8);
                delay(10);
            }
            if (j < 41)
            {
                line(x - 15, y + 96, x - j, y + 145 + j / 8);
                delay(25);
            }
            else
            {
                line(x - 15, y + 96, x - 70 + j, y + 155 - j / 8);
                delay(10);
            }
            cleardevice();
            x++;
        }
    }
    getch();
    closegraph();
    return 0;
}

Output :

You can also see the output of creating a man walking or moving using C or C++ graphics programing language in my YouTube channel as shown in below.

Conclusion :

By completing this article, you have gained valuable knowledge and skills in drawing a moving or walking man using C or C++ graphics programing language. Here, you have learned how to set up the graphics environment, draw shapes, implement animation effects using loops for bringing your ideas to life.

This article helps you for creating a wide range of other graphics program by C or C++ graphics programing language. With the help of the graphics.h library in Turbo C++, you can unleash your creativity and explore more complex drawings and animations by C or C++ graphics programing language. Thank you for visiting my site.

Scroll to Top