Placement of sliders outside canvas

Oopsy, totally forgotten that not all p5js canvases are at browser’s position (0, 0)! :man_facepalming:

Anyways, here are some “tricks”: :mage:

We don’t need to store the p5.Renderer returned by the p5:createCanvas() in some global variable. :convenience_store:

p5js already does it for us under its “secret” variables _renderer & _curElement: :male_detective:

So, in order to grab sketch’s main canvas coordinates, we just need: _renderer.position(). :smile_cat:

Of course, don’t forget to import “p5.dom.js” for the p5.Element::position() method. :flushed:

Another 1 is that all the id attributes secretly become global variables already. :shushing_face:

So rather than parent('canvasposition') as a string, simply pass the id global variable: parent(canvasposition). :yum:

2 Likes