[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: 面对对象编程
面对过程的程序设计方法意在将函数分成子函数,再依次调用这些函数来解决问题. 而面对对象的程序设计方法,来源于自然界,类是实例的抽象,实例是类的具体.自定义出来的对象是类,而所有的数据都可以看成是对象, ...
随机推荐
- MSDN WinUSB Example
The WinUSB user-mode library uses device interface classes to communicate with the kernel-mode USB s ...
- Revit API创建几何实体Solid并找到与之相交的元素
几何实体的创建方法之一:构成封闭底面,指定拉伸方向与拉伸高度.GeometryCreationUtilities ; , pt.Y - dBoxLength / , pt.Z); ...
- 初识GRUNT
什么是GRUNT? 基于任务的命令行工具.能做的事包括: ● 验证html,css, javascript● 压缩css, javascript● 编译CoffeeScript, TypeScript ...
- Ubuntu64位下使用eclipse闪退的解决
解决办法: 删除文件 [workspace]/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
- [开源]Google code Android开源项目(一)
[Android分享] [开源]Google code Android开源项目(一) [复制链接] 449122717 2 主题 2 好友 816 积分 No.4 中级开发者 升级 19.3 ...
- ArrayList的总结
1.ArrayList的特点 主要特点:按照插入顺序来保存元素,可以利用下标来查找值 2.ArrayList的优点: 按照下标访问元素最快 3.ArrayList的缺点: 在中间插入元素很慢 删除元素 ...
- Java获取当前类名的两种方法
适用于非静态方法:this.getClass().getName() 适用于静态方法:Thread.currentThread().getStackTrace()[1].getClassName() ...
- 嗜血法医第八季/全集Dexter 8迅雷下载
嗜血法医 第八季 Dexter Season 8 (2013) 本季看点:来自Showtime电视网的连环杀人犯<嗜血法医>Dexter作为今夏最重磅的剧集之一,已经于当地时间6月30日回 ...
- Android系统版本与API等级对应关系表
从Android官网拷过来的,方便查阅... 官网地址:https://developer.android.com/guide/topics/manifest/uses-sdk-element.htm ...
- ImportError: No module named caffe.proto解决办法
原文 https://blog.csdn.net/lanyuelvyun/article/details/73628152 在用自己的数据训练基于caffe的SSD模型的时候,我们需要将图片数据转 ...