본문 바로가기

Programming/Manim code

[012]TextMobject.set_color/set_color_by_map

반응형

Text Color: tex_to_color_map

        t1 = TexMobject(
            "P(A|B) = {P(A)P(B|A) \\over P(B)}",
            tex_to_color_map={
                "A": YELLOW,
                "B": BLUE,
            },
        )
        self.add(t1)
        self.wait()


Text Color: set_color_by_tex

        eq = TexMobject("x", "=", "L", "\\theta")
        eq.set_color_by_tex("\\theta", BLUE)

        self.add(eq)
        self.wait()


Text Color: set_color_by_tex_to_color_map(1)

        all_words = VGroup(
            TextMobject("You have a\\\\", "hypothesis"),
            TextMobject("You've observed\\\\some ", "evidence"),
            TexMobject(
                "\\text{You want}\\\\",
                "P", "(", "H", "|", "E", ")\\\\",
                "P", "\\left(",
                "\\substack{""\\text{Hypothesis} \\\\",
                "\\textbf{given} \\\\",
                "\\, \\text{the evidence} \\,}",
                "\\right)",
            ),
        )

        HYPOTHESIS_COLOR = YELLOW
        EVIDENCE_COLOR1 = BLUE_C
        EVIDENCE_COLOR2 = BLUE_E
        for words in all_words:
            words.set_color_by_tex_to_color_map({
                "hypothesis": HYPOTHESIS_COLOR,
                "H": HYPOTHESIS_COLOR,
                "evidence": EVIDENCE_COLOR1,
                "E": EVIDENCE_COLOR2,
            })

        all_words.arrange(DOWN)
        self.add(all_words)
        self.wait()


Text Color: set_color_by_tex_to_color_map (2)

        t2c = {
            "{x}": GREEN,
            "{t}": YELLOW,
        }

        t = TexMobject(
            "{d" , "T", "\\over", "\\partial", "x" + "}",
            "(", "{x}", ",", "{t}", ")",
        ).set_color_by_tex_to_color_map(t2c)

        self.add(t)
        self.wait()

 

반응형

'Programming > Manim code' 카테고리의 다른 글

[014]Text/TextMobject/TexMobject  (0) 2020.05.05
[013]Text: Transform  (0) 2020.05.05
[011]Text/TextMobject  (0) 2020.05.05
[010]save_state/restore  (0) 2020.05.05
[008]align_to/arrange/arrange_in_grid  (0) 2020.05.05