Esempio n. 1
0
 def get_quote(self, max_width=FRAME_WIDTH - 1):
     text_mobject_kwargs = {
         "alignment": "",
         "arg_separator": self.quote_arg_separator,
     }
     if isinstance(self.quote, str):
         if self.use_quotation_marks:
             quote = TextMobject("``%s''" %
                                 self.quote.strip(), **text_mobject_kwargs)
         else:
             quote = TextMobject("%s" %
                                 self.quote.strip(), **text_mobject_kwargs)
     else:
         if self.use_quotation_marks:
             words = [self.text_size + " ``"] + list(self.quote) + ["''"]
         else:
             words = [self.text_size] + list(self.quote)
         quote = TextMobject(*words, **text_mobject_kwargs)
         # TODO, make less hacky
         if self.quote_arg_separator == " ":
             quote[0].shift(0.2 * RIGHT)
             quote[-1].shift(0.2 * LEFT)
     for term, color in self.highlighted_quote_terms:
         quote.set_color_by_tex(term, color)
     quote.to_edge(UP, buff=self.top_buff)
     if quote.get_width() > max_width:
         quote.set_width(max_width)
     return quote
Esempio n. 2
0
 def add_title(self, title, scale_factor=1.5, animate=False):
     if not isinstance(title, Mobject):
         title = TextMobject(title).scale(scale_factor)
     title.to_edge(UP)
     title.add_background_rectangle()
     if animate:
         self.play(Write(title))
     self.add_foreground_mobject(title)
     self.title = title
     return self
Esempio n. 3
0
    def setup(self):
        MovingCameraScene.setup(self)
        frame = self.camera_frame
        frame.shift(DOWN)

        self.logo = Logo()
        name = TextMobject("3Blue1Brown")
        name.scale(2.5)
        name.next_to(self.logo, DOWN, buff=MED_LARGE_BUFF)
        name.set_sheen(-0.2, DR)
        self.channel_name = name
Esempio n. 4
0
 def add_title(self, title="Sample space", buff=MED_SMALL_BUFF):
     # TODO, should this really exist in SampleSpaceScene
     title_mob = TextMobject(title)
     if title_mob.get_width() > self.get_width():
         title_mob.set_width(self.get_width())
     title_mob.next_to(self, UP, buff=buff)
     self.title = title_mob
     self.add(title_mob)
Esempio n. 5
0
    def get_corner_numbers(self, value, symbol):
        value_mob = TextMobject(value)
        width = self.get_width() / self.card_width_to_corner_num_width
        height = self.get_height() / self.card_height_to_corner_num_height
        value_mob.set_width(width)
        value_mob.stretch_to_fit_height(height)
        value_mob.next_to(
            self.get_corner(UP + LEFT), DOWN + RIGHT,
            buff=MED_LARGE_BUFF * width
        )
        value_mob.set_color(symbol.get_color())
        corner_symbol = symbol.copy()
        corner_symbol.set_width(width)
        corner_symbol.next_to(
            value_mob, DOWN,
            buff=MED_SMALL_BUFF * width
        )
        corner_group = VGroup(value_mob, corner_symbol)
        opposite_corner_group = corner_group.copy()
        opposite_corner_group.rotate(
            np.pi, about_point=self.get_center()
        )

        return VGroup(corner_group, opposite_corner_group)
Esempio n. 6
0
def get_det_text(matrix, determinant=None, background_rect=False, initial_scale_factor=2):
    parens = TexMobject("(", ")")
    parens.scale(initial_scale_factor)
    parens.stretch_to_fit_height(matrix.get_height())
    l_paren, r_paren = parens.split()
    l_paren.next_to(matrix, LEFT, buff=0.1)
    r_paren.next_to(matrix, RIGHT, buff=0.1)
    det = TextMobject("det")
    det.scale(initial_scale_factor)
    det.next_to(l_paren, LEFT, buff=0.1)
    if background_rect:
        det.add_background_rectangle()
    det_text = VGroup(det, l_paren, r_paren)
    if determinant is not None:
        eq = TexMobject("=")
        eq.next_to(r_paren, RIGHT, buff=0.1)
        result = TexMobject(str(determinant))
        result.next_to(eq, RIGHT, buff=0.2)
        det_text.add(eq, result)
    return det_text
Esempio n. 7
0
 def get_author(self, quote):
     author = TextMobject(self.text_size + " --" + self.author)
     author.next_to(quote, DOWN, buff=self.author_buff)
     author.set_color(YELLOW)
     return author
Esempio n. 8
0
 def write(self, *text):
     self.add_content(TextMobject(*text))
     return self
Esempio n. 9
0
 def get_quote(self, max_width=FRAME_WIDTH - 1):
     text_mobject_kwargs = {
         "alignment": "",
         "arg_separator": self.quote_arg_separator,
     }
     if isinstance(self.quote, str):
         if self.use_quotation_marks:
             quote = TextMobject("``%s''" % self.quote.strip(),
                                 **text_mobject_kwargs)
         else:
             quote = TextMobject("%s" % self.quote.strip(),
                                 **text_mobject_kwargs)
     else:
         if self.use_quotation_marks:
             words = [self.text_size + " ``"] + list(self.quote) + ["''"]
         else:
             words = [self.text_size] + list(self.quote)
         quote = TextMobject(*words, **text_mobject_kwargs)
         # TODO, make less hacky
         if self.quote_arg_separator == " ":
             quote[0].shift(0.2 * RIGHT)
             quote[-1].shift(0.2 * LEFT)
     for term, color in self.highlighted_quote_terms:
         quote.set_color_by_tex(term, color)
     quote.to_edge(UP, buff=self.top_buff)
     if quote.get_width() > max_width:
         quote.set_width(max_width)
     return quote
Esempio n. 10
0
 def get_date_message(self):
     return TextMobject(
         self.pre_date_text,
         self.date,
         tex_to_color_map={self.date: YELLOW},
     )
Esempio n. 11
0
    def scroll_through_patrons(self):
        logo_box = Square(side_length=2.5)
        logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF)

        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)

        changed_patron_names = list(
            map(
                self.modify_patron_name,
                self.specific_patrons,
            ))
        changed_patron_names.sort()
        patrons = VGroup(*map(
            TextMobject,
            changed_patron_names,
        ))
        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(
            RIGHT,
            buff=LARGE_BUFF,
            aligned_edge=UP,
        )
        max_width = FRAME_WIDTH - 1
        if columns.get_width() > max_width:
            columns.set_width(max_width)
        underline.match_width(columns)
        # thanks.to_edge(RIGHT, buff=MED_SMALL_BUFF)
        columns.next_to(underline, DOWN, buff=2)

        columns.generate_target()
        columns.target.to_edge(DOWN, buff=4)
        vect = columns.target.get_center() - columns.get_center()
        distance = get_norm(vect)
        wait_time = 20
        always_shift(columns,
                     direction=normalize(vect),
                     rate=(distance / wait_time))

        self.add(columns, black_rect, line, thanks)
        self.wait(wait_time)
Esempio n. 12
0
 def construct(self):
     if 1 == 1:
         try:
             self.add_sound(
                 "sidewayoutput\\basicmanim\\geometry001a_01_01_01_01_01.wav",
                 time_offset=20)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\geometry001a_01_01_01_02_01.wav",
                 time_offset=68)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\geometry001a_01_01_01_02_02.wav",
                 time_offset=87)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\geometry001a_01_01_01_02_03.wav",
                 time_offset=100)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\geometry001a_01_01_01_03_01.wav",
                 time_offset=115)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\geometry001a_01_01_01_03_02.wav",
                 time_offset=131)
         except:
             pass
         self.play(
             StartScreens01(
                 [],
                 [],
                 [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"],
                  [r"\textbf{\textit{Geometry}}\\{{Part\ \textspA{I}a}"],
                  [
                      r"\tiny{\textrm{basic-manim.210301551v0\_geometry001a}}"
                  ], [],
                  [
                      r"\scriptsize{\textbf{Warning:\ The\ content\ may\ contain\ errors,\ mistakes\ and\ inaccuracies.\ Information\ must\ be\ verified\ and\ evaluated\ before\ use.}}"
                  ]],
             ))
     if 1 == 1:
         self.grow(r"\titleA{Geometry}", shift=[0, 3.6, 0])
         rows, cols = (10, 6)
         x0, y0 = axes_point([-5.5, 2.3, cols], [3, -0.7, rows])
         txty = [
             "TipableVMobject()", "Arc(radius=0.5)",
             "ArcBetweenPoints(LO,RO)", "CurvedArrow(LO,RO)",
             "CurvedDoubleArrow(LO,RO)", "Circle(radius=0.5)", "Dot()",
             "SmallDot()", "Ellipse()",
             "Annulus(inner_radius=0.25,outer_radius=0.5)",
             "AnnularSector(inner_radius=0.25,outer_radius=0.5)",
             "Sector(outer_radius=0.5)", "Line()", "DashedLine()",
             "TangentLine(Circle(),0)", "Arrow()", "Vector()",
             "DoubleArrow()", "Elbow()", "CubicBezier([RO,RU/2,LU/2,LO])",
             "Polygon(RO,RU/2,LU/2,LO)", "RegularPolygon().scale(0.5)",
             "Triangle().scale_about_point(0.5,[0,0,0])", "ArrowTip()",
             "Rectangle().scale(0.5)", "Square().scale(0.5)",
             "RoundedRectangle().scale(0.5)", "TipableVMobject()",
             "TipableVMobject()", "TipableVMobject()"
         ]
         strs = txty
         self.grow(
             *[
                 GeomPoint().move_to(each)
                 for i, each in enumerate(coord_grid(x0[:], y0[1::2])[:-3])
             ], )
         txty = [
             "TextMobject('" + txty[i].split('(', 1)[0] +
             "').scale(0.55).move_to([" + ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[:], y0[0::2]))
         ]
         strs = [
             strs[i] + ".shift([" + ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[:], y0[1::2]))
         ]
         strs = [j for i in zip(txty, strs) for j in i][:-6]
         exec("self.create(" + ','.join(strs) +
              ", run_time=42, lag_ratio=1)")
         self.fadeout()
     if 1 == 1:
         self.play(
             GrowFromCenter(
                 TextMobject(r"\titleA{TipableVMobject(VMobject)}").shift(
                     [0, 3.6, 0]).add_as_foreground(self)))
         rows, cols = (5, 3)
         x0, y0 = axes_point([1.1, 4.5, cols - 1, -4.5], [2.5, -1.2, rows])
         txty = [
             "TipableVMobject()", "Arc(radius = 0.5)",
             "ArcBetweenPoints(LO,RO)", "CurvedArrow(LO,RO)",
             r"\parbox{25em}{CurvedDoubleArrow(\bR{LO,RO)"
         ]
         strs = txty
         self.fadein(*[
             TextMobject(txty[i].split('(', 1)[0]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     run_time=5)
         self.grow(
             *[
                 TextMobject(strs[i]).move_to(each)
                 for i, each in enumerate(coord_grid(x0[1:2], y0))
             ],
             *[
                 GeomPoint().move_to(each)
                 for i, each in enumerate(coord_grid(x0[2:3], y0))
             ],
         )
         strs = [
             strs[i].replace("\\bR{", "").replace(
                 "\\parbox{25em}{", "").replace("\\", "") + ".shift([" +
             ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[2:3], y0))
         ]
         exec("self.create(" + ','.join(strs) +
              ", run_time=10, lag_ratio=0)")
         self.fadeout(exclude_mobjs="foreground")
     if 1 == 1:
         rows, cols = (7, 3)
         x0, y0 = axes_point([1.1, 4.5, cols - 1, -4.5], [3, -1.1, rows])
         txty = [
             "Circle(radius = 0.5)", "Dot()", "SmallDot()", "Ellipse()",
             r"\parbox{25em}{Annulus(inner\_radius = 0.25, \bR{outer\_radius = 0.5)",
             r"\parbox{25em}{AnnularSector(inner\_radius\bR{= 0.25, outer\_radius = 0.5)",
             r"Sector(outer\_radius = 0.5)"
         ]
         strs = txty
         self.fadein(*[
             TextMobject(txty[i].split('(', 1)[0]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     run_time=5)
         self.grow(
             *[
                 TextMobject(strs[i]).move_to(each)
                 for i, each in enumerate(coord_grid(x0[1:2], y0))
             ],
             *[
                 GeomPoint().move_to(each)
                 for i, each in enumerate(coord_grid(x0[2:3], y0))
             ],
         )
         strs = [
             strs[i].replace("\\bR{", "").replace(
                 "\\parbox{25em}{", "").replace("\\", "") + ".shift([" +
             ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[2:3], y0))
         ]
         exec("self.create(" + ','.join(strs) +
              ", run_time=6, lag_ratio=0)")
         self.fadeout(exclude_mobjs="foreground")
     if 1 == 1:
         rows, cols = (6, 3)
         x0, y0 = axes_point([1.1, 4.5, cols - 1, -4.5], [3, -1.1, rows])
         txty = [
             "Line()", "DashedLine()", "TangentLine(Circle(), 0)",
             "Arrow()", "Vector()", "DoubleArrow()"
         ]
         strs = txty
         self.fadein(*[
             TextMobject(txty[i].split('(', 1)[0]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     run_time=5)
         self.grow(
             *[
                 TextMobject(strs[i]).move_to(each)
                 for i, each in enumerate(coord_grid(x0[1:2], y0))
             ],
             *[
                 GeomPoint().move_to(each)
                 for i, each in enumerate(coord_grid(x0[2:3], y0))
             ],
         )
         strs = [
             strs[i].replace("\\bR{", "").replace(
                 "\\parbox{25em}{", "").replace("\\", "") + ".shift([" +
             ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[2:3], y0))
         ]
         exec("self.create(" + ','.join(strs) +
              ", run_time=5, lag_ratio=0)")
         self.fadeout()
     if 1 == 1:
         self.play(
             GrowFromCenter(
                 TextMobject(r"\titleA{VMobject}").shift(
                     [0, 3.6, 0]).add_as_foreground(self)))
         rows, cols = (3, 3)
         x0, y0 = axes_point([1.1, 4.5, cols - 1, -4.5], [3, -1.1, rows])
         txty = [
             "Elbow()",
             r"\parbox{25em}{CubicBezier(\bR{[RO, RU/2, LU/2, LO])",
             r"\parbox{25em}{Polygon(\bR{RO, RU/2, LU/2, LO)"
         ]
         strs = txty
         self.fadein(*[
             TextMobject(txty[i].split('(', 1)[0]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     run_time=5)
         self.grow(
             *[
                 TextMobject(strs[i]).move_to(each)
                 for i, each in enumerate(coord_grid(x0[1:2], y0))
             ],
             *[
                 GeomPoint().move_to(each)
                 for i, each in enumerate(coord_grid(x0[2:3], y0))
             ],
         )
         strs = [
             strs[i].replace("\\bR{", "").replace(
                 "\\parbox{25em}{", "").replace("\\", "") + ".shift([" +
             ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[2:3], y0))
         ]
         exec("self.create(" + ','.join(strs) +
              ", run_time=7, lag_ratio=0)")
         self.fadeout(exclude_mobjs="foreground")
     if 1 == 1:
         rows, cols = (6, 3)
         x0, y0 = axes_point([1.1, 4.5, cols - 1, -4.5], [3, -1.1, rows])
         txty = [
             "RegularPolygon().scale(0.5)",
             r"\parbox{25em}{Triangle().scale\_about\_point(\bR{0.5, [0, 0, 0])",
             "ArrowTip()", "Rectangle().scale(0.5)", "Square().scale(0.5)",
             r"\parbox{25em}{RoundedRectangle()\bR{.scale(0.5)"
         ]
         strs = txty
         self.fadein(*[
             TextMobject(txty[i].split('(', 1)[0]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     run_time=5)
         self.grow(
             *[
                 TextMobject(strs[i]).move_to(each)
                 for i, each in enumerate(coord_grid(x0[1:2], y0))
             ],
             *[
                 GeomPoint().move_to(each)
                 for i, each in enumerate(coord_grid(x0[2:3], y0))
             ],
         )
         strs = [
             strs[i].replace("\\bR{", "").replace(
                 "\\parbox{25em}{", "").replace("\\", "") + ".shift([" +
             ','.join(map(str, each)) + "])"
             for i, each in enumerate(coord_grid(x0[2:3], y0))
         ]
         exec("self.create(" + ','.join(strs) +
              ", run_time=9, lag_ratio=0)")
         self.fadeout()
     if 1 == 1:
         self.play(EndScreen01())
     self.wait(5)
Esempio n. 13
0
    def setup_axes(self, reback=False, animate=False):
        """
        This method sets up the axes of the graph.
        Parameters
        ----------
        animate (bool=False)
            Whether or not to animate the setting up of the Axes.
        """
        # reback和animate都为True时,只有reback生效
        # TODO, once eoc is done, refactor this to be less redundant.
        x_num_range = float(self.x_max - self.x_min)
        self.space_unit_to_x = self.x_axis_width / x_num_range
        if self.x_labeled_nums is None:
            self.x_labeled_nums = []
        if self.x_leftmost_tick is None:
            self.x_leftmost_tick = self.x_min
        x_axis = NumberLine(
            x_min=self.x_min,
            x_max=self.x_max,
            unit_size=self.space_unit_to_x,
            tick_frequency=self.x_tick_frequency,
            leftmost_tick=self.x_leftmost_tick,
            numbers_with_elongated_ticks=self.x_labeled_nums,
            color=self.axes_color,
            stroke_opacity=self.xyStrokeOpacity,
            decimal_number_config={"num_decimal_places": self.x_num_decimal_places}
        )
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
        if len(self.x_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.x_labeled_nums = [x for x in self.x_labeled_nums]
                # self.x_labeled_nums = [x for x in self.x_labeled_nums if x != 0]
            x_axis.add_numbers(*self.x_labeled_nums)
        if self.x_axis_label:
            x_label = TextMobject(self.x_axis_label)
            x_label.next_to(
                x_axis.get_tick_marks(), UP + RIGHT,
                buff=SMALL_BUFF
            )
            x_label.shift_onto_screen()
            x_axis.add(x_label)
            self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        self.space_unit_to_y = self.y_axis_height / y_num_range

        if self.y_labeled_nums is None:
            self.y_labeled_nums = []
        if self.y_bottom_tick is None:
            self.y_bottom_tick = self.y_min
        y_axis = NumberLine(
            x_min=self.y_min,
            x_max=self.y_max,
            unit_size=self.space_unit_to_y,
            tick_frequency=self.y_tick_frequency,
            leftmost_tick=self.y_bottom_tick,
            numbers_with_elongated_ticks=self.y_labeled_nums,
            color=self.axes_color,
            line_to_number_vect=LEFT,
            label_direction=LEFT,
            stroke_opacity=self.xyStrokeOpacity,
            decimal_number_config={"num_decimal_places": self.y_num_decimal_places}
        )
        y_axis.shift(self.graph_origin - y_axis.number_to_point(0))
        y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0))
        if len(self.y_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0]
            y_axis.add_numbers(*self.y_labeled_nums)
        if self.y_axis_label:
            y_label = TextMobject(self.y_axis_label)
            y_label.next_to(
                y_axis.get_corner(UP + RIGHT), UP + RIGHT,
                buff=SMALL_BUFF
            )
            y_label.shift_onto_screen()
            y_axis.add(y_label)
            self.y_axis_label_mob = y_label
        
        # 给对象绑定x_axis和y_axis属性
        # Ag 修改了reback和这里的顺序
        self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis)
        self.default_graph_colors = it.cycle(self.default_graph_colors)

        if self.add_coordinate_grid:
            self.lines_x_axis = self.get_vertical_lines_to_axis(
                num_lines=len(np.arange(self.x_min, self.x_max, self.x_tick_frequency))+1
                )
            self.lines_y_axis = self.get_horizontal_lines_to_axis(
                num_lines=len(np.arange(self.y_min, self.y_max, self.y_tick_frequency))+1
                )
            
        return self.reback_or_anim_axis(reback, animate)
