我在js上制作时钟。如何根据时间旋转时针?我需要以deg或rad转换时间吗?我的代码现在:
$(document).ready(function(){
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var img = new Image();
var bee = new Image();
var i = 40;
img.src = "images/clock.jpg";
img.onload = function(){
bee.src = "images/bee.jpg";
ctx.drawImage(img, 0, 0);
ctx.drawImage(bee, 95, 90);
setInterval(function(){
i = i+1;
ctx.save(); //saves the state of canvas
ctx.clearRect(0, 0, canvas.width, canvas.height); //clear the canvas
ctx.drawImage(img, 0, 0);
ctx.translate(canvas.width/2,canvas.height/2);
ctx.rotate(225*Math.PI/180);
ctx.drawImage(bee, -85, -90);
ctx.restore();
}, 100);
}
});
我的时钟sreen: Imgur
答案 0 :(得分:1)
...数学
分手
适用于时针