from manim import *
import numpy as np
import sympy as sp
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 InterceptCompare(Scene):
    def construct(self):
        self.add(head("一次函数：不同截距对比", "y = kx + b"))
        axes = Axes(x_range=[-5, 5, 1], y_range=[-5, 5, 1], x_length=7.6, y_length=5.2,
                    axis_config={"color": GREY_B})
        bs = [3, 0, -2]
        cols = [RED, BLUE, TEAL]
        lines = VGroup()
        for b, c in zip(bs, cols):
            g = axes.plot(lambda t, b=b: 0.8 * t + b, x_range=[-4.5, 4.5], color=c)
            g.set_stroke(width=5)
            lines.add(g)
        dots = VGroup(*[Dot(axes.c2p(0, b), color=c, radius=0.12)
                        for b, c in zip(bs, cols)])
        self.add(axes)
        self.play(LaggedStart(*[Create(g) for g in lines], lag_ratio=0.3), run_time=3.2)
        self.play(LaggedStart(*[FadeIn(d, scale=2) for d in dots], lag_ratio=0.2),
                  run_time=1.4)
        self.play(FadeIn(foot("b 决定直线与 y 轴的交点，k 不变则彼此平行")), run_time=0.4)
        self.wait(1.0)
