默认你装了Visual Studio,我装的VS2019
EasyX官网:https://easyx.cn/
咱们直接下载
下载后是一个
运行后,它会自动检测本地的VS,提供安装和卸载操做。咱们点击“安装”就完成了。
git
ps:相关项目仓库提取 码云 github
打开VS,新建 控制台应用
github
贴入官方文档的代码web
#include <easyx.h> // 引用图形库头文件 #include <conio.h> int main() { initgraph(640, 480); // 建立绘图窗口,大小为 640x480 像素 circle(200, 200, 100); // 画圆,圆心(200, 200),半径 100 _getch(); // 按任意键继续 closegraph(); // 关闭绘图窗口 return 0; }
而后编译运行
第一次比较慢,须要等待一会,加载完成后的效果就是一个圆。
OK,第一个程序完成了!svg
// 编译环境:Visual C++ 6.0,EasyX 20190314(beta) // http://www.easyx.cn // #include <graphics.h> #include <time.h> #include <conio.h> int main() { // 设置随机函数种子 srand((unsigned)time(NULL)); // 初始化图形模式 initgraph(640, 480); int x, y; char c; settextstyle(16, 8, _T("Courier")); // 设置字体 // 设置颜色 settextcolor(GREEN); setlinecolor(BLACK); for (int i = 0; i <= 479; i++) { // 在随机位置显示三个随机字母 for (int j = 0; j < 3; j++) { x = (rand() % 80) * 8; y = (rand() % 20) * 24; c = (rand() % 26) + 65; outtextxy(x, y, c); } // 画线擦掉一个像素行 line(0, i, 639, i); Sleep(10); // 延时 if (i >= 479) i = -1; // 循环处理 if (_kbhit()) break; // 按任意键退出 } // 关闭图形模式 closegraph(); }
// 编译环境:Visual C++ 6.0,EasyX 20190314(beta) // http://www.easyx.cn // #include <graphics.h> #include <time.h> #include <conio.h> #define MAXSTAR 200 // 星星总数 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(); // 关闭绘图窗口 }
// 编译环境:Visual C++ 6.0,EasyX 20190314(beta) // http://www.easyx.cn // #include <graphics.h> #include <conio.h> int main() { // 初始化图形窗口 initgraph(640, 480); MOUSEMSG m; // 定义鼠标消息 while(true) { // 获取一条鼠标消息 m = GetMouseMsg(); switch(m.uMsg) { case WM_MOUSEMOVE: // 鼠标移动的时候画红色的小点 putpixel(m.x, m.y, RED); break; case WM_LBUTTONDOWN: // 若是点左键的同时按下了 Ctrl 键 if (m.mkCtrl) // 画一个大方块 rectangle(m.x-10, m.y-10, m.x+10, m.y+10); else // 画一个小方块 rectangle(m.x-5, m.y-5, m.x+5, m.y+5); break; case WM_RBUTTONUP: return 0; // 按鼠标右键退出程序 } } // 关闭图形窗口 closegraph(); }
// 编译环境:Visual C++ 6.0,EasyX 20190314(beta) // http://www.easyx.cn // #include <graphics.h> #include <conio.h> int main() { // 建立绘图窗口 initgraph(640, 480); // 画渐变的天空(经过亮度逐渐增长) float H = 190; // 色相 float S = 1; // 饱和度 float L = 0.7f; // 亮度 for(int y = 0; y < 480; y++) { L += 0.0005f; setlinecolor( HSLtoRGB(H, S, L) ); line(0, y, 639, y); } // 画彩虹(经过色相逐渐增长) H = 0; S = 1; L = 0.5f; setlinestyle(PS_SOLID, 2); // 设置线宽为 2 for(int r = 400; r > 344; r--) { H += 5; setlinecolor( HSLtoRGB(H, S, L) ); circle(500, 480, r); } // 按任意键退出 _getch(); closegraph(); }