C and C++ Computer Graphics

Graphics program for man walking

Graphics program for man walking
#include <graphics.h>
#include <conio.h>
#include <dos.h>

int main() {
int gd = DETECT, gm;
int x, y = 300; // base Y position for walking

initgraph(&gd, &gm, "");

for (x = 50; x <= 500; x += 10) {
cleardevice();

// Draw ground
line(0, y+50, getmaxx(), y+50);

// Draw head
setcolor(WHITE);
circle(x, y-40, 15); // head

// Draw body
line(x, y-25, x, y+20);

// Draw arms (swing effect using x position)
if (x % 20 == 0) {
line(x, y-15, x-20, y+10); // left arm forward
line(x, y-15, x+20, y+10); // right arm backward
} else {
line(x, y-15, x+20, y+10); // right arm forward
line(x, y-15, x-20, y+10); // left arm backward
}

// Draw legs (alternate movement)
if (x % 20 == 0) {
line(x, y+20, x-15, y+50); // left leg forward
line(x, y+20, x+15, y+50); // right leg backward
} else {
line(x, y+20, x+15, y+50); // right leg forward
line(x, y+20, x-15, y+50); // left leg backward
}

delay(120); // control speed
}

setcolor(GREEN);
outtextxy(200, 400, "Walking Animation Complete!");

getch();
closegraph();
return 0;
}

Leave a comment

Your email address will not be published. Required fields are marked *