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

Set canvas context attributes #23

Closed
quinton-ashley opened this issue Jan 21, 2024 · 0 comments
Closed

Set canvas context attributes #23

quinton-ashley opened this issue Jan 21, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@quinton-ashley
Copy link
Collaborator

quinton-ashley commented Jan 21, 2024

Motivation:

Users should be able to set canvas context attributes.

p5.js currently doesn't expose the ability to change 2d canvas context attributes. They can only be changed when the canvas is created and getContext is used for the first time.

I'm especially interested in being able to set new defaults for q5.js:

Q5.canvasOptions = {
	alpha: false,
	desynchronized: true,
	colorSpace: 'display-p3'
};

alpha: most sketches do not take advantage of the canvas element's transparency and disabling it would improve performance

desynchronized: most sketches would benefit from desynchronization with the DOM, unless the sketch used DOM elements above the canvas.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
https://developer.chrome.com/blog/desynchronized

colorSpace: If the display supports "display-p3" I want q5 to use it. #21

Related issue:
processing/p5.js#5902

Implementation:

This could be done via a createCanvas input parameter. For example:

createCanvas(800, 600, '2d', {
  alpha: false
}); 

Users could also change the defaults held in Q5.canvasOptions which would have an effect on all instances of q5. I will need to do this on p5play.org because I actually do take advantage of the canvas's alpha via the clear function which makes light and dark mode possible on the site without needing to change the example code.

@quinton-ashley quinton-ashley self-assigned this Jan 21, 2024
@quinton-ashley quinton-ashley added the enhancement New feature or request label Jan 21, 2024
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

1 participant