专业网站建设报价,聊城专业网站建设制作,小程序制作步骤,宜丰做网站的情况说明#xff1a;
fabic默认绘图原点为left#xff1a;0#xff0c;top#xff1a;0
后端给我的内容是按照x#xff0c;y返回的#xff0c;需要将坐标系移到fabic画布的中心位置#xff0c;找了下网上合适的砖#xff0c;想一句命令直接设置#xff0c;结果没有。…情况说明
fabic默认绘图原点为left0top0
后端给我的内容是按照xy返回的需要将坐标系移到fabic画布的中心位置找了下网上合适的砖想一句命令直接设置结果没有。得得自己来了。
不得吐槽一句他母亲canvas这点就很有好呢用 transform 一行代码即可实现--ctx.translate(canvasWidth / 2, canvasHeight / 2)。附赠canvas将绘制的原点移动到画布中心的示例代码感兴趣的可以看下
const canvas document.getElementById(yourCanvasID);
const ctx canvas.getContext(2d); // 获取画布的宽度和高度
const canvasWidth canvas.width;
const canvasHeight canvas.height; // 将绘制原点移动到画布中心
ctx.translate(canvasWidth / 2, canvasHeight / 2); // 在新的原点处绘制一个矩形
ctx.fillStyle red;
ctx.fillRect(-50, -50, 100, 100);
坐标系转移
言归正传咱绘制一下坐标系。 据此可得 后端给出的x,y坐标我可以根据canvas.width/2 x ,canvas.height/2 - y来实现。
即为leftcanvas.width/2 x ,topcanvas.height/2-y
同理我给后端可接受的x,y,应该为(left-canvas.width/2 , canvas.height/2 - top ) 反正利用我小学n年级的数学知识计算是这样我去跟后端联调验证完美性去了~~