Guest User

Untitled

a guest
Jun 8th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. function drawImageRot(ctx,img,x,y,width,height,rad){
  2.  
  3. //Convert degrees to radian
  4. //var rad = deg * Math.PI / 180;
  5.  
  6. //Set the origin to the center of the image
  7. ctx.translate(x + width / 2, y + height / 2);
  8.  
  9. //Rotate the canvas around the origin
  10. ctx.rotate(rad);
  11.  
  12. //draw the image
  13. ctx.drawImage(img.getImage(),width / 2 * (-1),height / 2 * (-1),width,height);
  14.  
  15. //reset the canvas
  16. ctx.rotate(rad * ( -1 ) );
  17. ctx.translate((x + width / 2) * (-1), (y + height / 2) * (-1));
  18. }
Advertisement
Add Comment
Please, Sign In to add comment