绘制动画(3)

 1 //绘制一个沿 45 度移动的球,碰到窗口边界后反弹。
 2 #include<graphics.h>
 3 #include<conio.h>
 4 
 5 void runner(int x,int y)
 6 {
 7     int a=1,b=1;
 8     while(1)
 9     {
10         x=x+a;
11         y=y+b;
12         setcolor(RGB(0,0,255));
13         setfillcolor(RGB(0,0,255));
14         fillcircle(x,y,20);
15         Sleep(10);
16         setcolor(BLACK);
17         setfillcolor(BLACK);
18         fillcircle(x,y,20);//假如没有这一句的话 运动轨迹不会被清楚,从哪走过都会显示出来,也就是说要想把轨迹清楚,下面的要大于等于上面的半径
19         if(x==0||x==639)
20             a=-1*a;
21         if(y==0||y==479)
22             b=-1*b;
23     }
24 }
25 int main()
26 {
27     int x=0,y=0;
28     initgraph(640,480);
29     runner(x,y);
30     getch();
31     closegraph();
32 }
View Code
原文地址:https://www.cnblogs.com/firstsy0709/p/3642830.html