Javascript 旋转平方函数
我正在寻找一个在画布上使用函数绘制正方形的函数,即drawSquare();,参数“度”会使正方形倾斜。我不想倾斜画布。谢谢,如果您有问题,请发表评论。不要倾斜画布Javascript 旋转平方函数,javascript,canvas,rotation,Javascript,Canvas,Rotation,我正在寻找一个在画布上使用函数绘制正方形的函数,即drawSquare();,参数“度”会使正方形倾斜。我不想倾斜画布。谢谢,如果您有问题,请发表评论。不要倾斜画布 function drawRotatedSquare (x, y, width, height, rotate) { // rotate in radians ctx.setTransform(1, 0, 0, 1, x, y); // overwrite existing transform ctx.rotate(
function drawRotatedSquare (x, y, width, height, rotate) { // rotate in radians
ctx.setTransform(1, 0, 0, 1, x, y); // overwrite existing transform
ctx.rotate(rotate);
ctx.fillRect(-width / 2, -height / 2, width, height);
}
你可以做度到弧度的转换,我一直不明白为什么每个人都想这么做