Paths
A path in jCanvas consists of one or more connected lines, arcs, curves, or vectors.
Basic usage
You can draw a path using the drawPath()
method. It accepts a variable number of arguments which define the different kinds of subpaths within your path. These arguments are defined using p1
, p2
, p3
, and so on (however many as desired).
Note that for each of these subpath arguments, you must specify the type of the subpath (for instance, type: 'line'
).
Now, if you were to draw the quadratic curve in the above example using the drawQuadratic()
method, you must specify the x1
and y1
properties. However, using drawPath()
the curve continues from the last point on the previous subpath (p1
).
If you were to include the x1
and y1
properties, the curve would no longer be connected to the previous subpath. Consider the following example.
Arcs
You can also use the drawPath()
method to create sequences of interconnected arcs.
The following example will create a flower shape using arcs.
Note that the x
and y
coordinates for each subpath are relative to the x and y coordinates of the entire path.
Also note that the subpath objects inherit default property values from the global jCanvas preferences (which is set through the jCanvas()
method.
Arrows
Just like every other path type in jCanvas, generic paths support arrows at either end of the path. See the section on arrows for descriptions of the arrow properties.
For generic paths, arrow properties must be specified in a subpath object, not the entire path object.
SVG Paths
You can also draw an SVG path with drawPath()
via the d
property (new as of jCanvas v22.1.0). This allows you to integrate SVG with jCanvas, and even take advantage of jCanvas features like masking.
Using an SVG path as a mask
You can also use SVG paths as masks. See the relevant section of the Masking documentation for a comprehensive example.