Skip to content

Instantly share code, notes, and snippets.

@mngyuan
Created October 20, 2023 10:02
Show Gist options
  • Save mngyuan/606a0bf4542851e3d2fb2141357e3b58 to your computer and use it in GitHub Desktop.
Save mngyuan/606a0bf4542851e3d2fb2141357e3b58 to your computer and use it in GitHub Desktop.
Adding fullscreen to p5.js sketches
// Paste the following into any p5.js sketch, and press Enter to toggle fullscreen
function toggleFullScreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else if (document.exitFullscreen) {
document.exitFullscreen();
}
}
document.addEventListener(
'keydown',
(e) => {
if (e.key === 'Enter') {
toggleFullScreen();
}
},
false,
);
// Optional but allows the sketch to automatically resize
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment