Home > Web Front-end > JS Tutorial > body text

How are polygons different from polylines in FabricJS?

王林
Release: 2023-08-27 08:21:17
forward
1057 people have browsed it

FabricJS 中的多边形与折线有何不同?

We can create Polyline objects by creating instances of fabric.Polyline, and fabric.Polygon can be used to create Polygon instances. A polyline object can be represented by a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties such as angle, opacity, etc.

Polygons always connect the first point to the last point to form a closed area, while polylines do not. This can be demonstrated by the example given below.

grammar

new fabric.Polyline(points: Array, options: Object)
Copy after login

parameter

  • points - This parameter accepts an Array, which represents the array of points that make up the polyline object.

  • Options (optional) - This parameter is an object that provides additional customization to our object. Use this parameter to change the origin, stroke width, and many other properties associated with the Polyline object.

Example 1

Create a Fabric.Polyline() instance and add it to the canvas

Let's look at a code example to see how to add a polyline object to the canvas. The only required parameter is the points array, while the second parameter is an optional options object. Additionally, we will use the same points array in the Polygon to demonstrate the difference.




   
   

Creating an instance of fabric.Polyline() and adding it to our canvas

You can see that the polyline object doesn’t connects start to end

Copy after login

Example 2

Create an instance of fabric.Polygon() and add it to our canvas

Let's look at a code example to see how to add a polygon object to the canvas. The only required parameter is the points array, while the second parameter is an optional options object, we will provide the same options object as in the polyline example.




   
   

Creating an instance of fabric.Polygon() and adding it to our canva

You can see that the polygon object connects start to end to make a closed area

Copy after login

The above is the detailed content of How are polygons different from polylines in FabricJS?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!