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 FormulaFactor(Scene):
    def construct(self):
        self.add(head("公式推导：SymPy 自动因式分解", "sp.factor / MathTex"))
        x = sp.symbols("x")
        expr = x**3 - 6*x**2 + 11*x - 6
        fac = sp.factor(expr)
        a = MathTex(sp.latex(expr)).scale(1.2)
        b = MathTex(sp.latex(fac)).scale(1.2)
        self.add(a)
        self.wait(0.6)
        self.play(TransformMatchingTex(a, b), run_time=2.6)
        self.wait(1.0)
        self.play(b.animate.set_color(GREEN), run_time=1.0)
        self.play(FadeIn(foot("分解结果由 SymPy 算出，不需要手写")), run_time=0.4)
        self.wait(1.2)
