html canvas 骰子1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>骰子</title>
</head>
<body>
<canvas id="canvas" width="400" height="300"></canvas>
<script type="text/javascript">
function dice(){
this.ctx=null;
this.cwidth=400;
this.cheight=300;
this.dicex=50;
this.dicey=50;
this.dicewidth=100;
this.diceheight=100;
this.dotrad=6;
}
dice.prototype={
ready:function()
{
var ch=Math.floor(Math.random()*6)+1;
this.drawface(ch);
},
drawface:function(i)
{
this.ctx=document.getElementById("canvas").getContext("2d");
this.ctx.lineWidth=5;
this.ctx.clearRect(this.dicex,this.dicey,this.dicewidth,this.diceheight);
this.ctx.strokeRect(this.dicex,this.dicey,this.dicewidth,this.diceheight);
this.ctx.fillStyle="#000000"
switch(i)
{
case 1:
this.Draw1();
break;
case 2:
this.Draw2();
break;
case 3:
this.Draw1();
this.Draw2();
break;
case 4:
this.Draw4();
break;
case 5:
this.Draw1();
this.Draw4();
break;
case 6:
this.Draw4();
this.Draw6();
break;
}
},
Draw1:function(){
var dotx,doty;
this.ctx.beginPath();
dotx=this.dicex + .5 * this.dicewidth;
doty=this.dicey + .5 * this.diceheight;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
this.ctx.closePath();
this.ctx.fill()
},
Draw2:function(){
var dotx,doty;
this.ctx.beginPath();
dotx=this.dicex +3 * this.dotrad;
doty=this.dicey +3 * this.dotrad;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
dotx=this.dicewidth + this.dicex - 3 * this.dotrad;
doty=this.diceheight + this.dicey - 3 * this.dotrad
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
this.ctx.closePath();
this.ctx.fill()
},
Draw4:function(){
var dotx,doty;
this.ctx.beginPath();
dotx=this.dicex +3 * this.dotrad;
doty=this.dicey +3 * this.dotrad;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
dotx=this.dicewidth + this.dicex - 3 * this.dotrad;
doty=this.dicey + 3 * this.dotrad;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
this.ctx.closePath();
this.ctx.fill();
this.ctx.beginPath();
dotx=this.dicex + 3 * this.dotrad;
doty=this.dicey + this.diceheight - 3 * this.dotrad;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
dotx=this.dicex + this.dicewidth - 3 * this.dotrad;
doty=this.dicey + this.diceheight - 3 * this.dotrad;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
this.ctx.closePath();
this.ctx.fill()
},
Draw6:function(){
var dotx,doty;
this.ctx.beginPath();
dotx=this.dicex +3 * this.dotrad;
doty=this.dicey + 0.5 * this.diceheight;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
dotx=this.dicewidth+this.dicex - 3 * this.dotrad;
doty=this.dicey + 0.5 * this.diceheight;
this.ctx.arc(dotx,doty,this.dotrad,0,Math.PI*2,true);
this.ctx.closePath();
this.ctx.fill()
}
}
var c=new dice();
c.ready()
</script>
</body>
</html>
html canvas 骰子1的更多相关文章
- Html5最简单的游戏Demo——Canvas绘图的骰子
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- html5掷骰子的小demo
代码如下: <!DOCTYPE> <html> <title>柯乐义</title> <head> <script> var l ...
- 【整理】HTML5游戏开发学习笔记(1)- 骰子游戏
<HTML5游戏开发>,该书出版于2011年,似乎有些老,可对于我这样没有开发过游戏的人来说,却比较有吸引力,选择自己感兴趣的方向来学习html5,css3,相信会事半功倍.不过值得注意的 ...
- html5 canvas常用api总结(三)--图像变换API
canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...
- 【探索】利用 canvas 实现数据压缩
前言 HTTP 支持 GZip 压缩,可节省不少传输资源.但遗憾的是,只有下载才有,上传并不支持.如果上传也能压缩,那就完美了.特别适合大量文本提交的场合,比如博客园,就是很好的例子. 虽然标准不支持 ...
- 简单入门canvas - 通过刮奖效果来学习
一 .前言 一直在做PC端的前端开发,从互联网到行业软件.最近发现移动端已经成为前端必备技能了,真是不能停止学习.HTML5新增的一些东西,canvas是用的比较多也比较复杂的一个,简单的入门了一下, ...
- 获取Canvas当前坐标系矩阵
前言 在我的另一篇博文 Canvas坐标系转换 中,我们知道了所有的平移缩放旋转操作都会影响到画布坐标系.那在我们对画布进行了一系列操作之后,怎么再知道当前矩阵数据状态呢. 具体代码 首先请看下面的一 ...
- Canvas坐标系转换
默认坐标系与当前坐标系 canvas中的坐标是从左上角开始的,x轴沿着水平方向(按像素)向右延伸,y轴沿垂直方向向下延伸.左上角坐标为x=0,y=0的点称作原点.在默认坐标系中,每一个点的坐标都是直接 ...
- Canvas绘图之平移translate、旋转rotate、缩放scale
画布操作介绍 画布绘图的环境通过translate(),scale(),rotate(), setTransform()和transform()来改变,它们会对画布的变换矩阵产生影响. 函数 方法 描 ...
随机推荐
- 在Eclipse中添加C/C++插件
如果尚未安装 Eclipse,可直接下载包含C/C++的 Eclipse IDE http://www.eclipse.org/downloads/eclipse-packages/?osType=l ...
- Isometric terrain
Isometric terrainhttp://forum.mapeditor.org/t/isometric-terrain/192/2 无透视地图的地形制作时,将每一贴图逆时针旋转45度,则比较容 ...
- oracle 配置监听 windows下 oracle 12c
1, 在命令行窗口中 输入 hostname 查看主机名 2 查看本机ip地址 ,输入 ipconfig 本地连接 下面的 IPv4 地址 192.168.1.1053,测试连接 输入 ping lo ...
- WPF进度条系列①滑动小圆点
写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...
- 关于CDN下查找网站真实ip
关于CDN下查找网站真实ip From t00ls.net -----雨苁收集 杂乱无章,自己慢慢看,有问题加Q2359795780~~~~~~噗 先来几张t00lslogo ...
- Minimum Depth of Binary Tree [LeetCode]
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 【原作】关于Dynpro中的红绿灯显示
问题源自李宁的需求,就不说了. 关于ABAP中的红绿灯网上也有很多资料,不过貌似都是ABAP的程序,没怎么注意.后来根据需求要在Dynpro上也做出那样的效果,所以,研究了一下. 这种红绿灯在ABAP ...
- HEAD FIRST HTML & CSS学习笔记1
一.指定媒体类型=指定显示设备的类型 P400 有两种方式指定媒体类型: a. 直接在<link>标签中加属性media,例: <link href="print.css ...
- Git bash使用中...
理解Head指向分支及标签tag Head指向当前分支(如master),可以把每次提交完成的修改看成一个圈,在修改上可以开另一分支为接下来的修改做准备,未修改前新建的分支与当前分支可看成绕修改圈转: ...
- 自定义刷新tableView
// // LSTWholeTableController.m // BUDEJIE // // Created by admin on 16/8/17. // Copyright © 201 ...