Skip to content

Instantly share code, notes, and snippets.

View AndriiShtoiko's full-sized avatar

AndriiShtoiko

View GitHub Profile
@callumlocke
callumlocke / scale-canvas.ts
Last active August 27, 2024 18:45
How to fix a canvas so it will look good on retina/high-DPI screens.
/*
UPDATED for 2023 - Now much simpler. The old tricks are no longer needed.
The following code makes an 800×600 canvas that is always as sharp as possible for the device.
You still draw on it as if it's the logical size (800×600 in this case), but everything just
looks sharper on high-DPI screens. Regular non-sharp screens are not affected.
*/
const width = 800