码迷,mamicode.com
首页 > 其他好文 > 详细

【canvas】高级功能一 变形

时间:2015-04-20 20:31:14      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

【canvas】Demo1 scale缩放

技术分享

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>图片</title>
</head>
<body>

<canvas id="wapper" width="1000" height="1000"></canvas>

<script>
var wapper = document.getElementById(‘wapper‘),
	_2d = wapper.getContext(‘2d‘);/*2d的绘制对象*/

var logo = new Image();
logo.src = ‘http://icon.xgo-img.com.cn/mainpage/20150226/logo_07.jpg‘;

logo.onload = function (){
	_2d.drawImage(this, 5, 5);/*drawImage(img,x,y)*/

	_2d.scale(1, 1);
	_2d.drawImage(this, 200, 5);/*drawImage(img,x,y)*/

	_2d.scale(2,2);
	_2d.drawImage(this, 0, 50);/*drawImage(img,x,y)*/

	_2d.scale(0.2,0.2);
	_2d.drawImage(this, 0, 800);/*drawImage(img,x,y)*/


}
</script>
</body>
</html>

  

【canvas】Demo2 translate移动

技术分享

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>图片</title>
</head>
<body>

<canvas id="wapper" width="1000" height="1000"></canvas>

<script>
var wapper = document.getElementById(‘wapper‘),
	_2d = wapper.getContext(‘2d‘);/*2d的绘制对象*/

_2d.fillRect(10,10,100,50);
_2d.translate(70,70);
_2d.fillRect(10,10,100,50);

</script>
</body>
</html>

  

【canvas】Demo3 rotate旋转

技术分享

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>rotate</title>
</head>
<body>

<canvas id="wapper" width="1000" height="1000"></canvas>

<script>
var wapper = document.getElementById(‘wapper‘),
	_2d = wapper.getContext(‘2d‘);/*2d的绘制对象*/

_2d.fillRect(50,50,100,50);
_2d.rotate(10*Math.PI/180);/*以画布0.0为中心的旋转*/
_2d.fillRect(50,50,100,50);
</script>
</body>
</html>

  

123

123

123

123

123

123

123

123

123

123

123

123

123

123

【canvas】高级功能一 变形

标签:

原文地址:http://www.cnblogs.com/dtdxrk/p/4442312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!