Skip to content

Finally fixing the Color situation #2837

@MrDiver

Description

@MrDiver

To fix

As discussed on discord

The color situation in Manim is pretty janked right now and there are 2-3 different ways to manage Color. We do not really need all that duplicate functionality so i think we settled now on reworking the Enum in color.py to be the source of truth again. Making it Colors(str, Enum) to not break current functionality (but also benchmark that at first before doing that change because it could have drastic performance impact) and then so that IDE doesn't cry we add a .pyi file with the exported colors so that autocomplete works and then ditching colour.py because it is not compatible with pickle

Enhancement proposal

* Manim's colors are defined twice, [once in an enum](https://github.com/ManimCommunity

/manim/blob/main/manim/utils/color.py#L33-L260) and once as [constants](https://github.com
/ManimCommunity/manim/blob/main/manim/utils/color.py#L286-L366). It seems like the Enum was
introduced in # New colour enums- Try2 #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]

(https://github.com/ManimCommunity/manim/blob/main/manim/utils/color.py#L453-L478) 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

Related

Metadata

Metadata

Assignees

Labels

maintenancerefactoring, typos, removing clutter/dead code, and other code quality improvements

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions