php實現(xiàn)的中秋博餅游戲之繪制骰子圖案功能示例
本文實例講述了php實現(xiàn)的中秋博餅游戲之繪制骰子圖案功能。分享給大家供大家參考,具體如下:
最近公司中秋博餅(在廈門),自己沒事也想玩玩,所以就想動手寫了一個純php實現(xiàn)的中秋博餅游戲,既然要純php實現(xiàn),就要用php來生成圖案,所以第一步就先繪制骰子圖案。
平時很少使用php繪圖,不過查查資料還是繪制出來了,不多說了,代碼如下:
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點各點圖案,1/3/5顏色是藍色,2/4/6是紅色,效果圖如下:
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
PHP中類型轉(zhuǎn)換 ,常量,系統(tǒng)常量,魔術(shù)常量的詳解
這篇文章主要介紹了PHP中類型轉(zhuǎn)換 ,常量,系統(tǒng)常量,魔術(shù)常量的詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10php-redis中的sort排序函數(shù)總結(jié)
這篇文章主要介紹了php-redis中的sort排序函數(shù)總結(jié),本文講解了了按字母排序、排序取部分數(shù)據(jù)、使用外部key進行排序等排序方法,同時給出代碼實例,需要的朋友可以參考下2015-07-07php+ajax實現(xiàn)無刷新數(shù)據(jù)分頁的辦法
這篇文章主要介紹了php+ajax實現(xiàn)無刷新分頁的方法,詳細講述了數(shù)據(jù)庫的創(chuàng)建、Ajax文件的實現(xiàn)及PHP調(diào)用方法,需要的朋友可以參考下2015-11-11php面向?qū)ο?一) 初窺(php面向?qū)ο蠡A(chǔ)介紹)
這篇文章主要介紹了php面向?qū)ο蟮囊恍┲R,需要的朋友可以參考下2017-08-08PHP htmlspecialchars_decode()函數(shù)用法講解
今天小編就為大家分享一篇關(guān)于PHP htmlspecialchars_decode()函數(shù)用法講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03