from manim import *
config.background_color = WHITE

class kaestchen(Scene):
    def construct(self):

    # kaestchen
        line1 = Line([-2, 0, 0], [4, 0, 0])
        line1.set_stroke(BLACK, width=2)
        line2 = Line([-2, 0.5, 0], [-2, 0, 0])
        line2.set_stroke(BLACK, width=2)
        line3 = Line([-1, 0.5, 0], [-1, 0, 0])
        line3.set_stroke(BLACK, width=2)
        line4 = Line([0, 0.5, 0], [0, 0, 0])
        line4.set_stroke(BLACK, width=2)
        line5 = Line([1, 0.5, 0], [1, 0, 0])
        line5.set_stroke(BLACK, width=2)
        line6 = Line([2, 0.5, 0], [2, 0, 0])
        line6.set_stroke(BLACK, width=2)
        line7 = Line([3, 0.5, 0], [3, 0, 0])
        line7.set_stroke(BLACK, width=2)
        line8 = Line([4, 0.5, 0], [4, 0, 0])
        line8.set_stroke(BLACK, width=2)
        self.add(line1, line2, line3, line4, line5, line6, line7, line8)

    # elemente
        square1 = Square(side_length=0.25)
        square1.set_stroke(BLACK, width=2)
        square1.move_to([-5,2.5,0])
        square2 = Square(side_length=0.25)
        square2.set_stroke(BLACK, width=2)
        square3 = Square(side_length=0.25)
        square3.set_stroke(BLACK, width=2)
        square4 = Square(side_length=0.25)
        square4.set_stroke(BLACK, width=2)
        square2.move_to([-4.5,2.5,0])
        square3.move_to([-4,2.5,0])
        square4.move_to([-3.5,2.5,0])
        self.add(square1,square2,square3,square4)

    # elemente fliegen ins kästchenmodell
        self.play(square1.animate.shift([-1.75,0.3,0] - square1.get_center()))
        self.wait(1)
        self.play(square2.animate.shift([0.25,0.3,0] - square2.get_center()))
        self.wait(1)
        self.play(square3.animate.shift([-1.35,0.3,0] - square3.get_center()))
        self.wait(1)
        self.play(square4.animate.shift([3.25,0.3,0] - square4.get_center()))
        self.wait(1)

        self.wait(13)

    # kästchenmodell auflösen
        self.play(FadeOut(line1),FadeOut(line2),FadeOut(line8))
        self.wait(13)

    # trennstriche und elemente stauchen
        self.play(line3.animate.shift([-1.1,0.25,0] - line2.get_center()),
        square3.animate.shift([-0.35,0.3,0] - square3.get_center()),
        square1.animate.shift([-0.70,0.3,0] - square1.get_center()),
        line5.animate.shift([0.5,0.25,0] - line5.get_center()),
        square4.animate.shift([0.95,0.3,0] - square4.get_center()),
        line6.animate.shift([0.6,0.25,0] - line6.get_center()),
        line7.animate.shift([0.7,0.25,0] - line7.get_center()))

        self.wait(9)

    # arrow
        arrow1 = Arrow(start=[-0.55,-0.75,0], end=[-0.55,0.15,0], color=BLACK, max_stroke_width_to_length_ratio=10, max_tip_length_to_length_ratio=0.4)
        self.play(FadeIn(arrow1))
        self.wait(1.5)
        self.play(FadeOut(arrow1))

        arrow2 = Arrow(start=[-0.05,-0.75,0], end=[-0.05,0.15,0], color=BLACK, max_stroke_width_to_length_ratio=10, max_tip_length_to_length_ratio=0.4)
        self.play(FadeIn(arrow2))
        self.wait(1.5)
        self.play(FadeOut(arrow2))

        self.wait(20)
    # möglichkeiten simulieren
        self.play(FadeOut(line3),FadeOut(line4),FadeOut(line5),FadeOut(line6),FadeOut(line7),FadeOut(square1),FadeOut(square2),FadeOut(square3),FadeOut(square4))
        self.wait(1)

        square1.move_to([-1.75,0.3,0])
        square2.move_to([-1.4,0.3,0])
        square3.move_to([-1.05,0.3,0])
        square4.move_to([-0.7,0.3,0])
        line2.move_to([-0.45,0.3,0])
        line3.move_to([-0.35,0.3,0])
        line4.move_to([-0.25,0.3,0])
        line5.move_to([-0.15,0.3,0])
        line6.move_to([-0.05,0.3,0])

        self.play(FadeIn(square1),FadeIn(square2),FadeIn(square3),FadeIn(square4),FadeIn(line2),FadeIn(line3),FadeIn(line4),FadeIn(line5),FadeIn(line6))
        self.wait(3)

        self.play(line2.animate.shift([-0.825,0.3,0] - line2.get_center()),
        square4.animate.shift([-0.6,0.3,0] - square4.get_center()))
        self.wait(3)
