Fabric.js Polygon hasBorders属性

Fabric.js Polygon hasBorders属性

画布多边形指的是多边形可移动并可以根据需要进行拉伸。此外,多边形在初始描边颜色、形状、填充颜色或描边宽度方面可以进行自定义。

为了设置画布多边形的边框,使用了名为FabricJS的JavaScript库。在导入库之后,我们将在标签中创建一个包含多边形的画布块。接下来,我们将使用FabricJS提供的Canvas和polygon实例来设置画布多边形的边框,并在画布上渲染多边形,如下例所示。

语法:

fabric.Polygon([
   { x: pixel, y: pixel },
   { x: pixel, y: pixel },
   { x: pixel, y: pixel},
   { x: pixel, y: pixel},
   { x: pixel, y: pixel }],
   { hasBorders: boolean }
);

参数: 此函数接受一个参数,如上所述,以下是描述:

  • hasBorders: 它指定是否将边框显示出来。

注意: 创建多边形需要指定像素尺寸。

以下示例演示了在JavaScript中使用Fabric.JS Polygon的 hasBorders 属性:

示例1: 在此示例中,hasBorders属性被设置为false。

<!DOCTYPE html>  
<html>  
  
<head>  
     <!-- Loading the FabricJS library -->
    <script src=  
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">  
    </script>  
</head>  
  
<body>  
    <div style="text-align: center;width: 600px;">  
        <h1 style="color: green;">  
            GeeksforGeeks  
        </h1>  
        <b>  
            Fabric.js | Polygon hasBorders Property  
        </b>  
    </div> 
   
    <canvas id="canvas"
            width="600"
            height="200"
            style="border:1px solid #000000;">  
    </canvas>  
  
    <script>  
  
        // Initiate a Canvas instance  
        var canvas = new fabric.Canvas("canvas");  
  
        // Initiate a polygon instance  
        var polygon = new fabric.Polygon([  
        { x: 295, y: 10 },  
        { x: 235, y: 198 },  
        { x: 385, y: 78},  
        { x: 205, y: 78},  
        { x: 355, y: 198 }], {  
            hasBorders: false 
        });  
  
        // Render the polygon in canvas  
        canvas.add(polygon);  
    </script>  
</body>  
  
</html>

输出:

Fabric.js Polygon hasBorders属性

示例 2: 在这个示例中,hasBorders属性被设置为true。

<!DOCTYPE html>  
<html>  
  
<head>  
    <!-- Loading the FabricJS library -->
    <script src=  
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">  
    </script>  
</head>  
  
<body>  
    <div style="text-align: center;width: 600px;">  
        <h1 style="color: green;">  
            GeeksforGeeks  
        </h1>  
        <b>  
            Fabric.js | Polygon hasBorders Property  
        </b>  
    </div>  
  
    <canvas id="canvas"
            width="600"
            height="200"
            style="border:1px solid #000000;">  
    </canvas>  
  
    <script>  
  
        // Initiate a Canvas instance  
        var canvas = new fabric.Canvas("canvas");  
  
        // Initiate a polygon instance  
        var polygon = new fabric.Polygon([  
        { x: 295, y: 10 },  
        { x: 235, y: 198 },  
        { x: 385, y: 78},  
        { x: 205, y: 78},  
        { x: 355, y: 198 }], {  
            hasBorders: true 
        });  
  
        // Render the polygon in canvas  
        canvas.add(polygon);  
    </script>  
</body> 
   
</html>

输出:

Fabric.js Polygon hasBorders属性

参考: http://fabricjs.com/docs/fabric.Polygon.html#hasBorders

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程