Skip to content

adding properties to color object #7767

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

Closed
1 of 17 tasks
rruubboott opened this issue Apr 22, 2025 · 2 comments
Closed
1 of 17 tasks

adding properties to color object #7767

rruubboott opened this issue Apr 22, 2025 · 2 comments

Comments

@rruubboott
Copy link

Increasing access

By simplifying a process, making information more easily accessible by beginners.

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)

Feature enhancement details

The color object's r,g,b and a values could be accessible via literal properties called r,g,b,a (or at a push red, green,blue etc.)
So that is to say you could get access to the Red value of a color object via:
color.r or color.red
and not have to go into:
color.levels[0]

@LalitNarayanYadav
Copy link
Contributor

This is a great idea—accessing color components directly via color.r, color.g, color.b, and color.a would definitely make the API more intuitive, especially for beginners. It improves readability and aligns well with p5.js’s focus on accessibility and simplicity.

Relevant sub-areas: Color, Accessibility.

I'd be happy to contribute to this! Could you please point me to the relevant file(s) or location in the codebase where this change should be made?

@ksen0
Copy link
Member

ksen0 commented Jun 6, 2025

This is a good idea for the more object-oriented use of color, however since objects are already not a beginner-level topic, the easiest way to access these values is using blue(c) where c is the color object. The same is available for alpha, red, hue, and so on:

Image

Though it's possible to duplicate the functionality on the object too, this creates a maintenance challenge, so I'll close this issue for now, however it could be considered in the future.

@LalitNarayanYadav @rruubboott if either of you want to work on adding examples exploring color-related functions and making them more visible, you can check out the existing examples and propose some examples on the p5.js-website repo!

@ksen0 ksen0 closed this as completed Jun 6, 2025
@ksen0 ksen0 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants