#include#include #include int main(){ float x = 20; // 设定小球的初始水平坐标 float y = 300; // 设定小球的初始垂直坐标 float velocityx = 2; // 水平速度 float velocityY = 3; // 垂直速度 initgraph(600, 600); // 屏幕上初始化一个600 600的窗口 while (1){ cleardevice(); // 清除上一次循环画的图像 x += velocityx; // 更新水平位置 y += velocityY; // 更新垂直位置 if (x < 20 || x>580) { // 判断小球是否水平方向上到了窗口边缘,如果 到了边缘则反弹 velocityx = -velocityx; } else if (y > 580 || y < 20) { // 判断小球是否垂直方向上到了窗口边缘,如果 到了边缘则反弹 velocityY = -velocityY; } fillcircle(x, y, 20); // 画一个水平方向在x 垂直位置在y 半径为20 的圆 Sleep(10); // 睡眠10毫秒 } _getch(); closegraph(); return 0; }



