pushrbx icon

Convert Kelvin to grayscale color

pushrbx | PRO | 06/16/15 08:35:27 AM UTC | 0 ⭐ | 527 👁️ | Never ⏰ | []
C# |

440 B

|

None

|

0 👍

/

0 👎

// kelvin values are around 270-290 normally for room temperature
// we have to scale up those, so we multiply by 10
public Color KelvinToGrayscaleColor(int kelvin)
{
    kelvin *= 10;
    var min = 2200;
        var max = 3800;
    var highestBit = 255;
 
    var result = 0.0;
    if (item <= max && item >= min)
    {
        result = ((double)(highestBit) / ((double)(max - min))) * ((double)(item - min));
    }
 
    return new Color(result, result, result)
}

Comments