您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

如何使用 FabricJS 垂直翻转三角形?

2024/4/26 9:52:52发布4次查看
在本教程中,我们将学习如何使用 fabricjs 垂直翻转 triangle 对象。三角形是 fabricjs 提供的各种形状之一。为了创建一个三角形,我们必须创建一个 fabric.triangle 类的实例并将其添加到画布中。我们可以使用 flipy 属性垂直翻转三角形对象。
语法new fabric.triangle({ 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>passing flipy as key with a 'false' value</h2> <p>you can see that the triangle object has not been flipped vertically.</p> <canvas id="canvas"></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas("canvas"); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiate a triangle object var triangle = new fabric.triangle({ left: 75, top: 45, width: 180, height: 109, stroke: "#e3f988", strokewidth: 5, flipy: false, }); // create gradient fill triangle.set( "fill", new fabric.gradient({ type: "linear", coords: { x1: 0, y1: 0, x2: 0, y2: 100 }, colorstops: [ { offset: 0, color: "#545a2c" }, { offset: 1, color: "#6495ed" }, ], }) ); // add it to the canvas canvas.add(triangle); </script></body></html>
示例 2将 flipy 属性作为具有“true”值的键传递
在此示例中,我们有一个宽度为 180px 的三角形对象高度 109px,垂直线性渐变填充。当我们将 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>passing the flipy property as key with a 'true' value</h2> <p>you can see that the triangle object has been flipped vertically</p> <canvas id="canvas"></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas("canvas"); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiate a triangle object var triangle = new fabric.triangle({ left: 75, top: 45, width: 180, height: 109, stroke: "#e3f988", strokewidth: 5, flipy: true, }); // create gradient fill triangle.set( "fill", new fabric.gradient({ type: "linear", coords: { x1: 0, y1: 0, x2: 0, y2: 100 }, colorstops: [ { offset: 0, color:"#545a2c" }, { offset: 1, color: "#6495ed" }, ], }) ); // add it to the canvas canvas.add(triangle); </script></body></html>
以上就是如何使用 fabricjs 垂直翻转三角形?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录