[Canvas]New Running Dog
欲看效果请下载后用Chrome浏览器打开index.html观看,下载地址:https://files.cnblogs.com/files/xiandedanteng/51-NewRunningDog.rar
代码:
<!DOCTYPE html>
<html lang="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head>
<title>奔跑的狗 19.3.3 12:09</title>
</head>
<body onload="draw()">
<canvas id="myCanvus" width="130px" height="100px" style="border:1px dashed black;">
出现文字表示你的浏览器不支持HTML5
</canvas>
</body>
</html>
<script type="text/javascript">
<!--
var ctx;// 绘图环境
var cds;// 从大图中取小图的左边组
var img;// 大图
function draw(){
var canvas=document.getElementById('myCanvus');
canvas.width=130;
canvas.height=100;
ctx=canvas.getContext('2d');
img=new Image();
img.src="runingDog.jpg";
// 图块坐标
cds=[
{'x':'50','y':'30','width':'130','height':'70'},
{'x':'190','y':'30','width':'130','height':'70'},
{'x':'320','y':'30','width':'130','height':'70'},
{'x':'60','y':'110','width':'130','height':'70'},
{'x':'190','y':'110','width':'130','height':'70'},
{'x':'310','y':'110','width':'130','height':'70'}
];
animate();
};
var index=130;
var i=0;
function animate(){
ctx.clearRect(0,0,130,110);// 清除图案
ctx.strokeStyle = "black";
// 绘制地面
ctx.beginPath();
ctx.moveTo(0, 70);
ctx.lineTo(ctx.width,70);
ctx.stroke();
ctx.closePath();
index++;
if(index>108){
index=0;
}
i=index % 6;
// 截取一块图贴上
ctx.drawImage(img,cds[i].x,cds[i].y,cds[i].width,cds[i].height,0,0,cds[i].width,cds[i].height);
setTimeout( function(){
window.requestAnimationFrame(animate); /// 让浏览器自行决定帧速率
}, 0.35 * 1000 );// 延时350毫秒执行
}
//-->
</script>
[Canvas]New Running Dog的更多相关文章
- python基础之面对对象
Python3 面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本章节我们将详细介绍Python的面向对象编程. 如果你以前没有接触 ...
- Python学习笔记 for windows 二
函数 abs(-20) //结果为:20,绝对值函数 def 函数名称([参数1,参数2,参数3]): 执行语句 retu ...
- python基础——继承和多态
python基础——继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类 ...
- js 实现继承相关
☊ [要求]:实现一个Animal类, 和一个继承它的Dog类 ☛ [实现]: function Animal(name) { this.name = name; } Animal.prototype ...
- python的最最最最最基本语法(3)
模块:在Python中,一个.py文件就称之为一个模块(Module). 为了避免模块名冲突,Python又引入了按目录来组织模块的方法,称为包(Package).例如两个名不hello.py的模块分 ...
- javascript oo实现(转)
javascript oo实现 By purplebamboo 7月 13 2014 更新日期:8月 21 2014 文章目录 1. 原始时代最简单的oo实现 2. 石器时代的oo实现 3. 工业时代 ...
- python 继承和多态
在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类(Base class.Supe ...
- Slow Server? This is the Flow Chart You're Looking For--reference
Your high-powered server is suddenly running dog slow, and you need to remember the troubleshooting ...
- Day-8: 面对对象编程
面对过程的程序设计方法意在将函数分成子函数,再依次调用这些函数来解决问题. 而面对对象的程序设计方法,来源于自然界,类是实例的抽象,实例是类的具体.自定义出来的对象是类,而所有的数据都可以看成是对象, ...
随机推荐
- TCP握手与socket通信细节
http://www.jianshu.com/u/5qrPPM http://www.jianshu.com/p/f86512230707
- linux socket TCP UDP bind 同义IP和port
//TCP and UDP can bind to the same IP & port. #include <sys/types.h> #include <sys/sock ...
- linux虚拟机与winodows共享文件夹----linux安装VMware tools
虚拟机里面想要获取原来本机 系统的文件,十分麻烦.为了实现原系统与虚拟机的共享文件夹,可以通过安装vmware tools达到共享目的. 1 安装vmware tools (1)检查虚拟机上是否挂 ...
- Android自己定义控件系列二:自己定义开关button(一)
这一次我们将会实现一个完整纯粹的自己定义控件,而不是像之前的组合控件一样.拿系统的控件来实现.计划分为三部分:自己定义控件的基本部分,自己定义控件的触摸事件的处理和自己定义控件的自己定义属性: 以下就 ...
- 调用WScript.Shell时产生Automation 服务器不能创建对象的错误
我们经常需要通过生成ActiveXObject("WScript.Shell");来调某一exe文件, 如 //设置网页打印的页眉页脚为空 var HKEY_Root,HKEY_P ...
- iOS 项目一直在后台执行
我后来是这么解决不知道行不行,能够长期的在后台执行 首先我在xx-info.plist 里的 "Required background modes" 里增加"App pr ...
- mysql time zone时区的错误解决
错误提示: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zon ...
- CCBAnimationManager
#ifndef __CCB_CCBANIMATION_MANAGER_H__ #define __CCB_CCBANIMATION_MANAGER_H__ #include "cocos2d ...
- URAL 1837. Isenbaev's Number (map + Dijkstra || BFS)
1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...
- springboot redis多数据源设置
遇到这样一个需求:运营人员在发布内容的时候可以选择性的发布到测试库.开发库和线上库. 项目使用的是spring boot集成redis,实现如下: 1. 引入依赖 <dependency> ...