Easyx——基于easyx的c语言简单动画入门

Easyx——基于easyx的c语言简单动画入门_第1张图片

#include   //引入 easyx 图形库
#include 
#include 

#define High 800
#define Width 640 
#define ball_radius 20
int main()
{
	int ball_y=High/2;
    int ball_x=Width/2;
    int ball_vx = 10;
	int ball_vy = 10;


	initgraph(Width,High);   //初始化画布。大小为640*480

	BeginBatchDraw();  //开始批量绘图

    while (1)
    {
    
	setcolor(YELLOW);  //圆的线条为黄色
	setfillcolor(GREEN);   //圆内部位绿色填充
	fillcircle(ball_x,ball_y,ball_radius);  //画圆,圆心(100,100) 半径20
	
	FlushBatchDraw();  将之前的绘图输出
	
	Sleep(20);

	setcolor(BLACK);
	setfillcolor(BLACK);
	fillcircle(ball_x,ball_y,200);

	ball_y = ball_y + ball_vy;
	ball_x = ball_x +ball_vx;

    if (ball_x<=ball_radius||ball_x >=Width - ball_radius)
        ball_vx = -1 * ball_vx;
	if (ball_y<=ball_radius||ball_y >=High - ball_radius)
	    ball_vy = -1 *ball_vy;

	}

	EndBatchDraw();  //结束批量绘制,并执行未完成的绘制任务。
	closegraph();
return 0;
}

你可能感兴趣的:(Easyx——基于easyx的c语言简单动画入门)