Exemplo n.º 1
0
    def __init__(self, pi_creature, *content, **kwargs):
        digest_config(self, kwargs)
        bubble = pi_creature.get_bubble(
            *content,
            bubble_class=self.bubble_class,
            **self.bubble_kwargs
        )
        Group(bubble, bubble.content).shift_onto_screen()

        pi_creature.generate_target()
        pi_creature.target.change_mode(self.target_mode)
        if self.look_at_arg is not None:
            pi_creature.target.look_at(self.look_at_arg)

        change_mode = MoveToTarget(pi_creature, **self.change_mode_kwargs)
        bubble_creation = self.bubble_creation_class(
            bubble, **self.bubble_creation_kwargs
        )
        content_introduction = self.content_introduction_class(
            bubble.content, **self.content_introduction_kwargs
        )
        AnimationGroup.__init__(
            self, change_mode, bubble_creation, content_introduction,
            **kwargs
        )
 def __init__(self, mobject, **kwargs):
     digest_config(self, kwargs)
     rect = SurroundingRectangle(mobject,
                                 **self.surrounding_rectangle_config)
     if "surrounding_rectangle_config" in kwargs:
         kwargs.pop("surrounding_rectangle_config")
     AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))
Exemplo n.º 3
0
    def __init__(self, pi_creature, *content, **kwargs):
        digest_config(self, kwargs)
        bubble = pi_creature.get_bubble(
            *content,
            bubble_class=self.bubble_class,
            **self.bubble_kwargs
        )
        Group(bubble, bubble.content).shift_onto_screen()

        pi_creature.generate_target()
        pi_creature.target.change_mode(self.target_mode)
        if self.look_at_arg is not None:
            pi_creature.target.look_at(self.look_at_arg)

        change_mode = MoveToTarget(pi_creature, **self.change_mode_kwargs)
        bubble_creation = self.bubble_creation_class(
            bubble, **self.bubble_creation_kwargs
        )
        content_introduction = self.content_introduction_class(
            bubble.content, **self.content_introduction_kwargs
        )
        AnimationGroup.__init__(
            self, change_mode, bubble_creation, content_introduction,
            **kwargs
        )
Exemplo n.º 4
0
    def __init__(self, point, color=YELLOW, **kwargs):
        digest_config(self, kwargs)
        lines = VGroup()
        for angle in np.arange(0, TAU, TAU / self.num_lines):
            line = Line(ORIGIN, self.line_length * RIGHT)
            line.shift((self.flash_radius - self.line_length) * RIGHT)
            line.rotate(angle, about_point=ORIGIN)
            lines.add(line)
        lines.move_to(point)
        lines.set_color(color)
        lines.set_stroke(width=3)
        line_anims = [
            ShowCreationThenDestruction(
                line, rate_func=squish_rate_func(smooth, 0, 0.5)
            )
            for line in lines
        ]
        fade_anims = [
            UpdateFromAlphaFunc(
                line, lambda m, a: m.set_stroke(
                    width=self.line_stroke_width * (1 - a)
                ),
                rate_func=squish_rate_func(smooth, 0, 0.75)
            )
            for line in lines
        ]

        AnimationGroup.__init__(
            self, *line_anims + fade_anims, **kwargs
        )
Exemplo n.º 5
0
 def __init__(self, bubble, **kwargs):
     digest_config(self, kwargs)
     create_bubble = self.bubble_animation_class(
         bubble, *self.bubble_animation_args,
         **self.bubble_animation_kwargs)
     create_content = self.content_animation_class(
         VGroup(*bubble.content), *self.content_animation_args,
         **self.content_animation_kwargs)
     AnimationGroup.__init__(self, create_bubble, create_content, **kwargs)
Exemplo n.º 6
0
 def __init__(self, mobject, **kwargs):
     assert (isinstance(mobject, Mobject))
     digest_config(self, kwargs)
     if not hasattr(mobject, "lines"):
         self.generate_lines(mobject)
     if not hasattr(mobject, "rectangle"):
         self.generate_rec(mobject)
     mobject.rectangle.save_state()
     mobject.rectangle.set_width(0, stretch=True, about_edge=LEFT)
     AnimationGroup.__init__(self, ShowCreation(mobject.lines, lag_ratio=0),
                             Restore(mobject.rectangle), **kwargs)
