HTML canvas translate() Method
Example
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.fillRect(25, 25, 50, 50);
ctx.translate(25, 25);
ctx.fillRect(25, 25, 50, 50);
Meaning
The translate() method remaps the (0,0) position on the canvas.
Standard Syntax
JavaScript syntax:
context.translate(x,y);
Advertisement
Parameter Values
| Parameter | Description |
|---|---|
| x | Specifies the value to add to x (horizontal) coordinates. |
| y | Specifies the value to add to y (vertical) coordinates |