Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  172] [ 7]  / answers: 1 / hits: 15177  / 15 Years ago, wed, january 20, 2010, 12:00:00

We are building a sports application and would like to incorporate team colors in various portions of the app.



Now each team can be represented using several different colors.



What I would like to do is to perform a check to verify whether the two team colors are within a certain range of each other, so that I do not display two similar colors.



So, if team 1's primary team color has a value of rgb(255,0,0) (or #FF0000), and team 2's primary color is similar, say rgb(250,0,0), then we would choose a different color for one of the teams.



If possible, what approach could I take to perform the check?



Thanks


More From » java

 Answers
56

Here is a theoretical explanation



And the algo in C:



typedef struct {
unsigned char r, g, b;
} RGB;

double ColourDistance(RGB e1, RGB e2)
{
long rmean = ( (long)e1.r + (long)e2.r ) / 2;
long r = (long)e1.r - (long)e2.r;
long g = (long)e1.g - (long)e2.g;
long b = (long)e1.b - (long)e2.b;
return sqrt((((512+rmean)*r*r)>>8) + 4*g*g + (((767-rmean)*b*b)>>8));
}

[#97784] Monday, January 18, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
terrence questions
Sat, Jun 5, 21, 00:00, 3 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
;