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

transform图形变化

时间:2016-05-11 10:51:55      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</title> <style type="text/css"> #canvas{border:1px solid #eee ; display:block; background-color: #B36666; margin: 20px auto; } </style></head><body><div><canvas id = "canvas" width = "1300px" height = "800px"></canvas></div> <script type = "text/javascript" >
window.onload=function(){
var context = document.getElementById(‘canvas‘).getContext(‘2d‘)
/* transform 变化矩阵
context.transform(1,0,0,1,0,0); 默认值
参数2:x坐标的倾斜度
context.transform(1,2,0,1,0,0)
参数3:y坐标的倾斜度
context.transform(1,0,2,1,0,0)
参数1:x坐标的放大倍数
context.transform(3,0,0,1,0,0) == context.scale(3,1);
参数4:y坐标的放大倍数
context.transform(1,0,0,2,0,0) == context.scale(1,2);
参数5:x坐标的偏移
context.transform(1,0,0,1,50,0) == context.translate(50,0);
参数6:y坐标的偏移
context.transform(1,0,0,1,50,40) == context.translate(50,40);

注意: transform 会叠加
解决方案: context.setTransform(1,0,0,1,10,10);

*/
context.strokeStyle=‘#eeeeee‘;
context.fillStyle=‘rgba(70,200,200,0.5)‘;
context.lineWith = 9;

context.save();
context.transform(1,2,2,1,0,100);
context.transform(1,0,0,1,0,0); //有叠加,附加在之前的变化
context.fillRect(30,30,100,150);
context.strokeRect(30,30,100,150);
context.restore();

context.save();
context.setTransform(1,0,0,1,0,0);//解决叠加方案:
context.fillRect(300,30,100,150);
context.strokeRect(300,30,100,150);
context.restore();
}
</script> </body> </html>

transform图形变化

标签:

原文地址:http://www.cnblogs.com/vs1435/p/5480876.html

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