如何旋转这个形状?
我刚刚开始使用画布。我做了这个:
http://www.kingoslo.com/instruments/
转速计的箭头是使用画布绘制的。现在我正在尝试制作一个动画以使其围绕转速计的输入(而不是其本身)旋转。这就是我到目前为止所写的:
<script type="text/javascript">
var img = new Image();
function init(){
img.src = 'background.png';
setTimeout(draw,4000);
}
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
img.onload = function(){
ctx.drawImage(img,0,0);
ctx.beginPath();
ctx.moveTo(247,308);
ctx.bezierCurveTo(51, 408, 51, 410, 51, 411);
ctx.bezierCurveTo(53, 413, 52, 412, 249, 313);
ctx.fillStyle = "red";
ctx.fill();
}
}
</script>
我不知道如何进一步。另外,是否有涵盖这些内容的综合文档?
谢谢。
亲切的问候,
马吕斯
I am just starting out with canvas. I made this:
http://www.kingoslo.com/instruments/
The arrow for the tachometer is a drawn using canvas. Now I am trying to make an animation to rotate it around the enter of the tachometer (not itself). This is what I have written so far:
<script type="text/javascript">
var img = new Image();
function init(){
img.src = 'background.png';
setTimeout(draw,4000);
}
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
img.onload = function(){
ctx.drawImage(img,0,0);
ctx.beginPath();
ctx.moveTo(247,308);
ctx.bezierCurveTo(51, 408, 51, 410, 51, 411);
ctx.bezierCurveTo(53, 413, 52, 412, 249, 313);
ctx.fillStyle = "red";
ctx.fill();
}
}
</script>
I have no idea how to get further. Also, is there comprehensive documentation anywhere that covers these things?
Thanks.
Kind regards,
Marius
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你见过这个 https://github.com/vjt/canvas-speedometer
我已经编写了您的代码:
确保仪表的
中心点
必须位于图像的中心
,否则它将无法工作。您可以处理
i
的值来以米为单位旋转图钉。在这里,我拍摄了两张图像
https://i.sstatic.net/qbWeO.png
https://i.sstatic.net/SQEv6.png
代码:
<强>更新:
如果您想处理值为 rpm 的仪表
替换
为
输出:
Have you seen this https://github.com/vjt/canvas-speedometer
I have written your code:
Make sure that the
center point
of the meter must be atthe center of your image
else it will not work.You can handle value of
i
to rotate your pin in meter.Here, I have taken two images
https://i.sstatic.net/qbWeO.png
https://i.sstatic.net/SQEv6.png
CODE:
Update:
If you want to handle meter with value of rpm
Replace
with
output: