<!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>
<style>
*{ margin:0; padding:0;}
body{ background:black;}
#div1{ background:white; width:600px; margin:20px auto;}
</style>
<script>
window.onload = function(){
var oC = document.getElementById('c1');
var oGC = oC.getContext('2d');//绘制canvas的画板
var i = 0;
oGC.beginPath(); //开始绘制路径
//弧度 = 角度 * Math.PI/180
oGC.arc(300,200,200,-90*Math.PI/180,180*Math.PI/180,false);//圆形坐标,半径,弧度,
oGC.closePath();//结束绘制路径,起点终点相连接要写在stroke()之前。
oGC.stroke();//连线, oGC.beginPath();
oGC.arc(250,200,150,180*Math.PI/180,360*Math.PI/180,false);
oGC.stroke(); oGC.beginPath();
oGC.arc(400,200,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.stroke(); setInterval(function(){
oGC.clearRect(0,0,oC.width,oC.height);//清空画布
oGC.beginPath();
oGC.arc(i++,i++,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.stroke();
},30); };
</script>
</head> <body>
<div id="div1">
<canvas id="c1" width="600" height="600"></canvas>
</div>
</body>
</html>
<!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>
<style>
*{ margin:0; padding:0;}
body{ background:black;}
#div1{ background:white; width:600px; margin:20px auto;}
</style>
<script>
window.onload = function(){
var oC = document.getElementById('c1');
var oGC = oC.getContext('2d'); var i = 0; /*oGC.beginPath();
//弧度 = 角度 * Math.PI/180
oGC.arc(300,200,200,-90*Math.PI/180,180*Math.PI/180,false);
//oGC.closePath();
oGC.stroke(); oGC.beginPath();
oGC.arc(250,200,150,180*Math.PI/180,360*Math.PI/180,false);
oGC.stroke();
oGC.beginPath();
oGC.arc(400,200,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.stroke();*/ setInterval(function(){ oGC.clearRect(0,0,oC.width,oC.height); oGC.beginPath();
//弧度 = 角度 * Math.PI/180
oGC.arc(300,200,200,-90*Math.PI/180,180*Math.PI/180,false);
oGC.stroke(); oGC.beginPath();
oGC.arc(250,200,150,180*Math.PI/180,360*Math.PI/180,false);
oGC.stroke();
oGC.beginPath();
oGC.arc(400,200,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.stroke(); for(var i=0;i<ball.length;i++){ oGC.beginPath();
oGC.moveTo(ball[i].x,ball[i].y);
oGC.arc(ball[i].x,ball[i].y,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.fill();
} },1000/60); setInterval(function(){ for(var i=0;i<ball.length;i++){
ball[i].num++;
ball[i].x = Math.sin(ball[i].num*Math.PI/180) * ball[i].r + ball[i].startX;
ball[i].y = ball[i].r - Math.cos(ball[i].num*Math.PI/180) * ball[i].r + ball[i].startY;
}
},30); var ball = [];//定义数组
ball[0] = {//数组是对象json.
x : 300,
y : 0,
r : 200,
num : 0,
startX : 300,
startY : 0
}; };
</script>
</head> <body>
<div id="div1">
<canvas id="c1" width="600" height="600"></canvas>
</div>
</body>
</html>
<!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>
<style>
*{ margin:0; padding:0;}
body{ background:black;}
#div1{ background:white; width:600px; margin:20px auto;}
</style>
<script>
window.onload = function(){
var oC = document.getElementById('c1');
var oGC = oC.getContext('2d');
var i = 0;
var yImg = new Image();
yImg.src = 'person.png';
yImg.onload = function(){
setInterval(function(){
oGC.clearRect(0,0,oC.width,oC.height);
oGC.beginPath();
//弧度 = 角度 * Math.PI/180
oGC.arc(300,200,200,-90*Math.PI/180,180*Math.PI/180,false);
oGC.stroke(); oGC.beginPath();
oGC.arc(250,200,150,180*Math.PI/180,360*Math.PI/180,false);
oGC.stroke();
oGC.beginPath();
oGC.arc(400,200,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.stroke(); /*for(var i=0;i<ball.length;i++){
oGC.beginPath();
oGC.moveTo(ball[i].x,ball[i].y); oGC.arc(ball[i].x,ball[i].y,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.fill();
}*/ oGC.save();
oGC.translate(300,200);//平移,save()是为了防止translate()有坐标的累加。
oGC.rotate(iRotate);//旋转,参数是弧度
oGC.translate(-40,-40);
oGC.drawImage(yImg,0,0);
oGC.restore();
},1000/60); /*setInterval(function(){
for(var i=0;i<ball.length;i++){
ball[i].num++;
if( ball[i].num == 270 ){
ball[i].r = 150;
ball[i].startX = 250;
ball[i].startY = 50;
}
if( ball[i].num == 270 + 180 ){
alert('游戏结束');
window.location.reload();
}
ball[i].x = Math.sin(ball[i].num*Math.PI/180) * ball[i].r + ball[i].startX;
ball[i].y = ball[i].r - Math.cos(ball[i].num*Math.PI/180) * ball[i].r + ball[i].startY;
}
},30);*/ var ball = [];
setInterval(function(){
ball.push({
x : 300,
y : 0,
r : 200,
num : 0,
startX : 300,
startY : 0
});
},350); var iRotate = 0;
oC.onmousemove = function(ev){//弧度为鼠标的位置
var ev = ev || window.event;
var x = ev.clientX - oC.offsetLeft;
var y = ev.clientY - oC.offsetTop;
var a = x - 300;
var b = y - 200;
var c = Math.sqrt(a*a + b*b);
if(a>0 && b>0){
iRotate = Math.asin(b/c) + 90*Math.PI/180;
}
else if(a>0){
iRotate = Math.asin(a/c);
}
if(a<0 && b>0){
iRotate = -(Math.asin(b/c) + 90*Math.PI/180);
}
else if(a<0){
iRotate = Math.asin(a/c);
}
};
};
};
</script>
</head> <body>
<div id="div1">
<canvas id="c1" width="600" height="600"></canvas>
</div>
</body>
</html>
<!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>
<style>
*{ margin:0; padding:0;}
body{ background:black;}
#div1{ background:white; width:600px; margin:20px auto;}
</style>
<script>
window.onload = function(){
var oC = document.getElementById('c1');
var oGC = oC.getContext('2d'); var i = 0; var yImg = new Image(); yImg.src = 'person.png'; yImg.onload = function(){ setInterval(function(){ oGC.clearRect(0,0,oC.width,oC.height); oGC.beginPath();
//弧度 = 角度 * Math.PI/180
oGC.arc(300,200,200,-90*Math.PI/180,180*Math.PI/180,false);
oGC.stroke(); oGC.beginPath();
oGC.arc(250,200,150,180*Math.PI/180,360*Math.PI/180,false);
oGC.stroke();
oGC.beginPath();
oGC.arc(400,200,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.stroke(); for(var i=0;i<ball.length;i++){ oGC.beginPath();
oGC.moveTo(ball[i].x,ball[i].y);
oGC.arc(ball[i].x,ball[i].y,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.fill();
} oGC.save();
oGC.translate(300,200);
oGC.rotate(iRotate);
oGC.translate(-40,-40);
oGC.drawImage(yImg,0,0);
oGC.restore(); for(var i=0;i<bullet.length;i++){ oGC.save();
oGC.fillStyle = 'red';
oGC.beginPath();
oGC.moveTo(bullet[i].x,bullet[i].y);
oGC.arc(bullet[i].x,bullet[i].y,20,0*Math.PI/180,360*Math.PI/180,false);
oGC.fill();
oGC.restore();
} oGC.save();
oGC.font = '60px impact';
oGC.textBaseline = 'top';
oGC.fillStyle = 'red';
oGC.shadowOffsetX = 10;
oGC.shadowOffsetY = 10;
oGC.shadowColor = 'green';
oGC.shadowBlur = 5;
var w = oGC.measureText('简易祖玛').width;
var h = 60;
oGC.fillText('简易祖玛', (oC.width - w)/2 , 450 );
oGC.restore(); },1000/60); setInterval(function(){
for(var i=0;i<ball.length;i++){
ball[i].num++;
if( ball[i].num == 270 ){
ball[i].r = 150;
ball[i].startX = 250;
ball[i].startY = 50;
}
if( ball[i].num == 270 + 180 ){
alert('游戏结束');
window.location.reload();
}
ball[i].x = Math.sin(ball[i].num*Math.PI/180) * ball[i].r + ball[i].startX;
ball[i].y = ball[i].r - Math.cos(ball[i].num*Math.PI/180) * ball[i].r + ball[i].startY;
} for(var i=0;i<bullet.length;i++){
bullet[i].x = bullet[i].x + bullet[i].sX;
bullet[i].y = bullet[i].y + bullet[i].sY;
} for(var i=0;i<bullet.length;i++){
for(var j=0;j<ball.length;j++){
if( pz(bullet[i].x,bullet[i].y,ball[j].x,ball[j].y) ){
bullet.splice(i,1);//删除
ball.splice(j,1);
break;
}
}
}
},30); var ball = [];
setInterval(function(){
ball.push({
x : 300,
y : 0,
r : 200,
num : 0,
startX : 300,
startY : 0
});
},350); var iRotate = 0; oC.onmousemove = function(ev){
var ev = ev || window.event;
var x = ev.clientX - oC.offsetLeft;
var y = ev.clientY - oC.offsetTop; var a = x - 300;
var b = y - 200; var c = Math.sqrt(a*a + b*b); if(a>0 && b>0){
iRotate = Math.asin(b/c) + 90*Math.PI/180;
}
else if(a>0){
iRotate = Math.asin(a/c);
}
if(a<0 && b>0){
iRotate = -(Math.asin(b/c) + 90*Math.PI/180);
}
else if(a<0){
iRotate = Math.asin(a/c);
} }; var bullet = []; oC.onmousedown = function(ev){
var ev = ev || window.event; var x = ev.clientX - oC.offsetLeft;
var y = ev.clientY - oC.offsetTop; var a = x - 300;
var b = y - 200; var c = Math.sqrt(a*a + b*b); var speed = 5; var sX = speed * a/c;
var sY = speed * b/c; bullet.push({
x : 300,
y : 200,
sX : sX,
sY : sY
}); }; }; function pz(x1,y1,x2,y2){ var a = x1 - x2;
var b = y1 - y2; var c = Math.sqrt(a*a + b*b); if(c < 40){
return true;
}
else{
return false;
} } };
</script>
</head> <body>
<div id="div1">
<canvas id="c1" width="600" height="600"></canvas>
</div>
</body>
</html>

h5-10 canvas 简易祖玛的更多相关文章

  1. 简易祖玛--canvas

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. html 5 cavans 简易祖玛

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. html5 canvas简易版捕鱼达人游戏源码

    插件描述:html5利用canvas写的一个js版本的捕鱼,有积分统计,鱼可以全方位移动,炮会跟着鼠标移动,第一次打开需要鼠标移出背景图,再移入的时候就可以控制炮的转动,因为是用的mouseover触 ...

  4. h5标签canvas关于getImageData跨域的问题

    h5标签canvas关于getImageData跨域的问题 在学习h5的时候,canvas标签中getImageData()报错:security error! 具体代码如下(chrome浏览器): ...

  5. 关于h5绘制canvas生成图片的注意点!

    1.第一个是关于移动端自适应的问题: 答:如果是最后只要一张canvas生成的图片,而不是要绘制的canvas的图形,则不需要考虑自适应,绘制canvas的时候的宽高,可以直接写成UI提供的图的大小, ...

  6. 关于H5的Canvas

    1.什么是canvas? <canvas>标签是h5新增的,通过脚本(通常是js)来绘制图形,canvas只是一个图形容器,或者说是画布. canvas可以绘制路径.图形.字以及添加图像. ...

  7. HTML5 Canvas绘图基本使用方法, H5使用Canvas绘图

    Canvas 是H5的一部分,允许脚本语言动态渲染图像.Canvas 定义一个区域,可以由html属性定义该区域的宽高,javascript代码可以访问该区域,通过一整套完整的绘图功能(API),在网 ...

  8. H5使用Canvas绘图

    一.什么是Canvas Canvas 是H5的一部分,允许脚本语言动态渲染图像.Canvas 定义一个区域,可以由html属性定义该区域的宽高,javascript代码可以访问该区域,通过一整套完整的 ...

  9. Windows下虚拟机安装Ubuntu15.10 Destop简易操作过程

    一.前提环境: 1.vmware12.1,若您的系统是32位,请使用vmware10以下版本. 2.至少双核处理器,2G以上可用内存. 3.Ubuntu安装包(.iso后缀). 注:请尽量支持正版. ...

随机推荐

  1. Spark Streaming基础概念

    为了更好地理解Spark Streaming 子框架的处理机制,必须得要自己弄清楚这些最基本概念. 1.离散流(Discretized Stream,DStream):这是Spark Streamin ...

  2. 使用Attiny 85开发板制作BadUSB

    什么是BadUSB?请查看:http://www.baike.com/wiki/BadUSB 或者看看腾讯这个视频!https://v.qq.com/x/page/l01425u2igw.html   ...

  3. bootstrap-paginator基于bootstrap的分页插件

    bootstrap-paginator基于bootstrap的分页插件 GitHub 官网地址:https://github.com/lyonlai/bootstrap-paginator 步骤 引包 ...

  4. 用 Django2.0 做 简单的BBS(前端用 Bootstrap)

    实现目标: 开发首页显示BBS的标题和摘要,点击BBS的标题可跳转到BBS详细页面进行展示. 开发环境及开发工具: Python 3.6.3 Django 2.0 Pycharm 2017.3 实现过 ...

  5. 指定DIV局部刷新的简单实现,很简单,但是网上搜到的大部分都很复杂

    脚本部分: <script type="text/javascript"> $(function () { setInterval(function () { $(&q ...

  6. JSP_内置对象_out

    out对象是JspWriter类的实例,是向客户端输出内容的常用对象,常用方法如下: void println() 向客户端打印字符串 void clear() 清除缓冲区的内容,如果在flush之后 ...

  7. JDBC Druid式link

    准备工作:导入包------druid-1.0.9.jar    src文件夹下放下druid.properties文件 且其中的url和数据库名要配置完备 import JdbcUtils.JDBC ...

  8. console.log、toString方法与js判断变量类型

    Java调用system.print.out()是会调用toString方法打印js里的console.log也是控制台打印,很多时候,我们以为也是调用toString方法,其实并不是.我们在chro ...

  9. Apex语言(七)集合

    1.集合 集合是可以存储多个记录数的变量类型. List列表集合可以包含任何数量的数据,与数组类似. Set列表集合包含多个无序的唯一记录数,集合不能具有重复记录,与列表类似. Map地图是一个键值对 ...

  10. python学习之小小爬虫

    学习python一段时间了,写了一个图片的小小爬虫,分享下,不喜勿喷! #coding=utf-8 ''' Created on 2015-5-22 @author: 悦文 ''' import re ...