Exemplo n.º 7
0
 def __init__(self, mobject, **kwargs):
     assert (isinstance(mobject, Mobject))
     digest_config(self, kwargs)
     if not hasattr(mobject, "lines"):
         raise AttributeError("mobject must has lines attribute")
     if not hasattr(mobject, "rectangle"):
         raise AttributeError("mobject must has rectangle attribute")
     mobject.rectangle.generate_target()
     mobject.rectangle.target.set_width(0, stretch=True, about_edge=LEFT)
     AnimationGroup.__init__(self, Uncreate(mobject.lines, lag_ratio=0),
                             MoveToTarget(mobject.rectangle), **kwargs)
     del mobject.lines, mobject.rectangle
Exemplo n.º 8
0
 def __init__(self, vmobject, **kwargs):
     digest_config(self, kwargs)
     max_stroke_width = vmobject.get_stroke_width()
     max_time_width = kwargs.pop("time_width", self.time_width)
     AnimationGroup.__init__(
         self, *[
             VShowPassingFlash(
                 vmobject.deepcopy().set_stroke(width=stroke_width),
                 time_width=time_width,
                 **kwargs) for stroke_width, time_width in zip(
                     np.linspace(0, max_stroke_width, self.n_segments),
                     np.linspace(max_time_width, 0, self.n_segments))
         ])
Exemplo n.º 9
0
    def __init__(self, pi_creature, **kwargs):
        assert hasattr(pi_creature, "bubble")
        digest_config(self, kwargs, locals())

        pi_creature.generate_target()
        pi_creature.target.change_mode(self.target_mode)
        if self.look_at_arg is not None:
            pi_creature.target.look_at(self.look_at_arg)

        AnimationGroup.__init__(
            self,
            MoveToTarget(pi_creature),
            FadeOut(pi_creature.bubble),
            FadeOut(pi_creature.bubble.content),
        )
Exemplo n.º 10
0
    def __init__(self, pi_creature, **kwargs):
        assert hasattr(pi_creature, "bubble")
        digest_config(self, kwargs, locals())

        pi_creature.generate_target()
        pi_creature.target.change_mode(self.target_mode)
        if self.look_at_arg is not None:
            pi_creature.target.look_at(self.look_at_arg)

        AnimationGroup.__init__(
            self,
            MoveToTarget(pi_creature),
            FadeOut(pi_creature.bubble),
            FadeOut(pi_creature.bubble.content),
        )
Exemplo n.º 11
0
 def __init__(self, vmobject, **kwargs):
     digest_config(self, kwargs)
     max_stroke_width = vmobject.get_stroke_width()
     max_time_width = kwargs.pop("time_width", self.time_width)
     AnimationGroup.__init__(self, *[
         ShowPassingFlash(
             vmobject.deepcopy().set_stroke(width=stroke_width),
             time_width=time_width,
             **kwargs
         )
         for stroke_width, time_width in zip(
             np.linspace(0, max_stroke_width, self.n_segments),
             np.linspace(max_time_width, 0, self.n_segments)
         )
     ])
Exemplo n.º 12
0
    def construct(self):
        number_line = NumberLine(x_min=-2, x_max=2)
        text_1 = TextMobject("Theorem of") \
            .next_to(number_line, DOWN)
        text_2 = TextMobject("Beethoven") \
            .next_to(number_line, DOWN)
        dashed_line = DashedLine(
            number_line.get_left(),
            number_line.get_right(),
            color=YELLOW,
        ).set_stroke(width=11)

        self.add(number_line, text_1)

        self.play(
            LaggedStart(*[
                ShowCreationThenDestruction(dashed_segment)
                for dashed_segment in dashed_line
            ],
                        run_time=5),
            AnimationGroup(Animation(Mobject(), run_time=2.1),
                           ReplacementTransform(text_1, text_2),
                           lag_ratio=1))

        self.wait()
Exemplo n.º 13
0
    def construct(self):
        number_line = NumberLine(x_min=-2, x_max=2)
        triangle = RegularPolygon(3, start_angle=-PI / 2) \
            .scale(0.2) \
            .next_to(number_line.get_left(), UP, buff=SMALL_BUFF)
        numbers = VGroup(
            *[TextMobject("%s" % i) \
                  .next_to(number_line.get_tick(i - 2), DOWN) for i in range(1, 5)]
        )

        self.add(number_line)
        self.play(ShowCreation(triangle))
        self.wait(0.3)

        self.play(
            ApplyMethod(triangle.shift,
                        RIGHT * 4,
                        rate_func=linear,
                        run_time=4),
            *[
                AnimationGroup(Animation(Mobject(), run_time=i + 1),
                               Write(numbers[i]),
                               lag_ratio=1) for i in range(4)
            ],
        )

        self.wait()
Exemplo n.º 14
0
    def get_logo_animations(self, logo):
        layers = logo.spike_layers
        for i, layer in enumerate(layers):
            random.shuffle(layer.submobjects)
            for spike in layer:
                spike.save_state()
                spike.scale(0.5)
                spike.apply_complex_function(np.log)
                spike.rotate(-90 * DEGREES, about_point=ORIGIN)
                spike.set_fill(opacity=0)
            layer.rotate(i * PI / 5)

        logo.iris_background.save_state()
        logo.iris_background.scale(0.25)
        logo.iris_background.fade(1)

        return [
            Restore(
                logo.iris_background,
                run_time=3,
            ),
            AnimationGroup(*[
                LaggedStartMap(
                    Restore,
                    layer,
                    run_time=3,
                    path_arc=180 * DEGREES,
                    # rate_func=squish_rate_func(smooth, a / 3.0, (a + 1.9) / 3.0),
                    lag_ratio=0.8,
                ) for layer, a in zip(layers, [0, 0.2, 0.1, 0])
            ]),
            Animation(logo.pupil),
        ]
Exemplo n.º 15
0
 def __init__(self, *animations, time=None, group=False, time_wait=None, **kwargs):
     merge_config_kwargs(self, kwargs)
     while isinstance(animations[-1], (int, float, bool)):
         if isinstance(animations[-1], bool):
             if int(animations[-1]) == 1:
                 group = True
             animations = animations[:-1]
         elif isinstance(animations[-1], (int, float)):
             if animations[-1] > 0:
                 time = animations[-1]
             elif animations[-1] < 0:
                 time_wait = -animations[-1]
             animations = animations[:-1]
     if group:
         animations = [AnimationGroup(*animations, **kwargs)]
     anims = AGroup(*animations)
     if time is not None:
         self.time=time
     if self.delay:
         anims.add_to_back(Freeze(self.time))
     else:
         anims.add(Freeze(self.time))
     if time_wait is not None:
         anims.add(Freeze(time_wait))
     super().__init__(*anims, **kwargs)
Exemplo n.º 16
0
 def display(self, *args, run_time=0.07, **kwargs):
     if isinstance(args[-1], (int, float)):
         run_time = args[-1]
         args = args[:-1]
     try:
         self.play(AnimationGroup(*args), run_time=run_time, **kwargs)
     except:
         try:
             self.play(AnimationGroup(*args),
                       run_time=run_time * 4,
                       **kwargs)
         except:
             try:
                 self.play(AnimationGroup(*args),
                           run_time=run_time * 2,
                           **kwargs)
             except:
                 self.play(AnimationGroup(*args), run_time=1, **kwargs)
Exemplo n.º 17
0
 def __init__(self, *animations, run_time=0.1, **kwargs):
     anims = AGroup(
         #FadeIn(animation.mobject, run_time=0.01),
         *animations,
         # IndicateThenFadeOut(
         #    animation.mobject, run_time=0.1, scale_factor=1, color=None, ratio_array=[0.05, 0.95], rate_func=fadeout_func)  # ,ratio_array=[1.2, 1.1, 0.05]
         DFadeOut(AnimationGroup(*animations).mobject,
                  run_time=run_time, **kwargs)
     )
     super().__init__(*anims)
Exemplo n.º 18
0
 def __init__(self, vmobject, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([vmobject])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     digest_config(self, kwargs)
     max_stroke_width = vmobject.get_stroke_width()
     max_time_width = kwargs.pop("time_width", self.time_width)
     AnimationGroup.__init__(
         self, *[
             ShowPassingFlash(
                 vmobject.deepcopy().set_stroke(width=stroke_width),
                 time_width=time_width,
                 **kwargs) for stroke_width, time_width in zip(
                     np.linspace(0, max_stroke_width, self.n_segments),
                     np.linspace(max_time_width, 0, self.n_segments))
         ])
Exemplo n.º 19
0
    def construct(self):
        number_line = NumberLine(x_min=-2, x_max=2)
        triangle = RegularPolygon(3, start_angle=-PI / 2) \
            .scale(0.2) \
            .next_to(number_line.get_left(), UP, buff=SMALL_BUFF)
        text_1 = TextMobject("1") \
            .next_to(number_line.get_tick(-1), DOWN)
        text_2 = TextMobject("2") \
            .next_to(number_line.get_tick(0), DOWN)
        text_3 = TextMobject("3") \
            .next_to(number_line.get_tick(1), DOWN)
        text_4 = TextMobject("4") \
            .next_to(number_line.get_tick(2), DOWN)

        self.add(number_line)
        self.play(ShowCreation(triangle))
        self.wait(0.3)

        self.play(
            ApplyMethod(triangle.shift,
                        RIGHT * 4,
                        rate_func=linear,
                        run_time=4),
            AnimationGroup(Animation(Mobject(), run_time=1),
                           Write(text_1),
                           lag_ratio=1),
            AnimationGroup(Animation(Mobject(), run_time=2),
                           Write(text_2),
                           lag_ratio=1),
            AnimationGroup(Animation(Mobject(), run_time=3),
                           Write(text_3),
                           lag_ratio=1),
            AnimationGroup(Animation(Mobject(), run_time=4),
                           Write(text_4),
                           lag_ratio=1))

        self.wait()
Exemplo n.º 20
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.º 21
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.º 22
0
 def __init__(self, *mobjects, run_time=0.05, lag_ratio=1, **kwargs):
     while isinstance(mobjects[-1], (int, float)):
         run_time = run_time
         mobjects = mobjects[:-1]
     animations = AGroup()
     vmobjs = VGroup()
     mobjs = Group()
     for each in mobjects:
         if isinstance(each, (VMobject)):
             vmobjs.add(each)
         else:
             mobjs.add(each)
     if len(mobjs) > 0:
         animations.add(Show(mobjs, run_time=run_time, **kwargs))
     if len(vmobjs) > 0:
         animations.add(Write(vmobjs, run_time=run_time, **kwargs))
     super().__init__(
         AnimationGroup(*animations, run_time=run_time, lag_ratio=lag_ratio, **kwargs))
Exemplo n.º 23
0
    def get_logo_animations(self, logo):
        layers = logo.spike_layers

        for j, layer in enumerate(layers):
            for i, spike in enumerate(layer):
                spike.angle = (13 * (i + 1) * (j + 1) * TAU / 28) % TAU
                if spike.angle > PI:
                    spike.angle -= TAU
                spike.save_state()
                spike.rotate(spike.angle, about_point=ORIGIN)
                # spike.get_points()[1] = rotate_vector(
                #     spike.get_points()[1], TAU/28,
                # )
                # spike.get_points()[-1] = rotate_vector(
                #     spike.get_points()[-1], -TAU/28,
                # )

        def get_spike_animation(spike, **kwargs):
            return Restore(spike, path_arc=-spike.angle, **kwargs)

        logo.iris_background.save_state()
        # logo.iris_background.scale(0.49)
        logo.iris_background.set_fill(GREY_D, 0.5)

        return [
            Restore(
                logo.iris_background,
                rate_func=squish_rate_func(smooth, 2.0 / 3, 1),
                run_time=3,
            ),
            AnimationGroup(*[
                LaggedStartMap(
                    get_spike_animation,
                    layer,
                    run_time=2,
                    # rate_func=squish_rate_func(smooth, a / 3.0, (a + 0.9) / 3.0),
                    lag_ratio=0.2,
                ) for layer, a in zip(layers, [0, 2, 1, 0])
            ]),
            Animation(logo.pupil),
        ]
Exemplo n.º 24
0
    def show(
        self,
        text_anim: Animation = Write,
        arrow_anim: Animation = FadeInFromDown,
        **kwargs,
    ) -> AnimationGroup:
        """Workaround and shortcut method to overcome the bugs in `Write`.

        Args:
            text_anim (Animation, optional): The animation on the reactants and products. Defaults to Write.
            arrow_anim (Animation, optional): The animation on the arrow. Defaults to FadeInFromDown.

        Returns:
            AnimationGroup: The group of animations on the text and arrow.
        """
        text = VGroup(self[0:2 * len(self.reactants) - 1],
                      self[2 * len(self.reactants):])
        arrow = self[2 * len(self.reactants) - 1]

        if "text_kwargs" not in kwargs.keys():
            kwargs["text_kwargs"] = dict()

        if "arrow_kwargs" not in kwargs.keys():
            kwargs["arrow_kwargs"] = dict()

        if "group_kwargs" not in kwargs.keys():
            kwargs["group_kwargs"] = dict()

        print(kwargs["group_kwargs"])

        anim_group = AnimationGroup(text_anim(text), arrow_anim(arrow),
                                    **kwargs)

        try:
            print(anim_group.run_time)
        except Exception:
            pass
        return anim_group
Exemplo n.º 25
0
    def construct(self):
        number_line = NumberLine(x_min=-2, x_max=2)
        text = TextMobject("Text") \
            .next_to(number_line, DOWN)
        dashed_line = DashedLine(
            number_line.get_left(),
            number_line.get_right(),
            color=YELLOW,
        ).set_stroke(width=11)

        self.add(number_line)
        self.wait(0.3)

        self.play(
            LaggedStart(*[
                ShowCreationThenDestruction(dashed_segment)
                for dashed_segment in dashed_line
            ],
                        run_time=5),
            AnimationGroup(Animation(Mobject(), run_time=2.1),
                           Write(text),
                           lag_ratio=1))
        self.wait()
Exemplo n.º 26
0
 def diminish(self,
              *mobjects,
              run_time=1,
              pre_time=0.5,
              post_time=1,
              **kwargs):
     '''
     if not isinstance(mobject_or_chars, (list, tuple, ndarray)):
         mobject_or_chars = [mobject_or_chars]
     mobject = VGroup(*[MobjectOrChars(each) for each in mobject_or_chars])
     '''
     if not mobjects:
         mobjects = ListedMobject(self.mobjects)
     imobjs = Group()
     vmobjs = VGroup()
     mobjs = Group()
     for each in mobjects:
         if isinstance(each, ImageMobjectGroup):
             imobjs.add(each)
         elif isinstance(each, VMobject):
             vmobjs.add(each)
         else:
             mobjs.add(each)
     '''
     vmobjs=VGroup(*[each.remove_from_group(mobjects) for each in mobjects if isinstance(each, VMobject)])
     mobjs=Group(*[each for each in mobjects if isinstance(each, Mobject)])
     '''
     #mobject = GroupedMobject(mobjects)
     #keys = ["shift"]
     #[exec("mobject."+key+"(["+','.join(str(x) for x in kwargs.get(key))+"])",
     #      {"mobject": mobject}) for key in keys if key in kwargs]
     #self.wait(pre_time)
     self.play(
         AnimationGroup(DiminishToPoint(vmobjs, [0, 0, 0]), DFadeOut(mobjs),
                        ShrinkToCenter(imobjs)))
     self.wait(post_time)
     return self
Exemplo n.º 27
0
 def creation_anim(
         self,
         label_anim: Animation = FadeIn,
         brace_anim: Animation = GrowFromCenter) -> AnimationGroup:
     return AnimationGroup(brace_anim(self.brace), label_anim(self.label))
Exemplo n.º 28
0
 def reset_counters(self):
     reset_anims = [
         rhombus.change_counter_tex_animation(0) for rhombus in self.rhombi
     ]
     self.play(AnimationGroup(*reset_anims), run_time=1)
     self.wait()
Exemplo n.º 29
0
    def construct(self):
        if 1 == 1:
            try:
                self.add_sound(
                    "sidewayoutput\\basicmanim\\transform001b_01_01_02_01_01.wav",
                    time_offset=18)
                self.add_sound(
                    "sidewayoutput\\basicmanim\\transform001b_01_01_02_02_01.wav",
                    time_offset=48)
                self.add_sound(
                    "sidewayoutput\\basicmanim\\transform001b_01_01_02_02_02.wav",
                    time_offset=93)
                self.add_sound(
                    "sidewayoutput\\basicmanim\\transform001b_01_01_02_03_01.wav",
                    time_offset=148)
            except:
                pass
            self.play(
                StartScreens01(
                    [],
                    [],
                    [[r"\textbf{\textit{Basic-Manim from }\{Sideway\}}"],
                     [r"\textbf{\textit{Transform}}\\{Part\ \textspA{I}b}"],
                     [
                         r"\tiny{\textrm{basic-manim.210201951v0\_transform001b}}"
                     ], [],
                     [
                         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{Apply\ Transform}}}").
                    shift([0, 3.6, 0])))
            rows, cols = (7, 3)
            x = 5.
            x0, y0 = axes_point([-2.5, x, cols - 1, -5],
                                [2., -1.1, rows - 1, 3])
            txtx = ["\\underline{state 1}", "\\underline{state 2}"]
            txty = ["Method", "ApplyMethod", "ApplyFunction"]

            a1 = [
                "\\normalsize{sq[0]}", "\\normalsize{sq[1]}",
                "\\normalsize{sq[2]}"
            ]
            a2 = [
                r"\normalsize{sq[0]\\.shift([" + str(x) + r",\,0,\,0])}",
                r"\normalsize{ApplyMethod(\\sq[1].shift,\,[" + str(x) +
                r",\,0,\,0])}",
                r"\normalsize{ApplyFunction(\\lambda\,mob:\,mob.shift([" +
                str(x) + r",\,0,\,0]),\,sq[2])}"
            ]
            sq = [GeomSquare(0.75) for i in range(3)]

            self.fadein(
                *[
                    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]))
                ],
                *[GeomPoint(each) for each in coord_grid(x0[1:3], y0[2::2])],
                *[
                    MobjectOrChars(np.ravel(list(zip(a1,
                                                     a2)))[i]).move_to(each)
                    for i, each in enumerate(coord_grid(x0[1:3], y0[1::2]))
                ],
                *[
                    sq[i].move_to(each)
                    for i, each in enumerate(coord_grid(x0[1:2], y0[2::2]))
                ],
                run_time=5)
            self.play(AnimationGroup(
                ShowCreation(sq[0].shift([x, 0, 0]), run_time=0),
                ApplyMethod(sq[1].shift, [x, 0, 0]),
                ApplyFunction(lambda mob: mob.shift([x, 0, 0]), sq[2])),
                      run_time=15)
            self.fadeout()
        if 1 == 1:
            self.play(
                GrowFromCenter(
                    TextMobject(
                        r"\textit{\textbf{\underline{Apply Method}}}").shift(
                            [0, 3.6, 0]).add_as_foreground(self)))
            rows, cols = (8, 2)
            x0, y0 = axes_point([-1.5, 6, cols], [3, -0.9, rows])
            txty = [
                MobjectOrChars(each) for each in [
                    r"FadeToColor(sq[0],\,RED)", r"ScaleInPlace(sq[1],\,0.5))",
                    "ShrinkToCenter(sq[2])", "Restore(sq[3])"
                ]
            ]
            a1 = [
                MobjectOrChars("\\normalsize{sq[" + str(i) + "]}")
                for i in range(4)
            ]
            sq = [GeomSquare(0.75) for i in range(4)]
            self.fadein(
                *[
                    to_get_zlist(a1, sq)[i].move_to(each)
                    for i, each in enumerate(coord_grid(x0[1:2], y0))
                ],
                *[GeomPoint(each) for each in coord_grid(x0[1:2], y0[1::2])],
            )
            self.wait()
            sq[3].save_state()
            self.play(AnimationGroup(
                IndicateThenFadeOut(TextMobject(
                    r"Transform(sq[3], Circle().scale(0.375).\\move\_to(sq[3]).shift([1, 0, 0])))"
                ).move_to([x0[0], y0[7], 0]),
                                    scale_factor=1,
                                    ratio_array=[1, 0]),
                Transform(
                    sq[3],
                    Circle().scale(0.375).move_to(sq[3]).shift([1, 0, 0]))),
                      run_time=5)
            self.wait()
            self.fadein(
                *[
                    txty[i].move_to(each)
                    for i, each in enumerate(coord_grid(x0[0:1], y0[1::2]))
                ], )
            self.play(AnimationGroup(
                FadeToColor(sq[0], RED),
                ScaleInPlace(sq[1], 0.5),
                ShrinkToCenter(sq[2]),
                Restore(sq[3]),
            ),
                      run_time=35)
            self.fadeout(exclude_mobjs="foreground")
        if 1 == 1:
            rows, cols = (6, 2)
            x0, y0 = axes_point([-1.5, 6, cols], [3, -0.9, rows])
            txty = [
                MobjectOrChars(each) for each in [
                    r"ApplyPointwiseFunction(\\lambda\,pointarray:\,pointarray\,+\,[1,\,0,\,0],\,sq[0])",
                    r"ApplyMatrix([[1.23,\,0.9],\,[0,\,1]],\,sq[1])",
                    r"ApplyComplexFunction(lambda pointarray:\\pointarray\,+\,np.complex(1,\,0),\,sq[2])",
                ]
            ]
            a1 = [
                MobjectOrChars("\\normalsize{sq[" + str(i) + "]}")
                for i in range(4)
            ]
            sq = [GeomSquare(0.75) for i in range(4)]
            self.fadein(
                *[
                    to_get_zlist(a1, sq)[i].move_to(each)
                    for i, each in enumerate(coord_grid(x0[1:2], y0))
                ],
                *[GeomPoint(each) for each in coord_grid(x0[1:2], y0[1::2])],
            )
            self.wait()
            self.fadein(
                *[
                    txty[i].move_to(each)
                    for i, each in enumerate(coord_grid(x0[0:1], y0[1::2]))
                ], )
            self.play(AnimationGroup(
                ApplyPointwiseFunction(
                    lambda pointarray: pointarray + [1, 0, 0], sq[0]),
                ApplyMatrix([[1.23, 0.9], [0, 1]], sq[1]),
                ApplyComplexFunction(
                    lambda pointarray: pointarray + np.complex(1, 0), sq[2]),
            ),
                      run_time=45)
            self.fadeout()
        if 1 == 1:
            self.play(
                GrowFromCenter(
                    TextMobject(
                        r"\textit{\textbf{\underline{Swap Method}}}").shift(
                            [0, 3.6, 0])))
            rows, cols = (2, 2)
            count = m, n = [2, 6]
            x0, y0 = axes_point([-3.5, 6, cols], [2.4, -3.7, rows])
            geometrys = [GeomLine(), GeomRegularPolygon(n, radius=2)]
            txty = [
                MobjectOrChars(each) for each in [
                    r"Swap(*sqs)\\ \tiny{(same as CyclicReplace)}",
                    r"CyclicReplace(*sqs)",
                ]
            ]
            titles = [
                [
                    MobjectOrChars("\\normalsize{sq[" + str(i) + "]}")
                    for i in range(m)
                ],
                [
                    MobjectOrChars("\\normalsize{sq[" + str(i) + "]}")
                    for i in range(n)
                ],
            ]
            sqs = [
                [GeomSquare(1.) for i in range(m)],
                [GeomSquare(1.) for i in range(n)],
            ]
            [[
                sq.add(title).add(GeomPoint())
                for sq, title in zip(sqs[i], titles[i])
            ] for i in range(len(count))]
            self.fadein(*[
                geometrys[i].move_to(each)
                for i, each in enumerate(coord_grid(x0[1:], y0[0:]))
            ])
            self.fadein(*[
                Group(*[
                    sqs[j][i].move_to(each) for i, each in enumerate(
                        geometrys[j].get_counting_points())
                ]) for j in range(2)
            ])
            self.fadein(
                *[
                    txty[i].move_to(each)
                    for i, each in enumerate(coord_grid(x0[0:1], y0[0:]))
                ], )
            self.play(AnimationGroup(
                Swap(*sqs[0]),
                CyclicReplace(*sqs[1]),
            ),
                      run_time=35)
            self.fadeout()
        if 1 == 1:
            self.play(EndScreen01())
        self.wait(5)
Exemplo n.º 30
0
 def clean_up(self, surrounding_scene=None):
     AnimationGroup.clean_up(self, surrounding_scene)
     self.omega_creature.bubble = None
     if surrounding_scene is not None:
         surrounding_scene.add(self.omega_creature)
Exemplo n.º 31
0
 def clean_up_from_scene(self, scene=None):
     AnimationGroup.clean_up_from_scene(self, scene)
     self.pi_creature.bubble = None
     if scene is not None:
         scene.add(self.pi_creature)
Exemplo n.º 32
0
 def clean_up_from_scene(self, scene=None):
     AnimationGroup.clean_up_from_scene(self, scene)
     self.pi_creature.bubble = None
     if scene is not None:
         scene.add(self.pi_creature)
Exemplo n.º 33
0
 def construct_infinite_sum(self):
     for n in range(1, 11):
         # Get highlighted terms
         highlighted_terms = self.get_highlighted_terms(n)
         # Update highlight rectangles
         if n == 1:
             rects = self.get_highlight_rectangles(1)
             self.play(ShowCreation(rects), lag_ratio=0.2)
             self.wait()
         else:
             new_rects = self.get_highlight_rectangles(n)
             self.play(Transform(rects, new_rects))
             if n <= 4:
                 self.wait()
         # Show the detailed construction of the first four terms
         if n <= 4:
             # Make copies of the elements that are going to be moved
             highlighted_terms_copy = self.get_highlighted_terms(
                 n).deepcopy()
             times_symbols_copy = self.get_times_symbols().deepcopy()
             cdots_copy = self.get_cdots_symbol().deepcopy()
             # Move highlighted terms into position
             arranged_terms_list = []
             for i in range(4):
                 arranged_terms_list.append(highlighted_terms_copy[i])
                 arranged_terms_list.append(times_symbols_copy[i])
             arranged_terms_list.append(cdots_copy)
             arranged_terms = VGroup(*arranged_terms_list)
             arranged_terms.arrange_submobjects(RIGHT, buff=0.2)
             arranged_terms.next_to(self.sum_tex,
                                    UP,
                                    aligned_edge=RIGHT,
                                    buff=0.5)
             # Move highlighted terms into position
             anims_list = []
             for i in range(4):
                 anims_list.append(
                     ReplacementTransform(
                         self.get_highlighted_terms(n)[i].deepcopy(),
                         arranged_terms[2 * i],
                         lag_ratio=0,
                         run_time=2))
                 anims_list.append(
                     ReplacementTransform(
                         self.get_times_symbols()[i].deepcopy(),
                         arranged_terms[2 * i + 1],
                         lag_ratio=0,
                         run_time=2))
             anims_list.append(
                 ReplacementTransform(self.get_cdots_symbol().deepcopy(),
                                      arranged_terms[-1],
                                      lag_ratio=0,
                                      run_time=2))
             self.play(AnimationGroup(*anims_list))
             self.wait()
             if n == 1:
                 self.play(Transform(arranged_terms, self.get_sum_term(n)))
             else:
                 self.play(
                     Transform(arranged_terms, self.get_sum_term(n)),
                     Write(self.get_plus_symbol(n - 1)),
                 )
             self.wait()
         # And show the result for the remaining terms
         else:
             self.play(
                 Transform(
                     VGroup(
                         self.get_highlighted_terms(n).deepcopy(),
                         self.get_times_symbols().deepcopy(),
                         self.get_cdots_symbol().deepcopy(),
                     ),
                     self.get_sum_term(n),
                     lag_ratio=0,
                 ),
                 Write(self.get_plus_symbol(n - 1)),
             )
     # Add \cdots to the end.
     self.wait()
     self.play(FadeOut(rects), Write(self.sum_tex[-1][-4:]))
     self.wait()
Exemplo n.º 34
0
    def construct(self):
        logo = self.logo
        name = self.channel_name

        layers = logo.spike_layers

        logo.save_state()

        for layer in layers:
            for spike in layer:
                spike.save_state()
                point = np.array(spike.get_points()[0])
                angle = angle_of_vector(point)
                spike.rotate(-angle + 90 * DEGREES)
                spike.stretch_to_fit_width(0.2)
                spike.stretch_to_fit_height(0.5)
                spike.point = point
            for spike in layer[::2]:
                spike.rotate(180 * DEGREES)
            layer.arrange(LEFT, buff=0.1)
        layers.arrange(UP)
        layers.to_edge(DOWN)

        wrong_spike = layers[1][-5]
        wrong_spike.real_saved_state = wrong_spike.saved_state.copy()
        wrong_spike.saved_state.scale(0.25, about_point=wrong_spike.point)
        wrong_spike.saved_state.rotate(90 * DEGREES)
        self.wrong_spike = wrong_spike

        def get_spike_animation(spike, **kwargs):
            return Restore(spike, **kwargs)

        logo.iris_background.save_state()
        logo.iris_background.set_fill(opacity=0.0)
        logo.iris_background.scale(0.8)

        alt_name = name.copy()
        alt_name.set_stroke(BLACK, 5)

        self.play(
            Restore(
                logo.iris_background,
                rate_func=squish_rate_func(smooth, 1.0 / 3, 1),
                run_time=2,
            ),
            AnimationGroup(*(
                LaggedStartMap(
                    get_spike_animation,
                    layer,
                    run_time=2,
                    # rate_func=squish_rate_func(smooth, a / 3.0, (a + 0.9) / 3.0),
                    lag_ratio=2 / len(layer),
                    path_arc=-90 * DEGREES)
                for layer, a in zip(layers, [0, 2, 1, 0]))),
            Animation(logo.pupil),
            Write(alt_name),
            Write(name),
            run_time=3)

        self.wait(0.25)
        self.play(Transform(
            wrong_spike,
            wrong_spike.real_saved_state,
        ),
                  Animation(self.logo),
                  run_time=0.75)