Created
October 20, 2023 10:02
-
-
Save mngyuan/606a0bf4542851e3d2fb2141357e3b58 to your computer and use it in GitHub Desktop.
Adding fullscreen to p5.js sketches
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
// 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