php实现的中秋博饼游戏之绘制骰子图案功能示例


Posted in PHP onNovember 06, 2017

本文实例讲述了php实现的中秋博饼游戏之绘制骰子图案功能。分享给大家供大家参考,具体如下:

最近公司中秋博饼(在厦门),自己没事也想玩玩,所以就想动手写了一个纯php实现的中秋博饼游戏,既然要纯php实现,就要用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是红色,效果图如下:

php实现的中秋博饼游戏之绘制骰子图案功能示例

希望本文所述对大家PHP程序设计有所帮助。

PHP 相关文章推荐
phpfans留言版用到的install.php
Jan 04 PHP
mysql5的sql文件导入到mysql4的方法
Oct 19 PHP
Ajax+PHP 边学边练 之二 实例
Nov 24 PHP
不支持fsockopen但支持culr环境下下ucenter与modoer通讯问题
Aug 12 PHP
PHP命名空间(Namespace)的使用详解
May 04 PHP
深入eAccelerator与memcached的区别详解
Jun 06 PHP
PHP中的reflection反射机制测试例子
Aug 05 PHP
通过PHP简单实例介绍文件上传
Dec 16 PHP
php使用FFmpeg接口获取视频的播放时长、码率、缩略图以及创建时间
Nov 07 PHP
PHP用户注册邮件激活账户的实现代码
May 31 PHP
PHP常用字符串函数小结(推荐)
Aug 05 PHP
PHP时间日期增减操作示例【date strtotime实现加一天、加一月等操作】
Dec 21 PHP
PHP简单实现欧拉函数Euler功能示例
Nov 06 #PHP
Laravel中服务提供者和门面模式的入门介绍
Nov 06 #PHP
php实现的生成迷宫与迷宫寻址算法完整实例
Nov 06 #PHP
使用 laravel sms 构建短信验证码发送校验功能
Nov 06 #PHP
PHP中危险的file_put_contents函数详解
Nov 04 #PHP
PHP回调函数概念与用法实例分析
Nov 03 #PHP
PHP实现字符串翻转功能的方法【递归与循环算法】
Nov 03 #PHP
You might like
PHP4 与 MySQL 交互使用
2006/10/09 PHP
浅谈php中mysql与mysqli的区别分析
2013/06/10 PHP
PHP实现获取FLV文件的时间
2015/02/10 PHP
静态的动态续篇之来点XML
2006/08/15 Javascript
在html页面中包含共享页面的方法
2008/10/24 Javascript
Javascript 继承机制实例
2009/08/12 Javascript
jquery easyui的tabs使用时的问题
2010/03/23 Javascript
jQuery获取当前点击的对象元素(实现代码)
2016/05/19 Javascript
详解百度百科目录导航树小插件
2017/01/08 Javascript
javascript实现延时显示提示框效果
2017/06/01 Javascript
Javascript防止图片拉伸的自适应处理方法
2017/12/26 Javascript
利用angular、react和vue实现相同的面试题组件
2018/02/19 Javascript
详解swiper在vue中的应用(以3.0为例)
2018/09/20 Javascript
vue路由守卫及路由守卫无限循环问题详析
2019/09/05 Javascript
Vue中常用rules校验规则(实例代码)
2019/11/14 Javascript
Python字符遍历的艺术
2008/09/06 Python
Python中用于转换字母为小写的lower()方法使用简介
2015/05/19 Python
深入解析Python中函数的参数与作用域
2016/03/20 Python
Python 实现微信防撤回功能
2019/04/29 Python
Python 如何提高元组的可读性
2019/08/26 Python
Python unittest单元测试框架及断言方法
2020/04/15 Python
Python小白学习爬虫常用请求报头
2020/06/03 Python
JackJones官方旗舰店:杰克琼斯男装
2018/03/27 全球购物
深圳-东方伟业笔试部分
2015/02/11 面试题
金融专业大学生职业生涯规划范文
2014/01/16 职场文书
雪山饭庄的创业计划书范文
2014/01/18 职场文书
2014学校领导四风问题对照检查材料思想汇报
2014/09/22 职场文书
地方白酒代理协议书
2014/10/25 职场文书
财务部岗位职责范本
2015/04/14 职场文书
谁动了我的奶酪读书笔记
2015/06/30 职场文书
经典祝酒词大全
2015/08/12 职场文书
初中语文教学随笔
2015/08/15 职场文书
汉语拼音教学反思
2016/02/22 职场文书
祝福语集锦:给满月宝宝的祝福语
2019/11/20 职场文书
Python如何把不同类型数据的json序列化
2021/04/30 Python
CSS中妙用 drop-shadow 实现线条光影效果
2021/11/11 HTML / CSS