from manim import *


class LSgraph1(Scene):
    def construct(self):
        # self.camera.background_color = "WHITE"
        ax = Axes(
            x_range=[-0.3, 10.3, 1],
            y_range=[-0.3, 5.3, 1],
            x_length=10.6,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )

        self.camera.background_color = WHITE

        axes_lables = ax.get_axis_labels().set_color(BLACK)

        dot1 = Dot(point=ax.c2p(2, 1.3, 0), color=BLUE)
        dot2 = Dot(point=ax.c2p(3, 1.6, 0), color=BLUE)
        dot3 = Dot(point=ax.c2p(5, 2.0, 0), color=BLUE)
        dot4 = Dot(point=ax.c2p(8, 4.7, 0), color=BLUE)
        dot5 = Dot(point=ax.c2p(10, 4.2, 0), color=BLUE)

        function_graph = ax.plot(lambda x: 0.5 * x, color=BLACK)

        plot = VGroup(ax, axes_lables, dot1, dot2, dot3, dot4, dot5, function_graph)
        self.add(plot)


class LSgraph2(ThreeDScene):
    def construct(self):
        # self.camera.background_color = "WHITE"
        ax = ThreeDAxes(
            x_range=[-0.3, 10.3, 1],
            y_range=[-0.3, 10.3, 1],
            z_range=[-0.3, 10.3, 1],
            x_length=10.6,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )

        self.camera.background_color = WHITE
        self.set_camera_orientation(
            phi=56 * DEGREES, theta=-30 * DEGREES, gamma=-7 * DEGREES, zoom=0.5
        )

        axes_lables = ax.get_axis_labels().set_color(BLACK)

        plane = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[2, 8],
            v_range=[2, 8],
            checkerboard_colors=[BLUE, BLUE],
            fill_opacity=0.75,
            stroke_width=0,
        )

        vector = Arrow3D(ax.c2p(3, 3, 0), ax.c2p(6, 6, 3), color=RED)
        vector1 = Arrow3D(ax.c2p(3, 3, 0), ax.c2p(6, 6, 0), color=GREEN)

        line = Line(ax.c2p(6, 6, 0), ax.c2p(6, 6, 3), color=ORANGE)

        self.add(ax, axes_lables, vector, vector1, plane, line)


class Detgraph1(Scene):
    def construct(self):
        ax = Axes(
            x_range=[-5.3, 5.3, 1],
            y_range=[-5.3, 5.3, 1],
            x_length=7,
            y_length=7,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )
        x = ax.get_x_axis()
        x.numbers.set_color(BLACK)
        y = ax.get_y_axis()
        y.numbers.set_color(BLACK)

        self.camera.background_color = WHITE

        axes_lables = ax.get_axis_labels().set_color(BLACK)

        vec1 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(0, 1, 0), color=RED)
        vec2 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 0, 0), color=BLUE)

        plane = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[0, 1],
            v_range=[0, 1],
            checkerboard_colors=[GREEN, GREEN],
            fill_opacity=0.75,
            stroke_width=0,
        )

        text = MathTex(
            r"\begin{bmatrix} 1 & 0\\ 0 & 1\end{bmatrix}", color=BLACK
        ).move_to(ax.c2p(-2, 2, 0))

        self.add(ax, axes_lables, vec1, vec2, plane, text)


class Detgraph2(Scene):
    def construct(self):
        ax = Axes(
            x_range=[-5.3, 5.3, 1],
            y_range=[-5.3, 5.3, 1],
            x_length=7,
            y_length=7,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )
        x = ax.get_x_axis()
        x.numbers.set_color(BLACK)
        y = ax.get_y_axis()
        y.numbers.set_color(BLACK)
        self.camera.background_color = WHITE
        axes_lables = ax.get_axis_labels().set_color(BLACK)

        vec1 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(0, 1, 0), color=RED)
        vec2 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 0, 0), color=BLUE)
        plane1 = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[0, 1],
            v_range=[0, 1],
            checkerboard_colors=[GREEN, GREEN],
            fill_opacity=0.75,
            stroke_width=0,
        )

        vec3 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(0, 2, 0), color=PURPLE)
        vec4 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(3, 0, 0), color=PINK)
        plane2 = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[0, 3],
            v_range=[0, 2],
            checkerboard_colors=[YELLOW, YELLOW],
            fill_opacity=0.75,
            stroke_width=0,
        )

        text = MathTex(
            r"\mathbf{A} \begin{bmatrix} 3 & 0\\ 0 & 2\end{bmatrix}", color=BLACK
        ).move_to(ax.c2p(-2.5, 2, 0))

        self.add(ax, axes_lables, plane2, plane1, vec4, vec3, vec2, vec1, text)


