Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
palexdev opened this issue Dec 14, 2022 · 0 comments
Open

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

palexdev opened this issue Dec 14, 2022 · 0 comments
Labels
bug Something isn't working library: java

Comments

@palexdev
Copy link

palexdev commented Dec 14, 2022

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

@guidezpl guidezpl added bug Something isn't working library: java labels Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working library: java
Projects
None yet
Development

No branches or pull requests

2 participants