from manim import *
config.background_color = WHITE

class animation1(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(0.5)
        self.play(square2.animate.shift([0.25,0.3,0] - square2.get_center()))
        self.wait(0.5)
        self.play(square3.animate.shift([-1.35,0.3,0] - square3.get_center()))
        self.wait(0.5)
        self.play(square4.animate.shift([3.25,0.3,0] - square4.get_center()))
        self.wait(0.5)

        self.wait(1)
