def generate_symbol(self):
     symbol = VGroup(*[
         RegularPolygon(
             n=3, stroke_width=0, fill_color=self.color, fill_opacity=1)
         for i in range(2)
     ])
     symbol.arrange_submobjects(RIGHT, buff=0)
     symbol.set_height(self.inner_radius * 0.7)
     return symbol
Example #2
0
 def generate_symbol(self):
     symbol = VGroup(*[
         Rectangle(
             length = 2, width = 0.5, stroke_width = 0,
             fill_color = self.color, fill_opacity = 1,
         )
         for i in range(2)
     ])
     symbol.arrange_submobjects(RIGHT, buff = 0.5)
     symbol.set_height(self.inner_radius)
     return symbol
Example #3
0
 def arrange_subparts(self, *subparts):
     for i, piece in enumerate(subparts):
         piece.rotate(i * np.pi / 12, about_point=ORIGIN)
     p1, p2, p3, p4, p5, p6, p7 = subparts
     center_row = VGroup(p1, p4, p7)
     center_row.arrange_submobjects(RIGHT, buff=0)
     for p in p2, p3, p5, p6:
         p.set_width(p1.get_width())
     p2.move_to(p1.get_top(), DOWN + LEFT)
     p3.move_to(p1.get_bottom(), UP + LEFT)
     p5.move_to(p4.get_top(), DOWN + LEFT)
     p6.move_to(p4.get_bottom(), UP + LEFT)
    def construct(self):
        line1 = TextMobject(r"The vector $\vec{F}_{net}$ is the net ", "force",
                            " on object of mass ")
        line1.set_color_by_tex("force", BLUE)

        line2 = TextMobject("$m$", " and acceleration ", r"$\vec{a}$", ".")
        line2.set_color_by_tex_to_color_map({"m": YELLOW, "{a}": RED})

        sentence = VGroup(line1, line2)
        sentence.arrange_submobjects(DOWN, buff=MED_LARGE_BUFF)
        self.play(Write(sentence))
        self.wait(3)
    def construct(self):
        line1 = TexMobject(
            r"\text{The vector } \vec{F}_{net} \text{ is the net }",
            r"\text{force}", r"\text{ on object of mass }")
        line1.set_color_by_tex("force", BLUE)

        line2 = TexMobject("m", r"\text{ and acceleration }", r"\vec{a}", ".")
        line2.set_color_by_tex_to_color_map({"m": YELLOW, "{a}": RED})

        sentence = VGroup(line1, line2)
        sentence.arrange_submobjects(DOWN, buff=MED_LARGE_BUFF)
        self.play(Write(sentence))
        self.wait(3)
Example #6
0
 def add_remark(self):
     nl_text = TextMobject("数轴")
     nl_arrow = Arrow(ORIGIN, UP).match_height(nl_text)
     nl_remark = VGroup(nl_arrow, nl_text)
     nl_remark.scale(0.8)
     nl_remark.set_color(LIGHT_GREY)
     nl_remark.arrange_submobjects(RIGHT, buff = 0.1)
     nl_remark.next_to(self.axes.coords_to_point(0, 0), DOWN, buff = 0.1)
     nl_remark.to_edge(LEFT, buff = 0.15)
     frac_remark = TextMobject("圆内分数为圆心横坐标")
     frac_remark.scale(0.6)
     frac_remark.to_corner(DL, buff = 0.15)
     farey_sum_remark = TexMobject(
         "\\text{Farey Sum: }", "\\dfrac{a}{b} \\oplus \\dfrac{c}{d}", "=", "\\dfrac{a+c}{b+d}"
     )
     farey_sum_remark[1].set_color(YELLOW)
     farey_sum_remark[-1].set_color(PINK)
     farey_sum_remark.to_corner(DR, buff = 0.15)
     self.add(nl_remark, frac_remark, farey_sum_remark)
