from manim import *
import numpy as np
import sympy as sp
def head(cn, en):
    t = Text(cn, font="STLiti", font_size=27).to_edge(UP)
    s = Text(en, font="Consolas", font_size=20, color=YELLOW).next_to(t, DOWN, buff=0.10)
    return VGroup(t, s)
def foot(cn):
    return Text(cn, font="STLiti", font_size=20, color=YELLOW).to_edge(DOWN)
class FormulaExpand(Scene):
    def construct(self):
        self.add(head("公式推导：展开与回代", "sp.expand / TransformMatchingTex"))
        x = sp.symbols("x")
        src = sp.expand((2*x - 3) * (x + 5))
        dst = (2*x - 3) * (x + 5)
        a = MathTex(sp.latex(src)).scale(1.2)
        b = MathTex(sp.latex(dst)).scale(1.2)
        self.add(a)
        self.wait(0.6)
        self.play(TransformMatchingTex(a, b), run_time=2.4)
        self.wait(1.0)
        self.play(TransformMatchingTex(b, a), run_time=2.0)
        self.play(FadeIn(foot("展开式与因式式之间可以双向切换")), run_time=0.4)
        self.wait(0.8)
