Skip to content

Attempt to implement a theming concept #2015

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

Closed
wants to merge 18 commits into from
Closed

Attempt to implement a theming concept #2015

wants to merge 18 commits into from

Conversation

icedcoffeeee
Copy link
Collaborator

Overview: What does this pull request change?

This PR aims to implement a 'color theme' into manim.
Concerns:

  • Currently, this PR allows themes to be set only from a config file and not from the script
    • As far as i know, that would require the library to be reinitialized to account for the new variable values.
  • The way it is implemented is by redefining the greyscale colors, to another gradient.
    • Not a good implementation, but easiest to do without having to introduce a new constant MOBJECT_COLOR

Any and all opinions are welcome.

Motivation and Explanation: Why and how do your changes improve the library?

A light mode theme:
LightModeTest_ManimCE_v0 9 0
A sepia theme:
SepiaTest_ManimCE_v0 9 0
A seagreen theme:
SeagreenTest_ManimCE_v0 9 0

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Copy link
Member

@Darylgolden Darylgolden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work so far! I don't think redefining the grayscale gradient is a very good implementation of themes however. Right now, it seems like there are many places in which the colors of mobjects are hardcoded; for example, WHITE by default, RED for Circle, BLUE for polygrams, etc. It seems like a better approach to generalize this to something like MOBJECT_COLOR_A, MOBJECT_COLOR_B or THEME_COLOR_A, THEME_COLOR_B for example. These can be defined in a constants file like theme_sepia.py for example, and imported when the scene is set (perhaps you can make the theme a property of Scene, so that it can be changed in the middle of the scene). This can also easily be generalized for Axes, FunctionGraph, and so on. I'm not sure how the background_color code works but I'm guessing it can also be implemented with this approach. It seems like this approach will allow significantly more flexibility, if possible.

@icedcoffeeee
Copy link
Collaborator Author

there are many places in which the colors of mobjects are hardcoded

This is true, but there were never complaints abt this before theming.

It seems like a better approach to generalize this to something like MOBJECT_COLOR_A, MOBJECT_COLOR_B or THEME_COLOR_A, THEME_COLOR_B for example.

That's fair. I can try that.

(perhaps you can make the theme a property of Scene, so that it can be changed in the middle of the scene).

I don't think this is possible. I've experimented enough to understand that the initialization of the mobjects occur at the line
from manim import *. At that point every mobject already has their own set colors. This means that the constants you're describing can only be set externally.
You also mentioned other libraries that do this (on discord). All of them don't run like manim. Matplotlib and the like, approaches initialization the way #1901 proposed, which currently isn't feasible.

The whole idea clearly needs way more discussion. Until we can reach a general consensus, this should stay a draft.

@behackl
Copy link
Member

behackl commented Sep 6, 2021

I think there are multiple closely related design questions that are related to this PR. Obviously, one is whether a theme system makes sense for the library – but I don't really want to get into that with this comment.

I do want to bring attention to this suggestion made a while back on our Discord regarding an idea to make the Mobject default arguments customizable. Personally, I believe it would be desireable to provide users with an easy way of customizing the default color assigned to a particular Mobject class. Practically, this could be done by modifying a static attribute like Circle.config.color = ... as mentioned in the suggestion, but then we need to make sure that in examples like

>>> c1 = Circle()
>>> c2 = Circle(color=GREEN)
>>> Circle.config.color = PINK
>>> c3 = Circle()
>>> c4 = Circle(color=GREEN)

the colors are set as expected. The advantage of an approach like this would be that modifications to the default colors can also happen during runtime, the obvious disadvantage is that it is more difficult to get right. In this model, a particular theme would likely be a dictionary mapping Mobject classes to colors (plus a mechanism for the background color) – although I can also see the merit for setting the color of all mobjects simultaneously.

@aayushdutt
Copy link

It's be great if the themes are modular, so there can be a repository of many awesome themes designed by the community :)

@MrDiver
Copy link
Collaborator

MrDiver commented Jun 18, 2022

Closing this in favor of first discussing how to go about implementing such a feature

@MrDiver MrDiver closed this Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Rejected
Development

Successfully merging this pull request may close these issues.

5 participants