我怎样才能在manim的方程中只让x变成黄色并将x中的sub变成2.5?

问题描述 投票:0回答:1
class Lineargraph (Scene):
    def construct(self):

        # Intro
        wlabel1 = Text("Solve the equation")
        wlabel1.shift(UP*0.8)
        eqlabel1 = MathTex("y = 2x - 1", color = YELLOW)
        wlabel2 = Text("When")
        wlabel2.shift(DOWN*0.8 + LEFT*1)
        eqlabel2 = MathTex("x = 2.5", color = YELLOW).next_to(wlabel2)

        texts1 = VGroup(wlabel1,wlabel2,eqlabel1,eqlabel2)

        wlabel3 = Text("Solve the equation")
        wlabel3.shift(LEFT*3.3, UP*3.6)
        eqlabel3 = MathTex("y = 2x - 1", color = YELLOW).next_to(wlabel3)
        wlabel4 = Text("When").next_to(eqlabel3)
        eqlabel4 = MathTex("x = 2.5", color = YELLOW).next_to(wlabel4)
        texts2 = VGroup(wlabel3, wlabel4,eqlabel3,eqlabel4)

        # Method 1 subing in
        mthd1wlabel1 = Text("Method 1")
        mthd1wlabel1.shift(UP*2.7+LEFT*3.9)
        mthd1wlabel1.set_color_by_gradient(RED_D, YELLOW_E)
        mthd1wlabel2 = Text("By substituting x into 2.5")
        mthd1eqlabel1 = MathTex("y = 2x - 1")

        #Intro animation
        self.play(Write(wlabel1))
        self.play(Write(eqlabel1))
        self.play(Write(wlabel2))
        self.play(Write(eqlabel2))
        self.play(ReplacementTransform(texts1,texts2))

        #Method 1 animation
        self.play(Write(mthd1wlabel1.scale(1)))
        self.play(Write(mthd1wlabel2))
        self.play(ReplacementTransform(mthd1wlabel2, mthd1eqlabel1.scale(1.3)))

在 #Method1 动画中,我想将句子转换为方程。转换后,我想突出显示字母“x”。然后,将 x 更改为值 2.5。有人可以帮忙吗?

python manim
1个回答
0
投票

在下面的代码片段中,我展示了两个突出显示 x 的选项(比例+颜色和周围的矩形)。

    ...

    mthd1eqlabel1 = MathTex("y = 2x - 1", substrings_to_isolate='x')
    
    ...

    # Bigger - Smaller and different color
    self.wait()
    self.play(mthd1eqlabel1[1].animate.scale(1.5).set_color(RED))
    self.play(mthd1eqlabel1[1].animate.scale(1/1.5).set_color(WHITE))
    self.wait()
    
    # Surrounding rect
    rect = SurroundingRectangle(mthd1eqlabel1[1], color=RED)
    
    self.play(Create(rect))
    self.wait()
    self.play(FadeOut(rect))
    self.wait()
    
    # Replace value
    value = MathTex("\\cdot 2.5").scale(1.3).align_to(mthd1eqlabel1[1], LEFT).align_to(mthd1eqlabel1[1], DOWN).shift(0.1*RIGHT)
            
    self.play(Transform(mthd1eqlabel1[1], value), mthd1eqlabel1[2].animate.next_to(value, RIGHT))
    self.wait()

你没有具体提到它应该是什么样子,所以我做了一些基本的安排,以便你可以看到你可以在这里做什么。

© www.soinside.com 2019 - 2024. All rights reserved.