+ public static @ColorInt
+ int hslTriplet(float hue, float saturation, float lightness) {
+ @ColorLong long result;
+ float h = hue * 6;
+ float c = (1 - abs(2f * lightness - 1)) * saturation;
+ float h_mod_2 = h % 2;
+ float x = c * (1 - Math.abs(h_mod_2 - 1));
+ int r, g, b;
+ float m = lightness - c / 2f;
+
+ if (h < 1 || h == 6) return tupleToColor(c + m, x + m, 0 + m);
+ if (h < 2) return tupleToColor(x + m, c + m, 0 + m);
+ if (h < 3) return tupleToColor(0 + m, c + m, x + m);
+ if (h < 4) return tupleToColor(0 + m, x + m, c + m);
+ if (h < 5) return tupleToColor(x + m, 0 + m, c + m);
+ if (h < 6) return tupleToColor(c + m, 0 + m, x + m);
+
+ throw new IllegalArgumentException(String.format(
+ "Unexpected value for h (%1.3f) while converting hsl(%1.3f, %1.3f, %1.3f) to rgb",
+ h, hue, saturation, lightness));
+ }