Esempio n. 1
0
    def construct(self):
        formula = TexMobject(*([
            "{%d \\over %d} \\cdot" % (wallis_numer(n), wallis_denom(n))
            for n in range(1, self.n_terms + 1)
        ] + ["\\cdots"]))
        result = TexMobject("=", "{\\pi \\over 2}")
        result.scale(2)
        pi = result[-1][0]
        pi.set_color(YELLOW)
        circle = Circle(color=YELLOW)
        circle.surround(pi)
        question = TexMobject("?", color=YELLOW)
        question.scale(2).next_to(circle, RIGHT, buff=0.4)
        result_group = VGroup(result, circle, question)
        result_group.next_to(formula, DOWN)
        group = VGroup(formula, result_group)
        group.center().set_width(10)
        bg_rect = BackgroundRectangle(group, fill_opacity=0.5, buff=0.2)

        random_walks = VGroup(*[
            RandomWalk1DArrow(random_walk_string(30), step_size=0.5)
            for k in range(self.n_walks)
        ])
        for k, walk in enumerate(random_walks):
            walk.shift(random.randrange(-5, 5) * 2 * walk.step_size * UP)
        random_walks.center()

        text = TextMobject(self.part).scale(3).set_color(YELLOW)
        text.to_corner(RIGHT + DOWN)

        self.add(random_walks)
        self.add(FullScreenFadeRectangle())
        self.add(bg_rect, group, text)
Esempio n. 2
0
    def scroll_through_patrons(self):
        logo_box = Square(side_length=2.5)
        logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF)
        total_width = FRAME_X_RADIUS - logo_box.get_right()[0]

        black_rect = Rectangle(
            fill_color=BLACK,
            fill_opacity=1,
            stroke_width=0,
            width=FRAME_WIDTH,
            height=0.6 * FRAME_HEIGHT,
        )
        black_rect.to_edge(UP, buff=0)
        line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT)
        line.move_to(ORIGIN)
        self.add(line)

        thanks = TextMobject("Funded by the community, with special thanks to:")
        thanks.scale(0.9)
        thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF)
        thanks.set_color(YELLOW)
        underline = Line(LEFT, RIGHT)
        underline.scale_to_fit_width(thanks.get_width() + MED_SMALL_BUFF)
        underline.next_to(thanks, DOWN, SMALL_BUFF)
        thanks.add(underline)
        self.add(thanks)

        patrons = VGroup(*map(TextMobject, self.specific_patrons))
        patrons.scale(self.patron_scale_val)
        for patron in patrons:
            if patron.get_width() > self.max_patron_width:
                patron.scale_to_fit_width(self.max_patron_width)
        columns = VGroup(*[
            VGroup(*patrons[i::self.n_patron_columns])
            for i in range(self.n_patron_columns)
        ])
        for column in columns:
            for n, name in enumerate(column):
                name.shift(n * self.name_y_spacing * DOWN)
        columns.arrange_submobjects(
            RIGHT, buff=LARGE_BUFF,
            aligned_edge=UP,
        )
        columns.scale_to_fit_width(total_width - 1)
        columns.next_to(black_rect, DOWN, 3 * LARGE_BUFF)
        columns.to_edge(RIGHT)

        thanks.align_to(columns, alignment_vect=RIGHT)

        self.play(
            columns.move_to, 2 * DOWN, DOWN,
            columns.to_edge, RIGHT,
            Animation(black_rect),
            Animation(line),
            Animation(thanks),
            rate_func=None,
            run_time=self.run_time,
        )
Esempio n. 3
0
    def generate_points(self):
        body = Cube(side_length=1)
        for dim, scale_factor in enumerate(self.body_dimensions):
            body.stretch(scale_factor, dim=dim)
        body.scale_to_fit_width(self.width)
        body.set_fill(self.shaded_body_color, opacity=1)
        body.sort_submobjects(lambda p: p[2])
        body[-1].set_fill(self.body_color)
        screen_plate = body.copy()
        keyboard = VGroup(*[
            VGroup(*[
                Square(**self.key_color_kwargs)
                for x in range(12 - y % 2)
            ]).arrange_submobjects(RIGHT, buff=SMALL_BUFF)
            for y in range(4)
        ]).arrange_submobjects(DOWN, buff=MED_SMALL_BUFF)
        keyboard.stretch_to_fit_width(
            self.keyboard_width_to_body_width * body.get_width(),
        )
        keyboard.stretch_to_fit_height(
            self.keyboard_height_to_body_height * body.get_height(),
        )
        keyboard.next_to(body, OUT, buff=0.1 * SMALL_BUFF)
        keyboard.shift(MED_SMALL_BUFF * UP)
        body.add(keyboard)

        screen_plate.stretch(self.screen_thickness /
                             self.body_dimensions[2], dim=2)
        screen = Rectangle(
            stroke_width=0,
            fill_color=BLACK,
            fill_opacity=1,
        )
        screen.replace(screen_plate, stretch=True)
        screen.scale_in_place(self.screen_width_to_screen_plate_width)
        screen.next_to(screen_plate, OUT, buff=0.1 * SMALL_BUFF)
        screen_plate.add(screen)
        screen_plate.next_to(body, UP, buff=0)
        screen_plate.rotate(
            self.open_angle, RIGHT,
            about_point=screen_plate.get_bottom()
        )
        self.screen_plate = screen_plate
        self.screen = screen

        axis = Line(
            body.get_corner(UP + LEFT + OUT),
            body.get_corner(UP + RIGHT + OUT),
            color=BLACK,
            stroke_width=2
        )
        self.axis = axis

        self.add(body, screen_plate, axis)
        self.rotate(5 * np.pi / 12, LEFT, about_point=ORIGIN)
        self.rotate(np.pi / 6, DOWN, about_point=ORIGIN)
Esempio n. 4
0
    def generate_points(self):
        body = Cube(side_length=1)
        for dim, scale_factor in enumerate(self.body_dimensions):
            body.stretch(scale_factor, dim=dim)
        body.scale_to_fit_width(self.width)
        body.set_fill(self.shaded_body_color, opacity=1)
        body.sort_submobjects(lambda p: p[2])
        body[-1].set_fill(self.body_color)
        keyboard = VGroup(*[
            VGroup(*[
                Square(**self.key_color_kwargs)
                for x in range(12 - y % 2)
            ]).arrange_submobjects(RIGHT, buff=SMALL_BUFF)
            for y in range(4)
        ]).arrange_submobjects(DOWN, buff=MED_SMALL_BUFF)
        keyboard.stretch_to_fit_width(
            self.keyboard_width_to_body_width * body.get_width(),
        )
        keyboard.stretch_to_fit_height(
            self.keyboard_height_to_body_height * body.get_height(),
        )
        keyboard.next_to(body, OUT, buff=0.1 * SMALL_BUFF)
        keyboard.shift(MED_SMALL_BUFF * UP)
        body.add(keyboard)

        screen_plate = body.copy()
        screen_plate.stretch(self.screen_thickness /
                             self.body_dimensions[2], dim=2)
        screen = Rectangle(
            stroke_width=0,
            fill_color=BLACK,
            fill_opacity=1,
        )
        screen.replace(screen_plate, stretch=True)
        screen.scale_in_place(self.screen_width_to_screen_plate_width)
        screen.next_to(screen_plate, OUT, buff=0.1 * SMALL_BUFF)
        screen_plate.add(screen)
        screen_plate.next_to(body, UP, buff=0)
        screen_plate.rotate(
            self.open_angle, RIGHT,
            about_point=screen_plate.get_bottom()
        )
        self.screen_plate = screen_plate
        self.screen = screen

        axis = Line(
            body.get_corner(UP + LEFT + OUT),
            body.get_corner(UP + RIGHT + OUT),
            color=BLACK,
            stroke_width=2
        )
        self.axis = axis

        self.add(body, screen_plate, axis)
        self.rotate(5 * np.pi / 12, LEFT, about_point=ORIGIN)
        self.rotate(np.pi / 6, DOWN, about_point=ORIGIN)
Esempio n. 5
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)
Esempio n. 6
0
    def scroll_through_patrons(self):
        logo_box = Square(side_length=2.5)
        logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF)
        total_width = FRAME_X_RADIUS - logo_box.get_right()[0]

        black_rect = Rectangle(fill_color=BLACK,
                               fill_opacity=1,
                               stroke_width=0,
                               width=FRAME_WIDTH,
                               height=1.1 * FRAME_Y_RADIUS)
        black_rect.to_edge(UP, buff=0)
        line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT)
        line.move_to(black_rect, DOWN)
        line.shift(SMALL_BUFF * SMALL_BUFF * DOWN)
        self.add(line)

        patrons = VGroup(*map(TextMobject, self.specific_patrons))
        patrons.scale(self.patron_scale_val)
        for patron in patrons:
            if patron.get_width() > self.max_patron_width:
                patron.scale_to_fit_width(self.max_patron_width)
        columns = VGroup(*[
            VGroup(*patrons[i::self.n_patron_columns])
            for i in range(self.n_patron_columns)
        ])
        for column in columns:
            for n, name in enumerate(column):
                name.shift(n * self.name_y_spacing * DOWN)
        columns.arrange_submobjects(
            RIGHT,
            buff=LARGE_BUFF,
            aligned_edge=UP,
        )
        columns.scale_to_fit_width(total_width - 1)
        columns.next_to(black_rect, DOWN, 3 * LARGE_BUFF)
        columns.to_edge(RIGHT)

        self.play(
            columns.move_to,
            2 * DOWN,
            DOWN,
            columns.to_edge,
            RIGHT,
            Animation(black_rect),
            rate_func=None,
            run_time=self.run_time,
        )