3

I have been trying out Manim Community. I am wondering if there is a way to change the text colour to black through out the whole program by calling config.

I can change the background colour using config.background_color = WHITE. I have tried searching online and trying random things (like config.text_colour = BLACK) to no avail. Thanks!

Sony
  • 92
  • 4
  • 9

3 Answers3

3

There is a color parameter for Text.

For example,

from manim import *

class TextColor(Scene):
   def construct(self):
       self.add(Text('Hello',color=BLUE))

should give a blue colored text.

See the corresponding documentation: https://docs.manim.community/en/stable/reference/manim.mobject.svg.text_mobject.Text.html#manim.mobject.svg.text_mobject.Text

naveen521kk
  • 140
  • 1
  • 10
  • 1
    I don't think this is what OP wants. It seems he wants to set up a default colour for all of his Texts, as to not have to rewrite the `color=...` parameter each time – olirwin Apr 09 '21 at 20:11
  • 1
    I think that can't be done and it isn't always great to edit the source for this? Maybe make an [issue](https://github.com/manimcommunity/manim/issues)? – naveen521kk Apr 10 '21 at 16:37
  • 1
    Thank you for your help! olirwin got what I meant, I found a solution by editing the source. – Sony Apr 10 '21 at 19:28
1

One solution is to open the .../manim/mobject/svg/tex_mobject.py and change the colour there :

class TexMobject(SingleStringTexMobject):
    CONFIG = {
        "arg_separator": " ",
        "substrings_to_isolate": [],
        "tex_to_color_map": {},
        "color": YOUR_COLOUR,
    }

(credits to @Level-314 for this solution)

Of course this should also apply to Text.

olirwin
  • 545
  • 5
  • 21
  • Thank you for your help! I can't find the config files, I am using Manim Community. – Sony Apr 05 '21 at 21:16
  • I tried, but it unfortunately did not work. – Sony Apr 07 '21 at 20:53
  • What do you mean ? The default background color did not change ? – olirwin Apr 09 '21 at 08:00
  • I meant I couldn't find the path. After some digging, I have found it though! I'll post it as an answer because there are a few steps. Thank you for all your help!! – Sony Apr 10 '21 at 11:59
0

On Mac, I found the file at: /users/<accountName>/library/python/3.8/lib/python/site-packages/manim/svg/text_mobject.py. On Windows, it was found to be here: C:\Users\<accountName>\AppData\Local\Programs\Python\Python38\Lib\site-packages\manim\mobject\svg\text_mobject.py Then, text_mobject.py, I did two/three things:

  1. In line 68, there is this: from ...utils.color import WHITE, Colors. I added from ...utils.color import BLACK, Colors underneath. It gave me an error if I skipped this step.

  2. I went to line 129 and changed color=WHITE to color=BLACK.

  3. Only needed on Windows: Go to line 699 and color: str = WHITE, to color: str = BLACK, Credit for helping me find this goes to olirwin in the comments.

Note: I am using Manim Community v0.4

Sony
  • 92
  • 4
  • 9