from manim import *
# 切线样式：在圆的 0 / 1/8 / 3/8 / 3/4 四处各画一条切线
# 复现：manim -qh --disable_caching -a 20240822173706003.py
class TangentLineDemo(Scene):
    def construct(self):
        # 中文必须指定中文字体，否则 Text 会渲染成白色方块
        title = Text("切线样式：", font="STLiti", font_size=36)
        title.set_color_by_gradient(RED, YELLOW, GREEN)
        title.to_edge(UP, buff=0.3)
        rule = Line(LEFT * 6.5, RIGHT * 6.5, color=BLUE)
        rule.next_to(title, DOWN, buff=0.25)
        # 红色圆是切线的目标曲线，下移一点给标题留空间
        circle = Circle(radius=1.6, color=RED).shift(DOWN * 0.4)
        # alpha 是圆参数方程上的位置比例；length 决定切线向两端延伸多长
        specs = [(0, GREEN), (0.125, YELLOW), (0.375, BLUE), (0.75, PURPLE)]
        tangents = VGroup(*[
            TangentLine(circle, alpha=a, length=5.5, color=c) for a, c in specs
        ])
        self.play(Write(title), Create(rule), run_time=1)
        self.play(Create(circle), run_time=1)
        for line in tangents:
            self.play(Create(line), run_time=0.8)
        self.wait(1.6)
