Skip to content

Instantly share code, notes, and snippets.

@amix
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amix/238dd0341170df07dfc8 to your computer and use it in GitHub Desktop.
Save amix/238dd0341170df07dfc8 to your computer and use it in GitHub Desktop.
Configure a canvas element for high-def screens (retina)
# 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)
// 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