How to Draw Man Walking in Rain by C Programing Language

man walking in the rain with umbrella by C or C++ graphics programing language

Introduction :

Drawing a man walking in the rain with umbrella using C or C++ graphics program, is a very interesting and exciting project. By using the C or C++ programming language and functions of graphics.h library, you can create your imagination to life. Using this project you can explore the world of graphic programming and at the same time you learn the coding skills.

In this article, I shall show you how create a C or C++ graphics program that displays a man walking in the rain with umbrella in graphics mode. In this program, I discuss the necessary steps by which you can create a man walks in the rain with umbrella with the help of graphics.h library of Turbo C++ IDE. Here, I explore you how to create a man walking in the rain with umbrella by C or C++ graphics programing language with source code.

About the program :

In this program, I draw a man with head, hands, legs and body and also draw an umbrella with the help of functions of graphics.h library. Here I create realistic rain effects such as drawing random lines. In this program, the man is walking in the rain with umbrella when the rain drops fall. This process is run continues until the user presses any key.

Explanation of the program :

In this program, I tell about the process of how to create a man walking in the rain with umbrella by C or C++ graphics programming language. The logic of the program is very simple. Here I draw a man with head, body, hands and legs. The man holds an umbrella in his hand. The drawing is created by different color. At the same time I create same drawing with black color. So the first drawing disappear because the background color of the screen is also black.

I also draw random lines to show multiple raindrops on the screen with the same process. Now I continuously update the position of the man and raindrops on the screen. By which user see the animation of a man walking with umbrella on a rainy day.

At the beginning, first include graphics.h, stdlib.h, conio.h and dos.h library in your program. The graphics.h use for graphical function, stdlib.h use for rand() function, conio.h use for kbhit() function and dos.h use for delay() function.
In the main function, initialize the graphics mode using the initgraph() function of graphics.h library. The initgraph() function takes the graphics driver, graphics mode and BGI path as parameters.

You have to determine the maximum X and Y coordinates of the graphic mode by getmaxx() and getmaxy() functions. Now use kbhit() function in a while loop to check any key press by the user or not. Next, set the background color of the screen by setbkcolor() function. Then setcolor() function use for color of different shapes. After that, using fillellipse() and arc() function create the top of umbrella and rectangle() function use for draw the arm of umbrella.

Now draw the head of the man using circle() function. Here setfillstyle() and floodfill() functions use for draw the style and color of different shapes. You can draw body, hands and legs by line() function. The line() function also use for creating rain drops. For controls the speed of the movement or walking of the man in the rain with an umbrella, use delay() function. The rand() function use for creating random rain effects. Lastly, you can use the closegraph() function to close the graphics mode.

How run the program :

At first, you have to need a C compiler with graphics.h library like Turbo C++. If there is no compiler in your pc, you can install the Turbo C++ which includes the necessary graphics library. When you compile and execute the program on your pc, you will see the animation of a man walking in the rain with umbrella.

To run this program using the C or C++ graphics programming language, you have to open Turbo C++ on your pc for use the graphics.h library of the Turbo C++ IDE. After open Turbo C++, create a C or C++ file in Turbo C ++ IDE. Now copy the below source code of a man walking in the rain with umbrella and paste in your C or C++ file in the Turbo C++ IDE.

If you do not know how to copy paste in Turbo C++ IDE click my link. Then save the file with .c or .cpp extension and run the code. Now you will see a man is walking in the rain with umbrella on the screen. If You do not know how to use graphics.h library in the Turbo C++ IDE just follow my link.

Source code :

Now, you can copy the below source code and create a program which draw a man walking in the rain with umbrella using C or C++ graphics programing language.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
  int graphic_driver = DETECT, graphic_mode;
  int xmax, ymax, i = 0, j = 0, k = 0, l, m = 0, n = 0;
  initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
  xmax = getmaxx();
  ymax = getmaxy();
  while (!kbhit())
  {
    setbkcolor(0);
    setcolor(4);
    setfillstyle(1, 15);
    fillellipse(100 + i, ymax - 100, 40, 10);
    setfillstyle(1, 4);
    arc(100 + i, ymax - 100, 0, 180, 40);
    arc(100 + i, ymax, 68, 105, 110);
    floodfill(100 + i, ymax - 120, 4);
    setcolor(9);
    setfillstyle(1, 9);
    rectangle(98 + i, ymax - 100, 102 + i, ymax - 50);
    floodfill(100 + i, ymax - 70, 9);
    setcolor(10);
    setfillstyle(1, 10);
    circle(75 + i, ymax - 90, 10);
    floodfill(75 + i, ymax - 90, 10);
    line(75 + i, ymax - 80, 75 + i, ymax - 50);
    line(75 + i, ymax - 70, 100 + i, ymax - 80);
    line(75 + i, ymax - 70, 100 + i, ymax - 80);
    if (j <= 30)
    {
      line(75 + i, ymax - 50, 90 + i - j, ymax - 20);
      line(75 + i, ymax - 50, 60 + i + j, ymax - 20);
    }
    if (j > 30)
    {
      line(75 + i, ymax - 50, 29 + i + j, ymax - 20);
      line(75 + i, ymax - 50, 121 + i - j, ymax - 20);
    }
    delay(100);
    setcolor(0);
    setfillstyle(1, 0);
    fillellipse(100 + i, ymax - 100, 40, 10);
    setfillstyle(1, 0);
    arc(100 + i, ymax - 100, 0, 180, 40);
    arc(100 + i, ymax, 68, 105, 110);
    floodfill(100 + i, ymax - 120, 0);
    setcolor(0);
    setfillstyle(1, 0);
    rectangle(98 + i, ymax - 100, 102 + i, ymax - 50);
    floodfill(100 + i, ymax - 70, 0);
    setcolor(0);
    setfillstyle(1, 0);
    circle(75 + i, ymax - 90, 10);
    floodfill(75 + i, ymax - 90, 0);
    line(75 + i, ymax - 80, 75 + i, ymax - 50);
    line(75 + i, ymax - 70, 100 + i, ymax - 80);
    line(75 + i, ymax - 70, 100 + i, ymax - 80);
    if (j <= 30)
    {
      line(75 + i, ymax - 50, 90 + i - j, ymax - 20);
      line(75 + i, ymax - 50, 60 + i + j, ymax - 20);
      j++;
    }
    if (j > 30)
    {
      line(75 + i, ymax - 50, 29 + i + j, ymax - 20);
      line(75 + i, ymax - 50, 121 + i - j, ymax - 20);
      j++;
    }
    if (j == 61)
      j = 0;
    i++;
    for (l = 0; l <= xmax; l += 20)
    {
      m = rand() % ymax;
      n = rand() % ymax;
      setcolor(15);
      line(l, k, l, k + 5);
      setcolor(0);
      line(l, m, l, m + 5);
      line(l, n, l, n + 5);
    }
    k += 20;
    if (k > ymax)
      k = 0;
  }
  closegraph();
  return 0;
}

Output :

After running this above program on your pc, you see the output of creating a man walking in the rain with umbrella using C or C++ graphics programing language. You can also see video of my YouTube channel as shown in below.

Conclusion :

Drawing a man walking in the rain with umbrella using C or C++ graphics programing language can be a creative and fantastic project. By utilizing the C or C++ programming language and graphics library of Turbo C++ IDE, you can create your artistic idea to life on a computer screen. You can use my code in your graphics program and create a different type of animation with fundamental graphics functions of the Turbo C++ IDE. Thank you for visiting my site.

Scroll to Top