//利用EasyX反弹球
#include <graphics.h> //引用EasyX图形库
#include <conio.h>
#define high 480
#define width 640
int main()
{
float ball_x,ball_y;
float ball_vx,ball_vy;
float radius;
initgraph(width,high);
ball_x=width/2;
ball_y=high/2;
ball_vx=1;
ball_vy=1;
radius=20;
while (1)
{
//绘制黑线、黑色的填充的圆
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(ball_x,ball_y,radius);
//更新小圆的坐标
ball_x=ball_x+ball_vx;
ball_y=ball_y+ball_vy;
if((ball_x<=radius)||(ball_x>=width-radius))
ball_vx=-ball_x;
if((ball_y<=radius)||(ball_y>=high-radius))
ball_y=-ball_y;
setcolor(YELLOW);
setfillcolor(GREEN);
fillcircle(ball_x,ball_y,radius);
sleep(30);
}
closegraph();
return 0;
}