from big_ol_pile_of_manim_imports import *


class PhysicsQPart1(GraphScene):
    CONFIG = {
        "y_max": 6,
        "y_min": 0,
        "x_max": 9,
        "x_min": 0,
        "y_tick_frequency": 1,
        "x_tick_frequency": 1,
        "axes_color": BLUE,
        # "y_labeled_nums": range(0,7),
        # "x_labeled_nums": range(0,10),
    }

    def construct(self):
        self.setup_axes(animate=True)
        circle = Circle()
        circle.rotate(-90*DEGREES)
        circle.move_to([-3, -1.5, 0])
        circle2 = Circle()
        circle2.move_to([-3, -1.5, 0])
        circle3 = Circle(color=YELLOW)
        circle3.rotate(-90*DEGREES)
        circle3.move_to([-3, -1.5, 0])
        circle4 = Circle()
        circle4.move_to([2, 2, 0])
        circle4.rotate(-90*DEGREES)
        semicircle = Arc(angle=PI, color=YELLOW)
        semicircle.move_to([-3, -1, 0])
        semicircle.rotate(-90*DEGREES, about_point=[-3, -1.5, 0])
        semicircle2 = semicircle.copy()
        semicircle2.move_to([-2, 1.5, 0])
        eqto = TextMobject("=")
        eqto.next_to(semicircle2, RIGHT)
        radiusLine = Line([-3, -1.5, 0], [-3+1, -1.5, 0], color=GREEN)
        radiusLetter = TexMobject("R")
        radiusLetter.scale(0.75)
        radiusLetter.next_to(radiusLine, .5*UP)
        line = Line([-3, -2.5, 0], [-3+3.14159, -2.5, 0], color=YELLOW)
        lenLine = TexMobject(r"\frac { 2 \quad }{ 2 }")
        lenLine.next_to(eqto, RIGHT)
        lenLine2 = TexMobject(r"\pi R")
        lenLine2.next_to(eqto, 2*RIGHT + .5*UP)
        dot = Dot()
        dot.move_to([-3, -2.5, 0])
        dot1 = Dot()
        dot1.move_to([-3, -1.5, 0])
        dot2 = Dot()
        dot2.move_to([-3, -2.5, 0])
        dot3 = Dot()
        dot3.move_to([2, 1, 0])
        dot4 = Dot()
        dot4.move_to([2, 3, 0])
        pir = TexMobject(r"\pi R")
        pir.next_to(eqto, RIGHT)
        pir2 = TexMobject(r"\pi R")
        pir2.next_to(line, 3*DOWN)
        pirLine = Line([-3, -2.5, 0], [-3+3.14159, -2.5, 0], color=WHITE)
        pirLine.shift(.5*DOWN)
        pirLine2 = Line([-3, -3.125, 0], [-3, -3.25, 0])
        pirLine2.shift(.25*UP)
        pirLine3 = Line([-3+3.14159, -3.25, 0], [-3+3.14159, -3.125, 0])
        pirLine3.shift(.25*UP)
        perp = Line([-3+3.14159, -2.5, 0], [-3+3.14159, -0.5, 0], color=YELLOW)
        twoR = TexMobject("2R")
        twoR.next_to(perp, RIGHT)
        rtAngle = Rectangle(height=0.25, width=0.25, color=YELLOW)
        rtAngle.rotate(180*DEGREES)
        rtAngle.move_to([-3+3.14159-0.125, -2.5+0.125, 0])
        hypo = Line([-3+3.14159, -0.5, 0], [-3, -2.5, 0], color=YELLOW)
        heqto = TexMobject("d =")
        heqto.move_to([1, 1.5, 0])
        self.play(ShowCreation(circle), run_time=2)
        self.wait()
        self.play(ShowCreation(dot1), ShowCreation(
            radiusLine), Write(radiusLetter))
        self.wait()
        self.play(ShowCreation(dot))
        self.wait()
        self.play(ShowCreation(circle3))
        self.add(dot)
        self.wait()
        self.play(FadeOut(circle3))
        self.wait()
        self.play(ShowCreation(semicircle))
        self.add(dot)
        self.wait()
        self.play(Transform(semicircle.copy(), semicircle2))
        self.wait()
        self.play(Write(eqto), Write(lenLine), Write(lenLine2))
        self.wait()
        self.play(FadeOut(lenLine), run_time=0.5)
        self.play(Transform(lenLine2, pir), run_time=0.5)
        self.wait()
        self.play(Transform(semicircle, line))
        self.play(ReplacementTransform(pir.copy(), pir2))
        self.play(ShowCreation(pirLine2), run_time=0.25)
        self.play(ShowCreation(pirLine), run_time=0.5)
        self.play(ShowCreation(pirLine3), run_time=0.25)
        self.wait()
        self.play(ShowCreation(circle4), ShowCreation(dot3))
        self.wait()
        self.play(ClockwiseTransform(dot3, dot4), run_time=2)
        self.add(circle4.rotate(180*DEGREES))
        self.add(dot4)
        self.wait()
        self.play(Uncreate(dot4), Uncreate(dot3), Uncreate(circle4))
        self.wait()
        self.play(ShowCreation(dot2), run_time=1)
        for i in range(0, 121):
            circle2.shift(0.0261799*RIGHT)
            dot2.shift(0.0261799*RIGHT)
            dot2.rotate(-1.5*DEGREES, about_point=[-3 + i*0.0261799, -1.5, 0])
            self.add(circle2, dot2)
            self.wait(0.025)
        self.remove(circle2, dot2)
        self.play(ReplacementTransform(circle2.copy(), circle2.copy().move_to(
            [-3+3.14159, -1.5, 0])), ReplacementTransform(dot2.copy(), dot2.copy().move_to([-3+3.14159, -0.5, 0])), run_time=0)
        self.remove(line)
        self.add(line)
        self.add(dot)
        self.wait()
        self.wait()


