Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created November 4, 2022 10:16
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 mattdesl/b58683977c58ab191aa8795d4e960c35 to your computer and use it in GitHub Desktop.
Save mattdesl/b58683977c58ab191aa8795d4e960c35 to your computer and use it in GitHub Desktop.
meridian scaling script
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