Description
Increasing Access
By allowing websites to synchronize with the lifecycle of p5.js sketches, users will experience smoother transitions and less visual jarring. This can be especially beneficial for individuals sensitive to abrupt visual changes.
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build Process
- Unit Testing
- Internalization
- Friendly Errors
- Other (specify if possible)
Feature request details
Problem Description
Currently, there isn't a direct way to listen to lifecycle events such as when setup
starts or ends, and when draw
starts or ends. This can be beneficial for scenarios where users want to synchronize other animations or events on their page with the p5.js sketch lifecycle, like fading in a sketch once it's fully initialized.
Proposed Solution
Provide event listeners/hooks that can be attached to specific lifecycle moments:
preloadStarted
: Triggered when thepreload
function begins execution.preloadEnded
: Triggered when thepreload
function completes.setupStarted
: Triggered when thesetup
function begins execution.setupEnded
: Triggered when thesetup
function completes.drawStarted
: Triggered when thedraw
function begins execution.drawEnded
: Triggered when thedraw
function completes.
For instance, in a slideshow containing multiple p5 sketches, we could listen to the setupEnded
event on p5.js to smoothly fade in the next sketch once it has been initialized by p5.js and starts rendering on the canvas.
Alternatives considered
While users can currently use custom flags or counters to try and determine when certain functions start or end, having dedicated events would standardize this approach and make it more accessible and reliable.