Esempio n. 14
0
    def construct(self):
        quote = TextMobject("Imagination is more important than knowledge")
        quote.set_color(RED)
        quote.to_edge(UP)

        quote2 = TextMobject(
            "A person who never made a mistake never tried anything new")
        quote2.set_color(YELLOW)
        author = TextMobject("- Albert Einstein")
        author.scale(0.75)

        corner = quote.get_corner(DOWN + RIGHT)
        print("corner", corner)
        author.next_to(corner, ORIGIN)

        self.add(quote, author)
        self.wait(2)
        self.play(
            Transform(quote, quote2),
            ApplyMethod(author.move_to,
                        quote2.get_corner(DOWN + RIGHT) + DOWN + 2 * LEFT))
        self.play(ApplyMethod(author.scale, 1.5))
        author.match_color(quote2)
        self.play(FadeOut(quote), FadeOut(author))
        self.wait()
Esempio n. 15
0
    def construct(self):
        my_first_text = TextMobject("Writing with manim is fun")
        second_line = TextMobject("and easy to do!")
        second_line.next_to(my_first_text, DOWN)
        third_line = TextMobject("for me and you!")
        third_line.next_to(my_first_text, DOWN)

        self.add(my_first_text, second_line)
        self.wait(2)
        self.play(Transform(second_line, third_line))
        self.wait(2)
        second_line.shift(3 * DOWN)
        self.play(ApplyMethod(my_first_text.shift, 3 * UP))
        self.wait()
Esempio n. 16
0
 def construct(self):
     if 1 == 1:
         try:
             self.add_sound(
                 "sidewayoutput\\basicmanim\\growing001a_01_01_01_01_01.wav",
                 time_offset=19)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\growing001a_01_01_01_02_01.wav",
                 time_offset=43)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\growing001a_01_01_01_03_01.wav",
                 time_offset=89)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\growing001a_01_01_01_04_01.wav",
                 time_offset=136)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\growing001a_01_01_01_05_01.wav",
                 time_offset=180)
         except:
             pass
         self.play(
             StartScreens01(
                 [],
                 [],
                 [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"],
                  [r"\textbf{\textit{Growing}}\\{{Part\ \textspA{I}a}"],
                  [r"\tiny{\textrm{basic-manim.210300151v0\_growing001a}}"],
                  [],
                  [
                      r"\scriptsize{\textbf{Warning:\ The\ content\ may\ contain\ errors,\ mistakes\ and\ inaccuracies.\ Information\ must\ be\ verified\ and\ evaluated\ before\ use.}}"
                  ]],
             ))
     if 1 == 1:
         self.grow(r"\titleA{Growing}", shift=[0, 3.6, 0])
         rows, cols = (4, 3)
         x0, y0 = axes_point([1, 4, cols - 1, -4.5], [2.5, -1.9, rows])
         txty = ["Growing", " Diminishing", "One Direction", "Spin"]
         strs = [
             each + "(sqs[" + str(i) + "])" for i, each in enumerate([
                 "GrowFromCenter", "DiminishToCenter", "GrowArrow",
                 "SpinInFromNothing"
             ])
         ]
         sqs = [GeomSquare(1.2) for i in range(rows)]
         self.fadein(*[
             TextMobject(txty[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     *[
                         Group(GeomPoint(),
                               TextMobject("sqs[" + str(i) + "]"),
                               sqs[i]).move_to(each)
                         for i, each in enumerate(coord_grid(x0[2:3], y0))
                     ],
                     run_time=5)
         self.grow(*[
             TextMobject(strs[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[1:2], y0))
         ])
         exec("self.play(" + ','.join(strs) + "," + "run_time=15)")
         self.fadeout()
     if 1 == 1:
         self.grow(r"\titleA{GrowFrom}", shift=[0, 3.6, 0])
         rows, cols = (4, 3)
         x0, y0 = axes_point([1, 4, cols - 1, -4.5], [2.5, -1.9, rows])
         txty = [
             "GrowFromPoint", "GrowFromCenter", "GrowFromEdge",
             "GrowFromSide"
         ]
         strs = [
             txty[i] + "(sqs[" + str(i) + "]" + each + ")"
             for i, each in enumerate([",UP", "", ",UP", ",UP"])
         ]
         sqs = [GeomSquare(1.2) for i in range(rows)]
         self.fadein(*[
             TextMobject(txty[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     *[
                         Group(GeomPoint(),
                               TextMobject("sqs[" + str(i) + "]"),
                               sqs[i]).move_to(each)
                         for i, each in enumerate(coord_grid(x0[2:3], y0))
                     ],
                     run_time=5)
         self.grow(*[
             TextMobject(strs[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[1:2], y0))
         ])
         exec("self.play(" + ','.join(strs) + "," + "run_time=35)")
         self.fadeout()
     if 1 == 1:
         self.grow(r"\titleA{DiminishTo}", shift=[0, 3.6, 0])
         rows, cols = (4, 3)
         x0, y0 = axes_point([1, 4, cols - 1, -4.5], [2.5, -1.9, rows])
         txty = [
             "DiminishToPoint", "DiminishToCenter", "DiminishToEdge",
             "DiminishToSide"
         ]
         strs = [
             txty[i] + "(sqs[" + str(i) + "]" + each + ")"
             for i, each in enumerate([",UP", "", ",UP", ",UP"])
         ]
         sqs = [GeomSquare(1.2) for i in range(rows)]
         self.fadein(*[
             TextMobject(txty[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     *[
                         Group(GeomPoint(),
                               TextMobject("sqs[" + str(i) + "]"),
                               sqs[i]).move_to(each)
                         for i, each in enumerate(coord_grid(x0[2:3], y0))
                     ],
                     run_time=5)
         self.grow(*[
             TextMobject(strs[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[1:2], y0))
         ])
         exec("self.play(" + ','.join(strs) + "," + "run_time=38)")
         self.fadeout()
     if 1 == 1:
         self.grow(r"\titleA{One Direction}", shift=[0, 3.6, 0])
         rows, cols = (8, 3)
         x0, y0 = axes_point([1, 4, cols - 1, -4.5], [2.8, -0.9, rows])
         txty = to_get_zlist(
             ["GrowArrow", "ExpandArrow", "DiminishArrow", "RetractArrow"],
             n=2)
         strs = [txty[i] + "(sqs[" + str(i) + "])" for i in range(rows)]
         sqs = to_get_zlist([GeomRectangle(0.6, 1.2), GeomArrow()], n=(4, ))
         self.fadein(*[
             TextMobject(txty[i * 2]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0[:-1:2]))
         ],
                     *[
                         Group(GeomPoint(),
                               TextMobject("sqs[" + str(i) + "]"),
                               sqs[i]).move_to(each)
                         for i, each in enumerate(coord_grid(x0[2:3], y0))
                     ],
                     run_time=5)
         self.fadein(*[
             TextMobject(strs[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[1:2], y0))
         ])
         exec("self.play(" + ','.join(strs) + "," + "run_time=35)")
         self.fadeout()
     if 1 == 1:
         self.grow(r"\titleA{Spin}", shift=[0, 3.6, 0])
         rows, cols = (5, 3)
         x0, y0 = axes_point([1.8, 4, cols - 1, -4.2], [3, -1.5, rows])
         txty = [
             "SpinInFromNothing", "SpinInFrom", "SpinOutFrom", "SpinInTo",
             "SpinOutTo"
         ]
         strs = [
             txty[i] + "(sqs[" + str(i) + "]" + each + ")"
             for i, each in enumerate(["", "", "", "", ""])
         ]
         sqs = [
             GeomRegularPolygon(5, ORIGIN, 0.8).add(
                 GeomArrow([0, 0.07, 0], [0, 0.8, 0])) for i in range(rows)
         ]
         self.fadein(*[
             TextMobject(txty[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[0:1], y0))
         ],
                     *[
                         Group(GeomPoint(),
                               TextMobject("sqs[" + str(i) + "]"),
                               sqs[i]).move_to(each)
                         for i, each in enumerate(coord_grid(x0[2:3], y0))
                     ],
                     run_time=5)
         self.grow(*[
             TextMobject(strs[i]).move_to(each)
             for i, each in enumerate(coord_grid(x0[1:2], y0))
         ])
         exec("self.play(" + ','.join(strs) + "," + "run_time=50)")
         self.fadeout()
     if 1 == 1:
         self.play(EndScreen01())
     self.wait(5)
    def construct(self):
        self._main_title()

        text_one = TextMobject("Given a list of items sold")
        text_two: TextMobject = TextMobject(
            "Randomly choose items matching this distribution")
        text_two.next_to(text_one, DOWN)
        number_line = NumberLine(
            numbers_with_elongated_ticks=[0, 1],
            include_numbers=True,
            x_min=0,
            x_max=1,
            unit_size=10,
            tick_frequency=0.1,
            # decimal_number_config={"num_decimal_places": 1},
            numbers_to_show=[0, 1])
        number_line.next_to(text_two, UP)

        self.play(ShowCreation(text_one))
        self.wait()
        self.play(ShowCreation(text_two))
        self.wait(4)

        apples_text = TextMobject("Apples:")
        apples_text.set_color(self._apple_colour)

        apples_text.to_edge(UP)
        apples_text.align_to(text_two, LEFT)

        apple_count_text = TextMobject(f"{self._apple_count}")
        apple_count_text.set_color(self._apple_colour)
        apple_count_text.next_to(apples_text, RIGHT)

        banana_text = TextMobject("Bananas:")
        banana_text.set_color(self._banana_colour)

        banana_text.next_to(apples_text, DOWN)
        banana_text.align_to(apples_text, LEFT)

        banana_count_text = TextMobject(f"{self._banana_count}")
        banana_count_text.set_color(self._banana_colour)
        banana_count_text.next_to(banana_text, RIGHT)

        self.play(Transform(text_one, apples_text))
        self.play(ShowCreation(apple_count_text))
        self.play(ShowCreation(banana_text), ShowCreation(banana_count_text))

        banana_bar = Rectangle(
            height=0.4,
            width=number_line.point_to_number(self._banana_fraction * 10) *
            (number_line.number_to_point(1)[0]),
            color=self._banana_colour,
            fill_color=self._banana_colour,
            fill_opacity=0.75)
        banana_bar.next_to(banana_count_text, RIGHT + RIGHT)

        apple_bar = Rectangle(
            height=0.4,
            width=number_line.point_to_number(self._apple_fraction * 10) *
            (number_line.number_to_point(1)[0]),
            color=self._apple_colour,
            fill_color=self._apple_colour,
            fill_opacity=0.75)
        apple_bar.next_to(banana_bar, UP)
        apple_bar.align_to(banana_bar, LEFT)

        self.play(FadeIn(apple_bar), FadeIn(banana_bar))

        self.wait(1.5)

        apple_fraction_text = TextMobject("$\\frac{" + str(self._apple_count) +
                                          "}{" + str(self._apple_count +
                                                     self._banana_count) +
                                          "} = " + str(self._apple_fraction) +
                                          "$")
        apple_fraction_text.next_to(apple_bar, RIGHT)

        banana_fraction_text = TextMobject("$\\frac{" +
                                           str(self._banana_count) + "}{" +
                                           str(self._apple_count +
                                               self._banana_count) + "} = " +
                                           str(self._banana_fraction) + "$")
        banana_fraction_text.next_to(banana_bar, RIGHT)

        self.play(ShowCreation(apple_fraction_text))
        self.play(ShowCreation(banana_fraction_text))

        self.wait(2)

        number_line_map_text = TextMobject(
            "Map these counts to values between 0 and 1")
        number_line_map_text.next_to(text_two, UP)
        self.play(ShowCreation(number_line_map_text))

        self.wait(3)
        self.play(Transform(number_line_map_text, number_line))

        apple_num_ln_bar = Rectangle(
            height=0.4,
            # width=1 - self._apple_fraction * (number_line.number_to_point(1)[0]),
            width=number_line.point_to_number(self._apple_fraction * 10) *
            (number_line.number_to_point(1)[0]),
            color=self._apple_colour,
            fill_color=self._apple_colour,
            fill_opacity=0.25)
        apple_num_ln_bar.move_to(apple_bar, LEFT)
        self.add(apple_num_ln_bar)
        self.wait(2)
        self.play(
            ApplyMethod(apple_num_ln_bar.move_to,
                        number_line.number_to_point(0), LEFT))

        banana_num_ln_bar = Rectangle(
            height=0.4,
            width=number_line.point_to_number(self._banana_fraction * 10) *
            (number_line.number_to_point(1)[0]),
            color=self._banana_colour,
            fill_color=self._banana_colour,
            fill_opacity=0.25)
        banana_num_ln_bar.move_to(banana_bar, LEFT)
        self.add(banana_num_ln_bar)
        self.wait(2)
        self.play(
            ApplyMethod(banana_num_ln_bar.move_to,
                        number_line.number_to_point(1), RIGHT))

        text_scale: float = 0.75
        get_rnd_full = TextMobject(
            "Get a random number $n$ between 0 and 1 (uniform distribution)")

        get_apple_text = TextMobject(
            f"Apple\\quad if $n <= {self._apple_fraction}$",
            tex_to_color_map={"Apple": self._apple_colour})
        get_banana_text = TextMobject(
            f"Banana\\quad if $n > {self._apple_fraction}$",
            tex_to_color_map={"Banana": self._banana_colour})

        get_rnd_full.scale(text_scale)
        get_rnd_full.next_to(text_two, DOWN)
        get_banana_text.next_to(get_apple_text, DOWN)
        step_group = VGroup(get_apple_text, get_banana_text)

        brace = Brace(step_group, LEFT)
        step_text_d = brace.get_text("$n \\sim U(0, 1)$")
        step_text_d.scale(text_scale)
        step_text_d.next_to(get_rnd_full, DOWN + DOWN)
        step_text_d.shift(LEFT)
        brace.next_to(step_text_d, RIGHT)

        step_group.scale(text_scale)
        step_group.next_to(step_text_d, RIGHT + RIGHT + RIGHT)

        self.wait(2)
        self.play(ShowCreation(get_rnd_full))
        self.wait(2)
        self.play(ShowCreation(step_text_d))
        self.wait(2)

        self.play(GrowFromCenter(brace))
        self.wait()
        self.play(ShowCreation(get_apple_text))
        self.wait(2)
        self.play(ShowCreation(get_banana_text))

        # random_nos_to_draw = 10
        # main_arrow = Arrow(ORIGIN, DOWN * 1.3)
        # helper_arrow = Arrow(ORIGIN, LEFT * 1.3)
        #
        # for i in range(random_nos_to_draw):
        #   num: float = np.random.random_sample(1)
        #   point = number_line.number_to_point(num)
        #   arrow_colour = self._apple_colour if num <= self._apple_fraction else self._banana_colour
        #   arrow_recipient = get_apple_text if num <= self._apple_fraction else get_banana_text
        #
        #   main_arrow.set_color(arrow_colour)
        #
        #   if i == 0:
        #     main_arrow.next_to(point, UP)
        #     helper_arrow.next_to(arrow_recipient, RIGHT)
        #     self.play(GrowArrow(main_arrow), GrowArrow(helper_arrow))
        #   else:
        #     self.play(ApplyMethod(helper_arrow.next_to, arrow_recipient, RIGHT),
        #               ApplyMethod(main_arrow.next_to, point, UP))
        #   self.wait()
        #
        # self.play(FadeOut(main_arrow), FadeOut(helper_arrow))
        self.wait()
    def _main_title(self):
        paper_name_a = TextMobject(
            "Simulating human interactions in supermarkets to")
        paper_name_b = TextMobject(
            "measure the risk of COVID-19 contagion at scale")
        author_list_a = TextMobject(
            "Serge Plata\\quad Sumanas Sarma\\quad Melvin Lancelot")
        author_list_b = TextMobject(
            "Kristine Bagrova\\quad David Romano-Critchley")
        arxiv = TextMobject("arXiv:2006.15213")

        paper_name_a.shift(UP)
        paper_name_b.next_to(paper_name_a, DOWN)

        author_list_a.scale(0.8)
        author_list_b.scale(0.8)

        author_list_a.next_to(paper_name_b, DOWN + DOWN)
        author_list_b.next_to(author_list_a, DOWN)

        arxiv.scale(0.6)
        arxiv.next_to(author_list_b, DOWN + DOWN)

        self.play(FadeIn(paper_name_a), FadeIn(paper_name_b))
        self.wait()
        self.play(FadeIn(author_list_a), FadeIn(author_list_b))
        self.play(FadeIn(arxiv))

        self.wait(4)
        self.play(FadeOut(paper_name_a), FadeOut(paper_name_b),
                  FadeOut(author_list_a), FadeOut(author_list_b),
                  ApplyMethod(arxiv.move_to, BOTTOM + (UP * 0.5)))
Esempio n. 19
0
    def __init__(self,
                 screen01=[],
                 screen02=[],
                 screen03=[],
                 lag_ratio=1,
                 **kwargs):
        mobjs_1, mobjs_1_scale, mobjs_1_interval, mobjs_1_rate_func, \
            title_1, title_1_color, title_1_scale, title_1_position, title_1_shadow, \
            title_1_indicate_scale_factor, title_1_extra = screen01 + \
            ["", 2, 0.5, linear, "", "#0808B8", 2, [DOWN], [2, slice(0, 3, 2)],
             1.2, ""][len(screen01):]
        mobjs_2, mobjs_2_scale, mobjs_2_interval, mobjs_2_rate_func, \
            title_2, title_2_color, title_2_scale, title_2_position, title_2_shadow, \
            title_2_indicate_scale_factor, title_2_extra = screen02 + \
            ["", 2, 0.5, linear, "", "#0808B8", 1.2, [DOWN], [2, slice(1, 4, 2)],
             "", [slice(1, 2), WHITE, [-2.5, 0, 0]]][len(screen02):]
        [title, subtitle, filename, reference, warning, mobjes_3_run_time] =\
            screen03 + [[], [], [], [], [], 3][len(screen03):]
        [title, title_color, title_scale, title_position] = title + \
            ["", WHITE, 1, [UP]][len(title):]
        [subtitle, subtitle_color, subtitle_scale, subtitle_position] = subtitle + \
            ["", WHITE, 1, [0, 0, 0]][len(subtitle):]
        [filename, filename_color, filename_scale, filename_position] = filename + \
            ["", WHITE, 1, [0, -2.9, 0]][len(filename):]
        [reference, reference_color, reference_scale, reference_position] = reference + \
            ["", YELLOW, 1, [0, -3.3, 0]][len(reference):]
        [warning, warning_color, warning_scale, warning_position] = warning + \
            ["", YELLOW, 1, [0, -3.7, 0]
             ][len(warning):]

        startscreens = AGroup()
        if mobjs_1 != None:
            if mobjs_1 == "":
                try:
                    mobjs_1 = ImageMobjectGroup(
                        np.char.mod('%01d', range(0, 10)),
                        "sidewayoutput\\sidewayoutput2020yt")
                except:
                    mobjs_1 = ImageMobjectGroup(
                        np.char.mod('%01d', range(9, -1, -1)), "001\\")
            if title_1 == "":
                title_1 = PoweredBy
            title_1 = MobjectOrChars(title_1)
            title_1.set_color(title_1_color).scale(
                title_1_scale).align_on_border(
                    *title_1_position).add_shadow_mobjects(
                        title_1_shadow[0], title_1[title_1_shadow[1]])
            if title_1_extra != "":
                title_1[title_1_extra[0]].set_color(title_1_extra[1]).shift(
                    title_1_extra[2])
            if title_1_indicate_scale_factor == "":
                title_width = mobjs_1.get_width()
                title_1_indicate_scale_factor = (title_width -
                                                 0.5) / title_width
            startscreens.add(
                ShowSubmobjectsOneByOneAndFadeInThenIndicateThenFadeOut(
                    mobjs_1.scale(mobjs_1_scale),
                    title_1,
                    indicate_scale_factor=title_1_indicate_scale_factor,
                    show_rate_func=mobjs_1_rate_func,
                    run_time=mobjs_1_interval * (len(mobjs_1)),
                    **kwargs))
        if mobjs_2 != None:
            if mobjs_2 == "":
                strs = TextMobject(r"\textspA{%s}" % Project)
                mobjs_2 = Group(
                    Circle(fill_opacity=0.75),
                    RegularPolygon(fill_opacity=0.75),
                    Triangle(color=GREEN, fill_opacity=0.75),
                    Square(fill_opacity=0.75),
                    strs.set_color("#FFFFFF"),
                    strs.copy().set_color("#F8F8F8").scale(1.3),
                    strs.copy().set_color("#F8F8B8").scale(1.6),
                    strs.copy().set_color("#B8B8B8").scale(1.6),
                    strs.copy().set_color("#8888B8").scale(1.6),
                    strs.copy().set_color("#6868B8").scale(1.6),
                    strs.copy().set_color("#4848B8").scale(1.6),
                    strs.copy().set_color("#2828B8").scale(1.6),
                    strs.copy().set_color("#0808B8").scale(1.6),
                )
            if title_2 == "":
                title_2 = (r"{\tiny{\emph{Powered by}:}}\\ ", *PoweredBy)
            title_2 = MobjectOrChars(title_2)
            title_2.set_color(title_2_color).scale(
                title_2_scale).align_on_border(
                    *title_2_position).add_shadow_mobjects(
                        title_2_shadow[0], title_2[title_2_shadow[1]])
            if title_2_extra != "":
                title_2[title_2_extra[0]].set_color(title_2_extra[1]).shift(
                    title_2_extra[2])
            if title_2_indicate_scale_factor == "":
                title_width = mobjs_2.get_width()
                title_2_indicate_scale_factor = (title_width -
                                                 0.5) / title_width
            startscreens.add(
                ShowSubmobjectsOneByOneAndFadeInThenIndicateThenFadeOut(
                    mobjs_2.scale(mobjs_2_scale),
                    title_2,
                    indicate_scale_factor=title_2_indicate_scale_factor,
                    show_rate_func=mobjs_2_rate_func,
                    run_time=mobjs_2_interval * (len(mobjs_2)),
                    **kwargs))
        if title != None or subtitle != None:
            mobjs_3 = [Group(), "", ""]
            if title != None:
                txt_title = TextMobject(title).scale(title_scale)
                if txt_title.get_width() > 14:
                    txt_title.stretch_to_fit_width(14)
                mobjs_3[1] = txt_title.set_color(title_color).to_edge(
                    *title_position)
                mobjs_3[0].add(mobjs_3[1])
            if subtitle != None:
                mobjs_3[0].add(
                    TextMobject(subtitle).set_color(subtitle_color).scale(
                        subtitle_scale).shift(subtitle_position))
            if filename != None and filename != "":
                if reference == None or reference == "":
                    filename_position = reference_position
                mobjs_3[0].add(
                    TextMobject(filename).set_color(filename_color).scale(
                        filename_scale).shift(filename_position))
            if reference != None and reference != "":
                txt_reference = TextMobject(reference).scale(reference_scale)
                if txt_reference.get_width() > 14:
                    txt_reference.stretch_to_fit_width(14)
                mobjs_3[0].add(
                    txt_reference.set_color(reference_color).shift(
                        reference_position))
            if warning != None and warning != "":
                txt_warning = TextMobject(warning).scale(
                    warning_scale)  # height=0.3
                if txt_warning.get_width() > 14:
                    txt_warning.stretch_to_fit_width(14)
                mobjs_3[2] = txt_warning.set_color(warning_color).shift(
                    warning_position)
            animations = AGroup()
            if len(mobjs_3[0]) > 0:
                animations.add(
                    FadeIn(mobjs_3[0],
                           run_time=0.5,
                           scale_factor=1,
                           color=None))
            if len(mobjs_3[1]) > 0:
                animations.add(GrowFromCenter(Underline(mobjs_3[1])))
            if len(mobjs_3[2]) > 0:
                animations.add(
                    FadeInThenIndicate(mobjs_3[2],
                                       run_time=0.5,
                                       scale_factor=1.2,
                                       color=None))
            startscreens.add(
                FadeoutSuccession(AnimationGroup(*animations,
                                                 run_time=mobjes_3_run_time),
                                  run_time=0.05))
        super().__init__(AnimationGroup(*startscreens, lag_ratio=1), **kwargs)
Esempio n. 20
0
 def __init__(self, str, shift=[0, 3.6, 0], **kwargs):
     GrowFromCenter.__init__(self, TextMobject(
         r"\titleA{"+str+"}").shift(shift))
Esempio n. 21
0
    def initialize_texts(self):
        proof_texts = TextMobject("“证明”:", "涂颜色", "+", "换视角")
        proof_texts.arrange_submobjects(RIGHT)
        proof_texts.to_corner(LEFT + UP)

        imagine_3d_text = TextMobject("(想象这是一个三维图案...)")
        imagine_3d_text.to_corner(RIGHT + UP)
        imagine_3d_text.set_color(YELLOW)

        rhombi = VGroup(*[
            RhombusType(rhombus_config={"fill_opacity": 1})
            for RhombusType in (RRhombus, HRhombus, LRhombus)
        ])
        time_texts = VGroup(*[
            TexMobject("\\times", "n^2").scale(1.2).set_color(
                rhombus.get_fill_color()) for rhombus in rhombi
        ])
        rhombi_and_texts = VGroup(*[
            VGroup(rhombus, time_text).arrange_submobjects(RIGHT)
            for rhombus, time_text in zip(rhombi, time_texts)
        ])
        rhombi_and_texts.arrange_submobjects(RIGHT, buff=2)
        rhombi_and_texts.to_edge(UP, buff=1.4)

        equation = TexMobject(
            *["n^2" if k % 2 == 0 else "=" for k in range(5)])
        for text, color in zip(equation[::2], RHOMBI_COLOR_SET):
            text.set_color(color)
        qed = FakeQEDSymbol(jagged_percentage=0.1)
        qed.set_height(equation.get_height())
        conclusions = VGroup(equation, qed)
        conclusions.arrange_submobjects(RIGHT, buff=1)
        conclusions.to_corner(RIGHT + UP)

        self.proof_texts = proof_texts
        self.imagine_3d_text = imagine_3d_text
        self.rhombi = rhombi
        self.time_texts = time_texts
        self.rhombi_and_texts = rhombi_and_texts
        self.conclusions = conclusions
Esempio n. 22
0
 def construct(self):
     theorem_sc = TextMobject("可利颂镶嵌定理")
     theorem_sc.scale(1.8)
     theorem_eng = TextMobject("(Calisson Tiling Theorem)")
     theorem_eng.set_width(theorem_sc.get_width())
     theorem = VGroup(theorem_sc, theorem_eng)
     theorem.arrange_submobjects(DOWN)
     theorem.to_edge(RIGHT).shift(UP)
     self.play(FadeIn(theorem), run_time=1)
     author = TextMobject("@Solara570")
     author.scale(1.5)
     support = TextMobject("(Powered by @3Blue1Brown)")
     support.set_width(author.get_width())
     names = VGroup(author, support)
     names.arrange_submobjects(DOWN)
     names.to_corner(RIGHT + DOWN)
     self.play(FadeIn(names), run_time=1)
     self.wait(3)
Esempio n. 23
0
    def construct(self):
        square = Square(side_length=5, fill_color=YELLOW, fill_opacity=1)
        label = TextMobject("Text at an angle")
        label.bg = BackgroundRectangle(label, fill_opacity=1)
        label_group = VGroup(label.bg, label)

        label_group.rotate(TAU / 8)

        label2 = TextMobject("Boxed text", color=BLACK)
        label2.bg = SurroundingRectangle(label2,
                                         color=BLUE,
                                         fill_color=RED,
                                         fill_opacity=.5)
        label2_group = VGroup(label2, label2.bg)
        label2_group.next_to(label_group, DOWN)

        label3 = TextMobject("Rainbow")
        label3.scale(2)
        label3.set_color_by_gradient(RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
        label3.to_edge(DOWN)

        self.add(square)
        self.play(FadeIn(label_group))
        self.play(FadeIn(label2_group))
        self.play(FadeIn(label3))
        self.wait(2)
Esempio n. 24
0
 def get_probabalistic_message(self):
     return TextMobject(
         "New video every ", "Sunday ",
         "(with probability 0.3)",
         tex_to_color_map={"Sunday": YELLOW},
     )
Esempio n. 25
0
    def construct(self):
        eq1a = TextMobject("4x + 3y")
        eq1b = TextMobject("=")
        eq1c = TextMobject("0")

        eq2a = TextMobject("5x - 2y")
        eq2b = TextMobject("=")
        eq2c = TextMobject("3")

        eq1b.next_to(eq1a, RIGHT)
        eq1c.next_to(eq1b, RIGHT)

        eq2a.shift(DOWN)
        eq2b.shift(DOWN)
        eq2c.shift(DOWN)

        eq2a.align_to(eq1a, LEFT)
        eq2b.align_to(eq1b, LEFT)
        eq2c.align_to(eq1c, LEFT)

        eq_group = VGroup(eq1a, eq2a)
        braces = Brace(eq_group, LEFT)
        eq_text = braces.get_text("A pair of equations")

        self.add(eq1a, eq1b, eq1c)
        self.add(eq2a, eq2b, eq2c)
        self.play(GrowFromCenter(braces), Write(eq_text))

        self.wait(3)
Esempio n. 26
0
 def construct(self):
     if 1 == 1:
         try:
             self.add_sound(
                 "sidewayoutput\\basicmanim\\transform001a_01_01_01_01_01.wav",
                 time_offset=18)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\transform001a_01_01_01_02_01.wav",
                 time_offset=93)
             self.add_sound(
                 "sidewayoutput\\basicmanim\\transform001a_01_01_01_03_01.wav",
                 time_offset=135)
         except:
             pass
         self.play(
             StartScreens01(
                 [],
                 [],
                 [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"],
                  [r"\textbf{\textit{Transform}}\\{{Part\ \textspA{I}a}"],
                  [
                      r"\tiny{\textrm{basic-manim.210200551v0\_transform001a}}"
                  ], [],
                  [
                      r"\scriptsize{\textbf{Warning:\ The\ content\ may\ contain\ errors,\ mistakes\ and\ inaccuracies.\ Information\ must\ be\ verified\ and\ evaluated\ before\ use.}}"
                  ]],
             ))
     if 1 == 1:
         self.play(
             GrowFromCenter(
                 TextMobject(
                     r"\textit{\textbf{\underline{Transform}}}").shift(
                         [0, 3.6, 0])))
         squarea = Square()
         squareb = Square(side_length=4).shift([4, 0, 0])
         circlea = Circle()
         circleb = Circle(radius=2).shift([-4, 0, 0])
         linea = Line([-4, 3, 0], [4, 3, 0])
         lineb = Line([-3, -3, 0], [3, -3, 0])
         texta = TextMobject("AB").shift([0, -2.5, 0])
         textb = TextMobject("HI").shift([0, 2.5, 0])
         self.play(
             ShowCreation(Group(squarea, circlea, squareb, circleb, linea,
                                lineb),
                          lag_ratio=1,
                          run_time=12))
         self.play(Write(VGroup(texta, textb), lag_ratio=1, run_time=10))
         self.play(Transform(circlea, squarea, run_time=5))
         self.play(Transform(circlea, squareb, path_arc=3, run_time=5))
         self.play(Transform(squarea, circleb, path_arc=3, run_time=5))
         self.play(Transform(linea, lineb, path_arc=3, run_time=5))
         self.play(Transform(linea, circleb, path_arc=3, run_time=5))
         self.play(Transform(squareb, lineb, path_arc=3, run_time=5))
         self.play(Transform(texta, textb, path_arc=3, run_time=5))
         self.play(Transform(texta, circleb, path_arc=3, run_time=5))
         self.play(Transform(squareb, textb, path_arc=3, run_time=5))
         self.fadeout()
     if 1 == 1:
         self.play(
             GrowFromCenter(
                 TextMobject(
                     r"\textit{\textbf{\underline{Paths\ of\ Transform}}}").
                 shift([0, 3.6, 0])))
         rows, cols = (7, 5)
         x0, y0 = axes_point([0, 2, cols - 1, -4], [2.3, -1, rows - 1, 3])
         txtx = ["loc 1", "loc 2", "m1", "m2"]
         txty = [
             "ClockwiseTransform", "Transform", "CounterclockwiseTransform"
         ]
         a1 = Group()
         a2 = Group()
         a3 = Group()
         a4 = Group()
         for j in range(1, rows):
             a1.add(Circle().scale(0.2).move_to([x0[1], y0[j], 0]))
             a2.add(Square().scale(0.2).move_to([x0[2], y0[j], 0]))
             a3.add(
                 Dot([x0[3], y0[j], 0]).add_updater(lambda mob, obj=a1[
                     j - 1], x=x0[3], y=y0[j]: mob.become(obj.copy(
                     ).move_to([x, y, 0]))).suspend_updating())
             a4.add(
                 Dot([x0[4], y0[j], 0]).add_updater(lambda mob, obj=a2[
                     j - 1], x=x0[4], y=y0[j]: mob.become(obj.copy(
                     ).move_to([x, y, 0]))).suspend_updating())
         self.play(FadeIn(
             Group(
                 *[
                     TextMobject(txtx[i]).move_to(each)
                     for i, each in enumerate(coord_grid(x0[1:], y0[0:1]))
                 ], *[
                     TextMobject(txty[i]).move_to(each)
                     for i, each in enumerate(coord_grid(x0[0:1], y0[1::2]))
                 ], *[Dot(each) for each in coord_grid(x0[1:3], y0[1:])],
                 TextMobject(r"$\rightarrow$").move_to(
                     ([(x0[1] + x0[2]) / 2, y0[0], 0])), a1[::2], a2[::2],
                 a3, a4, *[
                     Square(stroke_width=2,
                            color="#FFFF00",
                            fill_opacity=0.3).add_updater(
                                lambda mob, obj=obj: mob.surround(
                                    obj, stretch=True, buff=0.2))
                     for obj in a1
                 ], *[
                     Square(stroke_width=2, color="#DC75CD").add_updater(
                         lambda mob, obj=obj: mob.surround(
                             obj, stretch=True, buff=0.3)) for obj in a2
                 ])),
                   run_time=5)
         self.wait(2)
         self.play(AnimationGroup(
             ClockwiseTransform(a2[0], a1[0]),
             ClockwiseTransform(a1[1], a2[1]),
             Transform(a1[2], a2[2]),
             Transform(a2[3], a1[3]),
             CounterclockwiseTransform(a1[4], a2[4]),
             CounterclockwiseTransform(a2[5], a1[5]),
         ),
                   run_time=25)
         self.wait(3)
         a1.shift([0.3, 0, 0]).set_color("#11FF00")
         self.wait(3)
         self.play(ApplyMethod(a1.shift, ([0.3, 0, 0])), run_time=3)
         self.fadeout()
     if 1 == 1:
         self.play(
             GrowFromCenter(
                 TextMobject(
                     r"\textit{\textbf{\underline{Methods\ of\ Transform}}}"
                 ).shift([0, 3.6, 0])))
         rows, cols = (9, 5)
         x0, y0 = axes_point([0, 2, cols - 1, -4], [2.3, -0.8, rows - 1, 3])
         txtx = ["loc 1", "loc 2", "m1", "m2"]
         txty = [
             "Transform", "ReplacementTransform", "TransformFromCopy",
             "MoveToTarget"
         ]
         a1 = Group()
         a2 = Group()
         a3 = Group()
         a4 = Group()
         for j in range(1, rows):
             a1.add(Circle().scale(0.2).move_to([x0[1], y0[j], 0]))
             a2.add(Square().scale(0.2).move_to([x0[2], y0[j], 0]))
             a3.add(Dot().move_to([x0[3], y0[j], 0]).add_updater(
                 lambda mob, obj=a1[j - 1], x=x0[3], y=y0[j]: mob.become(
                     obj.copy().move_to([x, y, 0]))).suspend_updating())
             a4.add(Dot().move_to([x0[4], y0[j], 0]).add_updater(
                 lambda mob, obj=a2[j - 1], x=x0[4], y=y0[j]: mob.become(
                     obj.copy().move_to([x, y, 0]))).suspend_updating())
         a1[6].target = a2[6]
         a1[7].target = a2[7]
         self.play(FadeIn(
             Group(
                 *[
                     TextMobject(txtx[i]).move_to(each)
                     for i, each in enumerate(coord_grid(x0[1:], y0[0:1]))
                 ], *[
                     TextMobject(txty[i]).move_to(each)
                     for i, each in enumerate(coord_grid(x0[0:1], y0[1::2]))
                 ], *[Dot(each) for each in coord_grid(x0[1:3], y0[1:])],
                 TextMobject(r"$\rightarrow$").move_to(
                     ([(x0[1] + x0[2]) / 2, y0[0], 0])), a1[::2], a2[::2],
                 a3, a4,
                 Group(*[
                     Square(
                         stroke_width=2, color="#FFFF00", fill_opacity=0.3).
                     add_updater(lambda mob, obj=obj: mob.surround(
                         obj, stretch=True, buff=0.2)) for obj in a1
                 ]),
                 Group(*[
                     Square(stroke_width=2, color="#DC75CD").add_updater(
                         lambda mob, obj=obj: mob.surround(
                             obj, stretch=True, buff=0.3)) for obj in a2
                 ]))),
                   run_time=5)
         self.wait(2)
         self.play(AnimationGroup(Transform(a1[0], a2[0]),
                                  Transform(a1[1], a2[1]),
                                  ReplacementTransform(a1[2], a2[2]),
                                  ReplacementTransform(a1[3], a2[3]),
                                  TransformFromCopy(a1[4], a2[4]),
                                  TransformFromCopy(a1[5], a2[5]),
                                  MoveToTarget(a1[6]), MoveToTarget(a1[7])),
                   run_time=40)
         self.wait(3)
         a1.shift([0.3, 0, 0]).set_color("#11FF00")
         self.wait(10)
         self.play(ApplyMethod(a1.shift, ([0.3, 0, 0])), run_time=5)
         self.fadeout()
     if 1 == 1:
         self.play(EndScreen01())
     self.wait(5)
Esempio n. 27
0
 def get_text(self, *text, **kwargs):
     text_mob = TextMobject(*text)
     self.put_at_tip(text_mob, **kwargs)
     return text_mob
Esempio n. 28
0
 def construct(self):
     self.add(TextMobject("TODO: %s" % self.message))
     self.wait()
Esempio n. 29
0
    def get_table(elts_list,
                  buff_length=0.3,
                  cell_length=1,
                  cell_height=1,
                  line_color=WHITE,
                  text_color=WHITE,
                  background_color=BLACK):

        nb_l = len(elts_list)
        nb_c = len(elts_list[0])

        l_fill = 0.015

        table = VGroup()
        grid = VGroup()
        result = VGroup()

        rec = Polygon(
            (-cell_length / 2, cell_height / 2, 0),
            (-cell_length / 2 + (nb_c * cell_length), cell_height / 2, 0),
            (-cell_length / 2 + (nb_c * cell_length), cell_height / 2 -
             (nb_l) * cell_height, 0),
            (-cell_length / 2, cell_height / 2 - (nb_l) * cell_height, 0),
            mark_paths_closed=True,
            close_new_points=True,
            fill_color=background_color,
            fill_opacity=1,
            color=background_color)

        for i in range(nb_l):
            for j in range(nb_c):
                #elt = Text(elts_list[i][j],color = text_color, font = "Open Sans Bold Italic")

                if elts_list[i][j] != " ":  #TextMobject doesnt like " " strings
                    elt = TextMobject(elts_list[i][j], color=text_color)
                    elt.move_to([j * cell_length, -i * cell_height, 0])

                    table.add(elt)

        for i in range(nb_l + 1):

            # start_line_hor = (0, -i * cell_height,0) # + (-cell_length ,cell_height,0)
            # end_line_hor = ((nb_c * cell_length), -i * cell_height,0) # + (-cell_length ,cell_height,0)
            start_line_hor = (-cell_length / 2 - l_fill,
                              cell_height / 2 - i * cell_height, 0
                              )  # + ( ,cell_height,0)
            end_line_hor = (-cell_length / 2 + (nb_c * cell_length) + l_fill,
                            cell_height / 2 - i * cell_height, 0
                            )  # + (-cell_length ,cell_height,0)

            line_hor = Line(start=start_line_hor,
                            end=end_line_hor,
                            color=line_color)
            grid.add(line_hor)

        for j in range(nb_c + 1):
            start_line_ver = (-cell_length / 2 + j * cell_length,
                              cell_height / 2 + l_fill, 0
                              )  # (-cell_length ,cell_height,0)
            end_line_ver = (-cell_length / 2 + j * cell_length,
                            cell_height / 2 - (nb_l) * cell_height - l_fill, 0
                            )  # (-cell_length ,cell_height,0)

            line_ver = Line(start=start_line_ver,
                            end=end_line_ver,
                            color=line_color)
            grid.add(line_ver)

        #Rec = Rectangle()

        result.add(rec)
        result.add(table)
        result.add(grid)
        return result
Esempio n. 30
0
 def get_supporter_note(self):
     return TextMobject(
         "(Available to supporters for review now)",
         color="#F96854",
     )
Esempio n. 31
0
 def get_text(self,
              text,
              scale=1,
              buff=0.1,
              invert_dir=False,
              invert_texto=False,
              remove_rot=False,
              **moreargs):
     linea_referencia = Line(self[0][0].get_start(), self[0][-1].get_end())
     texto = TextMobject(text, **moreargs)
     ancho = texto.get_height() / 2
     if invert_texto:
         inv = PI
     else:
         inv = 0
     if remove_rot:
         texto.scale(scale).move_to(self)
     else:
         texto.rotate(
             linea_referencia.get_angle()).scale(scale).move_to(self)
         texto.rotate(inv)
     if invert_dir:
         inv = -1
     else:
         inv = 1
     texto.shift(self.direccion * (buff + 1) * ancho * inv)
     return texto
Esempio n. 32
0
 def get_author(self, quote):
     author = TextMobject(self.text_size + " --" + self.author)
     author.next_to(quote, DOWN, buff=self.author_buff)
     author.set_color(YELLOW)
     return author
Esempio n. 33
0
    def initialize_texts(self):
        geom_text = TextMobject("一个边长为$n$的正六边形", "和一些边长为1的菱形")
        eqtri_text = TextMobject("它们都是由若干正三角形组成的")
        three_types_text = TextMobject("因为朝向不同,菱形被分成三种")
        try_tiling_text = TextMobject("现在用这些菱形", "镶嵌", "正六边形...")
        remark = TextMobject("(无间隙且不重叠地覆盖)")
        claim_text = TextMobject("最终的图案中", "每种菱形的数量一定都是$n^2$")
        twist_text = TextMobject("改变菱形的摆放方式", "或者改变正六边形的大小", "这个结论依然成立")
        how_to_prove_text = TextMobject("如何证明?", "")

        for text in (geom_text, claim_text, twist_text):
            text.arrange_submobjects(DOWN, aligned_edge=LEFT)
        try_tiling_text[1].set_color(GREEN)
        remark.scale(0.5)
        remark.set_color(GREEN)
        remark.next_to(try_tiling_text[1], DOWN, buff=0.1)
        how_to_prove_text.set_color(YELLOW)

        bg_texts = VGroup(
            geom_text,
            eqtri_text,
            three_types_text,
            VGroup(try_tiling_text, remark),
        )
        q_texts = VGroup(
            claim_text,
            twist_text,
        )
        for texts in (bg_texts, q_texts, how_to_prove_text):
            texts.arrange_submobjects(DOWN, aligned_edge=LEFT, buff=1)
            texts.to_corner(LEFT + UP)

        self.bg_texts = bg_texts
        self.q_texts = q_texts
        self.how_to_prove_text = how_to_prove_text
Esempio n. 34
0
 def finished(self):
     sorted_text = TextMobject("Sorted")
     sorted_text.move_to(2 * UP)
     self.add(sorted_text)
Esempio n. 35
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)

        changed_patron_names = map(
            self.modify_patron_name,
            self.specific_patrons,
        )
        patrons = VGroup(*map(
            TextMobject,
            changed_patron_names,
        ))
        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(
            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, buff=MED_SMALL_BUFF)
        columns.next_to(underline, DOWN, buff=2)

        columns.generate_target()
        columns.target.to_edge(DOWN, buff=2)
        vect = columns.target.get_center() - columns.get_center()
        distance = get_norm(vect)
        wait_time = 20
        always_shift(
            columns,
            direction=normalize(vect),
            rate=(distance / wait_time)
        )

        self.add(columns, black_rect, line, thanks)
        self.wait(wait_time)
Esempio n. 36
0
    def setup_axes(self, animate=False):
        # TODO, once eoc is done, refactor this to be less redundant.
        x_num_range = float(self.x_max - self.x_min)
        self.space_unit_to_x = self.x_axis_width / x_num_range
        if self.x_labeled_nums is None:
            self.x_labeled_nums = []
        if self.x_leftmost_tick is None:
            self.x_leftmost_tick = self.x_min
        x_axis = NumberLine(
            x_min=self.x_min,
            x_max=self.x_max,
            unit_size=self.space_unit_to_x,
            tick_frequency=self.x_tick_frequency,
            leftmost_tick=self.x_leftmost_tick,
            numbers_with_elongated_ticks=self.x_labeled_nums,
            color=self.axes_color
        )
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
        if len(self.x_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.x_labeled_nums = [x for x in self.x_labeled_nums if x != 0]
            x_axis.add_numbers(*self.x_labeled_nums)
        if self.x_axis_label:
            x_label = TextMobject(self.x_axis_label)
            x_label.next_to(
                x_axis.get_tick_marks(), UP + RIGHT,
                buff=SMALL_BUFF
            )
            x_label.shift_onto_screen()
            x_axis.add(x_label)
            self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        self.space_unit_to_y = self.y_axis_height / y_num_range

        if self.y_labeled_nums is None:
            self.y_labeled_nums = []
        if self.y_bottom_tick is None:
            self.y_bottom_tick = self.y_min
        y_axis = NumberLine(
            x_min=self.y_min,
            x_max=self.y_max,
            unit_size=self.space_unit_to_y,
            tick_frequency=self.y_tick_frequency,
            leftmost_tick=self.y_bottom_tick,
            numbers_with_elongated_ticks=self.y_labeled_nums,
            color=self.axes_color,
            line_to_number_vect=LEFT,
            label_direction=LEFT,
        )
        y_axis.shift(self.graph_origin - y_axis.number_to_point(0))
        y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0))
        if len(self.y_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0]
            y_axis.add_numbers(*self.y_labeled_nums)
        if self.y_axis_label:
            y_label = TextMobject(self.y_axis_label)
            y_label.next_to(
                y_axis.get_corner(UP + RIGHT), UP + RIGHT,
                buff=SMALL_BUFF
            )
            y_label.shift_onto_screen()
            y_axis.add(y_label)
            self.y_axis_label_mob = y_label

        if animate:
            self.play(Write(VGroup(x_axis, y_axis)))
        else:
            self.add(x_axis, y_axis)
        self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis)
        self.default_graph_colors = it.cycle(self.default_graph_colors)
Esempio n. 37
0
    def construct(self):
        # Add title
        title = self.title = TextMobject("Clicky Stuffs")
        title.scale(1.5)
        title.to_edge(UP, buff=MED_SMALL_BUFF)

        pi_creatures = VGroup(Randolph(), Mortimer())
        for pi, vect in zip(pi_creatures, [LEFT, RIGHT]):
            pi.set_height(title.get_height())
            pi.change_mode("thinking")
            pi.look(DOWN)
            pi.next_to(title, vect, buff=MED_LARGE_BUFF)
        self.add(title, pi_creatures)

        # Set the top of the screen
        logo_box = Square(side_length=2.5)
        logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF)

        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)

        # Add thanks
        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)

        # Build name list
        with open("manimlib/files/patrons.txt", 'r') as fp:
            names = [
                self.modify_patron_name(name.strip())
                for name in fp.readlines()
            ]

        if self.randomize_order:
            random.shuffle(names)
        else:
            names.sort()

        name_labels = VGroup(*map(TextMobject, names))
        name_labels.scale(self.patron_scale_val)
        for label in name_labels:
            if label.get_width() > self.max_patron_width:
                label.set_width(self.max_patron_width)
        columns = VGroup(*[
            VGroup(*name_labels[i::self.n_patron_columns])
            for i in range(self.n_patron_columns)
        ])
        column_x_spacing = 0.5 + max([c.get_width() for c in columns])

        for i, column in enumerate(columns):
            for n, name in enumerate(column):
                name.shift(n * self.name_y_spacing * DOWN)
                name.align_to(ORIGIN, LEFT)
            column.move_to(i * column_x_spacing * RIGHT, UL)
        columns.center()

        max_width = FRAME_WIDTH - 1
        if columns.get_width() > max_width:
            columns.set_width(max_width)
        underline.match_width(columns)
        columns.next_to(underline, DOWN, buff=3)

        # Set movement
        columns.generate_target()
        distance = columns.get_height() + 2
        wait_time = self.scroll_time
        frame = self.camera.frame
        frame_shift = ApplyMethod(
            frame.shift,
            distance * DOWN,
            run_time=wait_time,
            rate_func=linear,
        )
        blink_anims = []
        blank_mob = Mobject()
        for x in range(wait_time):
            if random.random() < 0.25:
                blink_anims.append(Blink(random.choice(pi_creatures)))
            else:
                blink_anims.append(Animation(blank_mob))
        blinks = Succession(*blink_anims)

        static_group = VGroup(black_rect, line, thanks, pi_creatures, title)
        static_group.fix_in_frame()
        self.add(columns, static_group)
        self.play(frame_shift, blinks)
Esempio n. 38
0
    def setup_axes(self, animate=False):
        # TODO, once eoc is done, refactor this to be less redundant.
        x_num_range = float(self.x_max - self.x_min)
        self.space_unit_to_x = self.x_axis_width / x_num_range
        if self.x_labeled_nums is None:
            self.x_labeled_nums = []
        if self.x_leftmost_tick is None:
            self.x_leftmost_tick = self.x_min
        x_axis = NumberLine(
            x_min=self.x_min,
            x_max=self.x_max,
            unit_size=self.space_unit_to_x,
            tick_frequency=self.x_tick_frequency,
            leftmost_tick=self.x_leftmost_tick,
            numbers_with_elongated_ticks=self.x_labeled_nums,
            color=self.axes_color
        )
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
        if len(self.x_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.x_labeled_nums = [x for x in self.x_labeled_nums if x != 0]
            x_axis.add_numbers(*self.x_labeled_nums)
        if self.x_axis_label:
            x_label = TextMobject(self.x_axis_label)
            x_label.next_to(
                x_axis.get_tick_marks(), UP + RIGHT,
                buff=SMALL_BUFF
            )
            x_label.shift_onto_screen()
            x_axis.add(x_label)
            self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        self.space_unit_to_y = self.y_axis_height / y_num_range

        if self.y_labeled_nums is None:
            self.y_labeled_nums = []
        if self.y_bottom_tick is None:
            self.y_bottom_tick = self.y_min
        y_axis = NumberLine(
            x_min=self.y_min,
            x_max=self.y_max,
            unit_size=self.space_unit_to_y,
            tick_frequency=self.y_tick_frequency,
            leftmost_tick=self.y_bottom_tick,
            numbers_with_elongated_ticks=self.y_labeled_nums,
            color=self.axes_color,
            line_to_number_vect=LEFT,
            label_direction=LEFT,
        )
        y_axis.shift(self.graph_origin - y_axis.number_to_point(0))
        y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0))
        if len(self.y_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0]
            y_axis.add_numbers(*self.y_labeled_nums)
        if self.y_axis_label:
            y_label = TextMobject(self.y_axis_label)
            y_label.next_to(
                y_axis.get_corner(UP + RIGHT), UP + RIGHT,
                buff=SMALL_BUFF
            )
            y_label.shift_onto_screen()
            y_axis.add(y_label)
            self.y_axis_label_mob = y_label

        if animate:
            self.play(Write(VGroup(x_axis, y_axis)))
        else:
            self.add(x_axis, y_axis)
        self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis)
        self.default_graph_colors = it.cycle(self.default_graph_colors)
Esempio n. 39
0
    def construct(self):
        text = TextMobject("Hello")

        # Just run rate_func backward
        self.play(Write(text, rate_func=lambda t: smooth(1 - t)))
        self.wait()