harmonize static method

int harmonize(
  1. int designColor,
  2. int sourceColor
)

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 fromHct = Hct.fromInt(designColor);
  final toHct = Hct.fromInt(sourceColor);
  final differenceDegrees =
      MathUtils.differenceDegrees(fromHct.hue, toHct.hue);
  final rotationDegrees = min(differenceDegrees * 0.5, 15.0);
  final outputHue = MathUtils.sanitizeDegreesDouble(fromHct.hue +
      rotationDegrees * MathUtils.rotationDirection(fromHct.hue, toHct.hue));
  return Hct.from(outputHue, fromHct.chroma, fromHct.tone).toInt();
}