⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap23.htm

📁 很实用的一本教程,尤其适用于刚接触c++的读者
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>范例二</title>
<link rel="stylesheet" href="../../../include/style.css">
</head>

<body>
<font SIZE="2">

<p><small><a href="../../../index.htm">首页</a> &gt;&gt; <a href="../../program.htm">程序设计</a> 
  &gt;&gt; <a href="../cbuilder.htm">C++ Builder</a>&nbsp; &gt;&gt;&nbsp; </small>图形程式设计基本观念&middot;范例二</p>

<p align="left"><!--webbot bot="ImageMap" rectangle=" (40,1) (71, 23)  chap24.htm" rectangle=" (4,1) (36, 23)  chap22.htm" src="../ch1/NextBack.gif" width="72" height="24" alt="NextBack.gif (743字节)" border="0" startspan --><MAP NAME="FrontPageMap"><AREA SHAPE="RECT" COORDS="40, 1, 71, 23" HREF="chap24.htm"><AREA SHAPE="RECT" COORDS="4, 1, 36, 23" HREF="chap22.htm"></MAP><a href="../../../_vti_bin/shtml.exe/program/C++/ch2/chap23.htm/map"><img ismap usemap="#FrontPageMap" border="0" height="24" alt="NextBack.gif (743字节)" src="../ch1/NextBack.gif" width="72"></a><!--webbot bot="ImageMap" endspan i-checksum="23023" --></p>
</font>

<p><font SIZE="2" color="#FF0000">&middot;简易绘图范例02</font></p>
<font SIZE="2">

<p>范例二的输出</p>
</font>

<p><font SIZE="2"><img SRC="Image2.gif" WIDTH="458" HEIGHT="344">图02</font></p>
<font SIZE="2">

<p>这个范例使用了画线的函式来画出图形,同样地我们来看看其关键的函式LineTo及MoveTo:</p>
</font><font SIZE="1">

<p>void __fastcall LineTo(int X, int Y);</p>

<p>函式说明</p>

<p>LineTo函式由画笔位置画一条至 (X,Y)点的直线,此直线不包含(X,Y)点,同时将画笔位置移至 
(X,Y)。此函式通常必须配合MoveTo来移动画笔位置。</p>

<p>此直线使用Pen来绘制。</p>

<p>void __fastcall MoveTo(int X, int Y);</p>

<p>函式说明</p>

<p>MoveTo是用以在呼叫LineTo前设定画笔位址值。呼叫此函式和直接设定PenPos属性的效果相同。</p>
</font><font SIZE="2">

<p>void __fastcall TForm1::FormPaint(TObject *Sender)</p>

<p>{</p>

<p>&nbsp;&nbsp;&nbsp; double A,x1,y1,x2,y2;</p>

<p>&nbsp;&nbsp;&nbsp; int D=150,E=50;</p>

<p>&nbsp;&nbsp;&nbsp; double L,M,O,P;</p>

<p>&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;240; i++)</p>

<p>&nbsp;&nbsp;&nbsp; {</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A = i*M_PI/120;</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L = D+D/3*(1+cos(12*A)/2)*cos(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x1 = 240+1.25*L*cos(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; M = E+E/3*(1+sin(12*A)/2)*cos(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x2 = 240+1.25*M*cos(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; O = D+D/3*(1+cos(10*A)/2)*sin(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y1 = 240-O*sin(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; P = E+E/2*(1+cos(15*A)/2)*sin(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y2 = 240-P*sin(A);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas-&gt;MoveTo(x1,y1);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas-&gt;LineTo(x2,y2);</p>

<p>&nbsp;&nbsp;&nbsp; }</p>

<p>}</p>

<p>以上的程式列表就是范例02的关键部份,也就是实际负责绘图的FormPaint部份,其中用了许多的叁角函数如sin,cos,M_PI等运算,我在此就不另加说明了,之所用使用了这些函数只是为了在介绍这些简单的函式时,利用这些简单函式所产生的美丽图形,加深你的印象及学习效果罢了。电脑绘图之所以迷人也在於此,它可以利用电脑强大的运算及绘图能力,很容易地将一些复杂的图显示出来。</p>

<p align="right"><!--webbot bot="ImageMap" rectangle=" (40,1) (71, 23)  chap24.htm" rectangle=" (4,1) (36, 23)  chap22.htm" src="../ch1/NextBack.gif" width="72" height="24" alt="NextBack.gif (743字节)" border="0" startspan --><MAP NAME="FrontPageMap1"><AREA SHAPE="RECT" COORDS="40, 1, 71, 23" HREF="chap24.htm"><AREA SHAPE="RECT" COORDS="4, 1, 36, 23" HREF="chap22.htm"></MAP><a href="../../../_vti_bin/shtml.exe/program/C++/ch2/chap23.htm/map1"><img ismap usemap="#FrontPageMap1" border="0" height="24" alt="NextBack.gif (743字节)" src="../ch1/NextBack.gif" width="72"></a><!--webbot bot="ImageMap" endspan i-checksum="41502" --></p>

<p>&middot;<small><a href="../../../index.htm">首页</a> &gt;&gt; <a href="../../program.htm">程序设计</a> 
  &gt;&gt; <a href="../cbuilder.htm">C++ Builder</a>&nbsp; &gt;&gt;&nbsp; </small>图形程式设计基本观念&middot;范例二</p>
</font>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -