#include <graphics.
h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
// Structure to hold raindrop data
struct Raindrop {
int x, y, speed;
};
// Function to initialize raindrops with random positions and speeds
void initRain(struct Raindrop raindrops[], int numDrops) {
for (int i = 0; i < numDrops; i++) {
raindrops[i].x = rand() % getmaxx();
raindrops[i].y = rand() % getmaxy();
raindrops[i].speed = rand() % 5 + 2; // Random speed for variation
// Function to draw falling raindrops and update their positions
void drawRain(struct Raindrop raindrops[], int numDrops) {
setcolor(CYAN);
for (int i = 0; i < numDrops; i++) {
line(raindrops[i].x, raindrops[i].y, raindrops[i].x, raindrops[i].y + 10);
raindrops[i].y += raindrops[i].speed; // Move the raindrop downward
// Reset raindrop position if it moves beyond the screen
if (raindrops[i].y > getmaxy()) {
raindrops[i].y = 0;
raindrops[i].x = rand() % getmaxx();
}
}
// Function to draw the umbrella
void drawUmbrella(int x, int y) {
setcolor(WHITE);
// Umbrella canopy
arc(x, y, 0, 180, 30); // Arc for umbrella top
line(x - 30, y, x + 30, y); // Bottom line of umbrella
line(x, y, x, y + 40); // Handle
// Function to draw a walking man with umbrella
void drawMan(int x, int y, int step) {
// Draw head
setcolor(WHITE);
circle(x, y + 50, 10);
// Draw body
line(x, y + 60, x, y + 100);
// Draw arms
line(x, y + 70, x - 20, y + 85); // Left arm
line(x, y + 70, x + 20, y + 60); // Right arm holding umbrella
// Draw legs with alternating movement
if (step % 2 == 0) {
// Left leg forward, right leg back
line(x, y + 100, x - 10, y + 120); // Left leg forward
line(x, y + 100, x + 10, y + 110); // Right leg back
} else {
// Right leg forward, left leg back
line(x, y + 100, x - 10, y + 110); // Left leg back
line(x, y + 100, x + 10, y + 120); // Right leg forward
// Function to draw background (can be modified to include more scenery)
void drawBackground() {
setcolor(WHITE);
// Draw some ground
line(0, getmaxy() - 50, getmaxx(), getmaxy() - 50);
// Function to draw the complete scene
void drawScene(int x, int y, int step, struct Raindrop raindrops[], int numDrops) {
cleardevice(); // Clear the screen
// Draw background elements
drawBackground();
// Draw rain
drawRain(raindrops, numDrops);
// Draw the man walking with umbrella
drawUmbrella(x, y);
drawMan(x, y, step);
// Main animation loop
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
// Man's starting position and step count
int x = 50, y = 200;
int step = 0;
// Define number of raindrops
const int numDrops = 300;
struct Raindrop raindrops[numDrops];
// Initialize raindrops
initRain(raindrops, numDrops);
// Main loop to animate the man and rain
while (!kbhit()) { // Run until a key is pressed
drawScene(x, y, step, raindrops, numDrops);
// Update the man's position and step for walking animation
x += 5;
step++;
// Reset man's position if he walks off-screen
if (x > getmaxx()) {
x = 0;
// Control the speed of the animation
delay(100);
} closegraph();
return 0;}