canvas旋转
方块围绕一点旋转的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{ background:#FFF}
#c1{ background:#C0BFC4}
</style>
<script>
window.onload = function()
{
var oC = document.getElementById("c1");
var oGc = oC.getContext("2d");
var num = 0;
oGc.translate(200,200);
setInterval(function(){
num++;
oGc.save();
oGc.clearRect(0,0,oC.width,oC.height);
oGc.rotate(num*Math.PI/180);
oGc.fillRect(0,0,50,50);
oGc.restore();
},30);
}
</script>
<title>无标题文档</title>
</head>
<body>
<canvas id="c1" width="800" height="600">
</canvas> <!--默认宽为300高为150-->
</body>
</html>
求大神帮我看看有问题吗?
我的代码运行是方块转过90度之后就开始有毛病了!