Last active
July 23, 2022 12:25
-
-
Save fffiloni/19c42c6dd13aab74a7e803d08feeecae to your computer and use it in GitHub Desktop.
How to resive canvas and its graphics on p5js
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
// Resizing the canvas is simple | |
resizeCanvas(new_width, new_height) | |
// Resizing graphics is tricky | |
function resizeGraphics(new_width, new_height, old_graphics){ | |
let new_graphics = createGraphics(new_width, new_height); | |
new_graphics.image(old_graphics, 0, 0, new_width, new_height); | |
return new_graphics; | |
} | |
//then call it directly to switch | |
graphics_you_need_to_resize = resizeGraphics(new_width, new_height, graphics_you_need_to_resize); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment