#include #include //包含图形库函数 #include //包含 getch() #include #include int main() { int x=200,y=200; int x0=5,y0=5; initgraph(400,400); setcolor(RGB(255,0,0)); //red green blue 三种颜色的设置 setfillstyle(RGB(255,0,0));//设置填充颜色 fillcircle(x,y,30); //让小球动起来 while(true) { Sleep(50); //50ms 1000ms=1s setcolor(RGB(0,0,0)); setfillstyle(RGB(0,0,0)); fillcircle(x,y,30); srand((unsigned)time(NULL));// 产生随机的种子数 if(x>=370) x0=-(rand()%5+1); //-1-5之间的随机数 if(y>=370) y0=-(rand()%5+1); if(x<=30) x0=(rand()%5+1); if(y<=30) y0=(rand()%5+1); x=x+x0; y=y+y0; setcolor(RGB(255,0,0)); setfillstyle(RGB(255,0,0)); fillcircle(x,y,30); } //line(50,50,200,200); //circle(200,200,100); //fillcircle(50,50,50); //设置填充颜色 setfillstyle(RGB(255,0,0)); getch();//等待输入字符 closegraph();//关闭图形环境 } 本文来源:https://www.wddqw.com/doc/81165c254b7302768e9951e79b89680202d86b5b.html