1.0.1 • Published 2 years ago

canvas-pattern v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

canvas-pattern

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Draw and cache a repeated pattern on a canvas context.

paypal coinbase twitter

npm.io

Installation

npm install canvas-pattern

Usage

import canvasPattern from "canvas-pattern";
import createCanvasContext from "canvas-context";

const { canvas, context } = createCanvasContext("2d");
document.body.appendChild(canvas);

const pattern = new Image();
pattern.src = "pattern.png";

canvasPattern(context, pattern);

API

Modules

Typedefs

canvasPattern

canvasPattern(context, source, options) ⇒ CanvasPattern

Draw and cache a repeated pattern on a canvas context.

Kind: Exported function

ParamTypeDefaultDescription
contextCanvasRenderingContext2DThe context to draw the pattern to
sourceCanvasImageSourceThe pattern to be drawn
optionsCanvasPatternOptions{}The options to position the pattern and controls its repetition

CanvasPatternRepetition : "repeat" | "repeat-x" | "repeat-y" | "no-repeat"

Kind: global typedef

CanvasPatternOptions : Object

Options to draw. All optional.

Kind: global typedef Properties

NameTypeDescription
patternCanvasPatternThe CanvasPattern to draw. Created and returned by the function for reuse.
repetitionCanvasPatternRepetitionA DOMString indicating how to repeat the pattern's image.
xnumber
ynumber
widthnumber
heightnumber

License

MIT. See license file.