Instance mode creating two canvas

Like all Processing flavors, setup() should be called once only.
Indeed, the <canvas>mousedown event is set to callback reset():

Let’s dissect createCanvas(600, 600).mousePressed(reset); chaining call, shall we?

Method p5::createCanvas() returns a p5.Renderer object:

And b/c it’s the default P2D default renderer, it is more precisely a p5.Renderer2D object:

The class p5.Renderer is also a subclass of the base class p5.Element:

Therefore, all p5.Element’s methods & properties are available to a p5.Renderer instance; including of course p5.Element::mousePressed():

The main diff. between p5.Element::mousePressed() & p5::mousePressed() methods:

is that the former acts upon its p5.Element only; while the later fires anywhere within the document where the sketch is being run:

3 Likes