0
点赞
收藏
分享

微信扫一扫

EasyX图形库安装,以及使用样例(vc6.0,vs2013,其他类同)


​​官网下载​​ ②解压安装

(由于自己电脑安装了vc6.0 和vs2013以该两个为例,其他都是一样的安装方法)

EasyX图形库安装,以及使用样例(vc6.0,vs2013,其他类同)_李阡殇


EasyX图形库安装,以及使用样例(vc6.0,vs2013,其他类同)_李阡殇_02


③图形库测试

利用图形库画星空 (l编译器vs 2013)

#include<stdafx.h>
#include <graphics.h>
#include <time.h>
#include <conio.h>

#define MAXSTAR 800 // 星星总数

struct STAR
{
double x;
int y;
double step;
int color;
};

STAR star[MAXSTAR];

// 初始化星星
void InitStar(int i)
{
star[i].x = 0;
star[i].y = rand() % 480;
star[i].step = (rand() % 5000) / 1000.0 + 1;
star[i].color = (int)(star[i].step * 255 / 6.0 + 0.5); // 速度越快,颜色越亮
star[i].color = RGB(star[i].color, star[i].color, star[i].color);
}

// 移动星星
void MoveStar(int i)
{
// 擦掉原来的星星
putpixel((int)star[i].x, star[i].y, 0);

// 计算新位置
star[i].x += star[i].step;
if (star[i].x > 640) InitStar(i);

// 画新星星
putpixel((int)star[i].x, star[i].y, star[i].color);
}

// 主函数
int main()
{
srand((unsigned)time(NULL)); // 随机种子
initgraph(640, 480); // 创建绘图窗口

// 初始化所有星星
for (int i = 0; i < MAXSTAR; i++)
{
InitStar(i);
star[i].x = rand() % 640;
}

// 绘制星空,按任意键退出
while (!_kbhit())
{
for (int i = 0; i < MAXSTAR; i++)
MoveStar(i);
Sleep(20);
}

closegraph(); // 关闭绘图窗口
}

EasyX图形库安装,以及使用样例(vc6.0,vs2013,其他类同)_李阡殇_03


控件使用实例,以及图像库的具体使用,参考下载的图形库的帮助文档。

EasyX图形库安装,以及使用样例(vc6.0,vs2013,其他类同)_#include_04


举报

相关推荐

0 条评论