#include<graphics.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> #include<dos.h> #include<bios.h> #include<math.h> #define ESC 0x11b0 #define R 8
out()
{
int key;
key=bioskey(0);
if(key==ESC)
exit(0);
}
void initgr(void) /*初始化 */ { int gd=DETECT,gm=0; initgraph(&gd,&gm,""); }
void main(void)
{
int minx=40;
int miny=40;
int maxx=400;
int maxy=400;
int x,y;
int cx,cy;
int addx=1,addy=-1;
x=(minx+maxx)/2;
y=(miny+maxy)/2; initgr(); rectangle(40,40,400,400);
while(1)
{
cx=x,cy=y;
x=x+addx,y=addy+y;
if(x<=minx+R+1||x>=maxx-R-1)
addx=-addx;
if(y<=miny+R+1||y>=maxy-R-1)
addy=-addy;
setcolor(WHITE);
circle(cx,cy,R);
delay(6000);
setcolor(RED);
circle(x,y,R);
if(bioskey(1))
out();
}
}