SOURCE

console 命令行工具 X clear

                    
>
console
var canvas = document.getElementById('canvas');
canvas.width = 500;
canvas.height = 500;
canvas.style.backgroundColor = '#ddd';
document.body.appendChild(canvas);

var ctx = canvas.getContext('2d');
var x = 100,
    y = 100,
    width = 150,
    height = 150,
    angle = 90,
    rectCenterPoint = {x: x+width/2, y: y+height/2}; // 矩形中心点

// 旋转前(红色矩形)
ctx.fillStyle = '#f00';
ctx.fillRect(x, y, width, height);

// 旋转后(绿色矩形)
ctx.translate(rectCenterPoint.x, rectCenterPoint.y);
ctx.rotate(angle);
ctx.translate(-rectCenterPoint.x, -rectCenterPoint.y);
ctx.fillStyle = '#690';
ctx.fillRect(x, y, width, height);
<canvas id="canvas" width="300" height="500">
</canvas>