casesandberg / react-color

:art: Color Pickers from Sketch, Photoshop, Chrome, Github, Twitter & more
http://casesandberg.github.io/react-color/
MIT License
12.04k stars 921 forks source link

Question about formula for contrasting color #619

Closed hibroseph closed 5 years ago

hibroseph commented 5 years ago

I needed to work in your color contraster that you made for the Block picker. The formula seems like you are multiplying arbrtary values by the RGB values and dividing by 1000. Can I ask how you came up with this formula? I'd love to know for my own personal knowledge.

Here is the contrasting color I am talking about. It is located with in the color.js file in the helpers directory

const yiq = ((col.rgb.r * 299) + (col.rgb.g * 587) + (col.rgb.b * 114)) / 1000
return (yiq >= 128) ? '#000' : '#fff'
hibroseph commented 5 years ago

I found an article explaining. If anyone is wondering https://24ways.org/2010/calculating-color-contrast/