Last active
February 20, 2019 13:57
-
-
Save krabbypattified/4d2dfaed5e0a2400fe516aff9ecdeab4 to your computer and use it in GitHub Desktop.
Repeated background image for canvas game engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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