我正在寻找一个公式来确定 RGB 颜色的红色度。我敢肯定有一些非常简单的公式,但我一直没能找到它。
基本上,它会是这样的:
function rednessAsPercent(r, g, b) {
// Does some math to determine redness.
}
alert(rednessAsPercent(255, 0, 0)); // Alerts: 100
alert(rednessAsPercent(255, 255, 0)); // Alerts: 0. This is pure yellow.
alert(rednessAsPercent(255, 122, 122)); // Alerts: ~50. This is sort of pink.
有任何想法吗?
谢谢!