使用 HTML5 Canvas - 围绕任意点旋转图像
将表盘旋转到半圆形(北半球)图像作为背景。 范围可以是 0 - 180 度。 在输入到进行画布转换的方法时,转盘将旋转并停在匹配的值上。 这是我根据 phrogz 传递的帮助和示例所做的尝试
Rotate the dial on top of a semi circular(Northern Hemisphere) image as background.
range could be 0 - 180 degrees.
on input to the method that does canvas transformation, the dial would rotate and stop over the matched value.
Here's what I was trying based on help and sample passed on by phrogz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您想要做的是:
在代码中:
这是一个工作示例,展示了这一点的实际效果。 (旋转的数学只是通过实验进行修改,以找到适合快速绘制的仪表盘的摆动量和弧度偏移量。)
很明显,您可以替换步骤 # 中的
translate
调用。上面的 3 条带有drawImage()
调用的偏移量。例如:当您有多个对象要在同一位置绘制时,建议使用上下文翻译。
In general, what you want to do is:
In code:
Here's a working example showing this in action. (The math for the rotation was just experimentally hacked to find a swing amount and offset in radians that fit the quickly-sketched gauge dial.)
As may be evident, you can substitute the
translate
call in step #3 above with offsets to thedrawImage()
call. For example:Using context translation is recommended when you have multiple objects to draw at the same location.