【问题标题】:How to make a needle image to rotate from 180 degree to 0, half of 360 degree如何使针图像从 180 度旋转到 0,360 度的一半
【发布时间】:2011-03-23 21:08:46
【问题描述】:
<!DOCTYPE html>
<html>
<head>
    <title>Canvas Cog</title>
    <script type="text/javascript">
        var cog = new Image();
        function init() {
            cog.src = 'needle.png'; // Set source path
            setInterval(draw,100);
        }
        var rotation = 0;
        function draw(){
            var ctx = document.getElementById('myCanvas').getContext('2d');
            ctx.globalCompositeOperation = 'destination-over';
            ctx.save();
            ctx.clearRect(0,0,500,500);
            ctx.translate(200,180); // to get it in the origin
            rotation +=1;
            ctx.rotate(rotation*Math.PI/180); //rotate in origin
            ctx.translate(0,-90); //put it back
            ctx.drawImage(cog,(-13.5),(-13.5),48,111);
            ctx.restore();
        }
        init();
    </script>
</head>
<body>
    <canvas width="500" height="500" id="myCanvas"></canvas>
</body>
</html>

【问题讨论】:

  • 脚本到底有什么问题?

标签: javascript image html rotation


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 1970-01-01
  • 2013-04-22
  • 2019-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多