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 ParametricBasic(Scene):
    def construct(self):
        self.add(head("参数方程绘制圆与椭圆", "ParametricFunction"))
        axes = Axes(x_range=[-3, 3, 1], y_range=[-3, 3, 1], x_length=7, y_length=5.4,
                    axis_config={"color": GREY_B})
        circ = ParametricFunction(lambda t: np.array([np.cos(t), np.sin(t), 0]),
                                  t_range=[0, TAU, 0.02], color=BLUE).set_stroke(width=6)
        ell = ParametricFunction(lambda t: np.array([2 * np.cos(t), 1.1 * np.sin(t), 0]),
                                 t_range=[0, TAU, 0.02], color=YELLOW).set_stroke(width=6)
        self.add(axes)
        self.play(Create(circ), run_time=2.2)
        self.play(Transform(circ, ell), run_time=2.2)
        self.play(FadeIn(foot("x=f(t), y=g(t)：同一曲线换参数即换形状")), run_time=0.4)
        self.wait(1.8)
