Skip to content

Instantly share code, notes, and snippets.

@onedayitwillmake
Created February 28, 2018 00:01
Show Gist options
  • Save onedayitwillmake/94fedaaff88d37ef776afbe375f42a29 to your computer and use it in GitHub Desktop.
Save onedayitwillmake/94fedaaff88d37ef776afbe375f42a29 to your computer and use it in GitHub Desktop.
Draw rotated, scaled image at position
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