颜色逻辑算法 [英] Color Logic Algorithm
问题描述
我们正在建立一个运动应用程序,并希望在应用程序的各个部分中加入团队色彩。
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.
所以,如果团队1的主要团队颜色的值为rgb(255,0,0)(或#FF0000),而团队2的主色相似,说rgb(250,0,0),那么我们将为其中一个团队选择不同的颜色。
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?
感谢
推荐答案
http://www.compuphase.com/cmetric.htm =nofollow noreferrer>理论解释
Here is a theoretical explanation
和算法C: / p>
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));
}
这篇关于颜色逻辑算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!