You would like to use instance mode . The first few examples use Global mode , and the next few examples use Instance mode . Instead of using the default canvas, in instance mode you control where p5js places the canvas element. If you have two containers, you should use:
new p5(leftSketch, 'left'); new p5(rightSketch, 'right');
leftSketch and rightSketch will be functions that accept the variable p. This variable is an instance of p5js, and you can control each element of the canvas separately.
source share