Created
February 28, 2018 00:01
-
-
Save onedayitwillmake/94fedaaff88d37ef776afbe375f42a29 to your computer and use it in GitHub Desktop.
Draw rotated, scaled image at position
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
let scale = 0.5; | |
let ox = deg; | |
let oy = 0; | |
let radians = deg * DEG_TO_RAD; | |
let xx = this.canvas.width * 0.5 + imageWidth * 0.5 * scale + ox; | |
let yy = this.canvas.height * 0.5 + imageHeight * 0.5 * scale + oy; | |
ctx.translate(xx,yy); | |
ctx.rotate(radians); | |
ctx.drawImage(image, 0, 0, imageWidth, imageHeight, -imageWidth * 0.5 * scale, -imageHeight * 0.5 * scale, imageWidth * scale, imageHeight * scale); | |
ctx.rotate(-radians); | |
ctx.translate(-xx,-yy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment