Пример #1
0
    def show_ghost_movement(self, vector):
        """
        This method plays an animation that partially shows the entire plane moving
        in the direction of a particular vector. This is useful when you wish to 
        convey the idea of mentally moving the entire plane in a direction, without
        actually moving the plane.

        Parameters
        ----------
        vector (Union[Arrow, list, tuple, np.ndarray])
            The vector which indicates the direction of movement.
        """
        if isinstance(vector, Arrow):
            vector = vector.get_end() - vector.get_start()
        elif len(vector) == 2:
            vector = np.append(np.array(vector), 0.0)
        x_max = int(FRAME_X_RADIUS + abs(vector[0]))
        y_max = int(FRAME_Y_RADIUS + abs(vector[1]))
        dots = VMobject(*[
            Dot(x * RIGHT + y * UP) for x in range(-x_max, x_max)
            for y in range(-y_max, y_max)
        ])
        dots.set_fill(BLACK, opacity=0)
        dots_halfway = dots.copy().shift(vector / 2).set_fill(WHITE, 1)
        dots_end = dots.copy().shift(vector)

        self.play(Transform(dots, dots_halfway, rate_func=rush_into))
        self.play(Transform(dots, dots_end, rate_func=rush_from))
        self.remove(dots)
Пример #2
0
    def show_ghost_movement(self, vector):
        if isinstance(vector, Arrow):
            vector = vector.get_end() - vector.get_start()
        elif len(vector) == 2:
            vector = np.append(np.array(vector), 0.0)
        x_max = int(FRAME_X_RADIUS + abs(vector[0]))
        y_max = int(FRAME_Y_RADIUS + abs(vector[1]))
        dots = VMobject(*[
            Dot(x * RIGHT + y * UP) for x in range(-x_max, x_max)
            for y in range(-y_max, y_max)
        ])
        dots.set_fill(BLACK, opacity=0)
        dots_halfway = dots.copy().shift(vector / 2).set_fill(WHITE, 1)
        dots_end = dots.copy().shift(vector)

        self.play(Transform(dots, dots_halfway, rate_func=rush_into))
        self.play(Transform(dots, dots_end, rate_func=rush_from))
        self.remove(dots)
Пример #3
0
 def __init__(self, vmobject: VMobject, **kwargs):
     super().__init__(**kwargs)
     self.vmobject: VMobject = vmobject
     self.boundary_copies: list[VMobject] = [
         vmobject.copy().set_style(stroke_width=0, fill_opacity=0)
         for x in range(2)
     ]
     self.add(*self.boundary_copies)
     self.total_time: float = 0
     self.add_updater(lambda m, dt: self.update_boundary_copies(dt))
Пример #4
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)
Пример #5
0
    def show_ghost_movement(self, vector):
        if isinstance(vector, Arrow):
            vector = vector.get_end() - vector.get_start()
        elif len(vector) == 2:
            vector = np.append(np.array(vector), 0.0)
        x_max = int(FRAME_X_RADIUS + abs(vector[0]))
        y_max = int(FRAME_Y_RADIUS + abs(vector[1]))
        dots = VMobject(*[
            Dot(x * RIGHT + y * UP)
            for x in range(-x_max, x_max)
            for y in range(-y_max, y_max)
        ])
        dots.set_fill(BLACK, opacity=0)
        dots_halfway = dots.copy().shift(vector / 2).set_fill(WHITE, 1)
        dots_end = dots.copy().shift(vector)

        self.play(Transform(
            dots, dots_halfway, rate_func=rush_into
        ))
        self.play(Transform(
            dots, dots_end, rate_func=rush_from
        ))
        self.remove(dots)
Пример #6
0
 def __init__(self, vmobject: 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.copy().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)
         )
     ])
 def get_piece_movement(self, pieces):
     start = VMobject(*pieces)
     target = VMobject(*[mob.target for mob in pieces])
     if self.leave_ghost_vectors:
         self.add(start.copy().fade(0.7))
     return Transform(start, target, lag_ratio=0)
Пример #8
0
 def get_piece_movement(self, pieces):
     start = VMobject(*pieces)
     target = VMobject(*[mob.target for mob in pieces])
     if self.leave_ghost_vectors:
         self.add(start.copy().fade(0.7))
     return Transform(start, target, submobject_mode="all_at_once")