Skip to content

Manim should support pre-defined color themes #310

@leotrs

Description

@leotrs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAdditions and improvements in generalnew featureEnhancement specifically adding a new feature (feature request should be used for issues instead)refactorRefactor or redesign of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions