简体   繁体   English

使用Fabric.js绘制贝塞尔曲线

[英]Draw bezier curve with Fabric.js

I want to draw Bezier, Used Fabric.js Path method, The question is Path will connect the beginning to the end, But I don't want to do that. 我想绘制Bezier,使用Fabric.js的Path方法,问题是Path将从头到尾连接,但是我不想这样做。

在此处输入图片说明

For your question that Path will connect the beginning to the end. 对于您的问题,Path将把起点连接到终点。

Yes it will connect. 是的,它将连接。

But I don't want to do that. 但是我不想那样做。

Though there is nothing as of now using which you can avoid this behavior. 尽管到目前为止没有什么可以避免这种行为的。 But yes there is a workaround using which your path wont look as if the beginning and end are joined. 但是,是的,有一种解决方法可以使您的路径看起来好像开始和结束都连接在一起。 See the demo below. 请参见下面的演示。 There are two paths one which shows the beginning and end joined(the triangle). 有两条路径显示开始和结束的连接(三角形)。 Second where the end and beginning do not appear to be joined(the arrow). 第二个结尾和开头似乎没有连接的地方(箭头)。 The difference between these two is just the fill property set to false in the second path ie The arrow. 两者之间的区别只是在第二条路径(即箭头)中将fill属性设置为false。 But if you omit the fill property or set it to some color it will look as similar to the first path(triangle) with joint end and beginning. 但是,如果省略fill属性或将其设置为某种颜色,则它看起来将类似于第一个路径(三角形),并具有结束点和开始点。 Hence you can create a bezier curve as required by you. 因此,您可以根据需要创建贝塞尔曲线。

 // initialize fabric canvas and assign to global windows object for debug var canvas = window._canvas = new fabric.Canvas('c'); //var canvas = new fabric.StaticCanvas('c'); var path = new fabric.Path('C 50 50 100 100 150 50 C 200 100 250 50 300 100', { left: 100, top: 50, stroke: 'red', strokeWidth: 1, fill: false, scaleY:3 }); canvas.add(path); var p = new fabric.Path('C 50 50 100 100 150 50 C 200 100 250 50 300 100',{ left: 200, top: 60, strokeWidth:2, scaleY:3 }); canvas.add(p); 
 <script src="https://rawgithub.com/kangax/fabric.js/master/dist/fabric.js"></script> <canvas id="c" width="600" height="600"></canvas> 

Hope it helps :) 希望能帮助到你 :)

UPDATE 更新

Fiddle 小提琴

Above is the fiddle link in this you will see two paths being created and the third one is not getting created because the path string passed is not valid. 上面是其中的小提琴链接,您将看到正在创建两个路径,而第三个未创建,因为传递的路径字符串无效。

Also can you please create a demo in fiddle with the actual problem you are facing. 也可以请您制作一个演示程序来解决您面临的实际问题。 Would be easy for me to help and understand the issue. 对我来说,帮助和理解问题将很容易。

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

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