-1

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.

aggaton
  • 3,066
  • 2
  • 25
  • 36

1 Answers1

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