Skip to content

[p5.js 2.0 RFC Proposal]: Color module rewrite #7018

@limzykenneth

Description

@limzykenneth

Increasing access

A color module that behaves more consistently with more powerful feature unlocks additional opportunity to explore colors and create p5.js sketches that can exist in environment that uses a wider variety of color profiles.

Which types of changes would be made?

  • Breaking change (Add-on libraries or sketches will work differently even if their code stays the same.)
  • Systemic change (Many features or contributor workflows will be affected.)
  • Overdue change (Modifications will be made that have been desirable for a long time.)
  • Unsure (The community can help to determine the type of change.)

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

What's the problem?

The current color system of p5.js has a few notable flaws:

  • All colors are coerced into being 8-bit RGB values and there are no support of colors wider than the RGB color space
  • Colors once created have the color mode of when they are created attached to them, ie. a color created when the sketch is in RGB color mode, will always be in RGB color mode even if the sketch's color mode is changes to HSB or something else.
  • Only RGB, HSL, and HSB are supported

What's the solution?

A new color module will be implemented. The some of the requirements of this new color module are:

The recommended references/inspirations for how this new color module should work are CSS color specs and color.js. However it is not recommended to bundle color.js as their approach, while very comprehensive, is somewhat complex and for p5.js 2.0 we should aim for as few external dependencies as possible.

At the same time while relying on browser CSS implementation may help simplify many of the implementation, it may be worth considering the potential scenario of p5.js itself, or even just the color module being used as a standalone module, being used outside of the browser.

Pros (updated based on community comments)

  • More intuitive and easy to use color API in p5.js

Cons (updated based on community comments)

  • Likely to break at least some sketches
  • There may be some API changes to how color object works as well

Proposal status

Under review

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Completed

Relationships

None yet

Development

No branches or pull requests

Issue actions