HTML5 Canvas: lật ngược hình (scale)
Để lật ngược hình (mirror transform) trong HTML5 Canvas chúng ta sử dụng scale với giá trị offsetX hoặc offsetY là -1.
1 2 3 4 5 |
// Lật ngược theo chiều ngang context.scale(-1,1); // lật ngược theo chiều dọc context.scale(1,-1); |
Ví dụ minh họa:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); // đưa điểm tâm chỉ tới giữa canvas context.translate(canvas.width / 2, canvas.height / 2); // quay context ngược theo chiều dọc context.scale(-1, 1); context.font = "30pt Calibri"; context.textAlign = "center"; context.fillStyle = "blue"; context.fillText("Hello World!", 0, 0); }; |
hello!
Submitted by hoidap on Thu, 01/05/2012 - 22:52.
- Login or register to post comments



.jpg)
