drawfunction is not optional.
rect(), etc) should go inside the
setup()function for set-up
draw()function, even if you don't want animation.
loop()can be used to prevent or enable animation by repeated calls to the
draw()function. The default is to animate.
rect()at the top-level (i.e. outside of the p5.js functions such
mousePressed(), etc). If you try to do this, you'll get an error such as
Uncaught ReferenceError: random is not defined
Did you just try to use p5.js's random() function? If so, you may want to move it into your sketch's setup() function.
setup(), if they need p5.js functions
random()function, you must do it in two parts:
var xPos;outside of the
xPos = random(0, 400);
heightwhich will hold the size of the canvas.