I looked through Observable and found two people making p5js notebooks:
I played around with their code and translated your simple test into this.
This Observable notebooks thing seems neat. I use jupyter notebooks regularly for python, and I’m glad there’s a javascript equivalent for this, need to read more on it later. Thanks for mentioning it.