class Detgraph3(Scene):
    def construct(self):
        ax = Axes(
            x_range=[-5.3, 5.3, 1],
            y_range=[-5.3, 5.3, 1],
            x_length=7,
            y_length=7,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )
        x = ax.get_x_axis()
        x.numbers.set_color(BLACK)
        y = ax.get_y_axis()
        y.numbers.set_color(BLACK)
        self.camera.background_color = WHITE
        axes_lables = ax.get_axis_labels().set_color(BLACK)

        vec1 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(0, 1, 0), color=RED)
        vec2 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 0, 0), color=BLUE)
        plane1 = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[0, 1],
            v_range=[0, 1],
            checkerboard_colors=[GREEN, GREEN],
            fill_opacity=0.75,
            stroke_width=0,
        )

        vec3 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 1, 0), color=PURPLE)
        vec4 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 0, 0), color=PINK)
        plane2 = Polygon(
            ax.c2p(0, 0, 0),
            ax.c2p(1, 0, 0),
            ax.c2p(2, 1, 0),
            ax.c2p(1, 1, 0),
            fill_color=YELLOW,
            fill_opacity=0.75,
            color=YELLOW,
        )

        text = MathTex(
            r"\mathbf{B} \begin{bmatrix} 1 & 1\\ 0 & 1\end{bmatrix}", color=BLACK
        ).move_to(ax.c2p(-2.5, 2, 0))

        self.add(ax, axes_lables, plane2, plane1, vec4, vec3, vec2, vec1, text)


class Detgraph4(Scene):
    def construct(self):
        ax = Axes(
            x_range=[-5.3, 5.3, 1],
            y_range=[-5.3, 5.3, 1],
            x_length=7,
            y_length=7,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )
        x = ax.get_x_axis()
        x.numbers.set_color(BLACK)
        y = ax.get_y_axis()
        y.numbers.set_color(BLACK)
        self.camera.background_color = WHITE
        axes_lables = ax.get_axis_labels().set_color(BLACK)

        vec1 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(0, 1, 0), color=RED)
        vec2 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 0, 0), color=BLUE)
        plane1 = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[0, 1],
            v_range=[0, 1],
            checkerboard_colors=[GREEN, GREEN],
            fill_opacity=0.75,
            stroke_width=0,
        )

        vec3 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 1, 0), color=PURPLE)
        vec4 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(2, -1, 0), color=PINK)
        plane2 = Polygon(
            ax.c2p(0, 0, 0),
            ax.c2p(2, -1, 0),
            ax.c2p(3, 0, 0),
            ax.c2p(1, 1, 0),
            fill_color=YELLOW,
            fill_opacity=0.75,
            color=YELLOW,
        )

        text = MathTex(
            r"\mathbf{C} \begin{bmatrix} 1 & 2\\ 1 & -1\end{bmatrix}", color=BLACK
        ).move_to(ax.c2p(-2.5, 2, 0))

        self.add(ax, axes_lables, plane2, plane1, vec4, vec3, vec2, vec1, text)


class Detgraph5(Scene):
    def construct(self):
        ax = Axes(
            x_range=[-5.3, 5.3, 1],
            y_range=[-5.3, 5.3, 1],
            x_length=7,
            y_length=7,
            axis_config={
                "include_numbers": True,
                "color": BLACK,
            },
        )
        x = ax.get_x_axis()
        x.numbers.set_color(BLACK)
        y = ax.get_y_axis()
        y.numbers.set_color(BLACK)
        self.camera.background_color = WHITE
        axes_lables = ax.get_axis_labels().set_color(BLACK)

        vec1 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(0, 1, 0), color=RED)
        vec2 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(1, 0, 0), color=BLUE)
        plane1 = Surface(
            lambda u, v: ax.c2p(u, v, u * 0),
            u_range=[0, 1],
            v_range=[0, 1],
            checkerboard_colors=[GREEN, GREEN],
            fill_opacity=0.75,
            stroke_width=0,
        )

        vec3 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(4, 2, 0), color=PURPLE)
        vec4 = Arrow3D(start=ax.c2p(0, 0, 0), end=ax.c2p(2, 1, 0), color=PINK)

        text = MathTex(
            r"\mathbf{C} \begin{bmatrix} 4 & 2\\ 2 & 1\end{bmatrix}", color=BLACK
        ).move_to(ax.c2p(-2.5, 2, 0))

        self.add(ax, axes_lables, plane1, vec3, vec4, vec2, vec1, text)


