harmonize static method
Blend the design color's HCT hue towards the key color's HCT hue, in a way that leaves the original color recognizable and recognizably shifted towards the key color.
designColor
ARGB representation of an arbitrary color.
sourceColor
ARGB representation of the main theme color.
Returns The design color with a hue shifted towards the
system's color, a slightly warmer/cooler variant of the design
color's hue.
Implementation
static int harmonize(int designColor, int sourceColor) {
final Hct fromHct = Hct.fromInt(designColor);
final Hct toHct = Hct.fromInt(sourceColor);
final double differenceDegrees =
MathUtils.differenceDegrees(fromHct.hue, toHct.hue);
final double rotationDegrees = min(differenceDegrees * 0.5, 15.0);
final double outputHue = MathUtils.sanitizeDegreesDouble(fromHct.hue +
rotationDegrees * MathUtils.rotationDirection(fromHct.hue, toHct.hue));
return Hct.from(outputHue, fromHct.chroma, fromHct.tone).toInt();
}