0

What is the ratio of coordinate on canvas and pixel?

20th Apr 2020, 8:26 PM
PR PRGR
PR PRGR - avatar
2 Answers
+ 1
TLDR; There is no ratio of coordinate on canvas to pixel ratio if the canvas is the size of the screen. You can add the distance to document borders and the canvas to get precise coordinates if needed. If you want your canvas to be the size of your whole screen, in the CSS you set do html, body { width:100%; height:100%; margin:0; } And then in the JS say the var name of your canvas is c var c = canvas; var k = c.getContext("2d"); k.canvas.width = window.innerWidth; k.canvas.height = window.innerHeight; If you do that the canvas to pixel ratio will be the same if you want it to be the size of your screen. If the canvas is only a portion of your screen, you could add the distance the canvas to the borders of the document.
21st Feb 2021, 5:04 AM
EthanE230
EthanE230 - avatar
+ 1
EthanE230 Thank you!
9th Apr 2021, 6:03 PM
PR PRGR
PR PRGR - avatar