canvas 方块旋转案例

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#c{
background:#ccc;
}
</style>
</head>
<body>
<canvas id="c" width="400px" height="400px"></canvas>
</body>
</html>
<script>
var d=document.getElementById("c");
var c=d.getContext("2d");
c.translate(100,100);
var num=0;
var t=setInterval(function(){
num++;
c.fillStyle="red";
c.clearRect(-100,-100,400,400);
c.rotate(num*(Math.PI/180));
c.fillRect(0,0,50,50);
num=0;
},1000/60);
</script>
原文地址:https://www.cnblogs.com/shangjun6/p/10881976.html