純php實現中秋博餅游戲(1):繪制骰子圖案


最近公司中秋博餅(在廈門),自己沒事也想玩玩,所以就想動手寫了一個純php實現的中秋博餅游戲,既然要純php實現,就要用php來生成圖案,所以第一步就先繪制骰子圖案。

平時很少使用php繪圖,不過查查資料還是繪制出來了,不多說了,代碼如下:

 1 header('Content-Type:image/png');
 2 $img   = imagecreatetruecolor(200, 200);
 3 $white = imagecolorallocate($img, 255, 255, 255);
 4 $grey  = imagecolorallocate($img, 100, 100, 100);
 5 $blue  = imagecolorallocate($img, 0, 102, 255);
 6 $red   = imagecolorallocate($img, 255, 0, 0);
 7 imagefill($img, 0, 0, $white);
 8 imageline($img, 10, 20, 10, 180, $grey);
 9 imageline($img, 10, 180, 20, 190, $grey);
10 imageline($img, 20, 190, 180, 190, $grey);
11 imageline($img, 180, 190, 190, 180, $grey);
12 imageline($img, 190, 180, 190, 20, $grey);
13 imageline($img, 190, 20, 180, 10, $grey);
14 imageline($img, 180, 10, 20, 10, $grey);
15 imageline($img, 20, 10, 10, 20, $grey);
16 
17 //1
18 imagefilledarc($img, 100, 100, 50, 50, 0, 0, $blue, IMG_ARC_PIE);
19 //2
20 //imagefilledarc($img, 60, 100, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
21 //imagefilledarc($img, 140, 100, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
22 //3
23 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
24 //imagefilledarc($img, 100, 100, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
25 //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
26 //4
27 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
28 //imagefilledarc($img, 50, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
29 //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
30 //imagefilledarc($img, 150, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
31 //5
32 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
33 //imagefilledarc($img, 50, 150, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
34 //imagefilledarc($img, 100, 100, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
35 //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
36 //imagefilledarc($img, 150, 50, 40, 40, 0, 0 , $blue, IMG_ARC_PIE);
37 //6
38 //imagefilledarc($img, 50, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
39 //imagefilledarc($img, 50, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
40 //imagefilledarc($img, 100, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
41 //imagefilledarc($img, 100, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
42 //imagefilledarc($img, 150, 150, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
43 //imagefilledarc($img, 150, 50, 40, 40, 0, 0 , $red, IMG_ARC_PIE);
44 
45 imagepng($img);
46 imagedestroy($img);

 

可以繪制出1-6點各點圖案,1/3/5顏色是藍色,2/4/6是紅色,效果圖如下:

純php實現中秋博餅游戲系列博文:

純php實現中秋博餅游戲(1):繪制骰子圖案
http://www.cnblogs.com/zqifa/p/php-dice-1.html
純php實現中秋博餅游戲(2):擲骰子並輸出結果
http://www.cnblogs.com/zqifa/p/php-dice-2.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM