# Class: PatternStyle

## PatternStyle(source)

#### new PatternStyle(source)

Pattern style represents an opaque object describing a pattern, based on an image, a canvas, or a video. The get method returns a CanvasPattern object https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern created by the context.createPattern() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`source` | CanvasImageSource | Source element of the pattern.

Source:
  - objects/style/PatternStyle.js, line 14

### Extends

- Style

### 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

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

#### matrix :Matrix

Transformation matrix applied to the pattern. The transformation allows to move, rotate and scale the pattern freely

##### Type:

- Matrix

Source:
  - objects/style/PatternStyle.js, line 45

#### 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

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

#### repetition :string

Repetition indicates how the pattern image should be repeated. Possible values are "repeat", "repeat-x", "repeat-y" or "no-repeat". More information about this attribute here https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createPattern.

##### Type:

- string

Source:
  - objects/style/PatternStyle.js, line 36

#### source :CanvasImageSource

Source of the pattern style. Can be a image, video or another canvas element By default a empty image element is created.

##### Type:

- CanvasImageSource

Source:
  - objects/style/PatternStyle.js, line 25

### Methods

#### 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:
  - Style#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:
  - Style#parse
Source:
  - objects/style/Style.js, line 49

#### serialize() → {Object}

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

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

##### Returns:

Serialized style data.

Type
  Object

#### setTransform(transform)

Applies an 2x3 transformation matrix representing a linear transform to the pattern.

##### Parameters:

Name | Type | Description
--- | --- | ---
`transform` | Array.<number> | 2x3 Transformation matrix.

Source:
  - objects/style/PatternStyle.js, line 56