Skip to content

Instantly share code, notes, and snippets.

@krabbypattified
Last active February 20, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krabbypattified/4d2dfaed5e0a2400fe516aff9ecdeab4 to your computer and use it in GitHub Desktop.
Save krabbypattified/4d2dfaed5e0a2400fe516aff9ecdeab4 to your computer and use it in GitHub Desktop.
Repeated background image for canvas game engine
const cameraXobject = new DOMMatrix().rotate(PI/8)
const inverse = cameraXobject.inverse()
const transformPoint = p => inverse.transformPoint(p)
const pat = ctx.createPattern(img, 'repeat')
ctx.fillStyle = pat
ctx.path = [
[0,0],
[ctx.canvas.width,0],
[0,ctx.canvas.height],
[ctx.canvas.width,ctx.canvas.height],
].map(transformPoint)
ctx.fill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment