您好,欢迎访问一九零五行业门户网

如何使用 FabricJS 垂直翻转圆?

在本教程中,我们将学习如何使用 fabricjs 垂直翻转 circle 对象。圆形是 fabricjs 提供的各种形状之一。为了创建一个圆圈,我们必须创建一个 fabric.circle 类的实例并将其添加到画布中。我们可以使用 flipy 属性垂直翻转圆形对象。
语法new fabric.circle({ flipy: boolean }: object)
参数选项(可选) - 此参数是一个对象 为我们的圈子提供额外的定制。使用此参数,可以更改与 flipy 为属性的对象相关的颜色、光标、描边宽度和许多其他属性等属性。
选项键flipy - 此属性接受布尔值。它允许我们垂直翻转对象。
示例 1将 flipy 作为带有 ' 的键传递false' 值
让我们看一个示例,向我们展示 fabricjs 中圆形对象的默认方向。由于我们向 flipy 属性传递了一个 false 值,因此圆形对象将不会垂直翻转。
<!doctype html><html> <head> <!-- adding the fabric js library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> </head> <body> <h2>how to flip a circle vertically using fabricjs?</h2> <p>this is the default orientation of the object. we have set <b>flipy</b> as false, but even if we don't use it, <b>flipy</b> will be by default set to false. </p> <canvas id="canvas"></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas("canvas"); var circle = new fabric.circle({ left: 215, top: 50, fill: "green", radius: 80, stroke: "#228b22", strokewidth: 2, flipy: false }); // create gradient fill circle.set("fill", new fabric.gradient({ type: "linear", coords: { x1: 0, y1: 0, x2: 0, y2: 50 }, colorstops: [{ offset: 0, color: "red" }, { offset: 1, color: "green" }, ], })); // adding them to the canvas canvas.add(circle); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); </script> </body></html>
示例 2将 flipy 属性作为具有“true”值的键传递
在此示例中,我们有一个半径为 80px 的圆形对象具有垂直线性渐变填充。当我们将 flipy 属性应用于圆形对象时,它会垂直翻转,因此我们看到渐变也翻转了。
<!doctype html><html> <head> <!-- adding the fabric js library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> </head> <body> <h2>how to flip a circle vertically using fabricjs?</h2> <p>here observe that the circle has flipped vertically (see the gradient), as we have set <b>flipy</b> to true.</p> <canvas id="canvas"></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas("canvas"); var circle = new fabric.circle({ left: 215, top: 50, fill: "green", radius: 80, stroke: "#228b22", strokewidth: 2, flipy: true }); // create gradient fill circle.set("fill", new fabric.gradient({ type: "linear", coords: { x1: 0, y1: 0, x2: 0, y2: 50 }, colorstops: [{ offset: 0, color: "red" }, { offset: 1, color: "green" }, ], })); // adding them to the canvas canvas.add(circle); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); </script> </body></html>
以上就是如何使用 fabricjs 垂直翻转圆?的详细内容。
其它类似信息

推荐信息