最近公司中秋博饼(在厦门),自己没事也想玩玩,所以就想动手写了一个纯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