Computer >> Máy Tính >  >> Lập trình >> Javascript

Cách phát hiện điểm trên canvas sau khi xoay canvas trong HTML5

Bất cứ khi nào chúng ta làm việc với canvas và muốn xoay canvas, chúng ta cần dịch điểm để vẽ điểm theo cách xoay của nó.

Có thể tạo một lớp biến đổi để phát hiện điểm trên canvas sau khi xoay canvas

var t = new Transform();
console.log(t.transformPoint(5,6)); //Transform point will be [5,6]

t.rotate(1); // Same transformations can be applied that we did to the canvas
console.log(t.transformPoint(5,6)); // Transformed point will be [-2.347, 7.449]