欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-07 13:57:37
...

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

#include <graphics.h>  //引入 easyx 图形库
#include <CONIO.H>
#include <math.h>

#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;
}
相关标签: c语言