예제 #1
0
    def rhs_could_be_any_number(self):
        rhs_list = [
            "2",         # The journey starts here.
            "3",         # The first number that pops into your head when you hear "2".
            "\\pi",      # The good ol' pi.
            "\\sqrt{2}", # The (most) famous irrational number.
            "42",        # The answer to everything.
            "17.29",     # TAXI.CAB
            "-1",        # A negative number, because why not?
            "e",         # The (most) famous mathematical constant.
            "\\dfrac{3+\\sqrt{13}}{2}", # The bronze ratio... and a fraction.
            "570",       # 1/3 of the author.
            "\\varphi",  # The golden ratio.
            "g_{64}",    # Gigigigigigigigantic...
            "0",         # And... stop!
            "N",
        ]
        anything_text = TextMobject("等号右边似乎可以放任何数...")
        anything_text.set_color(YELLOW)
        anything_text.to_edge(UP)
        equations = [
            VGroup(ExpTower(order = 5), TexMobject("=", rhs).scale(0.8)).scale(2.5)
            for rhs in rhs_list
        ]
        init_equation = equations[0]
        init_equation.arrange_submobjects(RIGHT, aligned_edge = DOWN)
        init_equation.next_to(anything_text, DOWN, buff = self.tower_edge_buff)
        init_equation.to_edge(LEFT, buff = self.tower_edge_buff)
        for equation in equations:
            equation[0].move_to(init_equation[0])
            equation[1][0].move_to(init_equation[1][0])
            equation[1][1].move_to(init_equation[1][1], aligned_edge = LEFT)

        self.play(FadeIn(init_equation))
        self.wait()
        self.play(Write(anything_text), run_time = 1)
        self.play(
            ShowCreationThenDestruction(SurroundingRectangle(init_equation[1][1])),
            run_time = 2
        )
        self.wait()
        for k, equation in enumerate(equations):
            if k > 0 and k != len(equations)-1:
                equation[0].move_to(init_equation[0])
                equation[1].move_to(init_equation[1], aligned_edge = LEFT)
                self.remove(equations[k-1])
                self.add(equations[k])
                self.wait(1./3)
            elif k == len(equations)-1:
                self.wait()
                self.play(ReplacementTransform(equations[k-1], equations[k]))
                self.wait()

        self.anything_text = anything_text
        self.equation = equations[-1]
예제 #2
0
 def generate_points(self):
     rect = SurroundingRectangle(self.covered_mob)
     rect.set_stroke(color = self.stroke_color, width = self.stroke_width)
     rect.set_fill(color = self.fill_color, opacity = self.fill_opacity)
     text = TextMobject(str(self.text))
     text.set_color(self.text_color)
     text.set_height(rect.get_height() * self.text_height_factor)
     text.move_to(rect)
     self.group = VGroup(rect, text)
     self.add(self.group)
예제 #3
0
    def add_words(self):
        # Wallis product
        product = TexMobject(*(["\\text{Wallis公式:}"] + [
            "{%d \\over %d} \\," % (wallis_numer(n), wallis_denom(n))
            for n in range(1, 8)
        ] + ["\\cdots = {\\pi \\over 2}"])).set_color(YELLOW)
        rect = SurroundingRectangle(product, color=YELLOW, buff=0.25)
        wallis_product = VGroup(product, rect)
        wallis_product.set_width(6)

        # All those steps
        nums = [TextMobject("%d. " % k) for k in [1, 2, 3, 4]]
        words = [
            TextMobject(word) for word in [
                "构造合适的矩形边长",
                "同种颜色的矩形的面积之和恒为1",
                "整个图形又像一个${1 \\over 4}$圆,半径是",
                "比较${1 \\over 4}$圆与矩形的面积",
            ]
        ]
        formulae = [
            TextMobject(formula) for formula in [
                "$a_0 = 1,\\, a_n = {1 \\over 2} \cdot {3 \\over 4} \cdots {2n-1 \\over 2n} (n \geq 1)$",
                "$a_0 a_n + a_1 a_{n-1} + \\cdots + a_n a_0 = 1$",
                "$\\begin{aligned} \
                r_n & = a_0 + a_1 + \\cdots + a_{n-1} \\\\ \
                    & = \\textstyle{3 \\over 2} \cdot {5 \\over 4} \cdots {2n-1 \\over 2n-2} \
                    \\quad (n \geq 2) \
                \\end{aligned}$",
                "${1 \\over 4} \\pi {r_n}^2 \\approx n \\quad \\Rightarrow \\quad \\text{Wallis公式}$"
            ]
        ]

        steps = VGroup()
        for num, word, formula in zip(nums, words, formulae):
            num.next_to(word, LEFT)
            formula.next_to(word, DOWN, aligned_edge=LEFT)
            steps.add(VGroup(num, word, formula))
        steps.arrange_submobjects(DOWN, buff=0.6, aligned_edge=LEFT)
        steps.set_width(6)
        steps.next_to(wallis_product, DOWN)
        VGroup(wallis_product, steps).center().to_edge(RIGHT, buff=0.15)

        # Sep line and QED
        sep_line = DashedLine(2 * TOP, 2 * BOTTOM, color=GREY, buff=0.5)
        sep_line.next_to(steps, LEFT)
        qed = QEDSymbol(height=0.570 / 2)
        qed.next_to(steps[-1][-1][-1], RIGHT, aligned_edge=DOWN)

        # Add everything
        self.add(wallis_product, steps, sep_line, qed)
