Baseline Widely available
Note: This feature is available in Web Workers.
The CanvasPattern.setTransform()
method uses a DOMMatrix
object as the pattern's transformation matrix and invokes it on the pattern.
matrix
A DOMMatrix
to use as the pattern's transformation matrix.
None (undefined
).
setTransform
method
This is a code snippet which uses the setTransform
method to create a CanvasPattern
with the specified pattern transformation from a DOMMatrix
. The pattern gets applied if you set it as the current fillStyle
and gets drawn onto the canvas when using the fillRect()
method, for example.
<canvas id="canvas"></canvas>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const matrix = new DOMMatrix([1, 0.2, 0.8, 1, 0, 0]);
const img = new Image();
img.src = "canvas_create_pattern.png";
img.onload = () => {
const pattern = ctx.createPattern(img, "repeat");
pattern.setTransform(matrix.rotate(-45).scale(1.5));
ctx.fillStyle = pattern;
ctx.fillRect(0, 0, 400, 400);
};
Specifications Browser compatibility See also
CanvasPattern
DOMMatrix
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4