Browse » Home
»
Program to create a moving ball screensaver
» Program to create a moving ball screensaver
Program to create a moving ball screensaver
Program to create a moving ball screensaver
#include <graphics.h>
#include <dos.h>
#include <conio.h>
void main()
{
int g,d,x=33,y;
d=DETECT;
initgraph(&d,&g,"c:\\tc\\bgi");
setbkcolor(2);
while(!kbhit())
{
for(y=10;y<100;y++)
{
if(kbhit())
{
break;
}
cleardevice();
setfillstyle(1,1);
circle(x,y,15);
floodfill(x,y,15);
delay(10);
x=x+5;
}
for(x=483;x>200;x--)
{
if(kbhit())
{
break;
}
cleardevice();
setfillstyle(1,1);
circle(x,y,15);
floodfill(x,y,15);
delay(1);
y++;
}
for(x=200;x>40;x--)
{
if(kbhit())
{
break;
}
cleardevice();
setfillstyle(1,1);
circle(x,y,15);
floodfill(x,y,15);
delay(1);
y--;
}
for(x=40;x<170;x++)
{
if(kbhit())
{
break;
}
cleardevice();
setfillstyle(1,1);
circle(x,y,15);
floodfill(x,y,15);
delay(1);
y--;
}
} //end of while
getch();
}
Output :
Running this program will create a moving ball in all directions of the screen
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment