from manim import *
import functools
Text = functools.partial(Text, font="Comic Sans")
config.tex_template = TexFontTemplates.comfortaa
class S1(Scene):
    def construct(self):
        t1 = Tex("Staircase Paradox").scale(2.5).to_edge(UP).set_color(RED)
        t2 = Tex("Requirements", r": Pythagoras theorem and logic").scale(1).set_color(BLUE)
        t3 = Tex("Paradox",r": It is a mathematical conclusion \\ so unexpected that it is difficult to accept even \\ though every step in the reasoning is valid.").scale(0.75).set_color(GREEN)
        t2[0].set_color(YELLOW)
        t3[0].set_color(GOLD)
        V1 = VGroup(t1, t2, t3).arrange(DOWN, buff=1)
        self.play(Write(V1, run_time=4.5))
        self.wait(5.5)
        self.play(FadeOut(V1))
class S2(Scene):
    def construct(self):
        stair = Polygon([0,0,0],[2,0,0],[2,-1.5,0],[-2,-1.5,0],[-2,1.5,0],[0,1.5,0])
        self.play(Create(stair,run_time=5))
        self.wait(2)
        t1 = MathTex("4").set_color(YELLOW).scale(1.5).shift(DOWN*2)
        t2 = MathTex("3").set_color(YELLOW).scale(1.5).shift(LEFT * 2.5)
        self.play(FadeIn(t1),FadeIn(t2),run_time = 1.5)
        self.wait(1.5)
        s2 = Polygon([-2,1.5,0],[0,1.5,0],[0,0,0],[2,0,0],[2,-1.5,0],stroke_width=5).set_color(RED_E).set_points_as_corners(([-2,1.5,0],[0,1.5,0],[0,0,0],[2,0,0],[2,-1.5,0]))
        self.add(s2)
        self.wait()
        V1 = VGroup(stair,t1,t2)
        self.play(s2.animate.shift(RIGHT*2.5),V1.animate.shift(LEFT*2.5))
        self.wait(1.5)
        l1 = Polygon([-2,1.5,0],[0,1.5,0])
        l2 = Polygon([0,1.5,0],[0,0,0])
        l3 = Polygon([0,0,0],[2,0,0])
        l4 = Polygon([2,0,0],[2,-1.5,0])
        V2 = VGroup(l1,l2,l3,l4).move_to(s2).set_color(RED_E)
        self.remove(s2)
        self.add(V2)
        self.play(l2.animate.shift(RIGHT*2),l3.animate.shift(UP*1.5),run_time = 2.5)
        self.wait()
        t3 = MathTex("4").set_color(GOLD).scale(1.5).next_to(V2,UP)
        t4 = MathTex("3").set_color(GOLD).scale(1.5).next_to(V2,RIGHT)
        self.play(FadeIn(t3),FadeIn(t4))
        self.wait()
        self.play(Indicate(t3),Indicate(t4))
        V3 = VGroup(V1,V2,t3,t4)
        t5 = Tex("Length of stair $= 4+3 = 7$").next_to(V3,DOWN)
        self.play(V3.animate.shift(UP*1.5),Write(t5))
        self.wait()
        self.play(FadeOut(V1,V2,V3,t5))
class S3(Scene):
    def construct(self):
        tri1 = Triangle()
        tri2 = Triangle().rotate(PI).move_to([0,-0.25,0])
        l1 = Line(stroke_width=5).rotate(30*DEGREES).set_color(PURPLE)
        l2 = Line(stroke_width=5).rotate(150*DEGREES).set_color(PURPLE)
        l3 = Line(stroke_width=5).rotate(PI/2).set_color(PURPLE)
        l4 = DashedVMobject(Polygon([0,1,0],[0.86602540378,0.5,0],[0.86602540378,-0.5,0],[0,-1,0],[-0.86602540378,-0.5,0],[-0.86602540378,0.5,0]),num_dashes=100).set_color(WHITE)
        V = VGroup(tri1,tri2,l1,l2,l3,l4).scale(3)
        self.add(V)
class S4(Scene):
    def construct(self):
        stair = Polygon([0,0,0],[1,0,0],[1,-3/4,0],[2,-3/4,0],[2,-3/2,0],[-2,-3/2,0],[-2,3/2,0],[-1,3/2,0],[-1,3/4,0],[0,3/4,0])
        self.play(Create(stair,run_time=5))
        self.wait(2)
        t1 = MathTex("4").set_color(YELLOW).scale(1.5).shift(DOWN*2)
        t2 = MathTex("3").set_color(YELLOW).scale(1.5).shift(LEFT * 2.5)
        self.play(FadeIn(t1),FadeIn(t2),run_time = 1.5)
        self.wait(1.5)
        s2 = Polygon([-2,3/2,0],[-1,3/2,0],[-1,3/4,0],[0,3/4,0],[0,0,0],[1,0,0],[1,-3/4,0],[2,-3/4,0],[2,-3/2,0],stroke_width=5).set_color(RED_E).set_points_as_corners(([-2,3/2,0],[-1,3/2,0],[-1,3/4,0],[0,3/4,0],[0,0,0],[1,0,0],[1,-3/4,0],[2,-3/4,0],[2,-3/2,0]))
        self.add(s2)
        self.wait()
        V1 = VGroup(stair,t1,t2)
        self.play(s2.animate.shift(RIGHT*2.5),V1.animate.shift(LEFT*2.5))
        self.wait(1.5)
        s3 = Polygon([-2,3/2,0],[2,3/2,0],[2,-3/2,0],stroke_width=5).set_points_as_corners(([-2,3/2,0],[2,3/2,0],[2,-3/2,0])).move_to(s2).set_color(ORANGE)
        self.play(TransformFromCopy(s2,s3),run_time = 2)
        self.wait()
        t3 = MathTex("4").set_color(GOLD).scale(1.5).next_to(s3,UP)
        t4 = MathTex("3").set_color(GOLD).scale(1.5).next_to(s3,RIGHT)
        self.play(FadeIn(t3),FadeIn(t4))
        self.wait()
        self.play(Indicate(t3),Indicate(t4))
        self.add(Tex("Therefore length of stair $=4+3 = 7$").to_edge(DOWN))
        self.wait(2)
class S5(Scene):
    def construct(self):
        tri = Polygon([0,0,0],[2,-1.5,0],[-2,-1.5,0],[-2,1.5,0],stroke_width=5)
        self.play(Create(tri))
        t1 = MathTex("4").set_color(YELLOW).scale(1.5).shift(DOWN * 2)
        t2 = MathTex("3").set_color(YELLOW).scale(1.5).shift(LEFT * 2.5)
        t3 = MathTex("7").set_color(YELLOW).scale(1.5).shift(RIGHT+UP)
        self.play(FadeIn(t1), FadeIn(t2), FadeIn(t3),run_time=1.5)
        self.wait(1.5)
        V1 = VGroup(tri,t1,t2,t3)
        t4 = MathTex("\\text{Acc. to pythagoras} \\\\ \sqrt{4^2+3^2} = 5").next_to(V1,buff=0.2).scale(0.75).set_color(GREEN).shift(UP)
        self.play(Write(t4),V1.animate.shift(LEFT*1.5),run_time = 3.5)
        self.wait(3.5)
        t5 = Tex("$5 = 7 ?$").next_to(V1,DOWN)
        self.play(Create(t5))
        self.wait(3.5)
        self.play(FadeOut(t4,t5))
        self.wait(1.5)
        t6 = Text("No matter how small \nit is, the staircase \nwill never become \na straight line.").next_to(V1)
        self.play(Write(t6,run_time=2.5))
        self.wait(3.5)
        self.play(FadeOut(V1,t6))
        t7 = Text("It's not a paradox, even if there are infinitely \nmany steps then there is an infinitesimal amount of distance \nsaved through the diagonal of each tiny step, and if each \nof these units are added up infinitely we will get \nthe desired result due to the fact infinite values don't have defined values, \nbut a good question to ask people to see how they think.",line_spacing=2).scale(0.5)
        self.play(Write(t7,run_time=1))
        self.wait(9)