Skip to content

[Java] Blend harmonize function not working properly? #71

Open
@palexdev

Description

@palexdev

Describe the bug
I'm trying to create a theme with three extra colors for these extra states: "warn", "info" and "success".
As stated in the MD3 guidelines, custom colors should be harmonized with the rest of the palette but the generated tonal palette is not equal to the one generated by the MD3 Theme Builder.

To Reproduce

// My primary color is the default one of the MD3 Theme Builder
Hct primary = Hct.from(298.980997210704, 47.8565263749703, 40.08324408746242); // Also HEX: #6750a4
Hct success = Hct.from(145.74707292816973, 53.04624876358251, 40.46292958087737); // Also HEX: #1C6E25

// Then armonize the success color
int harmonized = Blend.harmonize(success.toInt());

// Then generate TonalPalette as shown on the MD3 Theme Builder
int[] tones = new int[]{100, 99, 98, 95, 90, 80, 70, 60, 50, 40, 35, 30, 25, 20, 15, 10, 5, 0};
TonalPalette hmzPalette = TonalPalette.fromInt(harmonized);

Map<Integer, String> colors = new LinkedHashMap<>();
for (int tone : tones) {
    // Colors are also converted to HEX strings with no alpha
    colors.put(tone, Utils.toHexNoAlpha(hmzPalette.tone(tone)));
}

// Print the map

The results are:

{
  "100": "#FFFFFF",
  "99": "#F5FFF5",
  "98": "#E9FFED",
  "95": "#C0FFD6",
  "90": "#9BF5C0", // Expected #92F7BD
  "80": "#80D9A5", // Expected #75DAA2
  "70": "#64BC8B", // Expected #59BE88
  "60": "#48A172", // Expected #3CA36F
  "50": "#2B865A", // Expected #178857
  "40": "#006D43",
  "35": "#005F3A",
  "30": "#005231",
  "25": "#004529",
  "20": "#003920",
  "15": "#002D19",
  "10": "#002111",
  "5": "#001509",
  "0": "#000000"
}

Tones from 90 to 50 are not right.

Expected behavior
I expect TonalPalette to generate the same colors or at least to be much more precise as the colors shown by the MD3 Theme Builder. If I'm doing something wrong, then I expect the documentation here on this repository or on the MD3 guidelines website to be more precise

Notes
I tested this primarily in Java, but I think the issue is present in all the other languages too

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions