Bläddra i källkod

Added function to get a color gradient between green and red

Jorrit Rouwe 1 månad sedan
förälder
incheckning
390cefd44c
1 ändrade filer med 14 tillägg och 0 borttagningar
  1. 14 0
      Jolt/Core/Color.h

+ 14 - 0
Jolt/Core/Color.h

@@ -49,6 +49,20 @@ public:
 	/// Get a visually distinct color
 	static Color			sGetDistinctColor(int inIndex);
 
+	/// Get a color value on the gradient from green through yellow to red
+	/// @param inValue Value in the range [0, 1], 0 = green, 0.5 = yellow, 1 = red
+	static Color			sGreenRedGradient(float inValue)
+	{
+		if (inValue < 0.0f)
+			return Color::sGreen;
+		else if (inValue < 0.5f)
+			return Color(uint8(510.0f * inValue), 255, 0);
+		else if (inValue < 1.0f)
+			return Color(255, uint8(510.0f * (1.0f - inValue)), 0);
+		else
+			return Color::sRed;
+	}
+
 	/// Predefined colors
 	static const Color		sBlack;
 	static const Color		sDarkRed;