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

propertyexplanationtypedefault value
idthe unique id of the gradientString
stopsthe color stops along the gradientArray[]
typethe type of the gradientString“LinearGradient”
x1the x coordinate of the start of the gradient, between 0 and 100Number0
x2the x coordinate of the end of the gradient, between 0 and 100Number100
y1the y coordinate of the start of the gradient, between 0 and 100Number0
y2the y coordinate of the end of the gradient, between 0 and 100Number0

Methods

methodexplanationreturn 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 gradient

type (String): the type of the gradient
id (String): the unique id of the gradient
x1 (Number): x coordinate of the start
y1 (Number): y coordinate of the start
x2 (Number): x coordinate of the end
y2 (Number): y coordinate of the end
stops (Array): array of stop objects
Object