Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C Graphics Program for A Man Walking In Rain

Program in c to Draw a Man walking in the rain using graphics (CG) program. Program is made using 3 different objects. A man with Umbrella, Rain and Ground.


To draw rain we have used Rand() and Line() functions. Rand() function generates sequence of random numbers, which are location coordinates on-screen to draw rain using line() function. Speed of man can be adjusted using delay() function. Higher the delay lesser the speed.



#include
#include

#define ScreenWidth getmaxx()
#define ScreenHeight getmaxy()
#define GroundY ScreenHeight*0.75

int ldaisp=0;
void DrawManWithUmbrella(int a,int ldaisp)
{
    //Draw Umbrella
    pieslice(a+20,GroundY-120,0,180,40);
line(a+20,GroundY-120,a+20,GroundY-70);

    //Draw head
circle(a,GroundY-90,10);
line(a,GroundY-80,a,GroundY-30);

    //Draw hand
line(a,GroundY-70,a+10,GroundY-60);
line(a,GroundY-65,a+10,GroundY-55);
line(a+10,GroundY-60,a+20,GroundY-70);
line(a+10,GroundY-55,a+20,GroundY-70);

    //Draw legs
line(a,GroundY-30,a+ldaisp,GroundY);
line(a,GroundY-30,a-ldaisp,GroundY);
}

void Rain(int a)
{
int i,rx,ry;
for(i=0;i {
rx=rand() % ScreenWidth;
ry=rand() % ScreenHeight;
if(ry {
if(ryGroundY-120 && (rxa+60)))
line(rx,ry,rx+0.5,ry+4);
}
}
}

void main()
{
int gd=DETECT,gm,a=0;
initgraph(&gd,&gm,"C:\TurboC++\Disk\TurboC3\BGI");

    while(!kbhit())
{
//Draw Ground
line(0,GroundY,ScreenWidth,GroundY);
Rain(a);
ldaisp=(ldaisp+2)%20;
DrawManWithUmbrella(a,ldaisp);
delay(40);
cleardevice();
a=(a+2)%ScreenWidth;
}
getch();
}


Program in c to draw a Man walking in the rain using graphics programming.


This post first appeared on Ask For Program, please read the originial post: here

Share the post

C Graphics Program for A Man Walking In Rain

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×