#include <graphics.h>
#include <conio.h>
void f1();
void f2();
void f3();
void f4();
int x=100,y=100;
const int r = 100;
int main ()
{
initgraph(640,480);
f1();
closegraph();
}
void f1() //运动方向右下
{
for(;x<540&&y<380;x+=20,y+=20)
{
setlinecolor(RED);
setfillcolor(YELLOW);
fillcircle(x,y,r);
Sleep(100);
setlinecolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,r);
}
if(x>=540) //碰到右边界方向变为左下
f2();
if(y>=380) //碰到下边界方向变为右上
f3();
}
void f2() //运动方向左下
{
for(;x>100&&y<380;x-=20,y+=20)
{
setlinecolor(RED);
setfillcolor(YELLOW);
fillcircle(x,y,r);
Sleep(100);
setlinecolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,r);
}
if(x<=100)
f1();
if(y>=380)
f4();
}
void f3() //运动方向右上
{
for(;x<540&&y>100;x+=20,y-=20)
{
setlinecolor(RED);
setfillcolor(YELLOW);
fillcircle(x,y,r);
Sleep(100);
setlinecolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,r);
}
if(x>=540)
f4();
if(y<=100)
f1();
}
void f4() //运动方向左上
{
for(;x>100&&y>100;x-=20,y-=20)
{
setlinecolor(RED);
setfillcolor(YELLOW);
fillcircle(x,y,r);
Sleep(100);
setlinecolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,r);
}
if(x<=100)
f3();
if(y<=100)
f2();
}
第一次接触easyx,感觉很有意思,暑假一定要好好静下心来学东西