Ejemplo n.º 1
0
 def generate_points(self):
     hollow_tri = HollowTriangle(**self.triangle_config)
     bang = TexMobject("!")
     bang.set_height(hollow_tri.inner_height * 0.7)
     bang.move_to(hollow_tri.get_center_of_mass())
     self.add(hollow_tri, bang)
     self.set_color(self.color)
Ejemplo n.º 2
0
 def construct(self):
     wallis_rects_570 = WallisRectangles(order=570)
     quarter_circle = Sector(
         outer_radius=wallis_rects_570.get_height(),
         stroke_color=GREY,
         stroke_width=5.70,
         fill_opacity=0,
     )
     quarter_circle.move_arc_center_to(wallis_rects_570.get_bottom_left())
     text = TexMobject("n = 570")
     text.scale(1.5)
     text.move_to(wallis_rects_570.get_top_right())
     self.add(wallis_rects_570, quarter_circle, text)
     self.wait()
Ejemplo n.º 3
0
 def construct(self):
     wallis_rects_5 = WallisRectangles(rect_colors=[
         "#FF0000", "#FF8000", "#FFFF00", "#00FF00", "#0080FF"
     ],
                                       order=5)
     quarter_circle = Sector(
         outer_radius=wallis_rects_5.get_height(),
         stroke_color=GREY,
         stroke_width=5.70,
         fill_opacity=0,
     )
     quarter_circle.move_arc_center_to(wallis_rects_5.get_bottom_left())
     text = TexMobject("n = 5")
     text.scale(1.5)
     text.move_to(wallis_rects_5.get_top_right())
     self.add(wallis_rects_5, quarter_circle, text)
     self.wait()
Ejemplo n.º 4
0
    def construct(self):
        colors = ["#FF0000", "#FF8000", "#FFFF00", "#00FF00", "#0080FF"]
        wallis_rects_4 = WallisRectangles(
            order=5,
            rect_colors=colors,
        )
        vert_lines = VGroup(*[
            Line(3.5*UP, 3.5*DOWN, color = GREY, stroke_width = 3) \
            .next_to(wallis_rects_4.get_rectangle(0, k), direction, buff = 0)
            for k, direction in zip(list(range(5))+[4], [LEFT]*5+[RIGHT])
        ])
        horiz_lines = VGroup(*[
            Line(3.5*LEFT, 3.5*RIGHT, color = GREY, stroke_width = 3) \
            .next_to(wallis_rects_4.get_rectangle(k, 0), direction, buff = 0)
            for k, direction in zip(list(range(5))+[4], [DOWN]*5+[UP])
        ])
        for vert_line in vert_lines:
            vert_line.vertically_center()
        for horiz_line in horiz_lines:
            horiz_line.horizontally_center()
        vert_labels = VGroup(*[
            TexMobject("a_%d" % k) \
            .move_to((vert_lines[k].get_center() + vert_lines[k+1].get_center())/2) \
            .shift(3.5*DOWN)
            for k in range(5)
        ])
        horiz_labels = VGroup(*[
            TexMobject("a_%d" % k) \
            .move_to((horiz_lines[k].get_center() + horiz_lines[k+1].get_center())/2) \
            .shift(3.5*LEFT)
            for k in range(5)
        ])

        area_texs = VGroup()
        factors = [1.25, 1, 0.9, 0.7, 0.6]
        for p in range(5):
            for q in range(5 - p):
                rect = wallis_rects_4.get_rectangle(p, q)
                tex = TexMobject("{a_%d} {a_%d}" % (q, p))
                tex.scale(factors[p + q])
                tex.move_to(rect)
                area_texs.add(tex)

        figure = VGroup()
        figure.add(wallis_rects_4, vert_lines, horiz_lines, vert_labels,
                   horiz_labels, area_texs)
        figure.to_edge(LEFT)
        self.add(figure)

        tex_list = VGroup()
        for p in range(5):
            formula_string = (
                " + ".join(["a_%d a_%d" % (q, p - q)
                            for q in range(p + 1)]) + "=1")
            formula = TexMobject(formula_string)
            tex_list.add(formula)
        # tex_list.add(TexMobject("\\vdots"))
        tex_factors = np.linspace(1, 0.7, 5)
        for tex, color, factor in zip(tex_list, colors, tex_factors):
            tex.set_color(color)
            tex.scale(factor)
        tex_list.arrange_submobjects(DOWN, aligned_edge=LEFT)
        tex_list.to_edge(RIGHT)
        self.add(tex_list)
        self.wait()
Ejemplo n.º 5
0
    def add_figure(self):
        # Main figure
        wallis_rects = WallisRectangles(order=10)
        order = wallis_rects.get_order()

        # Variables and braces on the left
        left_rects = [
            wallis_rects.get_rectangle(k, 0) for k in [0, 1, 2, 3, -1]
        ]
        left_braces = [
            Brace(rect, direction=LEFT, buff=0.1) for rect in left_rects
        ]
        left_lengths = [
            TexMobject(symbol)
            for symbol in ["a_0", "a_1", "a_2", "a_3", "a_{n-1}"]
        ]
        left_lengths[-1].scale(0.7)
        for brace, length in zip(left_braces, left_lengths):
            brace.put_at_tip(length, buff=0.15)
        left_vdots = TexMobject("\\vdots")
        left_vdots.scale(2)
        left_vdots.move_to(
            (left_braces[-1].get_center() + left_braces[-2].get_center()) / 2)

        # Variables and braces on the bottom
        down_rects = [
            wallis_rects.get_rectangle(0, k) for k in [0, 1, 2, 3, -1]
        ]
        down_braces = [
            Brace(rect, direction=DOWN, buff=0.1) for rect in down_rects
        ]
        down_lengths = [
            TexMobject(symbol)
            for symbol in ["a_0", "a_1", "a_2", "a_3", "a_{n-1}"]
        ]
        down_lengths[-1].scale(0.7)
        for brace, length in zip(down_braces, down_lengths):
            brace.put_at_tip(length, buff=0.15)
        down_cdots = TexMobject("\\cdots")
        down_cdots.scale(2)
        down_cdots.move_to(
            (down_braces[-1].get_center() + down_braces[-2].get_center()) / 2)

        # The quarter circle
        quarter_circle = Sector(
            outer_radius=wallis_rects.get_height(),
            stroke_color=GREY,
            stroke_width=5.70,
            fill_opacity=0,
        )
        quarter_circle.move_arc_center_to(wallis_rects.get_bottom_left())

        # Add everthing
        figure_group = VGroup(
            wallis_rects,
            VGroup(*left_braces),
            VGroup(*left_lengths),
            left_vdots,
            VGroup(*down_braces),
            VGroup(*down_lengths),
            down_cdots,
            quarter_circle,
        )
        figure_group.center().to_edge(LEFT, buff=0.15)
        self.add(figure_group)
Ejemplo n.º 6
0
    def show_the_solution(self):
        # Prepare for the solution
        pre_solve = VGroup(*self.question[::2])
        self.play(
            ReplacementTransform(pre_solve, self.solve),
            FadeOut(self.question[1]),
            run_time = 1,
        )
        self.wait()

        # Manipulate LHS
        old_l_part, r_part = self.equation
        new_l_part = ExpTower(order = self.highest_order+1, is_infinite = True)
        new_l_part.match_height(old_l_part)
        new_l_part.next_to(r_part, LEFT, aligned_edge = DOWN)
        old_rect, new_rect = rects = [
            CoverRectangle(part, text = "2")
            for part in (old_l_part, new_l_part.get_exponent())
        ]
        old_two, new_two = twos = [
            rect.get_text_mob()
            for rect in rects
        ]
        self.play(DrawBorderThenFill(old_rect, run_time = 1))
        self.wait()
        self.play(
            ReplacementTransform(old_l_part, new_l_part),
            ReplacementTransform(old_rect, new_rect),
        )
        self.wait()
        new_equation = VGroup(new_l_part, r_part, new_rect)
        new_equation.generate_target()
        new_equation.target.scale(0.8)
        new_equation.target.shift(UP)
        self.play(MoveToTarget(new_equation))
        self.wait()

        # A little bit clean-up
        source_eq = VGroup(*[
            mob.copy()
            for mob in (new_l_part.get_base(), new_two, r_part[0], r_part[1])
        ])
        source_eq.generate_target()
        target_eq = TexMobject("x", "^2", "=", "2")
        target_eq.scale(3).next_to(source_eq, DOWN, buff = 1)
        for k, (old_part, new_part) in enumerate(zip(source_eq.target, target_eq)):
            old_part.move_to(new_part)
            if k == 1:
                old_part.scale(0.5)
                old_part.shift(RIGHT/4)
        self.play(
            FadeOut(new_rect),
            MoveToTarget(source_eq),
        )
        self.wait()

        # Reveal the final answer
        result = TexMobject("x", "=", "\\sqrt", "2")
        result.set_height(source_eq.get_height() * 0.7)
        result.move_to(source_eq)
        self.play(*[
            ReplacementTransform(source_eq[m], result[n], path_arc = angle)
            for m, n, angle in [(0, 0, 0), (1, 2, -TAU/3), (2, 1, 0), (3, 3, 0)]
        ])
        self.wait()
        qed = QEDSymbol()
        qed.next_to(result, RIGHT, aligned_edge = DOWN, buff = 1.5)
        self.play(FadeIn(qed))
        self.wait()