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 ParametricHeart(Scene):
    def construct(self):
        self.add(head("参数曲线：心形线", "ParametricFunction / t_range"))
        heart = ParametricFunction(
            lambda t: np.array([16 * np.sin(t)**3,
                                13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t), 0]),
            t_range=[0, TAU, 0.005], color=PINK)
        heart.set_stroke(PINK, width=6).scale(0.16).shift(DOWN * 0.3)
        self.play(Create(heart), run_time=3.4)
        self.play(heart.animate.set_fill(RED, opacity=0.4).set_stroke(RED, width=8), run_time=1.2)
        self.play(FadeIn(foot("缩放 t_range 外的幅值即可控制图形整体大小")), run_time=0.4)
        self.wait(1.6)
