欲看效果请下载后用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的更多相关文章

  1. python基础之面对对象

    Python3 面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本章节我们将详细介绍Python的面向对象编程. 如果你以前没有接触 ...

  2. Python学习笔记 for windows 二

    函数 abs(-20)                                        //结果为:20,绝对值函数 def 函数名称([参数1,参数2,参数3]): 执行语句 retu ...

  3. python基础——继承和多态

    python基础——继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类 ...

  4. js 实现继承相关

    ☊ [要求]:实现一个Animal类, 和一个继承它的Dog类 ☛ [实现]: function Animal(name) { this.name = name; } Animal.prototype ...

  5. python的最最最最最基本语法(3)

    模块:在Python中,一个.py文件就称之为一个模块(Module). 为了避免模块名冲突,Python又引入了按目录来组织模块的方法,称为包(Package).例如两个名不hello.py的模块分 ...

  6. javascript oo实现(转)

    javascript oo实现 By purplebamboo 7月 13 2014 更新日期:8月 21 2014 文章目录 1. 原始时代最简单的oo实现 2. 石器时代的oo实现 3. 工业时代 ...

  7. python 继承和多态

    在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类(Base class.Supe ...

  8. 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 ...

  9. Day-8: 面对对象编程

    面对过程的程序设计方法意在将函数分成子函数,再依次调用这些函数来解决问题. 而面对对象的程序设计方法,来源于自然界,类是实例的抽象,实例是类的具体.自定义出来的对象是类,而所有的数据都可以看成是对象, ...

随机推荐

  1. bitnami下mysql配置-包含phpMyAdmin配置

    mysql开启远程访问: 默认情况下mysql的绑定ip是bind-address=127.0.0.1 找到my.cnf bitnami@linux:~$ sudo find / -name my.c ...

  2. [Winform]缓存处理

    摘要 在对winform做的项目优化的时候,首先想到的是对查询,并不经常变化的数据进行缓存,但对web项目来说有System.Web.Caching.Cache类进行缓存,那么winform端该如何呢 ...

  3. C++ 实践总结

     对于一个应用程序而言,静态链接库可能被载入多次,而动态链接库仅仅会被载入一次. Gameloft面试之错误一 Event: 面试官说例如以下程序是能够链接通过的. class Base { Pu ...

  4. 轮子科技的.NET Core分享

    2016年8月11日 应轮子科技一众好友的邀请,在轮子科技给大家做了一个无责任的瞎聊段落,聊聊.NET的Core的一些内容. 恩,演讲者就只有我一个了,讲师是微软的 MVP 杨守斌,就是因为这个,所以 ...

  5. 咏南中间件新增MORMOT移动端演示

    咏南中间件新增MORMOT移动端演示 基于FMX,支持安卓.IOS移动端. 1)使用INDY 的HTTP控件进行查询: procedure TForm1.查询1Click(Sender: TObjec ...

  6. TWebHttpRequest使用

    TWebHttpRequest使用 TWebHttpRequest通过HTTP GET方法,向中间件REST API申请数据. procedure TForm1.WebButton1Click(Sen ...

  7. Apache Tomcat 9 Installation on Linux (RHEL and clones)

    Apache Tomcat 9 is not available from the standard RHEL distributions, so this article provides info ...

  8. CCConfiguration::sharedConfiguration()->loadConfigFile cocos2d-x 中文乱码问题及国际化解决方案

    from:://http://www.cnblogs.com/sunguangran/archive/2013/07/29/3222660.html 将显示文本单独保存为文本文件 在cocos2d-x ...

  9. malloc基本实现

    转自:http://www.cnblogs.com/wangshide/p/3932539.html 任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间 ...

  10. Spring Mvc如何通过注解的方式设置视图解析器的优先级

    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalRes ...