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.

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 = math.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();
}