21 Nisan 2015 Salı

Canvas Resim Döndürme

<body>
    <canvas width="1280" height="720" id="canvas"> </canvas>
    <script>
      var resim = new Image();
      resim.src= "r.png";  

       var ctx = document.getElementById('canvas').getContext('2d');
       var angle = 0;

        function dondur(derece) {
            return derece*(Math.PI/180); //derece
        }

        function animate() { 
            ctx.clearRect(0,0,1280,720);
            ctx.save();               
                ctx.translate(200,200);
                ctx.rotate(dondur(angle+=.5));
                ctx.drawImage(resim,-resim.width/2,-resim.height/2);          
            ctx.restore();
        }

        setInterval(animate, 20);
    </script>
</body>

Hiç yorum yok:

Yorum Gönder