繁体   English   中英

如何使用 Fabric.js 绘制可调节的直角

[英]how to draw adjustable Right Angle Using Fabric.js

我正在尝试使用矩形绘制直角。

我的问题不是使用两个矩形来绘制可调节的直角,我想使用此图像中的精确直角

直角

我正在使用下面的代码使用 fabric.js 添加矩形

  addRect = () => {
     this.canvas.add(new fabric.Rect({
        left: this.canvas.width / 2,
        top: this.canvas.height / 2,
        fill: '#ffa726',
        width: 100,
        centeredRotation: true,
        height: 100,
        originX: 'center',
        originY: 'center',
       strokeWidth: 0
                             }));
            }

请帮我解决这个问题。

您不能使用Rect来获得直角,但可以使用Polyline 这是一个例子:

const points = [
  {x: 5, y: 15},
  {x: 95, y: 15},
  {x: 95, y: 85},
]
const options = {
  strokeWidth: 20,
  stroke: 'orange',
  fill: null,
  strokeLineJoin: 'miter',
  strokeLineCap: 'butt'
}
const rightAngle = new fabric.Polyline(points, options)
canvas.add(rightAngle)

如果您想以交互方式调整点,您可以调整 Fabric.js 网站上自定义控件示例中的代码(多边形和折线类似)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM