home/ atoms/ p5-global-mode-only

P5LIVE runs p5 in global mode; instance-mode sketches (function sketch(p){}) must be rewritten before they work

P5LIVE injects p5 into the global scope, making all p5 functions (ellipse, fill, background, etc.) available as bare names without a namespace prefix. This is called global mode. Instance mode — the pattern function sketch(p){ p.setup = …; p.draw = … } — is not compatible with P5LIVE as-is: the p.ellipse-style calls won’t find the p object in scope. Pasted instance-mode code from the p5 editor or community sketches must be converted to bare function names. Similarly, add-on functions from p5.sound or HY5 only exist if the relevant library has been loaded.

Examples

Instance-mode: function sketch(p) { p.draw = function() { p.ellipse(50,50,30); }; } — won’t work in P5LIVE. Rewrite: function draw() { ellipse(50,50,30); }.

Assessment

A community sketch uses the pattern new p5(function(p){ p.draw = ... }). Explain why it fails in P5LIVE and rewrite the draw function in global mode.

“Pasting instance-mode sketches (`function sketch(p){ p.setup=…}`) won't work as-is.”
context/ · L1-instruments/p5live/gotchas.md · chunk 1