?? chap23.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> >> <a href="../../program.htm">程序設計</a>
>> <a href="../cbuilder.htm">C++ Builder</a> >> </small>圖形程式設計基本觀念·范例二</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">·簡易繪圖范例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> double A,x1,y1,x2,y2;</p>
<p> int D=150,E=50;</p>
<p> double L,M,O,P;</p>
<p> for (int i=0; i<240; i++)</p>
<p> {</p>
<p> A = i*M_PI/120;</p>
<p> L = D+D/3*(1+cos(12*A)/2)*cos(A);</p>
<p> x1 = 240+1.25*L*cos(A);</p>
<p> M = E+E/3*(1+sin(12*A)/2)*cos(A);</p>
<p> x2 = 240+1.25*M*cos(A);</p>
<p> O = D+D/3*(1+cos(10*A)/2)*sin(A);</p>
<p> y1 = 240-O*sin(A);</p>
<p> P = E+E/2*(1+cos(15*A)/2)*sin(A);</p>
<p> y2 = 240-P*sin(A);</p>
<p> Canvas->MoveTo(x1,y1);</p>
<p> Canvas->LineTo(x2,y2);</p>
<p> }</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>·<small><a href="../../../index.htm">首頁</a> >> <a href="../../program.htm">程序設計</a>
>> <a href="../cbuilder.htm">C++ Builder</a> >> </small>圖形程式設計基本觀念·范例二</p>
</font>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -