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)))
Exemplo n.º 2
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, GREEN, BLUE)
        label3.to_edge(DOWN)

        self.add(square)
        self.play(FadeIn(label_group))
        self.play(FadeIn(label2_group))
        self.play(FadeIn(label3))
        self.wait(2)
Exemplo n.º 3
0
    def construct(self):
        circle = Circle(color=PURPLE_A)

        square = Square(fill_color=GOLD_B, fill_opacity=1, color=GOLD_A)
        square.move_to(UP + LEFT)

        circle.surround(square)

        rectangle = Rectangle(height=2, width=3)

        ellipse = Ellipse(width=3, height=1, color=RED)
        ellipse.shift(2 * DOWN + 2 * RIGHT)

        pointer = CurvedArrow(2 * RIGHT, 5 * RIGHT, color=MAROON_C)

        arrow = Arrow(LEFT, UP)
        arrow.next_to(circle, DOWN + LEFT)

        rectangle.next_to(arrow, DOWN + LEFT)

        circle2 = Circle()
        circle2.surround(rectangle, buffer_factor=1)

        ring = Annulus(inner_radius=.5, outer_radius=1, color=BLUE)
        ring.next_to(ellipse, RIGHT)

        self.add(pointer)
        self.add(circle2)
        self.play(FadeIn(square))
        self.play(Rotating(square), FadeIn(circle))
        self.play(GrowArrow(arrow))
        self.play(GrowFromCenter(rectangle), GrowFromCenter(ellipse),
                  GrowFromCenter(ring))

        self.wait()
Exemplo n.º 4
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.play(FadeIn(my_first_text), FadeIn(second_line))
        self.wait(2)
        self.play(Transform(second_line, third_line))
        self.wait(2)

        self.play(ApplyMethod(my_first_text.shift, 3 * UP))
        self.play(Rotating(second_line), radians=PI, run_time=2)
        self.wait()
Exemplo n.º 5
0
 def paste_selection(self):
     clipboard_str = pyperclip.paste()
     # Try pasting a mobject
     try:
         ids = map(int, clipboard_str.split(","))
         mobs = map(self.id_to_mobject, ids)
         mob_copies = [m.copy() for m in mobs if m is not None]
         self.clear_selection()
         self.add_to_selection(*mob_copies)
         self.play(*(
             FadeIn(mc, run_time=0.5, scale=1.5)
             for mc in mob_copies
         ))
         return
     except ValueError:
         pass
     # Otherwise, treat as tex or text
     if set("\\^=+").intersection(clipboard_str):  # Proxy to text for LaTeX
         try:
             new_mob = Tex(clipboard_str)
         except LatexError:
             return
     else:
         new_mob = Text(clipboard_str)
     self.clear_selection()
     self.add(new_mob)
     self.add_to_selection(new_mob)
Exemplo n.º 6
0
    def construct(self):
        self.phase = 0

        big_wave = self.make_graph(lambda x: self.upper_func(x) * 3,
                                   UPPER_COLOR).shift(4.5 * LEFT)
        self.play(ShowCreation(big_wave),
                  run_time=2,
                  rate_func=lambda t: running_start(t, pull_factor=1))
        self.wait()

        upper_axes = self.make_axes(0.9, "E_1").shift(UPPER_POSITION)
        self.upper_graph = self.make_graph(self.upper_func,
                                           UPPER_COLOR).shift(UPPER_POSITION)

        middle_axes = self.make_axes(0.9, "E_2").shift(MIDDLE_POSITION)
        self.middle_graph = self.make_graph(
            self.middle_func, MIDDLE_COLOR).shift(MIDDLE_POSITION)

        lower_axes = self.make_axes(1.4, "E_1 + E_2").shift(LOWER_POSITION)
        self.lower_graph = self.make_graph(self.lower_func,
                                           LOWER_COLOR).shift(LOWER_POSITION)

        self.play(
            AnimationGroup(Transform(big_wave, self.upper_graph, run_time=1.2),
                           FadeIn(upper_axes),
                           lag_ratio=0.5))
        self.bring_to_back(upper_axes)

        self.play(FadeIn(middle_axes), FadeIn(self.middle_graph))
        # self.wait()
        self.play(FadeIn(lower_axes), FadeIn(self.lower_graph))
        self.wait(0.5)

        self.play(
            UpdateFromAlphaFunc(VGroup(self.middle_graph, self.lower_graph),
                                self.anim_pi_2),
            run_time=2,
        )
        self.wait(0.5)
        self.play(
            UpdateFromAlphaFunc(VGroup(self.middle_graph, self.lower_graph),
                                self.anim_pi_3),
            run_time=1.5,
        )
        self.wait()
        self.wait()
Exemplo n.º 7
0
 def __init__(self, mobject, run_time=1, ratio_array=[0.01, 0.5, 0.5], fadeout_func=rush_into, **kwargs):
     animations = AGroup(
         FadeIn(mobject, run_time=ratio_array[0]*run_time),
         Indicate(mobject, run_time=ratio_array[1]*run_time,  **kwargs),
         FadeOut(mobject, run_time=ratio_array[2]*run_time, rate_func=fadeout_func))
     [animations.remove(animations[i])
      for i in range(len(ratio_array)) if ratio_array[i] == 0]
     super().__init__(*animations, **kwargs)
Exemplo n.º 8
0
    def construct(self):
        self.quote = self.get_quote()
        self.author = self.get_author(self.quote)

        self.play(FadeIn(self.quote, **self.fade_in_kwargs))
        self.wait(2)
        self.play(Write(self.author, run_time=3))
        self.wait()
Exemplo n.º 9
0
 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()
     added_anims = added_anims or []
     self.play(FadeIn(mobject, shift=UP), self.teacher.change, target_mode,
               *added_anims)
Exemplo n.º 10
0
    def __init__(self, vmobject: VMobject, stroke_width: float = 2, **kwargs):
        digest_config(self, kwargs)
        outline = vmobject.copy()
        outline.set_fill(opacity=0)
        outline.set_stroke(width=stroke_width, opacity=1)

        rate_func = kwargs.get("rate_func", smooth)
        super().__init__(
            FadeIn(vmobject,
                   rate_func=squish_rate_func(rate_func, self.fade_lag, 1)),
            VShowPassingFlash(outline, time_width=1), **kwargs)
Exemplo n.º 11
0
    def __init__(self, animation, run_time=0.1, ratio_array=[1, 1, 1], fadeout_func=rush_into, **kwargs):
        animations = AGroup(
            FadeIn(animation.mobject, rate_func=linear, run_time=run_time),

            #ApplyMethod(VGroup(*animation.mobject[:]).set_stroke,{"opacity":1}, run_time=0),
            animation,
            # IndicateThenFadeOut(
            #    animation.mobject, run_time=1, scale_factor=1, color=None, ratio_array=[0.95, 0.05], rate_func=fadeout_func)  # ,ratio_array=[1.2, 1.1, 0.05]

        )
        super().__init__(*animations, **kwargs)
Exemplo n.º 12
0
    def construct(self):
        plane = NumberPlane(**self.plane_kwargs)
        plane.add(plane.get_axis_labels())
        self.add(plane)

        self.field = VGroup(*[
            self.calc_field(x * RIGHT + y * UP) for x in np.arange(-9, 9, 1)
            for y in np.arange(-5, 5, 1)
        ])

        source_charge = self.Positron().move_to(self.point_charge_loc)
        self.play(FadeIn(source_charge))
        self.play(ShowCreation(self.field))
        self.moving_charge()
Exemplo n.º 13
0
    def construct(self):
        ellipse = Ellipse(width=self.width, height=self.width / 2)
        circle = Ellipse(width=self.width, height=self.width)
        line = Ellipse(width=self.width, height=0)

        for m in [ellipse, circle, line]:
            m.set_color(self.color)

        self.play(FadeIn(ellipse))
        self.wait()
        self.play(ellipse.become, circle)
        self.wait()
        self.play(ellipse.become, line)
        self.wait()
Exemplo n.º 14
0
    def make_axes(self):
        self.axes = Axes(x_min=-self.axes_scale * FRAME_X_RADIUS,
                         x_max=self.axes_scale * FRAME_X_RADIUS,
                         y_min=-self.axes_scale * FRAME_Y_RADIUS,
                         y_max=self.axes_scale * FRAME_Y_RADIUS,
                         x_axis_config={"include_ticks": False},
                         y_axis_config={"include_ticks": False},
                         number_line_config={"color": self.axes_color})
        self.axes_labels = self.axes.get_axis_labels(
            x_label_tex="E_x", y_label_tex="E_y").set_color(self.axes_color)

        self.play(
            AnimationGroup(GrowFromCenter(self.axes),
                           FadeIn(self.axes_labels),
                           lag_ratio=0.4))
Exemplo n.º 15
0
    def moving_charge(self):
        num_charges = 4
        possible_points = [v.get_start() for v in self.field]
        points = random.sample(possible_points, num_charges)

        particles = VGroup(
            *[self.Positron().move_to(point) for point in points])
        for particle in particles:
            particle.velocity = np.array((0, 0, 0))

        self.play(FadeIn(particles))
        self.moving_particles = particles
        self.add_foreground_mobjects(self.moving_particles)
        self.always_continually_update = True
        self.wait(10)
Exemplo n.º 16
0
 def get_digit_increment_animations(self):
     result = []
     self.number += 1
     is_next_digit = self.is_next_digit()
     if is_next_digit:
         self.max_place += 1
     new_number_mob = self.get_number_mob(self.number)
     new_number_mob.move_to(self.number_mob, RIGHT)
     if is_next_digit:
         self.add_configuration()
         place = len(new_number_mob.split()) - 1
         result.append(FadeIn(self.dot_templates[place]))
         arrow = Arrow(new_number_mob[place].get_top(),
                       self.dot_templates[place].get_bottom(),
                       color=self.digit_place_colors[place])
         self.arrows.add(arrow)
         result.append(ShowCreation(arrow))
     result.append(Transform(self.number_mob, new_number_mob,
                             lag_ratio=0.5))
     return result
