Skip to content

pencil.js / pattern / Pattern

Class: Pattern ​

Defined in: pattern.ts:53

Repeated image usable as fill or stroke

Constructors ​

Constructor ​

ts
new Pattern(source, options?): Pattern;

Defined in: pattern.ts:68

Pattern constructor

Parameters ​

ParameterTypeDescription
sourcePatternSourceSource of the pattern
options?Partial<PatternOptions>Some options

Returns ​

Pattern

Properties ​

PropertyTypeDescriptionDefined in
optionsPatternOptionsSet of optionspattern.ts:59

Accessors ​

height ​

Get Signature ​

ts
get height(): number;

Defined in: pattern.ts:130

Height of the source

Returns ​

number


source ​

Get Signature ​

ts
get source(): HTMLCanvasElement | HTMLImageElement | null;

Defined in: pattern.ts:79

Drawable source of the pattern

Returns ​

HTMLCanvasElement | HTMLImageElement | null

Set Signature ​

ts
set source(newSource): void;

Defined in: pattern.ts:95

Change the source of the pattern

Parameters ​
ParameterTypeDescription
newSourcePatternSourceNew source for the pattern
Returns ​

void


width ​

Get Signature ​

ts
get width(): number;

Defined in: pattern.ts:123

Width of the source

Returns ​

number


className ​

Get Signature ​

ts
get static className(): "Pattern";

Defined in: pattern.ts:54

Returns ​

"Pattern"


defaultOptions ​

Get Signature ​

ts
get static defaultOptions(): PatternOptions;

Defined in: pattern.ts:184

Default options for this class

Returns ​

PatternOptions


repetition ​

Get Signature ​

ts
get static repetition(): object;

Defined in: pattern.ts:195

Repetition rules

Returns ​
none ​
ts
readonly none: "no-repeat" = "no-repeat";

Don't repeat

repeat ​
ts
readonly repeat: "repeat" = "repeat";

Repeat in both directions

x ​
ts
readonly x: "repeat-x" = "repeat-x";

Repeat only horizontally

y ​
ts
readonly y: "repeat-y" = "repeat-y";

Repeat only vertically

Methods ​

toJSON() ​

ts
toJSON(): PatternJSON;

Defined in: pattern.ts:157

Return a json ready object (only works with image sources)

Returns ​

PatternJSON


toString() ​

ts
toString(ctx): string | CanvasPattern;

Defined in: pattern.ts:138

Return a canvas pattern (or a transparent color when not ready)

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

string | CanvasPattern


from() ​

ts
static from(definition): Pattern;

Defined in: pattern.ts:177

Return an instance from a generic object

Parameters ​

ParameterTypeDescription
definitionOmit<PatternJSON, "constructor">Pattern definition

Returns ​

Pattern

Released under the MIT License.