manim icon indicating copy to clipboard operation
manim copied to clipboard

Color palette format and builder

Open OliverStrait opened this issue 1 year ago • 0 comments

Description of proposed feature

This idea spawned from discord messages about adding support for additional color palletes and how it is not that easy to use/find those that already are in. This is rough draft of model that could hold color information and transfer it to internal format only when needed first time (decreasing Construction calls at import for colors which will never used for individual animation). In Addittion, global namespace can be much cleaner if there is not floating all default colors like RED, WHITE, BLACK, etc.


# IDE see this information:
class AS2700_UI():
    Y14_GOLDEN_YELLOW:ManimColor ="#DDDDDD"
    #could also be only with annotation
    B13_NAVY_BLUE : ManimColor 
    DICTIONARY = {
        "Y14_GOLDEN_YELLOW": "GOLDEN YELLOW",
    }

# Runtime sees instances of this class:
class ColorBuilder:
    def __init__(self, dictionary:dict) -> None:
        self.dictionary = dictionary

    def __getattr__(self, name: str) -> Any:
        item = self.dictionary.get(name, "DEFAULT")

        # Calls transformer to internal color format
        color_object = ManimColor(item)
        #builds proper attribute, so next call returns color_object directly
        setattr(self, name, color_object)

        return color_object

#namespace substitution at import:
AS2700_UI = ColorBuilder(AS2700_API.DICTIONARY)

# Global namespace could start Colors, ColorsX11, etc.
# Or Pallette
ColorsAS2700 = AS2700_UI
PalletteAS2700 = AS2700_UI

How can the new feature be used?

#end user call:
yellow = ColorAS2700.Y14_GOLDEN_YELLOW

#or:
colors = ColorAS2700
colors = PalletteAS2700
yellow = colors.Y14_GOLDEN_YELLOW

OliverStrait avatar Aug 20 '24 21:08 OliverStrait