LinearGradient
The LinearGradient class represents a linear color gradient to be used for the stroke or fill color property. To create a LinearGradient object, use the linearGradient function:
let lg = msc.linearGradient({x1: 0, y1: 0, x2: 100, y2: 0});
Properties
| property | explanation | type | default value |
|---|---|---|---|
| id | the unique id of the gradient | String | |
| stops | the color stops along the gradient | Array | [] |
| type | the type of the gradient | String | “LinearGradient” |
| x1 | the x coordinate of the start of the gradient, between 0 and 100 | Number | 0 |
| x2 | the x coordinate of the end of the gradient, between 0 and 100 | Number | 100 |
| y1 | the y coordinate of the start of the gradient, between 0 and 100 | Number | 0 |
| y2 | the y coordinate of the end of the gradient, between 0 and 100 | Number | 0 |
Methods
| method | explanation | return type |
|---|---|---|
| addStop(offset, color, opacity) | adds a color stop to the gradient offset (Number): the position of the stop as a number between 0 and 100 color (String): the color of the stop opacity (Number): the opacity of the stop as a number between 0 and 1 | void |
| toJSON() | returns a JSON representation of the gradienttype (String): the type of the gradientid (String): the unique id of the gradientx1 (Number): x coordinate of the starty1 (Number): y coordinate of the startx2 (Number): x coordinate of the endy2 (Number): y coordinate of the endstops (Array): array of stop objects | Object |