Skip to main content
P5.js is a creative coding library that makes drawing and animation accessible. Helios enables precise control over P5.js sketches for video export.

Basic setup

P5.js has a built-in draw loop that must be disabled. Use noLoop() and drive rendering from Helios.

Critical patterns

Disable P5.js draw loop

P5.js automatically calls draw() at 60fps. You must disable this:
Then trigger draws manually from Helios:

Use Helios time, not P5 time

P5.js provides frameCount 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

Calling background() clears the canvas. For trails, use transparency:

Image and font loading

Preload assets in preload() to avoid loading delays:

Shape optimization

Use built-in shapes instead of beginShape() 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 forgot noLoop() in setup:

Animation not deterministic

You’re using P5.js time instead of Helios time:

Random values change on replay

P5.js random() is non-deterministic. Seed it or use a deterministic pattern:

Container not found

Ensure the container element exists before creating the sketch:

Canvas appears blurry

P5.js doesn’t automatically handle device pixel ratio. Set it manually: