A C++ to program to show 2D Bouncing Ball


#include <graphics.h>
#include <conio.h>
int main()
{
int gd = DETECT, gm, i;
initgraph(&gd, &gm, “”);
int x,y=0,j,t=400,c=1;
setcolor(RED);
setfillstyle(SOLID_FILL,YELLOW);
for(x=40;x<602;x++)
{
cleardevice();
circle(x,y,20);
floodfill(x,y,YELLOW);
delay(40);
if(y>=400)
{
c=0;
t-=20;
}
if(y<=(400-t))
c=1;
y=y+(c?15:-15);
}
getch();
}