<!DOCTYPE HTML>
<html>
<head>
<Title>Transformations Example</title>
<script>

window.onload = function() {
var canvas=document.getElementById("myCanvas");
var context=canvas.getContext("2d");

var rectWidth = 250;
var rectHeight = 75;

// 把context平移到画布的中心
context.translate(canvas.width/2,canvas.height/2);

// y方向的组成减半
context.scale(1,0.5);

// 顺时针旋转45度
context.rotate(-Math.PI/4);

context.fillStyle="blue";
context.fillRect(-rectWidth/2,-rectHeight/2,
rectWidth,rectHeight);

// 水平方向翻转context
context.scale(-1,1);

context.font="30pt Calibri";
context.textAlign="center";
context.fillStyle="#ffffff";
context.fillText("Mirror Image",3,10);

}

</script>
</head>
<body>
<canvas id="myCanvas" width="400" height="400"></canvas>
</body>
</html>

posted on 2011-11-10 23:23  zcjnever  阅读(3003)  评论(0编辑  收藏  举报