예제 #4
0
    def build_the_tower(self):
        highest_order = 6
        towers = [
            ExpTower(order = k, is_infinite = False)
            for k in range(1, highest_order + 1)
        ]
        towers.append(ExpTower(order = highest_order, is_infinite = True))
        heights = list(np.linspace(3, 4.5, highest_order + 2))
        for tower, height in zip(towers, heights):
            tower.set_height(height)

        init_tower = towers[0]
        final_tower = towers[-1]
        self.play(Write(init_tower))
        self.wait()
        for k, tower in enumerate(towers):
            if k < len(towers) - 2:
                new_tower = towers[k+1]
                new_exponent = new_tower.get_exponent()
                new_base = new_tower.get_base()
                self.play(
                    ReplacementTransform(tower, new_exponent),
                    Write(new_base),
                )
                self.wait()
            else:
                xs = final_tower.get_elements()
                expdots = final_tower.get_expdots()
                sur_rect = SurroundingRectangle(expdots)
                self.play(
                    ReplacementTransform(tower, xs, run_time = 1),
                    Write(expdots, run_time = 2),
                )
                self.play(
                    Indicate(expdots, run_time = 1),
                    ShowCreationThenDestruction(sur_rect, run_time = 2),
                )
                self.wait()
                break
        self.tower = final_tower
        self.highest_order = highest_order
예제 #5
0
    def construct(self):
        # Chart on the left
        colors = [WHITE, ORANGE, GREEN]
        titles = VGroup(*[
            TexMobject(text).set_color(color)
            for text, color in zip(["n", "p_n", "q_n"], colors)
        ])
        contents = VGroup(*[
            VGroup(*[
                TexMobject("%d" % num) for num in
                [k, central_binomial_coeff(k),
                 central_binomial_coeff(k)]
            ]) for k in range(8)
        ])
        titles.arrange_submobjects(RIGHT, buff=1)
        for num, line in enumerate(contents):
            for k, element in enumerate(line):
                buff = 0.6 + 0.8 * num
                element.next_to(titles[k], DOWN, aligned_edge=LEFT, buff=buff)
                element.set_color(colors[k])
        sep_line = Line(ORIGIN, 4.5 * RIGHT, stroke_width=5)
        sep_line.next_to(titles, DOWN)
        chart = VGroup(titles, contents, sep_line)
        chart.set_height(7)
        chart.center().to_edge(LEFT)
        self.add(chart)

        # Figures on the right
        std_zero_pos_axis = NumberLine(x_min=-2,
                                       x_max=2,
                                       color=GREY,
                                       unit_size=0.25,
                                       tick_size=0.05)
        std_zero_pos_axis.rotate(np.pi / 2)
        std_nocross_pos_axis = NumberLine(x_min=-4,
                                          x_max=4,
                                          color=GREY,
                                          unit_size=0.25,
                                          tick_size=0.05)
        std_nocross_pos_axis.rotate(np.pi / 2)
        std_time_axis = NumberLine(x_min=0,
                                   x_max=5.5,
                                   color=GREY,
                                   unit_size=0.25,
                                   tick_size=0.05)
        std_zero_axes = VGroup(std_zero_pos_axis, std_time_axis)
        std_nocross_axes = VGroup(std_nocross_pos_axis, std_time_axis)

        zero_walks = VGroup()
        for sequence in ["UUDD", "UDUD", "UDDU", "DDUU", "DUDU", "DUUD"]:
            axes = std_zero_axes.copy()
            zero_walk = RandomWalk1DArrow(sequence, step_size=0.25)
            zero_walk.move_start_to(axes[0].number_to_point(0))
            zero_walks.add(VGroup(axes, zero_walk))
        zero_walks.arrange_submobjects_in_grid(2, 3, buff=0.5)
        zero_rect = SurroundingRectangle(zero_walks, color=ORANGE, buff=0.4)
        zero_walks.add(zero_rect)

        nocross_walks = VGroup()
        for sequence in ["DDDD", "DDUD", "DDDU", "UUUU", "UUDU", "UUUD"]:
            axes = std_nocross_axes.copy()
            nocross_walk = RandomWalk1DArrow(sequence, step_size=0.25)
            nocross_walk.move_start_to(axes[0].number_to_point(0))
            nocross_walks.add(VGroup(axes, nocross_walk))
        nocross_walks.arrange_submobjects_in_grid(2, 3, buff=0.5)
        nocross_rect = SurroundingRectangle(nocross_walks,
                                            color=GREEN,
                                            buff=0.4)
        nocross_walks.add(nocross_rect)

        relation = TexMobject("p_2", "=", "q_2", "=", "6")
        relation[0].set_color(ORANGE)
        relation[2].set_color(GREEN)
        relation.scale(1.5)
        figure = VGroup(zero_walks, relation, nocross_walks)
        figure.arrange_submobjects(DOWN)
        figure.set_height(7)
        figure.center().to_edge(RIGHT)

        self.add(figure)
        self.wait()
예제 #6
0
 def add_display_frame(self, **kwargs):
     config = dict(self.default_display_frame_config)
     config.update(kwargs)
     self.display_frame = SurroundingRectangle(self, **config)
     self.add(self.display_frame)
     return self
예제 #7
0
 def __init__(self, mobject, **kwargs):
     digest_config(self, kwargs)
     rect = SurroundingRectangle(mobject,
                                 **self.surrounding_rectangle_config)
     AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))