class PhysicsQPart2(Scene):
    def construct(self):
        dot = Dot()
        dot.move_to([-3, -2.5, 0])
        dot02 = Dot()
        dot02.move_to([-3+3.14159, -2.5, 0])
        dot03 = Dot()
        dot03.move_to([-3+3.14159, -0.5, 0])
        perp = Line([-3+3.14159, -2.5, 0], [-3+3.14159, -0.5, 0], color=YELLOW)
        twoR = TexMobject("2r")
        twoR.next_to(perp, RIGHT)
        rtAngle = Rectangle(height=0.25, width=0.25, color=YELLOW)
        rtAngle.rotate(180*DEGREES)
        rtAngle.move_to([-3+3.14159-0.125, -2.5+0.125, 0])
        hypo = Line([-3, -2.5, 0], [-3+3.14159, -0.5, 0], color=YELLOW)
        heqto = TexMobject("d =")
        heqto.move_to([1, 1.5, 0])
        self.add(dot)
        self.play(ShowCreation(hypo))
        self.wait()
        self.play(ReplacementTransform(dot.copy(), dot02))
        self.add(dot)
        self.wait()
        self.play(ShowCreation(perp), ShowCreation(rtAngle),
                  ReplacementTransform(dot02.copy(), dot03))
        self.add(dot02)
        self.wait()
        self.play(ReplacementTransform(hypo.copy(), heqto))
        self.add(dot)
        self.wait()


class PhysicsQuestionTitle(Scene):
    def construct(self):
        question = TextMobject(
            "A wheel of radius 'R'\\\\rolls forward\\\\half a revolution.\\\\What is the displacement\\\\of a point of the wheel\\\\initially in contact\\\\with the ground?")
        question.scale(1.25)
        question.to_edge(RIGHT, buff=1)
        question.set_color_by_gradient(
            RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
        whoGave = TextMobject(
            "Question by: SXC Physics Club - Question of the month - August 2019")
        whoGave.scale(.75)
        whoGave.to_edge(DOWN)
        self.play(Write(question), run_time=3)
        self.play(Write(whoGave))
        self.wait(3)
