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

What is the range for the quantize interger and how does it relate to the pallette that is produced? #3

Open
michaelzero00 opened this issue Apr 28, 2021 · 3 comments

Comments

@michaelzero00
Copy link

I'm not sure how changing the quantize integer will affect the resulting colour pallette that is used?

@skratchdot
Copy link
Owner

skratchdot commented May 5, 2021

I'm not sure how changing the quantize integer will affect the resulting colour pallette that is used?

@michaelzero00 - Sorry for the delay on this (just now seeing it).

The quantize value should really be a float between 0 and 255 I think.

Here is a function for getting the value:

const getQuantizationValue = (numColors) => numColors > 1 ? 255 / (numColors - 1) : 255;

For example:

"web safe" colors have 6 possible values for each R/G/B value, so calling getQuantizationValue(6) gives us a quantization value of 51. (aka 51 = 255 / (6 - 1) aka 51 = 255 / 5)

  • decimal: 0, 51, 102, 153, 204, 255 (each value is incremented by 51)
  • hex: 00, 33, 66, 99, CC, FF

"web smart" colors have 16 possible values for each R/G/B value, so calling getQuantizationValue(16) gives us a quantization value of 17. (aka 17 = 255 / (16 - 1) aka 17 = 255 / 15)

  • decimal: 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 (each value is incremented by 17)
  • hex: 00, 11, 22, 33, 44, 55, 66, 77, 88, 99, AA, BB, CC, DD, EE, FF

I should update the documentation on how to use this. I also think I could've had a better API (and better variable names) for this.

@michaelzero00
Copy link
Author

michaelzero00 commented May 5, 2021 via email

@skratchdot
Copy link
Owner

skratchdot commented May 6, 2021

uggh. it looks like i throw an error for non integers for some reason:

if (!isInt(quantizeAmount)) {
throw new Error('quantizeAmount must be an integer');
}

but i think onecolor uses values between 0-1 at the end of the day, so I think floats would work 🤷

but i think if you think of it as a "step" value or something it makes more sense. so a value between 1-255. i might try to do testing and see if floats work. if they do i can publish a new version

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

No branches or pull requests

2 participants