Skip to content

pencil.js / linear-gradient / LinearGradient

Class: LinearGradient ​

Defined in: linear-gradient.ts:19

Linear gradient usable as fill or stroke

Constructors ​

Constructor ​

ts
new LinearGradient(
   fromPosition, 
   toPosition, 
   colorStops?
): LinearGradient;

Defined in: linear-gradient.ts:44

Linear gradient constructor

Parameters ​

ParameterTypeDescription
fromPosition| PositionDefinition | undefinedStarting position of the gradient (relative to the component)
toPosition| PositionDefinition | undefinedEnding position of the gradient (relative to the component)
colorStops?ColorStopsSet of colors to go through (key is position [from 0 to 1], value is the color)

Returns ​

LinearGradient

Example ​

ts
new LinearGradient([0, 0], [100, 0], {
    0: "red",
    1: "blue",
});

Properties ​

PropertyTypeDescriptionDefined in
colorStopsColorStopsSet of colors to go through (key is position [from 0 to 1], value is the color)linear-gradient.ts:31
fromPositionStarting position of the gradientlinear-gradient.ts:25
toPositionEnding position of the gradientlinear-gradient.ts:28

Accessors ​

className ​

Get Signature ​

ts
get static className(): "LinearGradient";

Defined in: linear-gradient.ts:20

Returns ​

"LinearGradient"

Methods ​

toJSON() ​

ts
toJSON(): LinearGradientJSON;

Defined in: linear-gradient.ts:62

Return a json ready object

Returns ​

LinearGradientJSON


toString() ​

ts
toString(ctx): CanvasGradient;

Defined in: linear-gradient.ts:54

Return a canvas gradient

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

CanvasGradient


from() ​

ts
static from(definition): LinearGradient;

Defined in: linear-gradient.ts:75

Return an instance from a generic object

Parameters ​

ParameterTypeDescription
definitionOmit<LinearGradientJSON, "constructor">LinearGradient definition

Returns ​

LinearGradient

Released under the MIT License.