
在本教程中,我们将学习如何使用 FabricJS 设置椭圆的水平和垂直半径。椭圆形是 FabricJS 提供的各种形状之一。为了创建一个椭圆,我们必须创建一个 Fabric.Ellipse 类的实例并将其添加到画布中。我们可以通过指定椭圆对象的位置、颜色、不透明度和尺寸来自定义椭圆对象。然而,最重要的属性是rx和ry,它们允许我们指定椭圆的水平和垂直半径。
语法
new fabric.Ellipse({ rx : Number, ry: Number }: Object)
参数
选项(可选)- 此参数是一个对象 为我们的椭圆提供额外的定制。使用此参数,可以更改与 rx 和 ry 属性的对象相关的颜色、光标、描边宽度和许多其他属性。
li>
选项键
rx – 此属性接受 数字值。分配的值确定椭圆对象的水平半径。
ry – 该属性接受 数字值。分配的值决定椭圆对象的垂直半径。
示例 1
rx时的默认外观/em> 和 ry 未使用
以下代码显示了当 rx 和 时椭圆对象将如何出现ry 属性未被使用。在此示例中,我们可以看到我们使用了填充颜色来发现椭圆,它是不可见的,因为我们没有为其分配水平和垂直半径。
Setting the horizontal and vertical radius of an Ellipse using FabricJS
Here we are getting a blank output because we have not assigned any horizontal and vertical radius.
// Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); // Initiate an ellipse instance var ellipse = new fabric.Ellipse({ left: 115, top: 50, fill: "red", }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250);
示例 2
将 rx 和 ry 属性作为键传递
在此示例中,我们分别向 rx 和 ry 属性传递值 100 和 70。因此,我们的椭圆对象的水平半径为 100 像素,垂直半径为 70 像素。
How to set the horizontal and vertical radius of Ellipse using FabricJS?
Here we have supplied the horizontal and vertical radius, rx and ry. Hence we are getting an ellipse of a definite dimension.
// Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); // Initiate an ellipse instance var ellipse = new fabric.Ellipse({ left: 115, top: 50, rx: 100, ry: 70, fill: "red", }); // Adding it to the canvas canvas.add(ellipse); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250);
以上就是如何使用 FabricJS 设置椭圆的水平和垂直半径?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/530368.html
微信扫一扫
支付宝扫一扫