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 ImplicitHeart(Scene):
    def construct(self):
        self.add(head("隐函数：心形线", "ImplicitFunction / cubic curve"))
        heart = ImplicitFunction(
            lambda x, y: (x**2 + y**2 - 1)**3 - x**2 * y**3,
            x_range=[-1.6, 1.6], y_range=[-1.3, 1.8], color=PINK)
        heart.set_stroke(PINK, width=7).scale(1.5)
        label = MathTex("(x^2+y^2-1)^3 = x^2y^3", color=GREEN).scale(0.7).to_corner(UR)
        self.add(label)
        self.play(Create(heart), run_time=3.4)
        self.play(heart.animate.set_stroke(RED, width=9), run_time=1.2)
        self.play(FadeIn(foot("隐式方程能表达显式函数难以描述的封闭曲线")), run_time=0.4)
        self.wait(1.6)
