Stroke

Stroke (border) of any Shape (objects that extend Shape class).

Constructor

new Stroke(widthopt, backgroundopt, alignmentopt, capopt, joinopt, miterLimitopt, dashSizeopt, dashGapSizeopt, dashPhaseopt)

Create an instance of a Stroke object.

Parameters:
NameTypeAttributesDefaultDescription
widthnumber<optional>
1

Specifies the thickness of the line. Default is 1 pixel thick.

backgroundstring<optional>
#000000

Stroke color. e.g. #008800. Setting gradients and a background image will be also possible in future.

alignmentStroke.Alignment<optional>

Where stroke line is drawn: outside of shape, on the edge, or inside. Default is Center. Valid values: Stroke.Alignment.Outside, Stroke.Alignment.Center, Stroke.Alignment.Inside.

capStroke.Cap<optional>

Defines the end cap style of the line. Default is Square. Valid values: Stroke.Cap.Square, Stroke.Cap.Butt, Stroke.Cap.Round.

joinStroke.Join<optional>

Specifies the line join style. Default is Miter. Valid values: Stroke.Join.Miter, Stroke.Join.Bevel, Stroke.Join.Round.

miterLimitnumber<optional>
10

Applicable when join is set to JOIN_MITER. It controls the maximum miter length. If the miter length exceeds this limit, the join is beveled instead.

dashSizenumber<optional>
null

Size of a dash in a dash pattern,

dashGapSizenumber<optional>
null

Size of gaps between dashes in dash pattern

dashPhasenumber<optional>
0

Specifies the starting point of the dash pattern. It determines where in the dash pattern the line starts. A positive value shifts the pattern to the right, and a negative value shifts it to the left.

Classes

Stroke

Members

(readonly) Alignment :number

Static enum for stroke alignment. Defines how the stroke is positioned relative to the shape’s outline.

Type:
  • number
Properties
NameTypeDescription
Insidenumber

Stroke fully inside the shape path.

Centernumber

Stroke centered on the shape path.

Outsidenumber

Stroke fully outside the shape path.

Example
Stroke.Alignment.Outside

(readonly) Cap :number

Static enum for stroke cap styles. Defines how the ends of open subpaths are drawn.

Type:
  • number
Properties
NameTypeDescription
Buttnumber

Flat end, no extension beyond the end point.

Roundnumber

Rounded end with a half-circle extension.

Squarenumber

Flat end extended by half the line width.

Example
Stroke.Cap.Round

(readonly) Join :number

Static enum for stroke join styles. Defines how two connected line segments are joined.

Type:
  • number
Properties
NameTypeDescription
Miternumber

Sharp corner with extended outer edges.

Roundnumber

Rounded corner with a circular arc.

Bevelnumber

Flattened corner with a straight cut.

Example
Stroke.Join.Bevel

Methods

toObject() → {object}

Convert Stroke to JSON Object to be able to store it or modify it and convert back to the Stroke object using Stroke.fromObject(stroke).

Returns:

Returns an object holding all properties of this Stroke object.

Type: 
object

(static) fromObject(stroke) → {Stroke}

Restore Stroke from JSON object that represents all properties of the Stroke object.

Parameters:
NameTypeDescription
strokeobject

JSON object that holds properties of a Stroke object. It can be generated by stroke.toObject().

Returns:

Returns an instance of a new Stroke object.

Type: 
Stroke