from manim import *
from manim import DARK_GREY, LIGHT_GREY, BLUE, PURPLE
config.background_color = WHITE

class sim(Scene):
    def construct(self):
        # erste stufe
        line1 = Line([-4, 0, 0], [-1,1.5,0])
        line2 = Line([-4, 0, 0], [-1,0,0])
        line3 = Line([-4, 0, 0], [-1,-1.5,0])
        line1.set_stroke(BLACK, width=1.5)
        line2.set_stroke(BLACK, width=1.5)
        line3.set_stroke(BLACK, width=1.5)
        dot1 = Dot(point=[-1,1.5,0], color='BLACK')
        dot2 = Dot(point=[-1,0,0], color='BLACK')
        dot3 = Dot(point=[-1,-1.5,0], color='BLACK')


        # Ergebnisse
        tex1 = MathTex(r"A_1", color=BLACK).scale(1)
        tex2 = MathTex(r"A_2", color=BLACK).scale(1)
        tex3 = MathTex(r"A_3", color=BLACK).scale(1)
        tex1.move_to([-0.5,1.5,0])
        tex2.move_to([-0.5,0,0])
        tex3.move_to([-0.5,-1.5,0])


        # beschriftung pfade stufe 1
        # Texte an Ästen
        tex1a = MathTex(r"P(A_1)", color=BLACK).scale(0.6)
        tex2a = MathTex(r"P(A_2)", color=BLACK).scale(0.6)
        tex3a = MathTex(r"P(A_3)", color=BLACK).scale(0.6)
        tex1a.move_to([-2.25,1.2,0]).rotate(PI/7)
        tex2a.move_to([-2.25,0.25,0])
        tex3a.move_to([-2.25,-0.6,0]).rotate(-PI/7)

        # zweite stufe
        line4 = Line([-0.2,1.5,0], [2,2,0])
        line5 = Line([-0.2,1.5,0], [2,1,0])
        line6 = Line([-0.2,0,0], [2,0.5,0])
        line7 = Line([-0.2,0,0], [2,-0.5,0])
        line8 = Line([-0.2,-1.5,0], [2,-1,0])
        line9 = Line([-0.2,-1.5,0], [2,-2,0])
        line4.set_stroke(BLACK, width=1.5)
        line5.set_stroke(BLACK, width=1.5)
        line6.set_stroke(BLACK, width=1.5)
        line7.set_stroke(BLACK, width=1.5)
        line8.set_stroke(BLACK, width=1.5)
        line9.set_stroke(BLACK, width=1.5)
        dot4 = Dot(point=[2,2,0], color='BLACK')
        dot5 = Dot(point=[2,1,0], color='BLACK')
        dot6 = Dot(point=[2,0.5,0], color='BLACK')
        dot7 = Dot(point=[2,-0.5,0], color='BLACK')
        dot8 = Dot(point=[2,-1,0], color='BLACK')
        dot9 = Dot(point=[2,-2,0], color='BLACK')


        # Ergebnisse
        tex4 = MathTex(r"B_1", color=BLACK).scale(1)
        tex5 = MathTex(r"B_2", color=BLACK).scale(1)
        tex6 = MathTex(r"B_1", color=BLACK).scale(1)
        tex7 = MathTex(r"B_2", color=BLACK).scale(1)
        tex8 = MathTex(r"B_1", color=BLACK).scale(1)
        tex9 = MathTex(r"B_2", color=BLACK).scale(1)
        tex4.move_to([2.5,2,0])
        tex5.move_to([2.5,1,0])
        tex6.move_to([2.5,0.5,0])
        tex7.move_to([2.5,-0.5,0])
        tex8.move_to([2.5,-1,0])
        tex9.move_to([2.5,-2,0])


        # beschriftung pfade stufe 2
        tex4a = MathTex(r"P(B_1|A_1)", color=BLACK).scale(0.6)
        tex4b = MathTex(r"P(B_2|A_1)", color=BLACK).scale(0.6)
        tex5a = MathTex(r"P(B_1|A_2)", color=BLACK).scale(0.6)
        tex5b = MathTex(r"P(B_2|A_2)", color=BLACK).scale(0.6)
        tex6a = MathTex(r"P(B_1|A_3)", color=BLACK).scale(0.6)
        tex6b = MathTex(r"P(B_2|A_3)", color=BLACK).scale(0.6)
        tex4a.move_to([0.5,2,0]).rotate(PI/14)
        tex4b.move_to([0.5,1,0]).rotate(-PI/14)
        tex5a.move_to([0.5,0.5,0]).rotate(PI/14)
        tex5b.move_to([0.5,-0.5,0]).rotate(-PI/14)
        tex6a.move_to([0.5,-1,0]).rotate(PI/14)
        tex6b.move_to([0.5,-2,0]).rotate(-PI/14)
        self.play(FadeIn(line1,line2,line3,dot1,dot2,dot3),
        FadeIn(tex1,tex2,tex3,tex1a,tex2a,tex3a))
        self.wait(1.5)
        self.play(FadeIn(tex4a,tex4b,tex5a,tex5b,tex6a,tex6b),FadeIn(line4),FadeIn(line5),FadeIn(line6),FadeIn(line7),FadeIn(line8),FadeIn(line9),
        FadeIn(dot4),FadeIn(dot5),FadeIn(dot6),FadeIn(dot7),FadeIn(dot8),FadeIn(dot9),
        FadeIn(tex4),FadeIn(tex5),FadeIn(tex6),FadeIn(tex7),FadeIn(tex8),FadeIn(tex9))

        self.wait(1.5)
        self.play(FadeOut(tex1,tex1a,tex2,tex2a,tex3,tex3a,tex4,tex5,tex6,tex7,tex8,tex9,tex4a,tex4b,tex5a,tex5b,tex6a,tex6b),
        FadeOut(line1,line2,line3,line4,line5,line6,line7,line8,line9),FadeOut(dot1,dot2,dot3,dot4,dot5,dot6,dot7,dot8,dot9))
        self.wait(1.5)

        # Baum umgekehrt aufbauen
        line6 = Line([-4,0,0], [-1,1.5,0])
        line7 = Line([-4,0,0], [-1,-1.5,0])
        line6.set_stroke(BLACK, width=1.5)
        line7.set_stroke(BLACK, width=1.5)
        dot6 = Dot(point=[-1,1.5,0], color='BLACK')
        dot7 = Dot(point=[-1,-1.5,0], color='BLACK')
        tex6 = MathTex(r"B_1", color=BLACK).scale(1)
        tex7 = MathTex(r"B_2", color=BLACK).scale(1)
        tex6.move_to([-0.5,1.5,0])
        tex7.move_to([-0.5,-1.5,0])
        # beschriftung pfade stufe 1
        tex1a = MathTex(r"P(B_1)", color=BLACK).scale(0.6)
        tex2a = MathTex(r"P(B_2)", color=BLACK).scale(0.6)
        tex1a.move_to([-2.5,1.1,0]).rotate(PI/6)
        tex2a.move_to([-2.5,-1.1,0]).rotate(-PI/6)
        self.play(FadeIn(line6,line7,dot6,dot7,tex6,tex7,tex1a,tex2a))

        line1 = Line([0, 1.5, 0], [3,2.5,0])
        line2 = Line([0, 1.5, 0], [3,1.5,0])
        line3 = Line([0, 1.5, 0], [3,0.5,0])
        line1.set_stroke(BLACK, width=1.5)
        line2.set_stroke(BLACK, width=1.5)
        line3.set_stroke(BLACK, width=1.5)
        dot1 = Dot(point=[3,2.5,0], color='BLACK')
        dot2 = Dot(point=[3,1.5,0], color='BLACK')
        dot3 = Dot(point=[3,0.5,0], color='BLACK')

        line1b = Line([0, -1.5, 0], [3,-0.5,0])
        line2b = Line([0, -1.5, 0], [3,-1.5,0])
        line3b = Line([0, -1.5, 0], [3,-2.5,0])
        line1b.set_stroke(BLACK, width=1.5)
        line2b.set_stroke(BLACK, width=1.5)
        line3b.set_stroke(BLACK, width=1.5)
        dot1b = Dot(point=[3,-0.5,0], color='BLACK')
        dot2b = Dot(point=[3,-1.5,0], color='BLACK')
        dot3b = Dot(point=[3,-2.5,0], color='BLACK')

        # beschriftung pfade stufe 2
        tex1d = MathTex(r"P(A_1|B_1)", color=BLACK).scale(0.6)
        tex2d = MathTex(r"P(A_2|B_1)", color=BLACK).scale(0.6)
        tex3d = MathTex(r"P(A_3|B_1)", color=BLACK).scale(0.6)
        tex1d.move_to([1.7,2.3,0]).rotate(PI/10)
        tex2d.move_to([1.7,1.7,0])
        tex3d.move_to([1.7,1.1,0]).rotate(-PI/10)
        tex1e = MathTex(r"P(A_1|B_2)", color=BLACK).scale(0.6)
        tex2e = MathTex(r"P(A_2|B_2)", color=BLACK).scale(0.6)
        tex3e = MathTex(r"P(A_3|B_2)", color=BLACK).scale(0.6)
        tex1e.move_to([1.7,-0.7,0]).rotate(PI/10)
        tex2e.move_to([1.7,-1.3,0])
        tex3e.move_to([1.7,-1.85,0]).rotate(-PI/10)

        # Ergebnisse
        tex1b = MathTex(r"A_1", color=BLACK).scale(1)
        tex2b = MathTex(r"A_2", color=BLACK).scale(1)
        tex3b = MathTex(r"A_3", color=BLACK).scale(1)
        tex1b.move_to([3.5,2.5,0])
        tex2b.move_to([3.5,1.5,0])
        tex3b.move_to([3.5,0.5,0])
        tex1c = MathTex(r"A_1", color=BLACK).scale(1)
        tex2c = MathTex(r"A_2", color=BLACK).scale(1)
        tex3c = MathTex(r"A_3", color=BLACK).scale(1)
        tex1c.move_to([3.5,-0.5,0])
        tex2c.move_to([3.5,-1.5,0])
        tex3c.move_to([3.5,-2.5,0])

        self.play(FadeIn(line1,line2,line3,line1b,line2b,line3b,dot1,dot2,dot3,dot1b,dot2b,dot3b,tex1b,tex2b,tex3b,tex1c,tex2c,tex3c,tex1d,tex2d,tex3d,tex1e,tex2e,tex3e))


        self.wait(10)
