Rotate image animation with canvas

var degrees = 0; var interval = 50; var img = new Image(); img.src = "http://codepad.co/images/body/logo.png"; function rotateImage() { degrees = (5 + degrees) % 360; var radians = degrees / 180 * Math.PI; var canvas = document.getElementById('2d'); var context = canvas.getContext('2d'); context.fillRect(0, 0, canvas.width, canvas.size); context.save(); context.translate(canvas.width/2, canvas.height/2); context.rotate(radians); context.translate(-img.width/2, -img.height/2); context.drawImage(img, 0, 0); context.restore(); setTimeout(rotateImage, interval); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.