Basic setup
P5.js has a built-in draw loop that must be disabled. UsenoLoop() and drive rendering from Helios.
Critical patterns
Disable P5.js draw loop
P5.js automatically callsdraw() at 60fps. You must disable this:
Use Helios time, not P5 time
P5.js providesframeCount and millis() for animation. Don’t use them with Helios:
Access Helios in draw function
Create the Helios instance in the outer scope to access it inside P5.js functions:Handle window resize
Update canvas size on window resize:Complete example with animation
Performance considerations
Canvas size and resolution
P5.js renders at the canvas resolution. Larger canvases are slower:Drawing complexity
P5.js is CPU-based. Avoid excessive draw calls per frame:Background clearing
Callingbackground() clears the canvas. For trails, use transparency:
Image and font loading
Preload assets inpreload() to avoid loading delays:
Shape optimization
Use built-in shapes instead ofbeginShape() when possible:
Frame rate considerations
P5.js is slower than WebGL-based libraries. Use lower FPS for complex sketches:Package dependencies
Common issues
Sketch runs too fast
You forgotnoLoop() in setup:
Animation not deterministic
You’re using P5.js time instead of Helios time:Random values change on replay
P5.jsrandom() is non-deterministic. Seed it or use a deterministic pattern: