-
Notifications
You must be signed in to change notification settings - Fork 1
/
canvas.js
43 lines (34 loc) · 850 Bytes
/
canvas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
let width = canvas.width;
let height = canvas.height;
resizeCanvas();
function resizeCanvas()
{
window.devicePixelRatio=2;
let sizeX = 480;
let sizeY = 640;
let ratioX = window.innerWidth/sizeX;
let ratioY = window.innerHeight/sizeY;
let ratio = Math.min(ratioX, ratioY);
if(window.innerWidth < sizeX)
{
canvas.style.width = window.innerWidth + "px";
}
else
{
canvas.style.width = sizeX*ratio + "px";
}
if(window.innerHeight < sizeY)
{
canvas.style.height = window.innerHeight + "px";
}
else
{
canvas.style.height = sizeY*ratio + "px";
}
let scale = window.devicePixelRatio;
canvas.width = Math.floor(sizeX * scale);
canvas.height = Math.floor(sizeY * scale);
ctx.scale(scale, scale);
}