Last active
August 29, 2015 14:07
-
-
Save amix/238dd0341170df07dfc8 to your computer and use it in GitHub Desktop.
Configure a canvas element for high-def screens (retina)
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
# Configure a canvas element for high-def screens (retina) | |
highDefCanvas = (canvas, context) -> | |
pixel_ratio = window.devicePixelRatio | |
if pixel_ratio | |
width = canvas.width | |
height = canvas.height | |
canvas.width = width * pixel_ratio | |
canvas.height = height * pixel_ratio | |
canvas.style.width = "#{width}px" | |
canvas.style.height = "#{height}px" | |
context.scale(pixel_ratio, pixel_ratio) |
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
// Configure a canvas element for high-def screens (retina) | |
function highDefCanvas(canvas, context) { | |
var height, pixel_ratio, width; | |
pixel_ratio = window.devicePixelRatio; | |
if (pixel_ratio) { | |
width = canvas.width; | |
height = canvas.height; | |
canvas.width = width * pixel_ratio; | |
canvas.height = height * pixel_ratio; | |
canvas.style.width = width + "px"; | |
canvas.style.height = height + "px"; | |
return context.scale(pixel_ratio, pixel_ratio); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment