Skip to content

Instantly share code, notes, and snippets.

@fffiloni
Last active July 23, 2022 12:25
Show Gist options
  • Save fffiloni/19c42c6dd13aab74a7e803d08feeecae to your computer and use it in GitHub Desktop.
Save fffiloni/19c42c6dd13aab74a7e803d08feeecae to your computer and use it in GitHub Desktop.
How to resive canvas and its graphics on p5js
// 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