easyx 订阅
EasyX 是针对 C/C++ 的图形库,可以帮助使用C/C++语言的程序员快速上手图形和游戏编程。比如,可以用 VC + EasyX 很快的用几何图形画一个房子,或者一辆移动的小车,可以编写俄罗斯方块、贪吃蛇、黑白棋等小游戏,可以练习图形学的各种算法,等等。 展开全文
EasyX 是针对 C/C++ 的图形库,可以帮助使用C/C++语言的程序员快速上手图形和游戏编程。比如,可以用 VC + EasyX 很快的用几何图形画一个房子,或者一辆移动的小车,可以编写俄罗斯方块、贪吃蛇、黑白棋等小游戏,可以练习图形学的各种算法,等等。
信息
外文名
EasyX
操作系统版本
Windows 2000 及以上系统
目    标
C/C++的图形库
用    途
帮助使用C/C++语言的程序员进行图形编程
中文名
EasyX
EasyX安装
系统支持 [1]  编译环境版本:Visual C++ 6.0、Visual Studio 2003/2008/2010/2012/2013/2015/2017/2019。安装执行 Setup.hta,并跟随提示安装即可。如果您想手动安装,将 include 和 lib 文件夹下的文件分别拷贝到 VC 对应的 include 和 lib 文件夹内即可。或者将 include 和 lib 文件夹放到任意位置,然后修改VC 中的 Lib 和 Include 的引用路径也可以。总之,就是要让 VC 能找到这几个文件。卸载由于安装程序并不改写注册表,因此您在“添加删除程序”中不会看到 EasyX 的卸载项。如需卸载,请执行 Setup.hta,并跟随提示卸载。新版本的安装程序并不能确保完全卸载旧版本,因此请保留相应版本的安装程序。文件列表说明下载的压缩包里文件列表及对应说明如下:include<文件夹>graphics.h 程序需要引用的头文件lib<文件夹>graphics.lib VC6 MBCS 版本库文件graphicsu.lib VC6 Unicode 版本库文件graphicsw.lib VC2008 / VC2010 MBCS 版本库文件graphicswu.lib VC2008 / VC2010 Unicode 版本库文件EasyX_Help.chm  帮助文件Setup.hta  安装程序项目依赖该绘图库采用静态链接方式,不会为您的程序增加任何额外的 DLL 依赖项。
收起全文
精华内容
下载资源
问答
  • easyx

    千次阅读 2016-05-16 18:45:33
    EasyX简易绘图实例 时间 2014-03-25 17:23:40 CSDN博客 原文 http://blog.csdn.net/u013629228/article/details/22079165 主题 技术 EasyX简易绘图实例 绘制一个圆从左向右移动 #include ...

    EasyX简易绘图实例

    EasyX简易绘图实例

    绘制一个圆从左向右移动

    <span style="font-size:18px;"><span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <graphics.h></span>
    <span style="FONT-WEIGHT: bold" class="keyword">int</span> main()
    {
    <span class="indent">  </span>initgraph(<span class="number" style="color:#09999;">640</span>,<span class="number" style="color:#09999;">480</span>);<span class="comment" style="color:#999988;FONT-STYLE: italic">//绘图环境640*480</span>
    <span class="indent">  </span>setcolor(WHITE);<span class="comment" style="color:#999988;FONT-STYLE: italic">//绘图前景色为白色</span>
    <span class="indent">  </span>setfillstyle(BS_SOLID);<span class="comment" style="color:#999988;FONT-STYLE: italic">//填充样式为固实填充</span>
    <span class="indent">  </span>setfillcolor(RED);<span class="comment" style="color:#999988;FONT-STYLE: italic">//填充颜色为蓝色</span>
    <span class="indent">  </span>BeginBatchDraw();<span class="comment" style="color:#999988;FONT-STYLE: italic">//开始批量绘图</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">for</span>(<span style="FONT-WEIGHT: bold" class="keyword">int</span> i=<span class="number" style="color:#09999;">50</span>; i<<span class="number" style="color:#09999;">600</span>; i++)
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span>circle(i,<span class="number" style="color:#09999;">100</span>,<span class="number" style="color:#09999;">40</span>);<span class="comment" style="color:#999988;FONT-STYLE: italic">//画圆</span>
    <span class="indent">  </span><span class="indent">  </span>floodfill(i, <span class="number" style="color:#09999;">100</span>, WHITE);<span class="comment" style="color:#999988;FONT-STYLE: italic">//填充</span>
    <span class="indent">  </span><span class="indent">  </span>FlushBatchDraw();<span class="comment" style="color:#999988;FONT-STYLE: italic">//执行未完成的绘制任务</span>
    <span class="indent">  </span><span class="indent">  </span>Sleep(<span class="number" style="color:#09999;">10</span>);<span class="comment" style="color:#999988;FONT-STYLE: italic">//挂起50毫秒</span>
    <span class="indent">  </span><span class="indent">  </span>cleardevice();<span class="comment" style="color:#999988;FONT-STYLE: italic">//用背景色清空屏幕</span>
    <span class="indent">  </span>}
    <span class="indent">  </span>EndBatchDraw();<span class="comment" style="color:#999988;FONT-STYLE: italic">//结束批量绘制</span>
    <span class="indent">  </span>closegraph();<span class="comment" style="color:#999988;FONT-STYLE: italic">//关闭图形环境</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">return</span> <span class="number" style="color:#09999;">0</span>;
    }</span>

    力学:弹跳球模拟程序

    <span style="font-size:18px;"><span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <graphics.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <conio.h></span>
    <span style="FONT-WEIGHT: bold" class="keyword">int</span> main()
    {
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">double</span> h = <span class="number" style="color:#09999;">300</span>;				<span class="comment" style="color:#999988;FONT-STYLE: italic">// 高度</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">double</span> v = <span class="number" style="color:#09999;">0</span>;				<span class="comment" style="color:#999988;FONT-STYLE: italic">// 速度(方向向下)</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">double</span> dv = <span class="number" style="color:#09999;">9.8</span> / <span class="number" style="color:#09999;">50</span>;		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 加速度(每 1/50 秒)</span>
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 初始化绘图窗口</span>
    <span class="indent">  </span>initgraph(<span class="number" style="color:#09999;">640</span>, <span class="number" style="color:#09999;">480</span>);
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画地平线</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">100</span>, <span class="number" style="color:#09999;">421</span>, <span class="number" style="color:#09999;">540</span>, <span class="number" style="color:#09999;">421</span>);
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">while</span>(!_kbhit())
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span>v += dv;				<span class="comment" style="color:#999988;FONT-STYLE: italic">// 根据加速度计算速度</span>
    <span class="indent">  </span><span class="indent">  </span>h -= (v - dv / <span class="number" style="color:#09999;">2</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 计算高度</span>
    <span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 如果高度低于地平线,实现反弹,速度方向取反</span>
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span> (h <= <span class="number" style="color:#09999;">0</span>)
    <span class="indent">  </span><span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>h += (v - dv / <span class="number" style="color:#09999;">2</span>);
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>v = - v * <span class="number" style="color:#09999;">0.9</span>;		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 反弹时能量损耗 10%</span>
    <span class="indent">  </span><span class="indent">  </span>}
    <span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画绿色球</span>
    <span class="indent">  </span><span class="indent">  </span>setcolor(GREEN);
    <span class="indent">  </span><span class="indent">  </span>circle(<span class="number" style="color:#09999;">320</span>, <span class="number" style="color:#09999;">400</span> - <span style="FONT-WEIGHT: bold" class="keyword">int</span>(h), <span class="number" style="color:#09999;">20</span>);
    <span class="indent">  </span><span class="indent">  </span>Sleep(<span class="number" style="color:#09999;">20</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 延时(每帧延时 1/50 秒)</span>
    <span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 擦掉球</span>
    <span class="indent">  </span><span class="indent">  </span>setcolor(BLACK);
    <span class="indent">  </span><span class="indent">  </span>circle(<span class="number" style="color:#09999;">320</span>, <span class="number" style="color:#09999;">400</span> - <span style="FONT-WEIGHT: bold" class="keyword">int</span>(h), <span class="number" style="color:#09999;">20</span>);
    <span class="indent">  </span>}
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 关闭绘图窗口</span>
    <span class="indent">  </span>closegraph();
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">return</span> <span class="number" style="color:#09999;">0</span>;
    }</span>

    钟表模拟程序(表针形式)

    <span style="font-size:18px;"><span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <graphics.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <conio.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <math.h></span>
    
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#<span class="keyword" style="color:#333333;">define</span>	PI	3.1415926536</span>
    
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> DrawHand(<span style="FONT-WEIGHT: bold" class="keyword">int</span> hour, <span style="FONT-WEIGHT: bold" class="keyword">int</span> minute, <span style="FONT-WEIGHT: bold" class="keyword">int</span> second)
    {
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">double</span> a_hour, a_min, a_sec;					<span class="comment" style="color:#999988;FONT-STYLE: italic">// 时、分、秒针的弧度值</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">int</span> x_hour, y_hour, x_min, y_min, x_sec, y_sec;	<span class="comment" style="color:#999988;FONT-STYLE: italic">// 时、分、秒针的末端位置</span>
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 计算时、分、秒针的弧度值</span>
    <span class="indent">  </span>a_sec = second * <span class="number" style="color:#09999;">2</span> * PI / <span class="number" style="color:#09999;">60</span>;
    <span class="indent">  </span>a_min = minute * <span class="number" style="color:#09999;">2</span> * PI / <span class="number" style="color:#09999;">60</span> + a_sec / <span class="number" style="color:#09999;">60</span>;
    <span class="indent">  </span>a_hour= hour * <span class="number" style="color:#09999;">2</span> * PI / <span class="number" style="color:#09999;">12</span> + a_min / <span class="number" style="color:#09999;">12</span>;
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 计算时、分、秒针的末端位置</span>
    <span class="indent">  </span>x_sec = <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">120</span> * sin(a_sec));
    <span class="indent">  </span>y_sec = <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">120</span> * cos(a_sec));
    <span class="indent">  </span>x_min = <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">100</span> * sin(a_min));
    <span class="indent">  </span>y_min = <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">100</span> * cos(a_min));
    <span class="indent">  </span>x_hour= <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">70</span> * sin(a_hour));
    <span class="indent">  </span>y_hour= <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">70</span> * cos(a_hour));
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画时针</span>
    <span class="indent">  </span>setlinestyle(PS_SOLID, <span class="number" style="color:#09999;">10</span>);
    <span class="indent">  </span>setcolor(WHITE);
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">320</span> + x_hour, <span class="number" style="color:#09999;">240</span> - y_hour, <span class="number" style="color:#09999;">320</span> - x_hour / <span class="number" style="color:#09999;">7</span>, <span class="number" style="color:#09999;">240</span> + y_hour / <span class="number" style="color:#09999;">7</span>);
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画分针</span>
    <span class="indent">  </span>setlinestyle(PS_SOLID, <span class="number" style="color:#09999;">6</span>);
    <span class="indent">  </span>setcolor(LIGHTGRAY);
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">320</span> + x_min, <span class="number" style="color:#09999;">240</span> - y_min, <span class="number" style="color:#09999;">320</span> - x_min / <span class="number" style="color:#09999;">5</span>, <span class="number" style="color:#09999;">240</span> + y_min / <span class="number" style="color:#09999;">5</span>);
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画秒针</span>
    <span class="indent">  </span>setlinestyle(PS_SOLID, <span class="number" style="color:#09999;">2</span>);
    <span class="indent">  </span>setcolor(RED);
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">320</span> + x_sec, <span class="number" style="color:#09999;">240</span> - y_sec, <span class="number" style="color:#09999;">320</span> - x_sec / <span class="number" style="color:#09999;">3</span>, <span class="number" style="color:#09999;">240</span> + y_sec / <span class="number" style="color:#09999;">3</span>);
    }
    
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> DrawDial()
    {
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 绘制一个简单的表盘</span>
    <span class="indent">  </span>circle(<span class="number" style="color:#09999;">320</span>, <span class="number" style="color:#09999;">240</span>, <span class="number" style="color:#09999;">2</span>);
    <span class="indent">  </span>circle(<span class="number" style="color:#09999;">320</span>, <span class="number" style="color:#09999;">240</span>, <span class="number" style="color:#09999;">60</span>);
    <span class="indent">  </span>circle(<span class="number" style="color:#09999;">320</span>, <span class="number" style="color:#09999;">240</span>, <span class="number" style="color:#09999;">160</span>);
    <span class="indent">  </span>outtextxy(<span class="number" style="color:#09999;">296</span>, <span class="number" style="color:#09999;">310</span>, <span class="string" style="color:#dd1144;">"BestAns"</span>);
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 绘制刻度</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">int</span> x, y;
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">for</span> (<span style="FONT-WEIGHT: bold" class="keyword">int</span> i=<span class="number" style="color:#09999;">0</span>; i<<span class="number" style="color:#09999;">60</span>; i++)
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span>x = <span class="number" style="color:#09999;">320</span> + <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">145</span> * sin(PI * <span class="number" style="color:#09999;">2</span> * i / <span class="number" style="color:#09999;">60</span>));
    <span class="indent">  </span><span class="indent">  </span>y = <span class="number" style="color:#09999;">240</span> + <span style="FONT-WEIGHT: bold" class="keyword">int</span>(<span class="number" style="color:#09999;">145</span> * cos(PI * <span class="number" style="color:#09999;">2</span> * i / <span class="number" style="color:#09999;">60</span>));
    
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span> (i % <span class="number" style="color:#09999;">15</span> == <span class="number" style="color:#09999;">0</span>)
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>bar(x - <span class="number" style="color:#09999;">5</span>, y - <span class="number" style="color:#09999;">5</span>, x + <span class="number" style="color:#09999;">5</span>, y + <span class="number" style="color:#09999;">5</span>);
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">else</span> <span style="FONT-WEIGHT: bold" class="keyword">if</span> (i % <span class="number" style="color:#09999;">5</span> == <span class="number" style="color:#09999;">0</span>)
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>circle(x, y, <span class="number" style="color:#09999;">3</span>);
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">else</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>putpixel(x, y, WHITE);
    <span class="indent">  </span>}
    }
    
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> main()
    {
    <span class="indent">  </span>initgraph(<span class="number" style="color:#09999;">640</span>, <span class="number" style="color:#09999;">480</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 初始化 640 x 480 的绘图窗口</span>
    
    <span class="indent">  </span>DrawDial();					<span class="comment" style="color:#999988;FONT-STYLE: italic">// 绘制表盘</span>
    
    <span class="indent">  </span>setwritemode(R2_XORPEN);	<span class="comment" style="color:#999988;FONT-STYLE: italic">// 设置 XOR 绘图模式</span>
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 绘制表针</span>
    <span class="indent">  </span>SYSTEMTIME ti;				<span class="comment" style="color:#999988;FONT-STYLE: italic">// 定义变量保存当前时间</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">while</span>(!kbhit())				<span class="comment" style="color:#999988;FONT-STYLE: italic">// 按任意键退出钟表程序</span>
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span>GetLocalTime(&ti);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 获取当前时间</span>
    <span class="indent">  </span><span class="indent">  </span>DrawHand(ti.wHour, ti.wMinute, ti.wSecond);	<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画表针</span>
    <span class="indent">  </span><span class="indent">  </span>Sleep(<span class="number" style="color:#09999;">1000</span>);			<span class="comment" style="color:#999988;FONT-STYLE: italic">// 延时 1 秒</span>
    <span class="indent">  </span><span class="indent">  </span>DrawHand(ti.wHour, ti.wMinute, ti.wSecond);	<span class="comment" style="color:#999988;FONT-STYLE: italic">// 擦表针(擦表针和画表针的过程是一样的)</span>
    <span class="indent">  </span>}
    <span class="indent">  </span>closegraph();				<span class="comment" style="color:#999988;FONT-STYLE: italic">// 关闭绘图窗口</span>
    }</span>
    3 辆行驶的小车
    <span style="font-size:18px;"><span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <graphics.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <conio.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <stdlib.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <stdio.h></span>
    
    <span class="comment" style="color:#999988;FONT-STYLE: italic">// 声明需要使用的函数</span>
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> carstart(<span style="FONT-WEIGHT: bold" class="keyword">int</span> x, <span style="FONT-WEIGHT: bold" class="keyword">int</span> y, <span style="FONT-WEIGHT: bold" class="keyword">int</span> z);
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> drawbus();
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> init();
    
    <span class="comment" style="color:#999988;FONT-STYLE: italic">// 定义全局变量</span>
    IMAGE img;
    
    
    <span class="comment" style="color:#999988;FONT-STYLE: italic"><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span>//</span>
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> main()
    {
    <span class="indent">  </span>init();
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">int</span> x=<span class="number" style="color:#09999;">0</span>, y=<span class="number" style="color:#09999;">0</span>, z=<span class="number" style="color:#09999;">0</span>;
    <span class="indent">  </span>BeginBatchDraw();
    
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">while</span>(!kbhit())
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span>x += <span class="number" style="color:#09999;">2</span>;
    <span class="indent">  </span><span class="indent">  </span>y++;
    <span class="indent">  </span><span class="indent">  </span>z += <span class="number" style="color:#09999;">3</span>;
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span> (x > <span class="number" style="color:#09999;">600</span>)	x = -<span class="number" style="color:#09999;">200</span>;
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span> (y > <span class="number" style="color:#09999;">600</span>)	y = -<span class="number" style="color:#09999;">200</span>;
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span> (z > <span class="number" style="color:#09999;">600</span>)	z = -<span class="number" style="color:#09999;">200</span>;
    
    <span class="indent">  </span><span class="indent">  </span>carstart(x, y, z); 
    <span class="indent">  </span><span class="indent">  </span>FlushBatchDraw(); 
    <span class="indent">  </span><span class="indent">  </span>Sleep(<span class="number" style="color:#09999;">5</span>);
    <span class="indent">  </span>}
    
    <span class="indent">  </span>EndBatchDraw();
    <span class="indent">  </span>closegraph();
    }
    
    
    <span class="comment" style="color:#999988;FONT-STYLE: italic"><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span>//</span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">// 初始化函数,初始化窗口大小,获取所画图片</span>
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> init()
    {
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 初始化窗口大小</span>
    <span class="indent">  </span>initgraph(<span class="number" style="color:#09999;">600</span>, <span class="number" style="color:#09999;">600</span>);
    
    <span class="indent">  </span>outtextxy(<span class="number" style="color:#09999;">70</span>, <span class="number" style="color:#09999;">250</span>, <span class="string" style="color:#dd1144;">"大家好,新手来报到,希望大家多多指教"</span>); 
    <span class="indent">  </span>outtextxy(<span class="number" style="color:#09999;">70</span>, <span class="number" style="color:#09999;">270</span>, <span class="string" style="color:#dd1144;">"下面你们会看到我程序的效果,程序很简单"</span>); 
    <span class="indent">  </span>outtextxy(<span class="number" style="color:#09999;">70</span>, <span class="number" style="color:#09999;">290</span>, <span class="string" style="color:#dd1144;">"希望以后再跟大家的交流中学到更多,希望自己以后能编出更好的程序"</span>); 
    <span class="indent">  </span>outtextxy(<span class="number" style="color:#09999;">70</span>, <span class="number" style="color:#09999;">320</span>, <span class="string" style="color:#dd1144;">"请按任意键进观看程序执行效果"</span>); 
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 等待按键按下</span>
    <span class="indent">  </span>getch();
    
    <span class="indent">  </span>cleardevice();						<span class="comment" style="color:#999988;FONT-STYLE: italic">// 清除上面的文字进入运行效果画面</span>
    <span class="indent">  </span>drawbus();							<span class="comment" style="color:#999988;FONT-STYLE: italic">// 调用绘图函数,绘制 BUS</span>
    <span class="indent">  </span>getimage(&img, <span class="number" style="color:#09999;">80</span>, <span class="number" style="color:#09999;">40</span>, <span class="number" style="color:#09999;">180</span>, <span class="number" style="color:#09999;">90</span>);	<span class="comment" style="color:#999988;FONT-STYLE: italic">// 获取 BUS 图片位置,保存在 img 变量中</span>
    }
    
    
    <span class="comment" style="color:#999988;FONT-STYLE: italic"><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span>//</span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">// 车辆行驶程序,通过 putimge 函数,改变移动的像素来达到图片移动</span>
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> carstart(<span style="FONT-WEIGHT: bold" class="keyword">int</span> x, <span style="FONT-WEIGHT: bold" class="keyword">int</span> y, <span style="FONT-WEIGHT: bold" class="keyword">int</span> z)
    {
    <span class="indent">  </span>cleardevice();
    <span class="indent">  </span>putimage(x, <span class="number" style="color:#09999;">40</span>, &img);
    <span class="indent">  </span>setlinestyle(PS_SOLID, <span class="number" style="color:#09999;">10</span>);   <span class="comment" style="color:#999988;FONT-STYLE: italic">//设置画线的大小</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">0</span>, <span class="number" style="color:#09999;">135</span>, <span class="number" style="color:#09999;">600</span>, <span class="number" style="color:#09999;">135</span>);
    <span class="indent">  </span>putimage(y, <span class="number" style="color:#09999;">220</span>, &img);
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">0</span>, <span class="number" style="color:#09999;">315</span>, <span class="number" style="color:#09999;">600</span>, <span class="number" style="color:#09999;">315</span>);
    <span class="indent">  </span>putimage(z, <span class="number" style="color:#09999;">380</span>, &img);
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">0</span>, <span class="number" style="color:#09999;">475</span>, <span class="number" style="color:#09999;">600</span>, <span class="number" style="color:#09999;">475</span>);
    }
    
    
    <span class="comment" style="color:#999988;FONT-STYLE: italic"><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span><span class="xmlDocTag">///</span>//</span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">// 绘制 BUS 函数,通过画一些线条,组合它们的位置,组合成一辆小车</span>
    <span style="FONT-WEIGHT: bold" class="keyword">void</span> drawbus()
    {
    <span class="indent">  </span>setcolor(RED);
    <span class="indent">  </span>setfillstyle(BLUE);
    
    <span class="indent">  </span>fillcircle(<span class="number" style="color:#09999;">120</span>, <span class="number" style="color:#09999;">120</span>, <span class="number" style="color:#09999;">10</span>); 		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的轮胎</span>
    <span class="indent">  </span>fillcircle(<span class="number" style="color:#09999;">200</span>, <span class="number" style="color:#09999;">120</span>, <span class="number" style="color:#09999;">10</span>); 		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的轮胎</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">80</span>,  <span class="number" style="color:#09999;">120</span>, <span class="number" style="color:#09999;">110</span>, <span class="number" style="color:#09999;">120</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的底部车板</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">80</span>,  <span class="number" style="color:#09999;">40</span>,  <span class="number" style="color:#09999;">80</span>,  <span class="number" style="color:#09999;">120</span>); 		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的四周车板</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">130</span>, <span class="number" style="color:#09999;">120</span>, <span class="number" style="color:#09999;">190</span>, <span class="number" style="color:#09999;">120</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的底部车板</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">210</span>, <span class="number" style="color:#09999;">120</span>, <span class="number" style="color:#09999;">250</span>, <span class="number" style="color:#09999;">120</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的底部车板</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">250</span>, <span class="number" style="color:#09999;">40</span>,  <span class="number" style="color:#09999;">250</span>, <span class="number" style="color:#09999;">120</span>); 		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的四周车板</span>
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">80</span>,  <span class="number" style="color:#09999;">40</span>,  <span class="number" style="color:#09999;">250</span>, <span class="number" style="color:#09999;">40</span>);		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车的顶部车板</span>
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车窗</span>
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">for</span>(<span style="FONT-WEIGHT: bold" class="keyword">int</span> x = <span class="number" style="color:#09999;">90</span>, y = <span class="number" style="color:#09999;">100</span>; x < <span class="number" style="color:#09999;">190</span> && y < <span class="number" style="color:#09999;">190</span>; x += <span class="number" style="color:#09999;">15</span>, y += <span class="number" style="color:#09999;">15</span>)
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span>rectangle(x, <span class="number" style="color:#09999;">60</span>, y, <span class="number" style="color:#09999;">70</span>);
    <span class="indent">  </span>}
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画车门</span>
    <span class="indent">  </span>rectangle(<span class="number" style="color:#09999;">220</span>, <span class="number" style="color:#09999;">60</span>, <span class="number" style="color:#09999;">240</span>, <span class="number" style="color:#09999;">120</span>);
    <span class="indent">  </span>line(<span class="number" style="color:#09999;">230</span>, <span class="number" style="color:#09999;">60</span>, <span class="number" style="color:#09999;">230</span>, <span class="number" style="color:#09999;">120</span>);
    <span class="indent">  </span>circle(<span class="number" style="color:#09999;">230</span>, <span class="number" style="color:#09999;">90</span>, <span class="number" style="color:#09999;">5</span>); 
    }</span>
    鼠标操作演示
    <span style="font-size:18px;"><span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <graphics.h></span>
    <span class="preprocessor" style="color:#999999;FONT-WEIGHT: bold">#include <conio.h></span>
    
    <span style="FONT-WEIGHT: bold" class="keyword">int</span> main()
    {
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 初始化图形窗口</span>
    <span class="indent">  </span>initgraph(<span class="number" style="color:#09999;">640</span>, <span class="number" style="color:#09999;">480</span>);
    
    <span class="indent">  </span>MOUSEMSG m;		<span class="comment" style="color:#999988;FONT-STYLE: italic">// 定义鼠标消息</span>
    
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">while</span>(<span style="FONT-WEIGHT: bold" class="keyword">true</span>)
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 获取一条鼠标消息</span>
    <span class="indent">  </span><span class="indent">  </span>m = GetMouseMsg();
    
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">switch</span>(m.uMsg)
    <span class="indent">  </span><span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">case</span> WM_MOUSEMOVE:
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 鼠标移动的时候画红色的小点</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>putpixel(m.x, m.y, RED);
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">break</span>;
    
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">case</span> WM_LBUTTONDOWN:
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 如果点左键的同时按下了 Ctrl 键</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span> (m.mkCtrl)
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画一个大方块</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>rectangle(m.x-<span class="number" style="color:#09999;">10</span>, m.y-<span class="number" style="color:#09999;">10</span>, m.x+<span class="number" style="color:#09999;">10</span>, m.y+<span class="number" style="color:#09999;">10</span>);
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">else</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 画一个小方块</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span>rectangle(m.x-<span class="number" style="color:#09999;">5</span>, m.y-<span class="number" style="color:#09999;">5</span>, m.x+<span class="number" style="color:#09999;">5</span>, m.y+<span class="number" style="color:#09999;">5</span>);
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">break</span>;
    
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">case</span> WM_RBUTTONUP:
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">return</span> <span class="number" style="color:#09999;">0</span>;	<span class="comment" style="color:#999988;FONT-STYLE: italic">// 按鼠标右键退出程序</span>
    <span class="indent">  </span><span class="indent">  </span>}
    <span class="indent">  </span>}
    
    <span class="indent">  </span><span class="comment" style="color:#999988;FONT-STYLE: italic">// 关闭图形窗口</span>
    <span class="indent">  </span>closegraph();
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">return</span> <span class="number" style="color:#09999;">0</span>
    }</span>

     模拟蒙特卡罗法求π的值

    <span style="font-size:18px;"><span class="comment" style="color:#999988;FONT-STYLE: italic">#include <graphics.h></span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">#include <conio.h></span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">#include <time.h></span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">#include <stdlib.h></span>
    <span class="comment" style="color:#999988;FONT-STYLE: italic">#include <stdio.h></span>
    <span style="FONT-WEIGHT: bold" class="keyword">int</span> main()
    {
    <span class="indent">  </span>long <span style="FONT-WEIGHT: bold" class="keyword">m</span>=<span class="number" style="color:#09999;">0</span>,n=<span class="number" style="color:#09999;">0</span>,i;
    <span class="indent">  </span>double xi,yi,<span style="FONT-WEIGHT: bold" class="keyword">y</span>;
    <span class="indent">  </span>initgraph(<span class="number" style="color:#09999;">640</span>, <span class="number" style="color:#09999;">480</span>);<span class="regexp" style="color:#09926;">//</span> 初始化 <span class="number" style="color:#09999;">640</span> <span style="FONT-WEIGHT: bold" class="keyword">x</span> <span class="number" style="color:#09999;">480</span> 的绘图窗口
    <span class="indent">  </span>setcolor(YELLOW);
    <span class="regexp" style="color:#09926;">//line</span>(<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">50</span>,<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">400</span>);line(<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">50</span>,<span class="number" style="color:#09999;">205</span>,<span class="number" style="color:#09999;">60</span>); line(<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">50</span>,<span class="number" style="color:#09999;">195</span>,<span class="number" style="color:#09999;">60</span>);
    <span class="regexp" style="color:#09926;">//line</span>(<span class="number" style="color:#09999;">50</span>,<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">400</span>,<span class="number" style="color:#09999;">200</span>);line(<span class="number" style="color:#09999;">400</span>,<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">390</span>,<span class="number" style="color:#09999;">195</span>); line(<span class="number" style="color:#09999;">400</span>,<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">390</span>,<span class="number" style="color:#09999;">205</span>);
    <span class="indent">  </span>rectangle(<span class="number" style="color:#09999;">220</span>,<span class="number" style="color:#09999;">100</span>,<span class="number" style="color:#09999;">420</span>,<span class="number" style="color:#09999;">300</span>);
    <span class="indent">  </span>circle(<span class="number" style="color:#09999;">320</span>,<span class="number" style="color:#09999;">200</span>,<span class="number" style="color:#09999;">100</span>);
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">srand</span>((unsigned)<span style="FONT-WEIGHT: bold" class="keyword">time</span>(NULL));
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">for</span>(i=<span class="number" style="color:#09999;">0</span>; i<<span class="number" style="color:#09999;">100000</span>; i++)   /<span class="variable" style="color:#08080;">*设</span>置产生随机数的个数<span class="variable" style="color:#08080;">*/</span>
    <span class="indent">  </span>{
    <span class="indent">  </span><span class="indent">  </span><span class="regexp" style="color:#09926;">/*---产生-1到1之间的随机数xi和yi-----*/</span>
    <span class="indent">  </span><span class="indent">  </span>xi=(<span style="FONT-WEIGHT: bold" class="keyword">rand</span>()<span class="variable" style="color:#08080;">%(</span><span class="number" style="color:#09999;">1000</span>-<span class="number" style="color:#09999;">0</span>+<span class="number" style="color:#09999;">1</span>)+<span class="number" style="color:#09999;">0</span>)/<span class="number" style="color:#09999;">500.0</span>-<span class="number" style="color:#09999;">1.0</span>;
    <span class="indent">  </span><span class="indent">  </span>yi=(<span style="FONT-WEIGHT: bold" class="keyword">rand</span>()<span class="variable" style="color:#08080;">%(</span><span class="number" style="color:#09999;">1000</span>-<span class="number" style="color:#09999;">0</span>+<span class="number" style="color:#09999;">1</span>)+<span class="number" style="color:#09999;">0</span>)/<span class="number" style="color:#09999;">500.0</span>-<span class="number" style="color:#09999;">1.0</span>;
    <span class="indent">  </span><span class="indent">  </span>putpixel((<span style="FONT-WEIGHT: bold" class="keyword">int</span>)(xi<span class="variable" style="color:#08080;">*100</span>+<span class="number" style="color:#09999;">320</span>),(<span style="FONT-WEIGHT: bold" class="keyword">int</span>)(yi<span class="variable" style="color:#08080;">*100</span>+<span class="number" style="color:#09999;">200</span>),(<span style="FONT-WEIGHT: bold" class="keyword">int</span>)GREEN);<span class="regexp" style="color:#09926;">/*在正方形区域内画点*/</span>
    <span class="indent">  </span><span class="indent">  </span>/<span class="variable" style="color:#08080;">*printf</span>(<span class="string" style="color:#dd1144;">"xi=<span class="variable" style="color:#08080;">%f</span>,yi=<span class="variable" style="color:#08080;">%f</span>\n"</span>,xi,yi);<span class="variable" style="color:#08080;">*/</span>
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">if</span>(yi<span class="variable" style="color:#08080;">*yi</span>>=(-(<span class="number" style="color:#09999;">1</span>-xi<span class="variable" style="color:#08080;">*xi</span>))&&yi<span class="variable" style="color:#08080;">*yi</span><=<span class="number" style="color:#09999;">1</span>-xi<span class="variable" style="color:#08080;">*xi</span>) /<span class="variable" style="color:#08080;">*判</span>断是否在圆内并计数<span class="variable" style="color:#08080;">*/</span>
    <span class="indent">  </span><span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">m</span>++,n++;
    <span class="indent">  </span><span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">else</span> <span style="FONT-WEIGHT: bold" class="keyword">m</span>++;
    <span class="indent">  </span><span class="indent">  </span>Sleep(<span class="number" style="color:#09999;">10</span>);
    <span class="indent">  </span>}
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">y</span>=<span class="number" style="color:#09999;">4.0</span><span class="variable" style="color:#08080;">*n</span>/<span style="FONT-WEIGHT: bold" class="keyword">m</span>;
    <span class="indent">  </span><span class="regexp" style="color:#09926;">/*计算PI值*/</span>
    <span class="indent">  </span>char str[<span class="number" style="color:#09999;">100</span>];
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">sprintf</span>(str,<span class="string" style="color:#dd1144;">"PI=<span class="variable" style="color:#08080;">%f</span>"</span>,<span style="FONT-WEIGHT: bold" class="keyword">y</span>);
    <span class="indent">  </span>outtextxy(<span class="number" style="color:#09999;">280</span>,<span class="number" style="color:#09999;">400</span>,str);
    <span class="indent">  </span>getch();
    <span class="indent">  </span>closegraph();<span class="regexp" style="color:#09926;">//</span> 关闭绘图窗口
    <span class="indent">  </span><span style="FONT-WEIGHT: bold" class="keyword">return</span> <span class="number" style="color:#09999;">0</span>;
    }</span>
    展开全文
  • EasyX

    2015-09-01 20:12:59
    #include #include void main() { initgraph(640, 480); int y = 80 ;  int xx = 20; int yy = 20; for(int x=100;; x+=xx,y+=yy) { // 绘制黄线、绿色填充的圆 setlinecolor(YELLOW);...
    #include <graphics.h>
    #include <conio.h>


    void main()
    {
    initgraph(640, 480);
    int y = 80 ; 
    int xx = 20;
    int yy = 20;
    for(int x=100;; x+=xx,y+=yy)
    {
    // 绘制黄线、绿色填充的圆
    setlinecolor(YELLOW);
    setfillcolor(GREEN);
    fillcircle(x, y, 20);


    // 延时
    Sleep(500);


    // 绘制黑线、黑色填充的圆
    setlinecolor(BLACK);
    setfillcolor(BLACK);
    fillcircle(x, y, 20);
    if(x>=620 || x<=20) //碰到边界反方向
    xx = -xx;
    if(y >=460 || y<=20)
    yy = -yy;
    }


    closegraph();
    }
    展开全文
  • EasyX_2018 EasyX_2018

    2019-04-24 18:32:08
    EasyX_2018
  • EasyX库使用入门

    万次阅读 多人点赞 2018-06-29 21:35:24
    下载最新版:EasyX官网 PS :Dev C++可能检测不到,建议使用Visual Studio Community2019, VS官网下载:https://visualstudio.microsoft.com/zh-hans/free-developer-offers/ 目录 一、基础 1.绘图环境 (1...

    下载最新版:EasyX官网

    PS :Dev C++可能检测不到,建议使用Visual Studio Community2019,

    VS官网下载:https://visualstudio.microsoft.com/zh-hans/free-developer-offers/


    目录

    一、基础

    1.绘图环境

    (1)initgraph

    (2)closegraph

    2.颜色

    (1)颜色常量

    (2)setcolor

    (3)setlinecolor

    (4)settextcolor

    (5)setbkcolor

    (6)setfillcolor

    3.样式

    (1)setbkmode

    (2)setlinestyle

    4.图形

    (1)circle

    (2)fillcircle

    (3)solidcircle

    (4)line

    (5)putpixel

    5.刷屏

    (1)BeginBatchDraw

    (2)FlushBatchDraw

    (3)EndBatchDraw

    (4)分析FlushBatchDraw的位置

    6.图像

    (1)IMAGE

    (2)loadimage

    (3)putimage

    7.清屏

    (1)cleardevice

    (2)clearrectangle

    8.输出字符串

    (1)outtextxy

    二、例子

    1.画十条平行直线

    2.以线绘制渐变色窗口

    3.用红蓝色交替画线

    4.动画效果

    (1)只有小球的代码:

    (2)复杂绘图代码:

    5.反弹的小球

    6.时钟

    7.雷霆战机

    8.更多例子见EasyX官网


     

    一、基础

    头文件:#include<graphics.h>

    1.绘图环境

    (1)initgraph

    初始化绘图环境

    原型:

    HWND initgraph(
    
        int width, //绘图环境的宽度
    
        int height, //绘图环境的高度
    
        int flag = NULL
    
    );

     

    参数:

    • flag
      绘图环境的样式,默认为 NULL。值为 SHOWCONSOLE 则保留原控制台窗口.

    (2)closegraph

    void closegraph();
    //关闭绘图环境

     

    2.颜色

    (1)颜色常量

    RGB方式

    setcolor(RGB(0,0,0));

    字母方式

    setcolor(BLACK);

    六个十六进制

    setcolor(0x000000);

    每两位十六进制分别对应,蓝色,绿色,红色。

    Link:RGB颜色对应表,想要的颜色自己去查一下。

    一些常见的颜色:

    • 0x000000 黑色
    • 0xFF0000 (深)蓝色
    • 0xFFAAAA (浅)蓝色
    • 0xFFFFFF 白色

    (2)setcolor

    设置前景颜色(字体颜色和线条颜色),等效于连续执行 easyx.h 中的 setlinecolor 和 settextcolor 函数。

    void setcolor(COLORREF color);

    (3)setlinecolor

    这个函数用于设置当前画线颜色。

    void setlinecolor(COLORREF color);

    (4)settextcolor

    这个函数用于设置当前文字颜色。

    void settextcolor(COLORREF color);

    (5)setbkcolor

    设置当前绘图背景色。

    void setbkcolor(COLORREF color);

    执行 cleardevice() 或 clearcliprgn() 等清除函数时,使用该颜色清空屏幕或裁剪区。

    (6)setfillcolor

    void setfillcolor(COLORREF color);

    设置当前填充颜色。

    3.样式

    (1)setbkmode

    设置图案填充和文字输出时的背景模式

    void setbkmode(int mode);

    参数:mode

    • OPAQUE 不透明的,背景用当前背景色填充(默认)。
    • TRANSPARENT 背景是透明的。

    (2)setlinestyle

    设置当前画线样式。

     

    原型1:

    void setlinestyle(
    
        const LINESTYLE* pstyle
    
    );

     

    • pstyle
      指向画线样式 LINESTYLE 的指针。

     

    原型2:

    void setlinestyle(
    
        int style,
    
        int thickness = 1,
    
        const DWORD *puserstyle = NULL,
    
        DWORD userstylecount = 0
    
    );

     

    •  style

      画线样式,由直线样式、端点样式、连接样式三类组成。可以是其中一类或多类的组合。同一类型中只能指定一个样式。

      【直线样式可以是以下值】


      端点样式可以是以下值】


      连接样式可以是以下值】
       
    • thickness
      线的宽度,以像素为单位。
    • puserstyle
      用户自定义样式数组,仅当线型为 PS_USERSTYLE 时该参数有效。
      数组第一个元素指定画线的长度,第二个元素指定空白的长度,第三个元素指定画线的长度,第四个元素指定空白的长度,以此类推。
    •  userstylecount
      用户自定义样式数组的元素数量。
    •  返回值:
      (无)

     

    示例:

    以下局部代码设置画线样式为点划线:

    setlinestyle(PS_DASHDOT);

    以下局部代码设置画线样式为宽度 3 像素的虚线,端点为平坦的:

    setlinestyle(PS_DASH | PS_ENDCAP_FLAT, 3);

    以下局部代码设置画线样式为宽度 10 像素的实线,连接处为斜面:

    setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 10);

    以下局部代码设置画线样式为自定义样式(画 5 个像素,跳过 2 个像素,画 3 个像素,跳过 1 个像素……),端点为平坦的:

    DWORD a[4] = {5, 2, 3, 1};
    setlinestyle(PS_USERSTYLE | PS_ENDCAP_FLAT, 1, a, 4);

     

    4.图形

    (1)circle

    画一个圆,准确地说,是一个圆形边框。

    void circle(
    
        int x, //圆的圆心 x 坐标。
    
        int y, //圆的圆心 y 坐标。
    
        int radius //圆的半径。
    
    );

     

    (2)fillcircle

    画填充圆(有边框)。使用当前线形和当前填充样式

    void fillcircle(
    
        int x,
    
        int y,
    
        int radius
    
    );

     

    (3)solidcircle

    这个函数用于画填充圆(无边框)。使用当前填充样式绘制

    void solidcircle(
    
        int x,
    
        int y,
    
        int radius
    
    );

     

    (4)line

    这个函数用于画直线。

    void line(
    
        int x1, //直线的起始点的 x 坐标。
    
        int y1, //直线的起始点的 y 坐标。
    
        int x2, //直线的终止点的 x 坐标。
    
        int y2 //直线的终止点的 y 坐标。
    
    );

     

    (5)putpixel

    这个函数用于画点。

    void putpixel(
    
        int x,         //点的 x 坐标。
    
        int y,         //点的 y 坐标。
    
        COLORREF color //点的颜色。
    
    );

     

    5.刷屏

    (1)BeginBatchDraw

    这个函数用于开始批量绘图。执行后,任何绘图操作都将暂时不输出到屏幕上,直到执行 FlushBatchDraw 或 EndBatchDraw 才将之前的绘图输出。

    用在循环外面,如例5

    void BeginBatchDraw();

    (2)FlushBatchDraw

    这个函数用于执行未完成的绘制任务。

    用在绘图中间。

    void FlushBatchDraw();

     

    (3)EndBatchDraw

    这个函数用于结束批量绘制,并执行未完成的绘制任务。

    void EndBatchDraw();

    (4)分析FlushBatchDraw的位置

    如例5,函数放在两次绘图中间而不是两次绘图的最下面,因为闪烁是蓝色小球没有被绘制出来,而不是黑色小球没有绘制。所以只要保证绘制出绿色小球,而在函数最贴近上面的绘制是一定能绘制的。如果用在两次绘图的最下面,如下面,再加个Sleep函数控制速度,结果就是什么都没有。因为绿色闪几毫秒就没了。

    BeginBatchDraw();
    
    while (1)
    
    {
        setcolor(GREEN);
        setfillcolor(BLUE);
        fillcircle(ball_x, ball_y, radius);
        Sleep(5);
        
        setcolor(BLACK);
        setfillcolor(BLACK);
        fillcircle(ball_x, ball_y, radius);
        
        FlushBatchDraw();
    
        ball_x += ball_vx;
        ball_y += ball_vy;
    
     
        if(ball_x <= radius || ball_x >= Width - radius)
            ball_vx = -ball_vx;
        if (ball_y <= radius || ball_y >= Height - radius)
            ball_vy = -ball_vy;
    }
    
    EndBatchDraw();

    6.图像

    (1)IMAGE

    实现 IMAGE 对象的直接赋值

    class IMAGE(int width = 0, int height = 0);

    公有成员:

    • int getwidth();
      返回 IMAGE 对象的宽度,以像素为单位。
    • int getheight();
      返回 IMAGE 对象的高度,以像素为单位。

    示例:

    以下局部代码创建 img1、img2 两个对象,之后加载图片 test.jpg 到 img1,并通过赋值操作将 img1 的内容拷贝到 img2:

    IMAGE img1, img2;
    loadimage(&img1, _T("test.jpg"));
    img2 = img1;以下局部代码创建 img 对象,之后加载图片 test.jpg,并将图片的宽高赋值给变量 w、h:
    
    IMAGE img;
    loadimage(&img, _T("test.jpg"));
    int w, h;
    w = img.getwidth();
    h = img.getheight();

    (2)loadimage

    这个函数用于从文件中读取图像。

    // 从图片文件获取图像(bmp/jpg/gif/emf/wmf/ico)
    
    void loadimage(
    
        IMAGE* pDstImg, // 保存图像的 IMAGE 对象指针
    
        LPCTSTR pImgFile, // 图片文件名
        
        int nWidth = 0, // 图片的拉伸宽度
    
        int nHeight = 0, // 图片的拉伸高度
    
        bool bResize = false // 是否调整 IMAGE 的大小以适应图片
    
    );
    // 从资源文件获取图像(bmp/jpg/gif/emf/wmf/ico)
    
    void loadimage(
    
        IMAGE* pDstImg, // 保存图像的 IMAGE 对象指针
    
        LPCTSTR pResType, // 资源类型
    
        LPCTSTR pResName, // 资源名称
        
        int nWidth = 0, // 图片的拉伸宽度
    
        int nHeight = 0, // 图片的拉伸高度
    
        bool bResize = false // 是否调整 IMAGE 的大小以适应图片
    
    );

    参数:

    • pDstImg
      保存图像的 IMAGE 对象指针。如果为 NULL,表示图片将读取至绘图窗口。 
    • pImgFile
      图片文件名。支持 bmp / jpg / gif / emf / wmf / ico 类型的图片。gif 类型的图片仅加载第一帧,不支持透明。
    • nWidth
      图片的拉伸宽度。加载图片后,会拉伸至该宽度。如果为 0,表示使用原图的宽度。
    •  nHeight
      图片的拉伸高度。加载图片后,会拉伸至该高度。如果为 0,表示使用原图的高度。
    •  bResize
      是否调整 IMAGE 的大小以适应图片。
    • pResType
      图片资源类型。
    • pResName
      图片资源名称。

    (3)putimage

    这个函数的几个重载用于在当前设备上绘制指定图像。

    // 绘制图像
    
    void putimage(
    
        int dstX,              // 绘制位置的 x 坐标
    
        int dstY,              // 绘制位置的 y 坐标
    
        IMAGE *pSrcImg,        // 要绘制的 IMAGE 对象指针
    
        DWORD dwRop = SRCCOPY  // 三元光栅操作码(详见备注)
    
    );

    备注:

     三元光栅操作码(即位操作模式),支持全部的 256 种三元光栅操作码,常用的几种如下:

    注:

    1. AND / OR / NOT / XOR 为布尔运算。

    2. "屏幕颜色"指绘制所经过的屏幕像素点的颜色。

    3. "图像颜色"是指通过 IMAGE 对象中的图像的颜色。

    4. "当前填充颜色"是指通过 setfillcolor 设置的用于当前填充的颜色。

      

    7.清屏

    (1)cleardevice

    这个函数用于清除屏幕内容。具体的,是用当前背景色清空屏幕,并将当前点移至 (0, 0)。

    void cleardevice();

    (2)clearrectangle

    这个函数用于清空矩形区域

    void clearrectangle(
    
        int left, //矩形左部 x 坐标。
    
        int top, //矩形上部 y 坐标。
    
        int right, //矩形右部 x 坐标。
    
        int bottom //矩形下部 y 坐标。
    
    );

     

    8.输出字符串

    (1)outtextxy

    这个函数用于在指定位置输出字符串。

    void outtextxy(
    
        int x, //字符串输出时头字母的 x 轴的坐标值
    
        int y, //字符串输出时头字母的 y 轴的坐标值
    
        LPCTSTR str
    
    );
    void outtextxy(
    
        int x,
    
        int y,
    
        TCHAR c
    
    );

    例子:如何使用LPCTSTR str和TCHAR c

    TCHAR s[100];
    
    _stprintf(s, _T("你的分数:%d"), kill);
    
    outtextxy((WINDOW_WIDTH / 2 + WIDTH / 2) + 50, WINDOW_HEIGHT/2, s);

     

    二、例子

    1.画十条平行直线

    #include <stdio.h>
    #include <graphics.h>
    
    int main()
    {
    	// 初始化窗口
    	initgraph(640, 480);
    	for (int y = 0; y <= 480; y += 48)
    	{
    		// 画线
    		line(0, y, 640, y);
    	}
    	// 暂停窗口,不让其退出
    	getchar();
    	// 关闭窗口
    	closegraph();
    
    	return 0;
    }

     

    2.以线绘制渐变色窗口

    #include <stdio.h>
    #include <graphics.h>
    
    int main()
    {
    	initgraph(640, 480);
    	for (int y = 0; y <= 480; y++)
    	{
    		setcolor(RGB(0, 0, y / 2));
    		line(0, y, 640, y);
    	}
    	getchar();
    	closegraph();
    
    	return 0;
    }

    3.用红蓝色交替画线

    #include <stdio.h>
    #include <graphics.h>
    
    int main()
    {
    	initgraph(640, 480);
    	for (int y = 0; y <= 480; y += 48)
    	{
    		if ((y / 48) % 2 == 1)
    			setcolor(RGB(255, 0, 0));
    		else
    			setcolor(RGB(0, 0, 255));
    		line(0, y, 640, y);
    	}
    	getchar();
    	closegraph();
    
    	return 0;
    }

     

    4.动画效果

    (1)只有小球的代码:

    #include <stdio.h>
    #include <graphics.h>
    
    int main()
    {
    	initgraph(640, 480);
    	setfillcolor(BLUE);
    	for (int y = 0; y <= 480; y += 10)
    	{
    		fillcircle(100, y, 25);
    		Sleep(100);
    		cleardevice();
    	}
    	getchar();
    	closegraph();
    
    	return 0;
    }

    (2)复杂绘图代码:

    #include <stdio.h>
    #include <graphics.h>
    
    int main()
    {
    	initgraph(640, 480);
    	for (int y = 0; y <= 480; y += 10)
    	{
    		setcolor(GREEN);
    		setfillcolor(BLUE);
    		fillcircle(100, y, 25);
    		Sleep(100);
    		/** 
    		 * 下面的意思是将绘制出来的圆在显示100毫秒后,将其用背景色覆盖掉
    		 * 这样就达到了清除了操作
    		 * 为什么不用cleardevice(),因为会将整个屏幕清空,而我们还想保留其他的画面呢
    		 */
    		setcolor(BLACK);		//不仅填充色要求是黑色,而且边框色要得改变,默认白色
    		setfillcolor(BLACK);
    		fillcircle(100, y, 25);
    	}
    	getchar();
    	closegraph();
    
    	return 0;
    }

    5.反弹的小球

    #include <graphics.h>
    #include <conio.h>
    
    #define Width 640
    #define Height 480
    int main()
    {
    	// 初始化绘图窗口
    	initgraph(640, 480);
    
    	double ball_x=100, ball_y=100;
    	double ball_vx=1, ball_vy=1;
    	double radius=25;
    
    
    	BeginBatchDraw();
    	while (1)
    	{
    		
    		setcolor(GREEN);
    		setfillcolor(BLUE);
    		fillcircle(ball_x, ball_y, radius);
    		Sleep(5);
    		FlushBatchDraw();
    		
    		setcolor(BLACK);
    		setfillcolor(BLACK);
    		fillcircle(ball_x, ball_y, radius);
    
    		ball_x += ball_vx;
    		ball_y += ball_vy;
    
    		if (ball_x <= radius || ball_x >= Width - radius)
    			ball_vx = -ball_vx;
    		if (ball_y <= radius || ball_y >= Height - radius)
    			ball_vy = -ball_vy;
    
    		
    	}
    	
    	EndBatchDraw();
        // 另一种不让控制台退出的暂停方式
    	system("pause");
    	closegraph();
            return 0;
    }

     

    6.时钟

    #include <graphics.h>
    #include <conio.h>
    #include <math.h>
    
    #define Width 640
    #define Height 480
    #define PI 3.14159
    
    int main()
    {
    	// 初始化绘图窗口
    	initgraph(640, 480, SHOWCONSOLE);
    
    
    	//秒针起始坐标
    	int center_x = Width / 2, center_y = Height / 2;
    	//秒针终点坐标
    	int secondEnd_x, secondEnd_y;
    	//分针终点坐标
    	int minuteEnd_x, minuteEnd_y;
    	//时针终点坐标
    	int hourEnd_x, hourEnd_y;
    
    
    	//秒针长度
    	int secondLength = Width / 4;
    	//分针长度
    	int minuteLength = Width / 5.5;
    	//时针长度
    	int hourLength = Width / 7;
    
    
    
    	//秒针对应转到角度
    	float secondAngle = 0;
    	//分针对应转到角度
    	float minuteAngle = 0;
    	//时针对应转到角度
    	float hourAngle = 0;
    
    	//定义变量存储系统时间
    	SYSTEMTIME ti;
    	BeginBatchDraw();
    
    	while (1)
    	{
    		setfillcolor(YELLOW);
    		setlinestyle(PS_DASHDOTDOT, 5);
    		setlinecolor(0x555555);
    		circle(center_x, center_y, secondLength + 30);
    		setcolor(0xAAAAAA);
    		setlinestyle(PS_DOT | PS_ENDCAP_SQUARE, 2);
    		circle(center_x, center_y, secondLength + 15);
    		for (int i = 0; i < 12; i++)
    		{
    			int x = center_x + cos(i * 30.0 / 360 * 2 * PI) * (secondLength + 15.0);
    			int y = center_y - sin(i * 30.0 / 360 * 2 * PI) * (secondLength + 15.0);
    			fillcircle(x , y , 5);
    		}
    
    
    		GetLocalTime(&ti);
    		secondAngle	= (ti.wSecond / 60.0) * (2 * PI);
    		minuteAngle	= (ti.wMinute / 60.0) * (2 * PI);
    		hourAngle = ((ti.wHour % 12) / 12.0) * (2 * PI) + (ti.wMinute / 60.0) * (2 * PI / 12.0);
    
    		secondEnd_x = center_x + secondLength * sin(secondAngle);
    		secondEnd_y = center_y - secondLength * cos(secondAngle);
    
    		minuteEnd_x = center_x + minuteLength * sin(minuteAngle);
    		minuteEnd_y = center_y - minuteLength * cos(minuteAngle);
    
    		hourEnd_x = center_x + hourLength * sin(hourAngle);
    		hourEnd_y = center_y - hourLength * cos(hourAngle);
    
    
    		//画秒针
    		setlinestyle(PS_SOLID, 1);
    		setcolor(WHITE);
    		line(center_x, center_y, secondEnd_x, secondEnd_y);
    
    		//画分针
    		setlinestyle(PS_SOLID, 2);
    		setcolor(GREEN);
    		line(center_x, center_y, minuteEnd_x, minuteEnd_y);
    
    		//画时针
    		setlinestyle(PS_SOLID, 5);
    		setcolor(RED);
    		line(center_x, center_y, hourEnd_x, hourEnd_y);
    
    
    		FlushBatchDraw();		
    
    
    		setlinestyle(PS_SOLID, 1);
    		setcolor(BLACK);
    		line(center_x, center_y, secondEnd_x, secondEnd_y);
    
    		setlinestyle(PS_SOLID, 2);
    		setcolor(BLACK);
    		line(center_x, center_y, minuteEnd_x, minuteEnd_y);
    
    		setlinestyle(PS_SOLID, 5);
    		setcolor(BLACK);
    		line(center_x, center_y, hourEnd_x, hourEnd_y);
    	}
    	EndBatchDraw();
    	system("pause");
    	closegraph();
    	return 0;
    }

     

    7.雷霆战机

    https://blog.csdn.net/sandalphon4869/article/details/80861915

    8.更多例子见EasyX官网

    https://www.codebus.cn/

    展开全文
  • Easyx贪吃蛇

    2017-01-17 09:36:40
    使用Easyx+C语言编写的贪吃蛇小游戏
  • 贪吃蛇easyx

    2018-07-04 09:27:39
    简单的贪吃蛇代码,结合了easyx,比较基础,大一工程实践
  • EasyX图形库

    2019-04-22 10:51:11
    EasyX图形库开发环境
  • EasyX安装包

    2015-06-11 10:09:30
    EasyX安装包,适用于几乎各种版本的VC++,下载解压后直接安装就可以。
  • easyx实时按键

    2019-02-16 08:41:14
    基于easyx和windows SDK的实时按键界面,按下某个键后会有响应的提示及按键按下时间
  • Easyx图形库库文件

    2019-04-15 13:19:31
    Easyx图形库库文件
  • About EasyX

    2020-11-23 17:43:26
    什么是EasyX? EasyX是一套简单,易用的图形交互库 为什么要学习使用它? 基础C语言的可视化和交互功能较弱,printf输出效果太简单,没有绘图,显示图片等功能;只有键盘交互,没有鼠标交互,有较大局限性,EasyX图形...

    什么是EasyX?

    EasyX是一套简单,易用的图形交互库

    为什么要学习使用它?

    基础C语言的可视化和交互功能较弱,printf输出效果太简单,没有绘图,显示图片等功能;只有键盘交互,没有鼠标交互,有较大局限性,EasyX图形库的引入可以在一定程度上解决这些问题!

    如何安装它?

    具体安装方法可以去官网看看,链接在此:link.

    我们可以用EasyX干什么?

    1.可以绘制简单的图形

    例如:绘制一个椭圆和圆
    代码如下:

    #include <easyx.h>			// 引用图形库头文件
    #include <conio.h>
    int main()
    {
    	initgraph(640, 480);	// 创建绘图窗口,大小为 640x480 像素
    
    	setfillcolor(GREEN);
    	ellipse(200, 150, 20, 10);//画椭圆
    	fillcircle(200, 200, 20);	// 画圆,圆心(200, 200),半径 20
    	_getch();				// 按任意键继续
    	closegraph();			// 关闭绘图窗口
    	return 0;
    }
    

    运行效果如下:
    在这里插入图片描述
    2.制作简单动画
    例如:制作一个实时钟表
    代码如下:(来自网络)

    #include <graphics.h>
    #include <conio.h>
    #include <math.h>
    
    #define High 480  // 游戏画面尺寸
    #define Width 640
    #define	PI	3.14159
    
    int main()
    {
    	initgraph(Width, High);		// 初始化 640 x 480 的绘图窗口
    	int center_x, center_y;      // 中心点的坐标,也是表的中心
    	center_x = Width / 2;
    	center_y = High / 2;
    	int secondLength = Width / 5;           // 秒针的长度
    	int minuteLength = Width / 6;           // 分针的长度
    	int hourLength = Width / 7;             // 时针的长度
    
    	int secondEnd_x, secondEnd_y;    // 秒针的终点
    	int minuteEnd_x, minuteEnd_y;    // 分针的终点
    	int hourEnd_x, hourEnd_y;    // 时针的终点
    	float secondAngle;       // 秒钟对应的角度
    	float minuteAngle;       // 分钟对应的角度
    	float hourAngle;         // 时钟对应的角度
    
    	SYSTEMTIME ti;				// 定义变量保存当前时间
    
    	BeginBatchDraw();
    	while (1)
    	{
    		// 绘制一个简单的表盘
    		setlinestyle(PS_SOLID, 1);
    		setcolor(WHITE);
    		circle(center_x, center_y, Width / 4);
    
    		// 画刻度
    		int x, y, i;
    		for (i = 0; i < 60; i++)
    		{
    			x = center_x + int(Width / 4.3 * sin(PI * 2 * i / 60));
    			y = center_y + int(Width / 4.3 * cos(PI * 2 * i / 60));
    
    			if (i % 15 == 0)
    				bar(x - 5, y - 5, x + 5, y + 5);
    			else if (i % 5 == 0)
    				circle(x, y, 3);
    			else
    				putpixel(x, y, WHITE);
    		}
    
    		outtextxy(center_x - 25, center_y + Width / 6, "我的时钟");
    
    		GetLocalTime(&ti);		// 获取当前时间
    		// 秒钟角度变化
    		secondAngle = ti.wSecond * 2 * PI / 60;  // 一圈一共2*PI,一圈60秒,一秒钟秒钟走过的角度为2*PI/60
    		// 分钟角度变化
    		minuteAngle = ti.wMinute * 2 * PI / 60 + secondAngle / 60;  // 一圈一共2*PI,一圈60分,一分钟分钟走过的角度为2*PI/60
    		// 时钟角度变化
    		hourAngle = ti.wHour * 2 * PI / 12 + minuteAngle / 12;  // 一圈一共2*PI,一圈12小时,一小时时钟走过的角度为2*PI/12
    		// 由角度决定的秒针端点坐标
    		secondEnd_x = center_x + secondLength * sin(secondAngle);
    		secondEnd_y = center_y - secondLength * cos(secondAngle);
    
    		// 由角度决定的分针端点坐标
    		minuteEnd_x = center_x + minuteLength * sin(minuteAngle);
    		minuteEnd_y = center_y - minuteLength * cos(minuteAngle);
    
    		// 由角度决定的时针端点坐标
    		hourEnd_x = center_x + hourLength * sin(hourAngle);
    		hourEnd_y = center_y - hourLength * cos(hourAngle);
    
    		setlinestyle(PS_SOLID, 2);
    		setcolor(YELLOW);
    		line(center_x, center_y, secondEnd_x, secondEnd_y); // 画秒针
    
    		setlinestyle(PS_SOLID, 5);
    		setcolor(BLUE);
    		line(center_x, center_y, minuteEnd_x, minuteEnd_y); // 画分针
    
    		setlinestyle(PS_SOLID, 10);
    		setcolor(RED);
    		line(center_x, center_y, hourEnd_x, hourEnd_y); // 画时针
    
    		FlushBatchDraw();
    		Sleep(10);
    
    		setcolor(BLACK);
    		setlinestyle(PS_SOLID, 2);
    		line(center_x, center_y, secondEnd_x, secondEnd_y);  // 隐藏前一帧的秒针
    		setlinestyle(PS_SOLID, 5);
    		line(center_x, center_y, minuteEnd_x, minuteEnd_y); // 隐藏前一帧的分针
    		setlinestyle(PS_SOLID, 10);
    		line(center_x, center_y, hourEnd_x, hourEnd_y); // 隐藏前一帧的时针
    	}
    
    	EndBatchDraw();
    	getch();				// 按任意键继续
    	closegraph();			// 关闭绘图窗口
    	return 0;
    }
    

    如果你对它感兴趣的话,你也可以试着去学习一下,我认为它会使你的“黑框框”更有趣!!!

    展开全文
  • easyx小游戏

    2018-07-17 09:15:25
    使用easyx实现的小游戏。 您上传的资源如果因版权、使用、内容完整度 等原因被举报并通过官方审核,将扣除通过该资源获得的全部积分。
  • EasyX学习

    千次阅读 多人点赞 2018-10-09 11:29:48
    天天玩黑白界面,前段时间突然看到一个图形界面库,虽然是各位前辈玩烂的东西,但是还是勾起了我的兴致。...EasyX的绘制函数,可以看看EasyX_Help,里面分类的也比较清楚。贴吧也有很多大佬踩过的坑可...
  • 最新EasyX库下载

    2021-01-17 20:26:28
    最新EasyX库下载
  • easyx使用说明

    2018-05-12 15:20:31
    easyx是一个很方便,也很简单的图形库,可以使用于c/c++,该图形库与c++的多线程结合,可以做出非常炫酷的效果来。
  • EasyX入门笔记

    千次阅读 多人点赞 2021-05-07 19:02:46
    什么是EasyX EasyX是一个适合像我这样的蒟蒻编程初学者操作的图形渲染库。 本质上,EasyX是将Windows繁琐的图形绘制操作封装在头文件中,从而实现用函数简单的调用。 使用EasyX 百度EasyX官网,从官网中即可下载安装...
  • 关于EasyX

    千次阅读 2018-06-17 22:48:51
    简单使用EasyX前言:为了提高c语言的可视化与交互性,可以使用EasyX插件,可以快速进行图形设计,但需要注意:EasyX 是针对 C++ 的图形库,如果c语言中使用需要将后缀名改为.cpp一、安装:登陆访问官网:...
  • freetype测试-easyx

    2019-02-16 08:57:18
    freetype测试程序,界面使用easyx库。首先要安装freetype
  • EasyX学习资料

    2016-11-27 23:02:49
    好久没来上传资源了,EasyX的包,C下的,已经很老了吧,不过还是分享出来给大家看看学习啦~
  • easyx帮助文档

    2015-03-28 22:26:34
    easyx帮助文档详细介绍了easyx图形库里的所有函数,包含简单的说明示例代码,文档通俗易懂。此文档是.CHM格式文件,查阅方便快捷
  • EasyX见缝插针

    2021-06-12 21:18:02
    EasyX见缝插针 如何实现一个见缝插针游戏?? 如何绘制圆盘与针 如何实现旋转 如何按下空格发射针 如何判定游戏输赢 1.绘制圆盘以及一根针 #include<graphics.h> #include<conio.h> #define WIDTH 800 /...
  • 【C++】贪吃蛇 for EasyX

    2021-03-27 14:52:44
    【C++】贪吃蛇 for EasyX
  • EasyX小球碰壁

    2015-07-05 10:48:15
    EasyX头文件下的C++程序代码,小球随机动,碰壁以后反弹
  • EasyX_Help.chm

    2021-04-25 16:51:20
    EasyX_Help.chm

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,873
精华内容 1,949
关键字:

easyx