from manim import *
config.background_color = WHITE

class urn(Scene):
    def construct(self):
        #group = VGroup(Dot(LEFT), Dot(ORIGIN), Dot(RIGHT, color=RED), Dot(2 * RIGHT)).scale(1.4)
        #dest = Dot([0, 5, 0], color=YELLOW)

        # urne
        line1 = Line([-4, 1, 0], [-4, -1, 0])
        line1.set_stroke(BLACK, width=2)
        line2 = Line([-4, -1, 0], [-1, -1, 0])
        line2.set_stroke(BLACK, width=2)
        line3 = Line([-1, -1, 0], [-1, 1, 0])
        line3.set_stroke(BLACK, width=2)
        self.play(FadeIn(line1),FadeIn(line2),FadeIn(line3))
        self.wait(0.5)


        # kaestchen
        line4 = Line([1.5, 0.5, 0], [5.5, 0.5, 0])
        line4.set_stroke(BLACK, width=2)
        line5 = Line([1.5, 1, 0], [1.5, 0, 0])
        line5.set_stroke(BLACK, width=2)
        line6 = Line([2.5, 1, 0], [2.5, 0, 0])
        line6.set_stroke(BLACK, width=2)
        line7 = Line([3.5, 1, 0], [3.5, 0, 0])
        line7.set_stroke(BLACK, width=2)
        line8 = Line([4.5, 1, 0], [4.5, 0, 0])
        line8.set_stroke(BLACK, width=2)
        line9 = Line([5.5, 1, 0], [5.5, 0, 0])
        line9.set_stroke(BLACK, width=2)
        self.play(FadeIn(line4), FadeIn(line5), FadeIn(line6), FadeIn(line7), FadeIn(line8), FadeIn(line9))
        lab1 = LabeledDot(MathTex("1", color=BLACK), color=WHITE).scale(1)
        lab2 = LabeledDot(MathTex("2", color=BLACK), color=WHITE).scale(1)
        lab3 = LabeledDot(MathTex("...", color=BLACK), color=WHITE).scale(1)
        lab4 = LabeledDot(MathTex("n", color=BLACK), color=WHITE).scale(1)
        lab1.move_to(2*RIGHT)
        lab2.move_to(3*RIGHT)
        lab3.move_to(4*RIGHT)
        lab4.move_to(5*RIGHT)
        self.play(FadeIn(lab1), FadeIn(lab2), FadeIn(lab3), FadeIn(lab4))
        self.wait(1)

        dot1 = LabeledDot(MathTex("1", color=WHITE), color=BLACK).scale(1)
        dot2 = LabeledDot(MathTex("2", color=WHITE), color=BLACK).scale(1)
        dot3 = LabeledDot(MathTex("3", color=WHITE), color=BLACK).scale(1)
        dot4 = LabeledDot(MathTex("4", color=WHITE), color=BLACK).scale(1)
        dot5 = LabeledDot(MathTex("n", color=WHITE), color=BLACK).scale(1)

        dot1.move_to([-2.5,0,0])
        dot2.next_to(dot1, RIGHT)
        dot3.next_to(dot1, LEFT)
        dot4.next_to(dot1, UP)
        dot5.next_to(dot2, UP)
        self.play(FadeIn(dot1), FadeIn(dot2), FadeIn(dot3), FadeIn(dot4), FadeIn(dot5))

        #circle1 = Circle(radius=0.3, color=BLACK, fill_opacity=1)
        #tex1 = MathTex(r"1", color=WHITE).scale(0.5)
        #circle2 = Circle(radius=0.3, color=BLACK, fill_opacity=1)
        #tex2 = MathTex(r"2", color=WHITE).scale(0.5)
        #circle3 = Circle(radius=0.3, color=BLACK, fill_opacity=1)
        #tex3 = MathTex(r"3", color=WHITE).scale(0.5)
        #circle4 = Circle(radius=0.3, color=BLUE_B, fill_opacity=1)
        #circle1.move_to(LEFT)
        #tex1.move_to(LEFT)
        #circle2.next_to(circle1, LEFT)
        #tex2.next_to(circle1, LEFT)
        #circle3.next_to(circle1, RIGHT)
        #tex2.next_to(circle1, RIGHT)
        #circle4.next_to(circle1, UP)

        #circle3 = Circle(radius=0.3, color=BLUE_B, fill_opacity=1)
        #circle3.shift(UP+2*LEFT)
        #circle4 = Circle(radius=0.3, color=BLUE_B, fill_opacity=1)
        #circle4.shift(DOWN+2*LEFT)
        #circle5 = Circle(radius=0.3, color=BLUE_B, fill_opacity=1)

        # kugel nr 1
        dest_2 = dot2.get_center()
        self.play(dot2.animate.shift([-2.5, 1.5, 0] - dot2.get_center()))
        self.wait(0.5)
        self.play(dot2.animate.shift([0, 1.5, 0] - dot2.get_center()))
        self.wait(0.5)
        self.play(dot2.animate.shift([0, 0, 0] - dot2.get_center()))
        self.wait(0.5)


        # 1 in zweite spalte eintragen
        strich1 = LabeledDot(MathTex("|", color=BLACK), color=WHITE).scale(0.9)
        # strich1 = LabeledDot(MathTex("1", color=BLACK), color=WHITE).scale(1)
        strich1.next_to(lab2, UP)
        self.play(FadeIn(strich1))

        # Kugel 3 zurück in die Urne
        self.play(dot2.animate.shift([0, 1.5, 0] - dot2.get_center()))
        self.wait(0.5)
        self.play(dot2.animate.shift([-1.5, 1.5, 0] - dot2.get_center()))
        self.wait(0.5)
        self.play(dot2.animate.shift(dest_2 - dot2.get_center()))
        self.wait(2)

        # kugel nr 1
        dest_1 = dot1.get_center()

        self.play(dot1.animate.shift([-1.6, 1.5, 0] - dot1.get_center()))
        self.wait(0.5)
        self.play(dot1.animate.shift([0, 1.5, 0] - dot1.get_center()))
        self.wait(0.5)
        self.play(dot1.animate.shift([0, 0, 0] - dot1.get_center()))
        self.wait(0.5)

        # 2 in erste spalte eintragen
        strich2 = LabeledDot(MathTex("|", color=BLACK), color=WHITE).scale(0.9)
        # strich2 = LabeledDot(MathTex("2", color=BLACK), color=WHITE).scale(1)
        strich2.next_to(lab1, UP)
        self.play(FadeIn(strich2))

        # Kugel 2 zurück in die Urne
        self.play(dot1.animate.shift([0, 1.5, 0] - dot1.get_center()))
        self.wait(0.5)
        self.play(dot1.animate.shift([-1.6, 1.5, 0] - dot1.get_center()))
        self.wait(0.5)
        self.play(dot1.animate.shift(dest_1 - dot1.get_center()))
        self.wait(0.5)

        self.wait(36)
