from manim import *
import numpy as np
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 ImplicitEllipse(Scene):
    def construct(self):
        self.add(head("隐函数 + ValueTracker 动态椭圆", "always_redraw / ValueTracker"))
        axes = Axes(x_range=[-4, 4, 1], y_range=[-3, 3, 1], x_length=8, y_length=5.6,
                    axis_config={"color": GREY_B})
        a, b = ValueTracker(1.0), ValueTracker(1.0)
        ell = always_redraw(lambda: ImplicitFunction(
            lambda x, y: x**2 / a.get_value()**2 + y**2 / b.get_value()**2 - 1,
            x_range=[-4, 4], y_range=[-3, 3], color=GREEN).set_stroke(GREEN, width=6))
        self.add(axes, ell)
        self.play(a.animate.set_value(3.0), run_time=2.5)
        self.play(b.animate.set_value(2.0), run_time=2.5)
        self.play(FadeIn(foot("改变参数即重算等值线，曲线实时跟随")), run_time=0.4)
        self.wait(1.4)
