Created
November 4, 2022 10:16
-
-
Save mattdesl/b58683977c58ab191aa8795d4e960c35 to your computer and use it in GitHub Desktop.
meridian scaling script
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
let width, height, pixelRatio; | |
const W = window; | |
const defaultAspect = 9 / 16; | |
const aspect = W.A || defaultAspect; | |
const targetHeight = W.S || 2048; | |
const targetWidth = ~~(targetHeight * aspect); | |
const inputHeight = W.H || W.innerHeight * W.devicePixelRatio; | |
const targetRatio = | |
W.R != null ? W.R : Math.max(1, inputHeight / targetHeight); | |
height = targetHeight; | |
width = ~~(height * aspect); | |
pixelRatio = targetRatio; | |
let canvas; | |
if (W.C) canvas = W.C; | |
else if (D && D.body && D.createElement) { | |
canvas = D.body.appendChild(D.createElement("canvas")); | |
} | |
const context = canvas ? canvas.getContext("2d") : null; | |
if (canvas) { | |
canvas.width = ~~(width * pixelRatio); | |
canvas.height = ~~(height * pixelRatio); | |
const CS = canvas.style; | |
if (CS) { | |
const resize = () => { | |
CS.position = "absolute"; | |
CS.display = "block"; | |
CS.top = CS.left = CS.right = CS.bottom = "0"; | |
CS.width = CS.margin = "auto"; | |
CS.height = "100%"; | |
}; | |
W.onresize = resize; | |
resize(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment