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

Color palette format and builder #3912

Open
OliverStrait opened this issue Aug 20, 2024 · 0 comments
Open

Color palette format and builder #3912

OliverStrait opened this issue Aug 20, 2024 · 0 comments
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)

Comments

@OliverStrait
Copy link

OliverStrait commented Aug 20, 2024

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 OliverStrait added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Aug 20, 2024
@OliverStrait OliverStrait changed the title Color palet format and builder Color palette format and builder Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant