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,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.play(FadeOut(tex4a,tex4b,tex5a,tex5b,tex6a,tex6b))

        # Beschriftung Pfade Stufe 2 ändern
        tex4a = MathTex(r"P(B_1)", color=BLACK).scale(0.6)
        tex4b = MathTex(r"P(B_2)", color=BLACK).scale(0.6)
        tex5a = MathTex(r"P(B_1)", color=BLACK).scale(0.6)
        tex5b = MathTex(r"P(B_2)", color=BLACK).scale(0.6)
        tex6a = MathTex(r"P(B_1)", color=BLACK).scale(0.6)
        tex6b = MathTex(r"P(B_2)", 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(tex4a,tex4b,tex5a,tex5b,tex6a,tex6b))
        self.wait(5)