Exemplo n.º 17
0
    def fadein(self, *mobjects, run_time=1, pre_time=0.5, post_time=1):

        self.wait(pre_time)
        self.play(FadeIn(Group(*mobjects)))
        self.wait(post_time)
        return self
Exemplo n.º 18
0
 def __init__(self, mobject, **kwargs):
     super().__init__(
         FadeIn(mobject, **kwargs),
         Indicate(mobject, **kwargs),
         **kwargs
     )
Exemplo 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)
    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()
Exemplo n.º 21
0
 def FadeInWindow(self):
     return FadeIn(self.background_mobject),
Exemplo n.º 22
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)
Exemplo n.º 23
0
    def construct(self):
        self.phase = 0

        point_x, point_y = self.comp_point(0)

        self.make_axes()

        self.ellipse = VMobject(color=self.path_color)

        self.phi = TexMobject(r"\Delta \Phi = ").set_color(BLACK).shift(4 *
                                                                        RIGHT +
                                                                        2 * UP)
        self.phi_0 = TexMobject("0").set_color(BLACK).next_to(self.phi, RIGHT)
        self.phi_pi_2 = TexMobject(r"\frac{\pi}{2}").set_color(BLACK).next_to(
            self.phi, RIGHT).shift(0.06 * DOWN)
        self.phi_3_pi_4 = TexMobject(r"\frac{3 \pi}{4}").set_color(
            BLACK).next_to(self.phi, RIGHT)

        self.x_vector = Vector(point_x * RIGHT,
                               color=self.axes_vector_color,
                               **self.vector_args)
        self.y_vector = Vector(point_y * UP,
                               color=self.axes_vector_color,
                               **self.vector_args)

        self.xy_vector = Vector(point_x * RIGHT + point_y * UP,
                                color=self.xy_vector_color,
                                **self.vector_args)

        update_group = VGroup(
            self.ellipse,
            self.xy_vector,
            self.x_vector,
            self.y_vector,
        )

        self.wait(1.6)
        self.add(self.ellipse)

        self.play(FadeIn(self.x_vector))
        # self.wait(1)
        self.play(FadeIn(self.y_vector))
        self.wait(4)
        self.play(FadeIn(self.xy_vector))
        self.play(UpdateFromAlphaFunc(update_group,
                                      self.do_vectors_and_ellipse_period),
                  run_time=self.period,
                  rate_func=linear)
        self.play(
            UpdateFromAlphaFunc(update_group,
                                self.do_vectors_only_period,
                                run_time=self.period,
                                rate_func=linear))
        self.play(
            AnimationGroup(UpdateFromAlphaFunc(update_group,
                                               self.do_vectors_only_period,
                                               run_time=self.period,
                                               rate_func=linear),
                           AnimationGroup(FadeIn(self.phi),
                                          FadeIn(self.phi_0)),
                           lag_ratio=0.7))
        self.play(
            UpdateFromAlphaFunc(update_group,
                                self.do_vectors_only_period,
                                run_time=self.period,
                                rate_func=linear))

        self.x_vector.set_color(BLACK)
        self.play(UpdateFromAlphaFunc(update_group,
                                      self.do_90_phase_shift,
                                      rate_func=linear),
                  FadeOut(self.ellipse),
                  FadeOut(self.phi_0),
                  FadeIn(self.phi_pi_2),
                  run_time=self.period / 4)

        self.phase = np.pi / 2
        self.ellipse.set_points([])
        self.x_vector.set_color(self.axes_vector_color)

        self.play(UpdateFromAlphaFunc(update_group,
                                      self.do_vectors_and_ellipse_period),
                  run_time=self.period,
                  rate_func=linear)
        for _ in range(3):
            self.play(UpdateFromAlphaFunc(update_group,
                                          self.do_vectors_only_period),
                      run_time=self.period,
                      rate_func=linear)

        self.x_vector.set_color(BLACK)
        self.play(UpdateFromAlphaFunc(update_group,
                                      self.do_45_phase_shift,
                                      rate_func=linear),
                  FadeOut(self.ellipse),
                  FadeOut(self.phi_pi_2),
                  FadeIn(self.phi_3_pi_4),
                  run_time=self.period / 8)

        self.phase = 3 * np.pi / 4
        self.ellipse.set_points([])
        self.x_vector.set_color(self.axes_vector_color)

        self.play(UpdateFromAlphaFunc(update_group,
                                      self.do_vectors_and_ellipse_period),
                  run_time=self.period,
                  rate_func=linear)

        self.play(
            AnimationGroup(UpdateFromAlphaFunc(
                update_group,
                self.do_vectors_only_period_hide,
                rate_func=linear,
                run_time=self.period),
                           AnimationGroup(FadeOut(self.phi_3_pi_4),
                                          FadeOut(self.phi)),
                           lag_ratio=0.7))
        self.play(FadeOut(self.axes), FadeOut(self.axes_labels))
        self.wait()