Supporting existing canvas element for createCanvas() and createGraphics()#6229
Supporting existing canvas element for createCanvas() and createGraphics()#6229Qianqianye merged 5 commits intoprocessing:mainfrom
Conversation
|
I think this looks good! I made an example showing the issue with I think that's fine, because if your intention was to use this to inject p5 into another library's canvas, then we intentionally don't want to be messing with the attributes they've set up. So maybe we can just add a note in the docs about this? e.g.:
|
Forgot to remove the alt-text of an example that was never added.
Co-authored-by: Dave Pagurek <dave@davepagurek.com>
|
Thanks @ffd8 for working on it and @davepagurek for reviewing! |
Resolves #4564
Changes:
createCanvas()andcreateGraphics()(includingp5.Graphics), to both accept passing a 3rd or 4th param (depending on ifrendereris given) with an existing html canvas element. WithincreateGraphics(), it was necessary to both replace thedefaultCanvas0(created with setup) and tell p5 that the_defaultGraphicsCreatedis false to re-initiate the renderer. WithcreateGraphics(), in only required intercepting the creation of a canvas element which would have been applied to the body (or node).createCanvas()changescreateGraphics()changesp5.GraphicschangesPR Checklist
npm run lintpasses