JSFiddle - React, Tailwind, and code Playground
CSS
#img {
display:none
}
canvas {
border:1px solid #000
}
JavaScript
var c = cs.getContext("2d")
var gridWidth=128
var gridHeight=64
var spriteWidth=gridWidth
var spriteHeight=img.height/img.width*gridWidth
cs.width = window.innerWidth //spriteWidth*10
cs.height = window.innerHeight //spriteHeight*10
var ox = cs.width/2-spriteWidth/2
var oy = spriteHeight
window.onresize=function(){
cs.width = window.innerWidth //spriteWidth*10
cs.height = window.innerHeight //spriteHeight*10
//this clears the canvas
ox = cs.width/2-spriteWidth/2
oy = spriteHeight
draw()
}
draw()
function renderImage(x, y) {
c.drawImage(img, ox + (x - y) * spriteWidth/2, oy + (y + x) * gridHeight/2-(spriteHeight-gridHeight),spriteWidth,spriteHeight)
}
function draw(){
for(var x = 0; x < 10; x++) {
for(var y = 0; y < 10; y++) {
renderImage(x,y)
}}
}