class Detgraph6(Scene):
    def construct(self):
        self.camera.background_color = WHITE

        text1 = MathTex(
            r"\begin{bmatrix} a & b & c\\ d & e & f\\ g & h & i\\ \end{bmatrix} \begin{matrix} a & b\\ d & e\\ g & h\\ \end{matrix}",
            color=BLACK,
        ).scale(0.5)
        text2 = (
            MathTex(
                r"\Rightarrow a \cdot e \cdot i + b \cdot f \cdot g + c \cdot d \cdot h - g \cdot e \cdot c - h \cdot f \cdot a - i \cdot d \cdot b",
                color=BLACK,
            )
            .move_to([0, -1, 0])
            .scale(0.5)
        )

        arrow1 = Arrow(
            [0, 0, 0],
            [1.2, -0.9, 0],
            max_tip_length_to_length_ratio=0.1,
            stroke_width=0.7,
            color=RED,
        ).move_to([-0.4, -0.1, 0])
        arrow2 = Arrow(
            [0, 0, 0],
            [1.2, -0.9, 0],
            max_tip_length_to_length_ratio=0.1,
            stroke_width=0.7,
            color=RED,
        ).move_to([0, -0.1, 0])
        arrow3 = Arrow(
            [0, 0, 0],
            [1.2, -0.9, 0],
            max_tip_length_to_length_ratio=0.1,
            stroke_width=0.7,
            color=RED,
        ).move_to([0.4, -0.1, 0])

        arrow4 = Arrow(
            [0, 0, 0],
            [1.2, 0.9, 0],
            max_tip_length_to_length_ratio=0.1,
            stroke_width=0.7,
            color=BLUE,
        ).move_to([-0.3, -0.1, 0])
        arrow5 = Arrow(
            [0, 0, 0],
            [1.2, 0.9, 0],
            max_tip_length_to_length_ratio=0.1,
            stroke_width=0.7,
            color=BLUE,
        ).move_to([0.1, -0.1, 0])
        arrow6 = Arrow(
            [0, 0, 0],
            [1.2, 0.9, 0],
            max_tip_length_to_length_ratio=0.1,
            stroke_width=0.7,
            color=BLUE,
        ).move_to([0.5, -0.1, 0])

        self.add(text1, text2, arrow1, arrow2, arrow3, arrow4, arrow5, arrow6)


class Detgraph7(Scene):
    def construct(self):
        self.camera.background_color = WHITE

        text1 = MathTex(
            r"\begin{bmatrix} a & b & 0 & 0\\ c & d & 0 & 0 \\ 0 & 0 & e & f \\ 0 & 0 & g & h \end{bmatrix}",
            color=BLACK,
        ).scale(0.5)
        text2 = (
            MathTex(
                r"\Rightarrow \text{det } \begin{bmatrix} a & b \\ c & d \end{bmatrix} \cdot \text{det } \begin{bmatrix} e & f \\ g & h \end{bmatrix}",
                color=BLACK,
            )
            .move_to([0, -1, 0])
            .scale(0.5)
        )

        box1 = Polygon([0, 0, 0], [0.6, 0, 0], [0.6, 0.6, 0], [0, 0.6, 0]).move_to(
            [-0.36, 0.3, 0]
        )
        box2 = Polygon(
            [0, 0, 0], [0.6, 0, 0], [0.6, 0.6, 0], [0, 0.6, 0], color=RED
        ).move_to([0.36, -0.3, 0])
        box3 = Polygon([0, 0, 0], [0.6, 0, 0], [0.6, 0.6, 0], [0, 0.6, 0]).move_to(
            [-0.3, -1, 0]
        )
        box4 = Polygon(
            [0, 0, 0], [0.6, 0, 0], [0.6, 0.6, 0], [0, 0.6, 0], color=RED
        ).move_to([1.13, -1, 0])

        self.add(text1, text2, box1, box2, box3, box4)
