# Class: LinearGradientStyle

## LinearGradientStyle()

#### new LinearGradientStyle()

Linear gradient style, represents a gradient of colors from a point to another interpolating in between. Behind the of the two points used the color is solid. The get method returns a CanvasGradient https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient when generated.

Source:
  - objects/style/LinearGradientStyle.js, line 15

### Extends

- GradientStyle

### Members

#### cache :string|CanvasGradient|CanvasPattern

Cached style object pre-generated from previous calls. To avoid regenerating the same style object every cycle. Inherited classes should write their own get method that returns the style object and stores it in this property.

##### Type:

- string | CanvasGradient | CanvasPattern

Inherited From:
  - Style#cache
Source:
  - objects/style/Style.js, line 17

#### colors :Array.<GradientColorStop>

List of colors that compose this gradient ordered. You need to add at least one color stop to have a visible gradient.

##### Type:

- Array.<GradientColorStop>

Inherited From:
  - GradientStyle#colors
Source:
  - objects/style/GradientStyle.js, line 23

#### end :Vector2

The coordinates of the ending point of the gradient.

##### Type:

- Vector2

Source:
  - objects/style/LinearGradientStyle.js, line 31

#### needsUpdate :boolean

Indicates if the style object needs to be updated, should be used after applying changed to the style in order to generate a new object. Inherited classes should implement this functionality.

##### Type:

- boolean

Inherited From:
  - Style#needsUpdate
Source:
  - objects/style/Style.js, line 26

#### start :Vector2

The coordinates of the starting point of the gradient.

##### Type:

- Vector2

Source:
  - objects/style/LinearGradientStyle.js, line 24

### Methods

#### addColorStop(offset, color)

Add a new color stop defined by an offset and a color to the gradient. If the offset is not between 0 and 1 inclusive, or if color can't be parsed as a CSS color, an error is raised.

##### Parameters:

Name | Type | Description
--- | --- | ---
`offset` | number | Offset of the color stop between 0 and 1 inclusive.
`color` | string | CSS color value.

Inherited From:
  - GradientStyle#addColorStop
Source:
  - objects/style/GradientStyle.js, line 36

#### get(context) → {string|CanvasGradient|CanvasPattern}

Get generated style object from style data and the drawing context.

##### Parameters:

Name | Type | Description
--- | --- | ---
`context` | CanvasRenderingContext2D | Context being used to draw the object.

Overrides:
  - GradientStyle#get
Source:
  - objects/style/Style.js, line 35

##### Returns:

Return the canvas style object generated.

Type
  string | CanvasGradient | CanvasPattern

#### parse(data)

Parse the style attributes from JSON object data created with the serialize() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | Serialized style data.

Overrides:
  - GradientStyle#parse
Source:
  - objects/style/Style.js, line 49

#### serialize() → {Object}

Serialize the style to JSON object, called by the objects using these styles.

Overrides:
  - GradientStyle#serialize
Source:
  - objects/style/Style.js, line 42

##### Returns:

Serialized style data.

Type
  Object