当前位置: 代码迷 >> 综合 >> Easyx——基于easyx的c语言简单动画入门
  详细解决方案

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

热度:30   发布时间:2023-12-01 10:52:38.0

在这里插入图片描述

#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*480BeginBatchDraw();  //开始批量绘图while (1){
    setcolor(YELLOW);  //圆的线条为黄色setfillcolor(GREEN);   //圆内部位绿色填充fillcircle(ball_x,ball_y,ball_radius);  //画圆,圆心(100,100) 半径20FlushBatchDraw();  将之前的绘图输出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;
}