manim icon indicating copy to clipboard operation
manim copied to clipboard

Improve and simplify Manim's color handling

Open Darylgolden opened this issue 3 years ago • 6 comments

Enhancement proposal

  • Manim's colors are defined twice, once in an enum and once as constants. It seems like the Enum was introduced in #488 as an attempt to clean up the code, with constants having to be explicitly imported. However, for convenience the community eventually decided to import all the constants, and then to appease people's editors and linters the constants eventually had to be explicitly defined as well. I think we should either only define colors in an enum, or define them as constants, but not both. Seeing how the natural trend is to go towards convenience, I think they should be defined as constants. Furthermore, they should be instances of the Color class from the colour module (or @marcin-serwin's fork).
  • We have many functions for converting between color representations that duplicate the functionality of existing, specialized libraries. Any uses of those should be replaced, probably by methods of Color, and the functions eventually removed.

Additional comments

Darylgolden avatar Jan 09 '22 06:01 Darylgolden

This sounds like a great proposal. Could I be assigned to this issue?

BrorSebastianSjovald avatar Mar 03 '22 12:03 BrorSebastianSjovald

Before removing them completely do you think a deprecation warning should be used? I'm thinking of doing both versions

BrorSebastianSjovald avatar Mar 04 '22 14:03 BrorSebastianSjovald

Thank you for your interest in contributing! I've assigned you to the issue.

Regarding the first point: I've realized that random_color relies on an object containing information on all preset colors, so perhaps it might not be desirable to remove such an object entirely. Perhaps Colors should be a list? I'm not sure.

Yes, a deprecation warning should be used where practical, but if it's not easily feasible then it can be left out. I'm not sure what you're referring to with "doing both versions".

Darylgolden avatar Mar 05 '22 07:03 Darylgolden

I have already started kinda working on it in #2553 (The name could've been better 😅) Let me know if you would like to work on it with me together!

ad-chaos avatar Mar 05 '22 07:03 ad-chaos

I'll look into variations we can do for the random_color. Some sort of way to gather all the different colors should be implemented. Are the colors limited to the ones currently implemented as constants or enums? Otherwise a random hexcolor code could maybe be used?

What I meant by the two versions was one with the deprecation warnings and one with those functions removed.

@Kiran-Raj-Dev I'll look into your PR!

BrorSebastianSjovald avatar Mar 06 '22 15:03 BrorSebastianSjovald

We can only do this if Color can be pickled but for now it uses lambdas and thus cannot be serialized in to a file which hinders us from implemeting this feature

  • https://github.com/ManimCommunity/manim/issues/2837

MrDiver avatar Jun 18 '22 21:06 MrDiver

fixed with #2837

MrDiver avatar Aug 11 '23 13:08 MrDiver