HTML5 Cavnas: translate
Để di chuyển con trỏ tới một điểm (như moveTo) chúng ta có thể dùng phương thúc translate().
Cú pháp:
1 |
context.translate(xOffset, yOffset); |
Ví dụ về HTML5 Canvas Translate

Javascript:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); var rectWidth = 150; var rectHeight = 75; // dịch chuyển điểm của context vào giữa context.translate(canvas.width / 2, canvas.height / 2); context.fillStyle = "blue"; context.fillRect(-rectWidth / 2, -rectHeight / 2, rectWidth, rectHeight); }; |



.jpg)
