Javascript examples for Canvas Reference:translate
The translate() method move the (0,0) position on the canvas.
context.translate(x, y);
Parameter | Description |
---|---|
x | The value to add to horizontal (x) coordinates |
y | The value to add to vertical (y) coordinates |
Draw a rectangle in position (10,10), set new (0,0) position to (70,70).
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.fillRect(10, 10, 100, 50);//from w ww. j ava 2s.c om ctx.translate(70, 70); ctx.fillRect(10, 10, 100, 50); </script> </body> </html>