颜色的逻辑算法 [英] Color Logic Algorithm

查看:214
本文介绍了颜色的逻辑算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在建设一个体育应用程序,并希望将球队的颜色在应用程序的各个部分。

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

现在每支球队可以重新$ P $用几种不同的颜色psented。

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?

感谢

推荐答案

下面是

和在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