Rotating around an arbitrary point: HTML5 Canvas

后端 未结 2 1931
生来不讨喜
生来不讨喜 2020-12-29 08:11

Come see the amazing disappearing rectangle!

But seriously I have a really simple HTML5 canvas that just draws a rectangle(using lineTo instead of rect for a

2条回答
  •  囚心锁ツ
    2020-12-29 08:51

    When you rotate the canvas, it rotates from the origin (0, 0), so your rectangle ends up getting rotated off the screen.

    See this example where it's only rotated 45 deg: http://jsfiddle.net/wjLSm/

    One way to fix this is to translate the canvas by its width & height/2: http://jsfiddle.net/wjLSm/1/ (then 0,0 is at the middle -- be aware of this)

提交回复
热议问题