[Python] Manim Community: Color in Equation by Text

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I have following Python code to display a matrix in Manim Community:

    from manim import *

    class Example(Scene):
    def construct(self):
    A = MathTex(
    r"A="
    r"\begin{pmatrix}"
    r"a_{11} & a_{12} & \dots & a_{1n}\\"
    r"a_{21} & a_{22} & \dots & a_{2n}\\"
    r"\vdots & \vdots & \ddots & \vdots\\"
    r"a_{n1} & a_{n2} & \dots & a_{nn}"
    r"\end{pmatrix}"
    ).center()

    self.play(Write(A))



    I'd like to give every "a" the same color (like red for example).

    I know I can display the indices, and then color each "a" individually by index, but this gets increasingly tideous for bigger equations.

    Is there a way to do such things smarter, like a color in by text, or by iterating over the equation?

    Continue reading...

Compartilhe esta Página