ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
21.48k stars 1.58k forks source link

Manim should support pre-defined color themes #310

Closed leotrs closed 3 years ago

leotrs commented 4 years ago

Color themes would allow the user to change all colors in a scene by changing just one line of code. A theme could be as simple as just a list of pre-defined colors. For example:

from manim import Scene, Circle, Text, colors

theme = colors.some_theme_name

class ColorThemeExample(Scene):
    def construct(self):
        circle = Circle(color=theme[0], stroke_color=theme[1])
        text = manim.TextMobject("some text", color=theme[2])
        self.add(circle, text)

Here, colors.some_theme_name could really just be the list ["RED", "GREEN", "BLUE"]. But then if there was another theme defined as colors.some_other_theme = ["BLACK", "ORANGE", "BROWN"], changing all three colors throughout the scene could be done in a single line of code.

Note that this is already feasible on the user side. A user may define their own list of colors, and swap them as they see fit. What I'm suggesting is that manim should ship with a few of these pre-defined. For example, if the user wants their video to look like 3b1b's videos, they could use a pre-defined colors.theme_3b1b. Or if they want their videos to look different, they could use a different pre-defined, or user-defined theme.

Implementing them as lists would be extremely easy. However, we could also provide more complicated pre-defined themes using dictionaries, that make use of meaningful keys such as theme["text_color"], theme["graph_color"], theme["background_color"], and so on.

A next step would be to implement a ColorTheme class that allows the user to do things such as ColorTheme.interpolate("text_color", "background_color", 0.5) to get a color that is halfway between two pre-defined colors. (Note this is currently possible with manim.utils.color.interpolate_color, so implementing such a class would be mostly a matter of refactoring.) A next NEXT step would be to implement something like Scene.register_color_theme(ColorTheme) which would automatically convert the color of every TextMobject to ColorTheme["text_color"], or something along those lines.

What do y'all think? I think we could easily start by providing pre-defined themes that are just lists.

huguesdevimeux commented 4 years ago

Good suggestion. Would love to see a PR of that. However, I'm not convinced of the usefulness of that :

A next step would be to implement a ColorTheme class that allows the user to do things such as ColorTheme.interpolate("text_color", "background_color", 0.5) to get a colour that is halfway between two pre-defined colors.7

I don't think the standard user will ever use that, as this can be done quite easily with the utils or by hand, adding this to ColorTheme would be too much and don't fit in such class.

I'd love to see other's opinion, who have certainly way more experience than me in manim projects.

leotrs commented 4 years ago

Yeah you're right, I think this suggestion should just add lists/dicts containing a bunch of harmonizing colors. The ColorTheme suggestion is probably useless/bloatware.

leotrs commented 3 years ago

Closing in favor of #279