php實(shí)現(xiàn)的中秋博餅游戲之繪制骰子圖案功能示例
本文實(shí)例講述了php實(shí)現(xiàn)的中秋博餅游戲之繪制骰子圖案功能。分享給大家供大家參考,具體如下:
最近公司中秋博餅(在廈門(mén)),自己沒(méi)事也想玩玩,所以就想動(dòng)手寫(xiě)了一個(gè)純php實(shí)現(xiàn)的中秋博餅游戲,既然要純php實(shí)現(xiàn),就要用php來(lái)生成圖案,所以第一步就先繪制骰子圖案。
平時(shí)很少使用php繪圖,不過(guò)查查資料還是繪制出來(lái)了,不多說(shuō)了,代碼如下:
header('Content-Type:image/png'); $img = imagecreatetruecolor(200, 200); $white = imagecolorallocate($img, 255, 255, 255); $grey = imagecolorallocate($img, 100, 100, 100); $blue = imagecolorallocate($img, 0, 102, 255); $red = imagecolorallocate($img, 255, 0, 0); imagefill($img, 0, 0, $white); imageline($img, 10, 20, 10, 180, $grey); imageline($img, 10, 180, 20, 190, $grey); imageline($img, 20, 190, 180, 190, $grey); imageline($img, 180, 190, 190, 180, $grey); imageline($img, 190, 180, 190, 20, $grey); imageline($img, 190, 20, 180, 10, $grey); imageline($img, 180, 10, 20, 10, $grey); imageline($img, 20, 10, 10, 20, $grey); //1 imagefilledarc($img, 100, 100, 50, 50, 0, 0, $blue, IMG_ARC_PIE); //2 //imagefilledarc($img, 60, 100, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 140, 100, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //3 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //imagefilledarc($img, 100, 100, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //4 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 50, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 150, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //5 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //imagefilledarc($img, 50, 150, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //imagefilledarc($img, 100, 100, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //imagefilledarc($img, 150, 50, 40, 40, 0, 0 , $blue, IMG_ARC_PIE); //6 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 50, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 100, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 100, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE); //imagefilledarc($img, 150, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE); imagepng($img); imagedestroy($img);
可以繪制出1-6點(diǎn)各點(diǎn)圖案,1/3/5顏色是藍(lán)色,2/4/6是紅色,效果圖如下:
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語(yǔ)法入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- php實(shí)現(xiàn)的網(wǎng)頁(yè)版剪刀石頭布游戲示例
- php實(shí)現(xiàn)貪吃蛇小游戲
- php猜單詞游戲
- php實(shí)現(xiàn)的簡(jiǎn)易掃雷游戲?qū)嵗?/a>
- PHP實(shí)現(xiàn)扎金花游戲之大小比賽的方法
- jQuery+PHP實(shí)現(xiàn)的擲色子抽獎(jiǎng)游戲?qū)嵗?/a>
- PHP使用header()輸出圖片緩存實(shí)例
- php將圖片文件轉(zhuǎn)換成二進(jìn)制輸出的方法
- php讀取圖片內(nèi)容并輸出到瀏覽器的實(shí)現(xiàn)代碼
- PHP提取數(shù)據(jù)庫(kù)內(nèi)容中的圖片地址并循環(huán)輸出
- php實(shí)現(xiàn)的中秋博餅游戲之?dāng)S骰子并輸出結(jié)果功能詳解
相關(guān)文章
PHP中類(lèi)型轉(zhuǎn)換 ,常量,系統(tǒng)常量,魔術(shù)常量的詳解
這篇文章主要介紹了PHP中類(lèi)型轉(zhuǎn)換 ,常量,系統(tǒng)常量,魔術(shù)常量的詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10php實(shí)現(xiàn)webservice實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)webservice的方法,以實(shí)例形式講述了webservice的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下2014-11-11php-redis中的sort排序函數(shù)總結(jié)
這篇文章主要介紹了php-redis中的sort排序函數(shù)總結(jié),本文講解了了按字母排序、排序取部分?jǐn)?shù)據(jù)、使用外部key進(jìn)行排序等排序方法,同時(shí)給出代碼實(shí)例,需要的朋友可以參考下2015-07-07linux下 C語(yǔ)言對(duì) php 擴(kuò)展
linux C語(yǔ)言對(duì) php 擴(kuò)展的設(shè)置技巧2008-12-12封裝一個(gè)PDO數(shù)據(jù)庫(kù)操作類(lèi)代碼
數(shù)據(jù)庫(kù)PDO操作類(lèi),網(wǎng)上好多朋友需要的,可以參考下。2009-09-09php+ajax實(shí)現(xiàn)無(wú)刷新數(shù)據(jù)分頁(yè)的辦法
這篇文章主要介紹了php+ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)的方法,詳細(xì)講述了數(shù)據(jù)庫(kù)的創(chuàng)建、Ajax文件的實(shí)現(xiàn)及PHP調(diào)用方法,需要的朋友可以參考下2015-11-11php基于表單密碼驗(yàn)證與HTTP驗(yàn)證用法實(shí)例
這篇文章主要介紹了php基于表單密碼驗(yàn)證與HTTP驗(yàn)證用法,以實(shí)例形式較為詳細(xì)的分析了表單密碼驗(yàn)證與HTTP驗(yàn)證的原理與相關(guān)注意事項(xiàng),具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01php面向?qū)ο?一) 初窺(php面向?qū)ο蠡A(chǔ)介紹)
這篇文章主要介紹了php面向?qū)ο蟮囊恍┲R(shí),需要的朋友可以參考下2017-08-08PHP htmlspecialchars_decode()函數(shù)用法講解
今天小編就為大家分享一篇關(guān)于PHP htmlspecialchars_decode()函數(shù)用法講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03