Esempio n. 1
0
 def update_mobject(self, alpha):
     ApplyMethod.update_mobject(self, alpha)
     if alpha == 0:
         return
     radians = alpha * self.total_tire_radians
     for tire in self.mobject.get_tires():
         tire.rotate_in_place(radians)
Esempio n. 2
0
 def __init__(self, car, target_point, **kwargs):
     assert isinstance(car, Car)
     ApplyMethod.__init__(self, car.move_to, target_point, **kwargs)
     displacement = self.target_mobject.get_right() - self.starting_mobject.get_right()
     distance = get_norm(displacement)
     if not self.moving_forward:
         distance *= -1
     tire_radius = car.get_tires()[0].get_width() / 2
     self.total_tire_radians = -distance / tire_radius
Esempio n. 3
0
 def get_zoom_in_animation(self, run_time=2, **kwargs):
     frame = self.zoomed_camera.frame
     full_frame_height = self.camera.get_frame_height()
     full_frame_width = self.camera.get_frame_width()
     frame.save_state()
     frame.stretch_to_fit_width(full_frame_width)
     frame.stretch_to_fit_height(full_frame_height)
     frame.center()
     frame.set_stroke(width=0)
     return ApplyMethod(frame.restore, run_time=run_time, **kwargs)
Esempio n. 4
0
    def animate_product(self, left, right, result):
        l_matrix = left.get_mob_matrix()
        r_matrix = right.get_mob_matrix()
        result_matrix = result.get_mob_matrix()
        circle = Circle(radius=l_matrix[0][0].get_height(), color=GREEN)
        circles = VGroup(*[
            entry.get_point_mobject()
            for entry in (l_matrix[0][0], r_matrix[0][0])
        ])
        (m, k), n = l_matrix.shape, r_matrix.shape[1]
        for mob in result_matrix.flatten():
            mob.set_color(BLACK)
        lagging_anims = []
        for a in range(m):
            for b in range(n):
                for c in range(k):
                    l_matrix[a][c].set_color(YELLOW)
                    r_matrix[c][b].set_color(YELLOW)
                for c in range(k):
                    start_parts = VGroup(l_matrix[a][c].copy(),
                                         r_matrix[c][b].copy())
                    result_entry = result_matrix[a][b].split()[c]

                    new_circles = VGroup(*[
                        circle.copy().shift(part.get_center())
                        for part in start_parts.split()
                    ])
                    self.play(Transform(circles, new_circles))
                    self.play(
                        Transform(
                            start_parts,
                            result_entry.copy().set_color(YELLOW),
                            path_arc=-np.pi / 2,
                            submobject_mode="all_at_once",
                        ), *lagging_anims)
                    result_entry.set_color(YELLOW)
                    self.remove(start_parts)
                    lagging_anims = [
                        ApplyMethod(result_entry.set_color, WHITE)
                    ]

                for c in range(k):
                    l_matrix[a][c].set_color(WHITE)
                    r_matrix[c][b].set_color(WHITE)
        self.play(FadeOut(circles), *lagging_anims)
        self.wait()
Esempio n. 5
0
    def compile_play_args_to_animation_list(self, *args):
        """
        Add animations so that all pi creatures look at the
        first mobject being animated with each .play call
        """
        animations = Scene.compile_play_args_to_animation_list(self, *args)
        if not self.any_pi_creatures_on_screen():
            return animations

        non_pi_creature_anims = [anim for anim in animations if anim.mobject not in self.get_pi_creatures()]
        if len(non_pi_creature_anims) == 0:
            return animations
        first_anim = non_pi_creature_anims[0]
        # Look at ending state
        first_anim.update(1)
        point_of_interest = first_anim.mobject.get_center()
        first_anim.update(0)

        for pi_creature in self.get_pi_creatures():
            if pi_creature not in self.get_mobjects():
                continue
            if pi_creature in first_anim.mobject.submobject_family():
                continue
            anims_with_pi_creature = [anim for anim in animations if pi_creature in anim.mobject.submobject_family()]
            for anim in anims_with_pi_creature:
                if isinstance(anim, Transform):
                    index = anim.mobject.submobject_family().index(pi_creature)
                    target_family = anim.target_mobject.submobject_family()
                    target = target_family[index]
                    if isinstance(target, PiCreature):
                        target.look_at(point_of_interest)
            if not anims_with_pi_creature:
                animations.append(
                    ApplyMethod(pi_creature.look_at, point_of_interest)
                )
        return animations
Esempio n. 6
0
 def get_zoomed_display_pop_out_animation(self, **kwargs):
     display = self.zoomed_display
     display.save_state(use_deepcopy=True)
     display.replace(self.zoomed_camera.frame, stretch=True)
     return ApplyMethod(display.restore)
Esempio n. 7
0
 def __init__(self, pi_creature, **kwargs):
     ApplyMethod.__init__(self, pi_creature.blink, **kwargs)