Cycle

Write a program to simulate the man riding a bicycle.



#include<graphics.h>
#include<math.h>

void main()
{
	int gd=DETECT,gm,i,j=-168;
	double x,y,x1,y1,x2,y2,x3,y3,
x4,y4,x5,y5,step=(12*M_PI)/360,a=0.0;
	initgraph(&gd,&gm,"c:\\tc\\bgi");
	while(!kbhit())
	{
	circle(50+j,270,28);
	setfillstyle(SOLID_FILL,BLACK);
	for(i=0;i<=360;i+=15)
		sector(50+j,270,i,i+15,25,25);

	circle(140+j,270,28);
	for(i=0;i<=360;i+=15)
	       sector(140+j,270,i,i+15,25,25);

	x=90+15*cos(a);
	y=275+15*sin(a);
	x1=90-15*cos(a);
	y1=275-15*sin(a);
	setcolor(WHITE);
	line(90+j,275,x+j,y);
	setcolor(WHITE);
	a+=step;
	if(a>=2*M_PI)
	a=0.00;
	x2=x+10; y2=y-35;
	x3=x1+10; y3=y1-35;
	x4=x-40; y4=y-5;
	x5=x+50; y5=y-5;
	circle(x4+j,y4,4);
	circle(x5+j,y5,4);
	setfillstyle(SOLID_FILL,WHITE);
	floodfill(x4+j,y4,WHITE);
	floodfill(x5+j,y5,WHITE);

	line(x+j,y,x2+j,y2);
	line(70+j,222,x2+j,y2);

	setcolor(GREEN);
	setfillstyle(EMPTY_FILL,WHITE);
	for(i=0;i<=360;i+=72)
		sector(90+j,275,i,i+72,8,8);
	setcolor(WHITE);

	line(50+j,268,90+j,273);
	line(50+j,271,90+j,276);
	line(50+j,268,50+j,272);
	line(90+j,273,90+j,277);

	line(49+j,268,71+j,232);
	line(51+j,268,73+j,232);

	line(71+j,232,89+j,275);
	line(73+j,232,91+j,275);

	line(139+j,270,124+j,232);
	line(141+j,270,126+j,232);

	line(72+j,231,125+j,231);
	line(72+j,233,125+j,233);

	line(90+j,274,125+j,233);
	line(90+j,276,125+j,235);

	line(72+j,232,71+j,227);
	line(68+j,227,80+j,226);
	line(63+j,222,68+j,227);
	line(63+j,222,77+j,223);
	line(77+j,223,80+j,226);
	setfillstyle(SOLID_FILL,WHITE);
	floodfill(70+j,225,WHITE);

	line(125+j,232,123+j,225);
	line(123+j,225,129+j,225);
	line(115+j,221,129+j,221);
	rectangle(115+j,220,125+j,222);
	arc(129+j,223,270,90,2);
	setcolor(WHITE);

	line(50+j,269,89+j,267);
	line(50+j,271,89+j,283);

	setcolor(WHITE);
	line(90+j,275,x1+j,y1);

	setcolor(WHITE);
	line(x1+j,y1,x3+j,y3);
	line(70+j,222,x3+j,y3);

	line(70+j,222,75+j,180);
	circle(75+j,168,12);

	line(75+j,190,95+j,210);
	line(95+j,210,120+j,220);
	line(75+j,190,105+j,205);
	line(105+j,205,120+j,219);
	delay(10);
	j++;
	if(j==getmaxx())
	j=-168;
	clearviewport();
	}
	closegraph();
}



Output
1

One Reply to “Cycle”

Leave a Reply

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