Libgdx:如何选择具有浮点值的颜色

时间:2016-06-24 12:05:40

标签: java colors libgdx

我想制作一种色轮,你输入一个浮动值来获得某种颜色

以下是我目前的代码:

private Color Wheel(float WheelPos) {
    WheelPos = 255 - WheelPos;
    if(WheelPos < 85) {
        return new Color((255 - WheelPos * 3)/255, 0,(WheelPos * 3)/255,1);
    }
    if(WheelPos < 170) {
        WheelPos -= 85;
        return new Color(0, (WheelPos * 3)/255, (255 - WheelPos * 3)/255,1);
    }
    WheelPos -= 170;
    return new Color((WheelPos * 3)/255, (255 - WheelPos * 3)/255, 0,1);
}

r,g,b颜色之间的颜色看起来并不丰富多彩 如何让这些颜色更亮? enter image description here

1 个答案:

答案 0 :(得分:1)

如果您希望一切都很明亮,可以使用输入值作为色调,然后根据色调,饱和度和值计算颜色(饱和度和值都是最大值)。

数学取自Android的Color类,并简化为完全饱和度/值:

//note, hue is on 0-360 scale.
public static Color hueToSaturatedColor(float hue) {
    float r,g,b;
    float Hprime = hue/60;
    float X = 1 - Math.abs(Hprime%2 - 1);
    if (Hprime<1){
        r = 1;
        g = X;
        b = 0;
    } else if (Hprime<2){
        r = X;
        g = 1;
        b = 0;
    } else if (Hprime<3){
        r = 0;
        g = 1;
        b = X;
    } else if (Hprime<4){
        r = 0;
        g = X;
        b = 1;
    } else if (Hprime<5){
        r = X;
        g = 0;
        b = 1;
    } else if (Hprime<6){
        r = 1;
        g = 0;
        b = X;
    } else {
        r = 0;
        g = 0;
        b = 0;
    }

    return new Color(r, g, b, 1);
}