I have a color selector that allows a user to change fore and background color for a grid. I wondered if there is a way to compare two colors in the #FFFFFF format to get a "likeness" rating, i.e. to try and verify if the foreground colors are readable on a specified background.
Asked
Active
Viewed 106 times
-1
-
2There is, you can compute the Euclidean distance between the colors. – adeneo Apr 21 '15 at 18:32
-
3http://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js – adeneo Apr 21 '15 at 18:32
1 Answers
1
If colour_1 = #aabbcc
and colour_2 = #AABBCC
you could do something like:
diff = sqrt((aa - AA)^2 + (bb - BB)^2 + (cc - CC)^2)
The smaller this value is, the more alike the two colours should be.

bjpelcdev
- 303
- 3
- 9