?? 用c語言畫立體五角星 - 櫻花草 - 網(wǎng)易博客.txt
字號:
用C語言畫立體五角星 - 櫻花草 - 網(wǎng)易博客 網(wǎng)易博客| 找朋友| 圈子| 拍拍| 搜索 注冊| 登錄 真誠是永恒的天堂
相識是天意,相知是人意,有情便有誼,我們能聚在一起,因?yàn)樾挠徐`犀。 首頁 日志 相冊 音樂 收藏 好友 關(guān)于我 日志
那人~~那情~~那景世界上最遙遠(yuǎn)的距離
字號: 大大 中中 小小 用C語言畫立體五角星 立 體 五 角 星
設(shè)計(jì)思路:
1、通過給定的圓半徑,計(jì)算出圓上平均分布的五個(gè)頂點(diǎn)的坐標(biāo),再計(jì)算出相應(yīng)小圓的半徑及旋轉(zhuǎn)36度后小圓上平均分布的五個(gè)點(diǎn)的坐標(biāo)。用線將各對應(yīng)點(diǎn)連接起來形成五角星。
2、通過循環(huán)畫間斷弧線形成動(dòng)態(tài)的光芒效果。
3、本例應(yīng)用到數(shù)組及數(shù)學(xué)中的正弦和余弦函數(shù)。
圖例:
公式:x=x0+r*cos(a);
y=y0-r*sin(a);
a為從起點(diǎn)到該點(diǎn)的旋轉(zhuǎn)角度。
由于C語言中sin、cos等函數(shù)中的參數(shù)是依弧度計(jì)算的,因此需要進(jìn)行度數(shù)轉(zhuǎn)換。一般先用#define PI
3.1415926這樣的宏定義定義PI。2*PI為一個(gè)圓周,2*PI/360為角度1度的值,簡化為PI/180。比如需要計(jì)算30度的正弦值,按下式:
sin(30*PI/180);
五角星內(nèi)接的小圓半徑的求法:
數(shù)學(xué)公式:yc=r×sin(18°); 或yc=r×cos(72°);
r0=yc÷cos(36°)
轉(zhuǎn)成C語言語句:
yc=r*sin(18*PI/180);
r0=yc/cos(36*PI/180);
或直接寫成:r0=r*sin(18*PI/180)/cos(36*PI/180);
例:
#include<graphics.h>
#include<math.h> /* 插入數(shù)學(xué)頭文件 */
#define PI 3.1415926 /* 宏定義 PI */
float th=PI/180; /*定義全局變量 th */
main()
{
int gd=DETECT,gm,i,j;
initgraph(&gd,&gm,"");
setbkcolor(BLUE);
star(320,240,120); /*調(diào)用自定義函數(shù)star()。*/
while(!kbhit()) /*下面循環(huán)體是繪制光芒部分,可以不要 */
{
setcolor(YELLOW);
for(j=0;j<20;j++)
{
for(i=0;i<120;i++)
ellipse(320,240,i*3,1+i*3,125+j*20,125+j*10);
delay(5000);
}
setcolor(BLACK);
for(j=0;j<20;j++)
{
for(i=0;i<120;i++)
ellipse(320,240,i*3,1+i*3,125+j*20,125+j*10);
delay(5000);
}
}
getch();
closegraph();
}
star(int x,int y,int r)
{
int r0=r*sin(18*th)/cos(36*th); /*計(jì)算小圓半徑r0 */
int i,color;
int x1[6],y1[6],x2[6],y2[6];
for(i=0;i<6;i++)
{
x1[i]=x+r*cos((90+i*72)*th); /* 計(jì)算出大圓上的五個(gè)平均分布點(diǎn)的坐標(biāo)*/
y1[i]=y-r*sin((90+i*72)*th);
x2[i]=x+r0*cos((54+i*72)*th); /* 計(jì)算出小圓上的五個(gè)平均分布點(diǎn)的坐標(biāo)*/
y2[i]=y-r0*sin((54+i*72)*th);
}
setcolor(RED);
for(i=0;i<5;i++) /* 將相應(yīng)的點(diǎn)用線連接起來。*/
{
line(x,y,x1[i],y1[i]);
line(x,y,x2[i],y2[i]);
line(x1[i],y1[i],x2[i],y2[i]);
line(x1[i],y1[i],x2[i+1],y2[i+1]);
}
for(i=0;i<10;i++) /* 分別填充相應(yīng)部位,形成立體效果*/
{
setfillstyle(1,i%2?RED:LIGHTRED);
floodfill(x+10*cos(i*36*th),y-10*sin(i*36*th),RED);
}
}
最近讀者
shinewave 零點(diǎn)任務(wù) 苗苗 大帥
分享(0) 評論(0) 分類:學(xué)習(xí)44次閱讀 2007-07-06 12:13
我要登錄 ->
公司簡介- 聯(lián)系方法- 招聘信息- 客戶服務(wù)- 相關(guān)法律- 用戶反饋- 舉報(bào)不良信息-
網(wǎng)易公司版權(quán)所有 ©1997-2008
JSWindow
正在加載中... {if coms != null && coms.length != 0} <div id="comShowHeader_${parentId}" class="g_h_20 g_c_mgin"> <span class="g_p_right g_c_hand n_ n7" style="margin-left:10px" onclick="${containerObjName}.closeComments('${parentId}');return false;" title="關(guān)閉"> </span> <ul class="g_menu_09 g_w_at com_page"> <li> {if (coms != null) && (comCount > (commentRange * pageNum))} <a id="spnNextPage_${parentId}" class="g_c_noul c06" href="#" onclick="${containerObjName}.moveToPage(${pageNum} + 1, true);return false;">下頁</a> {else}<span class="c09">下頁</span>{/if} </li> <li><span class="ckck c07">${pageNum}/${totalPageNum}</span></li> <li> {if pageNum > 1} <a id="spnPrevPage_${parentId}" class="g_c_noul c06" href="#" onclick="${containerObjName}.moveToPage(${pageNum} - 1, true);return false;">上頁</a> {else}<span class="c09">上頁</span>{/if} </li> </ul> </div> <div class="g_p_hide g_c_mgin g_table" id="comShowContent_${parentId}"> {for com in coms} <table class="g_w_100 bd1b g_com_table" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="layout_l"> {if com.publisherName != null && com.publisherName != ""} <a href="http://${com.publisherName|parentDomain}${prefix}/" target="_blank"> {if com.publisherAvatar==null || com.publisherAvatar==0 || com.publisherAvatar==-1000} <img class="g_img_04 g_c_hand bd01" id="imgPubPic_${com.id}" src="${formatImageUrl(defaultVisitorAvatarUrl)}" onerror="this.src='http://st.blog.163.com/style/common/stranger.gif'"/> {else} <img class="g_img_04 g_c_hand bd01" id="imgPubPic_${com.id}" src="${formatImageUrl(com.publisherAvatarUrl)}" onerror="this.src='http://st.blog.163.com/style/common/stranger.gif'" /> {/if} </a> <div class="g_t_hide nick"><a id="aComPubName_${com.id}" class="g_p_block g_h_20 c05" href="http://${com.publisherName|parentDomain}${prefix}/" title="${com.publisherNickname|escape}" target="_blank"> {if com.publisherId == hostId}<span class="n_ m9com" title="博主"> </span>{/if}${com.publisherNickname|escape}</a></div> {else} <span class="g_p_block g_h_20 g_t_hide g_w_100 c08 t_12">${com.publisherNickname|escape}</span> <div class="c09 g_w_95 t_12" style="padding-top:8px">${com.ipName}</div> {/if} </td> <td class="layout_r"> <table class="g_w_100"> <tr> <td class="t"><div class="c g_t_wrap c07" id="comContent${com.id}">${com.content}</div></td> </tr> <tr> <td colspan="3" class="b"> {if supportDeleteComment == true && visitorId == hostId} <a class="c06 g_p_right g_c_ul" id="delcomm_${com.id}" onclick="${containerObjName}.deleteComment('${com.id}');return false;" href="#">刪除</a> <nobr class="bd1c g_p_right md"> | </nobr> {/if} {if noCommentRight == false} {if com.publisherName != null && com.publisherName != ""} <a id="comReply_${com.id}" class="c06 g_p_right g_c_ul " onclick="${containerObjName}.reply('${com.id}',true,'${com.publisherNickname|escape|js_string}','${com.publisherName|parentDomain}${prefix}');return false;" href="#">回復(fù)</a> {else} <a id="comReply_${com.id}" class="c06 g_p_right g_c_ul " onclick="${containerObjName}.reply('${com.id}',false,'${com.publisherNickname|escape|js_string}','${com.ipName}');return false;" href="#">回復(fù)</a> {/if} {/if} <span class="g_p_right c09 tim md"> ${NetEase.DateTime.formatRecentDate(com.publishTime,"yyyy-MM-dd HH:mm")}</span> {if !isHomeModule && com.circleId>0}<span class="g_p_left c09">來源: <span class="c06">[</span><a class="c06" href="${circleBaseUrl}/${com.circleUrlName}/" target="_blank">${com.circleName}</a><span class="c06">]</span></span>{/if} </td> </tr> </table> </td> </tr> </table> {/for} </div> <div class="g_h_20 bd1b g_c_mgin"> <ul class="g_menu_09 g_w_at com_page"> <li> {if (coms != null) && (comCount > (commentRange * pageNum))} <a id="spnNextPage_${parentId}" class="g_c_noul c06" href="#" onclick="${containerObjName}.moveToPage(${pageNum} + 1, true);return false;">下頁</a> {else}<span class="c09">下頁</span>{/if} </li> <li><span class="ckck c07">${pageNum}/${totalPageNum}</span></li> <li> {if pageNum > 1} <a id="spnPrevPage_${parentId}" class="g_c_noul c06" href="#" onclick="${containerObjName}.moveToPage(${pageNum} - 1, true);return false;">上頁</a> {else}<span class="c09">上頁</span>{/if} </li> </ul> </div> {else} {if noCommentRight == false} <div id="comShowHeader_${parentId}" class="g_h_20 g_c_mgin"> <span class="g_p_right g_c_hand n_ n7" onclick="${containerObjName}.closeComments('${parentId}');return false;" title="關(guān)閉" > </span> </div> {/if} {/if} <div class="g_c_pdin"> {if (noCommentRight == true)} <div class="loginsection"> {if allowComment == 0} <span class="n_ n21"> </span>登錄后你可以發(fā)表評論,請先登錄。 </span><a href="#" onclick="showLoginDlg(DomainMap.serverHostName);return false;">登錄>></a> {elseif allowComment == 100} {if visitorRank==-100} <span class="n_ n21"> </span>登錄并添加博主為好友可以發(fā)表評論,請先登錄。 <a href="#" onclick="showLoginDlg(DomainMap.serverHostName);return false;">登錄>></a> {elseif visitorRank ==0} <span class="n_ n21"> </span>添加博主為好友可以發(fā)表評論,請先加為好友。 <a id="AComment${parentId}" href="#" onclick="pageTopBar.showAddFriend();return false;">加為好友>></a> {/if} {elseif allowComment == 10000} <span class="n_ n21"> </span>該內(nèi)容僅供欣賞。 {/if} </div> {else} <div> {if visitorRank <= -100} <div class="g_layout_05 g_h_25 g_t_left" style="margin-bottom:7px;"> <input type="text" id="username${parentId}" style="width:170px;" class="bd01 g_t_disable nvb g_c_input" name="username${parentId}" value="${userName}" maxlength="18"/> <a class="c06" href="#" onclick="showLoginDlg(DomainMap.serverHostName);return false;">我要登錄 -></a> </div> {else} <div class="g_layout_05"> <div class="l g_t_left"> {if visitorAvatarDefault == true} <img class="g_img_04 bd01" src="${formatImageUrl(defaultVisitorAvatarUrl)}" onerror="this.src='http://st.blog.163.com/style/common/stranger.gif'" width="60px" height="60px" title="顯示頭像"> {else} <img class="g_img_04 bd01" src="${formatImageUrl(visitorAvatar)}" onerror="this.src='http://st.blog.163.com/style/common/stranger.gif'" width="60px" height="60px" title="顯示頭像"> {/if} </div> <div class="r g_t_left"><input class="bd01 g_t_disable vb g_c_input" style="width:170px;" id="username${parentId}" name="username${parentId}" value="${userName}" type="text" maxlength="18"/></div> <div class="g_p_clear g_t_space"> </div> </div> {/if} <div class="g_c_smvdn bd01" id="edt${parentId}"></div> <div id="validCode${parentId}" class="g_c_mvdn g_t_left g_h_25" style="display:none;"></div> <div class="g_h_30 g_c_mvdn g_t_left g_w_100"> <input class="g_c_button bd01 butn" id="$$_pubbtn${parentId}" onclick="${containerObjName}.addComment('${parentId}'); return false;" type="submit" {if disabled == true}disabled="true" {/if} value="發(fā)表評論" {if hasCancelBtn==false}style="font-weight:700;"{/if}/> {if hasCancelBtn}<input class="g_c_button bd01 butn" id="$$_comcancelbtn${parentId}" onclick="${containerObjName}.closeComments('${parentId}');return false;" type="submit" {if disabled == true}disabled="true" {/if} value="取 消"/>{/if} <span id="$$_comsubmithint${parentId}" style="display:none;"></span> </div> </div> {/if} </div>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -