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 相关文章推荐
Apache, PHP在Windows 9x/NT下的安装与配置 (二)
Oct 09 PHP
小偷PHP+Html+缓存
Nov 25 PHP
PHP获取当前页面完整URL的实现代码
Jun 10 PHP
ThinkPHP中pathinfo的访问模式、路径访问模式及URL重写总结
Aug 23 PHP
php限制上传文件类型并保存上传文件的方法
Mar 13 PHP
php返回相对时间(如:20分钟前,3天前)的方法
Apr 14 PHP
php操作MongoDB类实例
Jun 17 PHP
在Windows系统下使用PHP生成Word文档的教程
Jul 03 PHP
PHP CURL或file_get_contents获取网页标题的代码及两者效率的稳定性问题
Nov 30 PHP
Yii快速入门经典教程
Dec 28 PHP
浅谈PHP中的数据传输CURL
Sep 06 PHP
php获取当前url地址的方法小结
Jan 10 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
php,ajax实现分页
2008/03/27 PHP
PHP模块 Memcached功能多于Memcache
2011/06/14 PHP
PHP如何通过传引用的思想实现无限分类(代码简单)
2015/10/13 PHP
Linux下快速搭建php开发环境
2017/03/13 PHP
php实现支持中文的文件下载功能示例
2017/08/30 PHP
JS 参数传递的实际应用代码分析
2009/09/13 Javascript
Mootools 1.2教程 选项卡效果(Tabs)
2009/09/15 Javascript
JavaScript高级程序设计 XML、Ajax 学习笔记
2011/09/10 Javascript
让网页跳转到指定位置的jquery代码非书签
2013/09/06 Javascript
巧用jquery解决下拉菜单被Div遮挡的相关问题
2014/02/13 Javascript
jquery实现弹出div,始终显示在屏幕正中间的简单实例
2014/03/08 Javascript
JavaScript模块随意拖动示例代码
2014/05/27 Javascript
Jquery简单分页实现方法
2015/07/24 Javascript
jQuery+CSS实现的网页二级下滑菜单效果
2015/08/25 Javascript
jQuery实现带动画效果的多级下拉菜单代码
2015/09/08 Javascript
学习使用bootstrap基本控件(table、form、button)
2016/04/12 Javascript
angular.js分页代码的实例
2016/07/27 Javascript
jQuery操作复选框(CheckBox)的取值赋值实现代码
2017/01/10 Javascript
微信小程序自定义tabBar组件开发详解
2020/09/24 Javascript
node.js 基于cheerio的爬虫工具的实现(需要登录权限的爬虫工具)
2019/04/10 Javascript
详解jQuery中的getAll()和cleanData()
2019/04/15 jQuery
原生js实现密码强度验证功能
2020/03/18 Javascript
[01:12]快闪回顾DOTA2亚洲邀请赛(DAC) 静候2018新征程开启
2018/03/11 DOTA
[01:05:07]DOTA2-DPC中国联赛 正赛 DLG vs Dragon BO3 第一场2月1日
2021/03/11 DOTA
Python基于聚类算法实现密度聚类(DBSCAN)计算【测试可用】
2018/12/26 Python
Django中ORM外键和表的关系详解
2019/05/20 Python
python操作kafka实践的示例代码
2019/06/19 Python
html5+css如何实现中间大两头小的轮播效果
2018/12/06 HTML / CSS
迪奥官网:Dior.com
2018/12/04 全球购物
简述Linux文件系统通过i节点把文件的逻辑结构和物理结构转换的工作过程
2016/01/06 面试题
优秀员工自荐信范文
2013/10/05 职场文书
网络专业学生个人的自我评价
2013/12/16 职场文书
奥巴马演讲稿
2014/01/08 职场文书
修理厂厂长岗位职责
2014/01/30 职场文书
环境保护与污染治理求职信
2014/07/16 职场文书
车队安全员岗位职责
2015/02/15 职场文书