Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createCanvas compatible API #231

Closed
TiborUdvari opened this issue Sep 12, 2024 · 2 comments
Closed

createCanvas compatible API #231

TiborUdvari opened this issue Sep 12, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@TiborUdvari
Copy link
Collaborator

We should consider an interface similar to the p5.js way of doing things. It would reduce friction if we could take an existing WEBGL sketch and change it to a WEBXR AR or VR sketch by doing something like this:

function setup(){
  createCanvas(1000, 1000, AR);
}

instead of

function preload() {
  createARCanvas();
}

The current p5.js implementation for reference:

/**
 * @method createCanvas
 * @param  {Number} [width]
 * @param  {Number} [height]
 * @param  {HTMLCanvasElement} [canvas]
 * @return {p5.Renderer}
 */
p5.prototype.createCanvas = function(w, h, renderer, canvas) {

It would have to add a parameter to consider starting the sketch automatically as well: #224

@TiborUdvari TiborUdvari added the enhancement New feature or request label Sep 12, 2024
@TiborUdvari TiborUdvari self-assigned this Sep 12, 2024
@stalgiag
Copy link
Owner

Yeah this makes sense. The reason that this wasn't done initially is that modifying p5 prototypes directly is not recommended in the library authoring guidelines for p5. That said, I believe we had to do this elsewhere so it wouldn't be the most extreme departure.

@TiborUdvari
Copy link
Collaborator Author

Yes, I think generally it's a good idea, but in think in these cases it would make sense. I think people would expect and interface like this.

I'm adding this feature with #235

This keeps the createARCanvas type functionality still working, although there are now a few lines like
p5.instance._incrementPreload(); in the __createButton that are not needed if the preload method is used for initialisation.

A future refactor could/should be done to better differentiate the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants