JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="canvas" width="500" height="500"></canvas>
JavaScript
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var image = new Image();
var drawTile = function(x, y, tile, width, height) {
context.drawImage(image, (tile % 6) * width, Math.floor(tile / 6) * height, width, height, x, y, width, height);
};
image.onload = function() {
// draw all 12 tiles:
var i = 0;
setInterval(function() {
context.clearRect(0,0,500,500);
drawTile(0, 0, i, 48, 32);
i++;
if (i > 11) i = 0;
}, 85);
}
image.src = 'http://i.stack.imgur.com/qkWe2.png';