Two.Path
Extends: Two.Shape
This is the primary primitive class for creating all drawable shapes in Two.js. Unless specified methods return their instance of Two.Path for the purpose of chaining.
Constructor
| Argument | Description |
|---|---|
| vertices | A list of Two.Anchors that represent the order and coordinates to construct the rendered shape. |
| closed | Describes whether the shape is closed or open. |
| curved | Describes whether the shape automatically calculates bezier handles for each vertex. |
| manual | Describes whether the developer controls how vertices are plotted or if Two.js automatically plots coordinates based on closed and curved booleans. |
fromObject
Two.Path.fromObject
Returns: Two.Path
| Argument | Description |
|---|---|
| obj | Object notation of a Two.Path to create a new instance |
closed
Two.Path.closed
Determines whether a final line is drawn between the final point in the vertices array and the first point.
curved
Two.Path.curved
When the path is automatic = true this boolean determines whether the lines between the points are curved or not.
beginning
Two.Path.beginning
Number between zero and one to state the beginning of where the path is rendered.
Two.Path.beginning is a percentage value that represents at what percentage into the path should the renderer start drawing.
ending
Two.Path.ending
Number between zero and one to state the ending of where the path is rendered.
Two.Path.ending is a percentage value that represents at what percentage into the path the renderer should stop drawing.
fill
Two.Path.fill
The value of what the path should be filled in with.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value for more information on CSS's colors as String.
stroke
Two.Path.stroke
The value of what the path should be outlined in with.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value for more information on CSS's colors as String.
vertices
Two.Path.vertices
An ordered list of anchor points for rendering the path.
A list of Two.Anchor objects that consist of what form the path takes.
automatic
Two.Path.automatic
Determines whether or not Two.js should calculate curves, lines, and commands automatically for you or to let the developer manipulate them for themselves.
dashes
Two.Path.dashes
Array of numbers. Odd indices represent dash length. Even indices represent dash space.
A list of numbers that represent the repeated dash length and dash space applied to the stroke of the path.
See: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray for more information on the SVG stroke-dasharray attribute.
copy
Two.Path.copy
| Argument | Description |
|---|---|
| path | The reference Two.Path |
Copy the properties of one Two.Path onto another.
clone
Two.Path.clone
Returns: Two.Path
| Argument | Description |
|---|---|
| parent | The parent group or scene to add the clone to. |
Create a new instance of Two.Path with the same properties of the current path.
toObject
Two.Path.toObject
Returns: Object
Return a JSON compatible plain object that represents the path.
dispose
Two.Path.dispose
Returns: Two.Path
Release the path's renderer resources and detach all events. This method cleans up vertices collection events, individual vertex events, control point events, and disposes fill/stroke effects (calling dispose() on Gradients and Textures for thorough cleanup) while preserving the renderer type for potential re-attachment to a new renderer.
getBoundingClientRect
Two.Path.getBoundingClientRect
Returns: Object
- Returns object with top, left, right, bottom, width, height attributes.
| Argument | Description |
|---|---|
| shallow | Describes whether to calculate off local matrix or world matrix. |
Return an object with top, left, right, bottom, width, and height parameters of the path.
contains
Two.Path.contains
Returns: Boolean
| Argument | Description |
|---|---|
| x | x coordinate to hit test against |
| y | y coordinate to hit test against |
| options | Optional options object |
| options.ignoreVisibility | If true, hit test against path.visible = false shapes |
| options.tolerance | Padding to hit test against in pixels |
Check to see if coordinates are within a Two.Path's bounding rectangle
getPointAt
Two.Path.getPointAt
Returns: Object
| Argument | Description |
|---|---|
| t | Percentage value describing where on the Two.Path to estimate and assign coordinate values. |
| obj | Object to apply calculated x, y to. If none available returns new Object. |
Given a float t from 0 to 1, return a point or assign a passed obj's coordinates to that percentage on this Two.Path's curve.
plot
Two.Path.plot
Based on closed / curved and sorting of vertices plot where all points should be and where the respective handles should be too.
smooth
Two.Path.smooth
| Argument | Description |
|---|---|
| options | Configuration for smoothing. |
| options.type | Type of smoothing algorithm. |
| options.from | Index of vertices to start smoothing |
| options.to | Index of vertices to terminate smoothing |
Adjust vertex handles to generate smooth curves without toggling automatic.
subdivide
Two.Path.subdivide
| Argument | Description |
|---|---|
| limit | How many times to recurse subdivisions. |
Insert a Two.Anchor at the midpoint between every item in Two.Path.vertices.
clip
Two.Path.clip
Tells Two.js renderer if this object represents a mask for another object (or not).
strokeAttenuation
Two.Path.strokeAttenuation
When set to true, stroke width scales with transformations (default behavior). When false, stroke width remains constant in screen space.
When strokeAttenuation is false, the stroke width is automatically adjusted to compensate for the object's world transform scale, maintaining constant visual thickness regardless of zoom level. When true (default), stroke width scales normally with transformations.