xxxxxxxxxx
34
let mImage;
let xOff;
let yOff;
function preload() {
mImage = loadImage("./abaporu_M.jpg");
}
function setup() {
createCanvas(windowWidth, windowHeight);
pixelDensity(1);
print("Original size: ", mImage.width, " x ", mImage.height);
noLoop();
if (mImage.width > width) {
mImage.resize(width, 0);
}
if (mImage.height > height) {
mImage.resize(0, height);
}
print("Scaled size: ", mImage.width, " x ", mImage.height);
xOff = (width - mImage.width) / 2;
yOff = (height - mImage.height) / 2;
}
function draw() {
background(0);
push();
translate(xOff, yOff);
image(mImage, 0, 0);
pop();
}