0

hello guys,

the following code is taken from my senior. i am unable to under stand its logic .

because i am new in graphics can u guys kindly explain its logics

thanks.

```
#include<graphics.h>
#include<conio.h>
#define left 0
#define top 0
#define right 639
#define bottom 479
#define radius 20
void main ()
{
int gdriver = DETECT, gmode, errorcode;
int x,y,dx,dy,oldx,oldy;
unsigned char ballbuff[2000];
initgraph(&gdriver, &gmode, "");
rectangle(left, top, right,bottom);
x=left+radius+10;
y= top+radius +10;
setbkcolor(BROWN);
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL,YELLOW);
circle(x,y,radius);
floodfill(x,y,LIGHTGREEN);
getimage(x-radius,y-radius,x+radius,y+radius,ballbuff);
dx=2;dy=2;
while(!kbhit())
{
putimage(x-radius,y-radius,ballbuff,COPY_PUT);
oldx=x;oldy=y;
x+=dx;y+=dy;
if(x==left+radius+2||x>=right-radius-2)
dx=-dx;
if(y==top+radius+2||y>=bottom-radius-2)
dy=-dy;
putimage(oldx-radius,oldy-radius-2,ballbuff,XOR_PUT);
delay(1);
}
getch();
closegraph();
}
```