首页 > web前端 > js教程 > 正文

如何使用 FabricJS 垂直翻转圆?

WBOY
发布: 2023-08-24 12:29:02
转载
1059人浏览过

如何使用 fabricjs 垂直翻转圆?

在本教程中,我们将学习如何使用 FabricJS 垂直翻转 Circle 对象。圆形是 FabricJS 提供的各种形状之一。为了创建一个圆圈,我们必须创建一个 Fabric.Circle 类的实例并将其添加到画布中。我们可以使用 flipY 属性垂直翻转圆形对象。

语法

new fabric.Circle({ flipY: Boolean }: Object)
登录后复制

参数

  • 选项(可选) - 此参数是一个对象 为我们的圈子提供额外的定制。使用此参数,可以更改与 flipY 为属性的对象相关的颜色、光标、描边宽度和许多其他属性等属性。

  • ul>

    选项键

    • flipY - 此属性接受布尔值。它允许我们垂直翻转对象。

    示例 1

    flipY 作为带有 ' 的键传递false' 值

    图像转图像AI
    图像转图像AI

    利用AI轻松变形、风格化和重绘任何图像

    图像转图像AI 65
    查看详情 图像转图像AI

    让我们看一个示例,向我们展示 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 垂直翻转圆?的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号