Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 旋转平方函数_Javascript_Canvas_Rotation - Fatal编程技术网

Javascript 旋转平方函数

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(

我正在寻找一个在画布上使用函数绘制正方形的函数,即drawSquare();,参数“度”会使正方形倾斜。我不想倾斜画布。谢谢,如果您有问题,请发表评论。

不要倾斜画布

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);
}
你可以做度到弧度的转换,我一直不明白为什么每个人都想这么做