Example #7
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=3,
            stroke_color=BLACK,
            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)

        thanks = TextMobject(self.thanks_words)
        thanks.scale(0.9)
        thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF)
        thanks.set_color(YELLOW)
        underline = Line(LEFT, RIGHT)
        underline.match_width(thanks)
        underline.scale(1.1)
        underline.next_to(thanks, DOWN, SMALL_BUFF)
        thanks.add(underline)

        patrons = VGroup(*list(map(TextMobject, self.specific_patrons)))
        patrons.scale(self.patron_scale_val)
        for patron in patrons:
            if patron.get_width() > self.max_patron_width:
                patron.set_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,
        )
        if columns.get_width() > self.max_patron_width:
            columns.set_width(total_width - 1)

        thanks.to_edge(RIGHT)
        columns.next_to(thanks, DOWN, 3 * LARGE_BUFF)

        columns.generate_target()
        columns.target.move_to(2 * DOWN, DOWN)
        columns.target.align_to(thanks, alignment_vect=RIGHT)
        vect = columns.target.get_center() - columns.get_center()
        distance = get_norm(vect)
        wait_time = 20
        columns_shift = ContinualMovement(columns,
                                          direction=normalize(vect),
                                          rate=(distance / wait_time))

        self.add(columns_shift, black_rect, line, thanks)
        self.wait(wait_time)
Example #8
0
 def construct_infinite_sum(self):
     for n in range(1, 11):
         # Get highlighted terms
         highlighted_terms = self.get_highlighted_terms(n)
         # Update highlight rectangles
         if n == 1:
             rects = self.get_highlight_rectangles(1)
             self.play(ShowCreation(rects), lag_ratio=0.2)
             self.wait()
         else:
             new_rects = self.get_highlight_rectangles(n)
             self.play(Transform(rects, new_rects))
             if n <= 4:
                 self.wait()
         # Show the detailed construction of the first four terms
         if n <= 4:
             # Make copies of the elements that are going to be moved
             highlighted_terms_copy = self.get_highlighted_terms(
                 n).deepcopy()
             times_symbols_copy = self.get_times_symbols().deepcopy()
             cdots_copy = self.get_cdots_symbol().deepcopy()
             # Move highlighted terms into position
             arranged_terms_list = []
             for i in range(4):
                 arranged_terms_list.append(highlighted_terms_copy[i])
                 arranged_terms_list.append(times_symbols_copy[i])
             arranged_terms_list.append(cdots_copy)
             arranged_terms = VGroup(*arranged_terms_list)
             arranged_terms.arrange_submobjects(RIGHT, buff=0.2)
             arranged_terms.next_to(self.sum_tex,
                                    UP,
                                    aligned_edge=RIGHT,
                                    buff=0.5)
             # Move highlighted terms into position
             anims_list = []
             for i in range(4):
                 anims_list.append(
                     ReplacementTransform(
                         self.get_highlighted_terms(n)[i].deepcopy(),
                         arranged_terms[2 * i],
                         lag_ratio=0,
                         run_time=2))
                 anims_list.append(
                     ReplacementTransform(
                         self.get_times_symbols()[i].deepcopy(),
                         arranged_terms[2 * i + 1],
                         lag_ratio=0,
                         run_time=2))
             anims_list.append(
                 ReplacementTransform(self.get_cdots_symbol().deepcopy(),
                                      arranged_terms[-1],
                                      lag_ratio=0,
                                      run_time=2))
             self.play(AnimationGroup(*anims_list))
             self.wait()
             if n == 1:
                 self.play(Transform(arranged_terms, self.get_sum_term(n)))
             else:
                 self.play(
                     Transform(arranged_terms, self.get_sum_term(n)),
                     Write(self.get_plus_symbol(n - 1)),
                 )
             self.wait()
         # And show the result for the remaining terms
         else:
             self.play(
                 Transform(
                     VGroup(
                         self.get_highlighted_terms(n).deepcopy(),
                         self.get_times_symbols().deepcopy(),
                         self.get_cdots_symbol().deepcopy(),
                     ),
                     self.get_sum_term(n),
                     lag_ratio=0,
                 ),
                 Write(self.get_plus_symbol(n - 1)),
             )
     # Add \cdots to the end.
     self.wait()
     self.play(FadeOut(rects), Write(self.sum_tex[-1][-4:]))
     self.wait()
Example #9
0
class TeacherStudentsScene(PiCreatureScene):
    CONFIG = {
        "student_colors": [BLUE_D, BLUE_E, BLUE_C],
        "teacher_color": GREY_BROWN,
        "student_scale_factor": 0.8,
        "seconds_to_blink": 2,
        "screen_height": 3,
    }

    def setup(self):
        PiCreatureScene.setup(self)
        self.screen = ScreenRectangle(height=self.screen_height)
        self.screen.to_corner(UP + LEFT)
        self.hold_up_spot = self.teacher.get_corner(UP +
                                                    LEFT) + MED_LARGE_BUFF * UP

    def create_pi_creatures(self):
        self.teacher = Mortimer(color=self.teacher_color)
        self.teacher.to_corner(DOWN + RIGHT)
        self.teacher.look(DOWN + LEFT)
        self.students = VGroup(
            *[Randolph(color=c) for c in self.student_colors])
        self.students.arrange_submobjects(RIGHT)
        self.students.scale(self.student_scale_factor)
        self.students.to_corner(DOWN + LEFT)
        self.teacher.look_at(self.students[-1].eyes)
        for student in self.students:
            student.look_at(self.teacher.eyes)

        return [self.teacher] + list(self.students)

    def get_teacher(self):
        return self.teacher

    def get_students(self):
        return self.students

    def teacher_says(self, *content, **kwargs):
        return self.pi_creature_says(self.get_teacher(), *content, **kwargs)

    def student_says(self, *content, **kwargs):
        if "target_mode" not in kwargs:
            target_mode = random.choice([
                "raise_right_hand",
                "raise_left_hand",
            ])
            kwargs["target_mode"] = target_mode
        student = self.get_students()[kwargs.get("student_index", 1)]
        return self.pi_creature_says(student, *content, **kwargs)

    def teacher_thinks(self, *content, **kwargs):
        return self.pi_creature_thinks(self.get_teacher(), *content, **kwargs)

    def student_thinks(self, *content, **kwargs):
        student = self.get_students()[kwargs.get("student_index", 1)]
        return self.pi_creature_thinks(student, *content, **kwargs)

    def change_all_student_modes(self, mode, **kwargs):
        self.change_student_modes(*[mode] * len(self.students), **kwargs)

    def change_student_modes(self, *modes, **kwargs):
        added_anims = kwargs.pop("added_anims", [])
        self.play(self.get_student_changes(*modes, **kwargs), *added_anims)

    def get_student_changes(self, *modes, **kwargs):
        pairs = list(zip(self.get_students(), modes))
        pairs = [(s, m) for s, m in pairs if m is not None]
        start = VGroup(*[s for s, m in pairs])
        target = VGroup(*[s.copy().change_mode(m) for s, m in pairs])
        if "look_at_arg" in kwargs:
            for pi in target:
                pi.look_at(kwargs["look_at_arg"])
        submobject_mode = kwargs.get("submobject_mode", "lagged_start")
        return Transform(start,
                         target,
                         submobject_mode=submobject_mode,
                         run_time=2)

    def zoom_in_on_thought_bubble(self,
                                  bubble=None,
                                  radius=FRAME_Y_RADIUS + FRAME_X_RADIUS):
        if bubble is None:
            for pi in self.get_pi_creatures():
                if hasattr(pi, "bubble") and isinstance(
                        pi.bubble, ThoughtBubble):
                    bubble = pi.bubble
                    break
            if bubble is None:
                raise Exception("No pi creatures have a thought bubble")
        vect = -bubble.get_bubble_center()

        def func(point):
            centered = point + vect
            return radius * centered / get_norm(centered)

        self.play(
            *
            [ApplyPointwiseFunction(func, mob) for mob in self.get_mobjects()])

    def teacher_holds_up(self,
                         mobject,
                         target_mode="raise_right_hand",
                         added_anims=None,
                         **kwargs):
        mobject.move_to(self.hold_up_spot, DOWN)
        mobject.shift_onto_screen()
        mobject_copy = mobject.copy()
        mobject_copy.shift(DOWN)
        mobject_copy.fade(1)
        added_anims = added_anims or []
        self.play(ReplacementTransform(mobject_copy, mobject),
                  self.teacher.change, target_mode, *added_anims)
Example #10
0
 def organize_matrices(self, left, right, result):
     equals = TexMobject("=")
     everything = VGroup(left, right, equals, result)
     everything.arrange_submobjects()
     everything.set_width(FRAME_WIDTH - 1)
     self.add(everything)