In my drawings, I’d like to set the xy axis centred in the middle of the screen and rescaled between -0.5 and 0.5 instead of using screen coordinates. That makes the drawing independent of screen resolution.
I tried:
function draw() {
background(255);
let _ratio = windowWidth / windowHeight;
let _scale;
// keep aspect ratio and use centre square of the screen.
if (_ratio >= 1.0) {
_scale = windowHeight;
} else {
_scale = windowWidth;
}
// translate to the centre of the screen
translate(windowWidth / 2, windowHeight / 2);
// scale coordinate system between
scale(_scale);
line(-0.5, 0, 0.5, 0); // x-axis
line(0, -0.5, 0, 0.5); // y-axis
}
Now all strokes are scaled as well. How can I normalise the coordinate system only without rescaling the strokes?
I know I can use map
function to recalculate every coordinate, but that makes the code rather long if I have to remap every coordinate before calling a draw function.