Example #1
0
 def __init__(self, mobject, **kwargs):
     digest_config(self, kwargs)
     if self.scale_about_point is None:
         self.scale_about_point = mobject.get_center()
     if self.rotate_about_point is None:
         self.rotate_about_point = mobject.get_center()
     Animation.__init__(self, mobject, **kwargs)
Example #2
0
    def __init__(self, *animations, **kwargs):
        digest_config(self, kwargs)
        if len(animations) > 1:
            if isinstance(animations[-1], (int, float)):
                if animations[-1] >= 0:
                    self.run_time = animations[-1]
                    animations = animations[:-1]
                else:
                    self.fix_time = -animations[-1]
                    animations = animations[:-1]
            if animations[-1].run_time < 1. / 60:  #./15
                #self.error=animations[-1].run_time
                animations[-1].run_time = 1. / 15
        self.animations = animations
        if self.fix_time is not None and self.run_time is None:
            for anim in self.animations:
                if not self.retain or (anim.run_time is None or
                                       (anim.run_time >= 0.001
                                        and anim.run_time <= 1)):
                    anim.run_time = self.fix_time
        if self.group is None:
            self.group = Group(*remove_list_redundancies(
                [anim.mobject for anim in animations]))

        self.init_run_time()
        Animation.__init__(self, self.group, **kwargs)
    def __init__(self, homotopy, mobject, **kwargs):
        def function_at_time_t(t):
            return lambda p: homotopy(p[0], p[1], p[2], t)

        self.function_at_time_t = function_at_time_t
        digest_config(self, kwargs)
        Animation.__init__(self, mobject, **kwargs)
Example #4
0
    def __init__(self, AnimationClass, mobject, arg_creator=None, **kwargs):
        for key in ["rate_func", "run_time"]:
            if key in AnimationClass.CONFIG:
                setattr(self, key, AnimationClass.CONFIG[key])
        digest_config(self, kwargs)
        for key in "rate_func", "run_time", "lag_ratio":
            if key in kwargs:
                kwargs.pop(key)

        if arg_creator is None:
            def arg_creator(mobject):
                return (mobject,)
        self.subanimations = [
            AnimationClass(
                *arg_creator(submob),
                run_time=self.run_time,
                rate_func=squish_rate_func(
                    self.rate_func, beta, beta + self.lag_ratio
                ),
                **kwargs
            )
            for submob, beta in zip(
                mobject,
                np.linspace(0, 1 - self.lag_ratio, len(mobject))
            )
        ]
        Animation.__init__(self, mobject, **kwargs)
Example #5
0
 def __init__(self, *animations, **kwargs):
     digest_config(self, kwargs)
     self.animations = animations
     if self.group is None:
         self.group = Group(*remove_list_redundancies(
             [anim.mobject for anim in animations]))
     Animation.__init__(self, self.group, **kwargs)
Example #6
0
 def __init__(self, decimal_number_mobject, number_update_func, **kwargs):
     digest_config(self, kwargs, locals())
     if self.tracked_mobject:
         dmc = decimal_number_mobject.get_center()
         tmc = self.tracked_mobject.get_center()
         self.diff_from_tracked_mobject = dmc - tmc
         self.diff_from_tracked_mobject = dmc - tmc
     Animation.__init__(self, decimal_number_mobject, **kwargs)
Example #7
0
 def __init__(self, mobject, mode="linear", **kwargs):
     if not isinstance(mobject, PiCreatureClass):
         raise Exception("FlashThroughClass mobject must be a PiCreatureClass")
     digest_config(self, kwargs)
     self.indices = list(range(mobject.height * mobject.width))
     if mode == "random":
         np.random.shuffle(self.indices)
     Animation.__init__(self, mobject, **kwargs)
Example #8
0
 def __init__(self, *animations: Animation, **kwargs):
     digest_config(self, kwargs)
     self.animations = [prepare_animation(anim) for anim in animations]
     if self.group is None:
         self.group = Group(*remove_list_redundancies(
             [anim.mobject for anim in animations]))
     self.init_run_time()
     Animation.__init__(self, self.group, **kwargs)
Example #9
0
 def __init__(self, mobject, mode="linear", **kwargs):
     if not isinstance(mobject, PiCreatureClass):
         raise Exception(
             "FlashThroughClass mobject must be a PiCreatureClass")
     digest_config(self, kwargs)
     self.indices = list(range(mobject.height * mobject.width))
     if mode == "random":
         np.random.shuffle(self.indices)
     Animation.__init__(self, mobject, **kwargs)
Example #10
0
    def __init__(self, homotopy, mobject, **kwargs):
        """
        Homotopy a function from (x, y, z, t) to (x', y', z')
        """
        def function_at_time_t(t):
            return lambda p: homotopy(p[0], p[1], p[2], t)

        self.function_at_time_t = function_at_time_t
        digest_config(self, kwargs)
        Animation.__init__(self, mobject, **kwargs)
Example #11
0
 def __init__(self, AnimationClass, mobjects, **kwargs):
     full_kwargs = AnimationClass.CONFIG
     full_kwargs.update(kwargs)
     full_kwargs["mobject"] = Mobject(*[
         mob.get_point_mobject()
         for mob in mobjects
     ])
     self.centers_container = AnimationClass(**full_kwargs)
     full_kwargs.pop("mobject")
     Animation.__init__(self, Mobject(*mobjects), **full_kwargs)
     self.name = str(self) + AnimationClass.__name__
Example #12
0
    def __init__(self, mobject, target_mobject, **kwargs):
        # Copy target_mobject so as to not mess with caller
        self.original_target_mobject = target_mobject
        target_mobject = target_mobject.copy()
        mobject.align_data(target_mobject)
        self.target_mobject = target_mobject
        digest_config(self, kwargs)
        self.init_path_func()

        Animation.__init__(self, mobject, **kwargs)
        self.name += "To" + str(target_mobject)
Example #13
0
    def __init__(self, *sub_anims, **kwargs):
        sub_anims = [x for x in sub_anims if not(x.empty)]
        digest_config(self, locals())
        self.update_config(**kwargs)  # Handles propagation to self.sub_anims

        if len(sub_anims) == 0:
            self.empty = True
            self.run_time = 0
        else:
            self.run_time = max([a.run_time for a in sub_anims])
        everything = Mobject(*[a.mobject for a in sub_anims])
        Animation.__init__(self, everything, **kwargs)
Example #14
0
 def __init__(self, clock, **kwargs):
     digest_config(self, kwargs)
     assert (isinstance(clock, Clock))
     rot_kwargs = {"axis": OUT, "about_point": clock.get_center()}
     hour_radians = -self.hours_passed * 2 * np.pi / 12
     self.hour_rotation = Rotating(clock.hour_hand,
                                   radians=hour_radians,
                                   **rot_kwargs)
     self.minute_rotation = Rotating(clock.minute_hand,
                                     radians=12 * hour_radians,
                                     **rot_kwargs)
     Animation.__init__(self, clock, **kwargs)
Example #15
0
 def __init__(self, *animations, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args(animations)
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     digest_config(self, kwargs)
     self.animations = animations
     if self.group is None:
         self.group = Group(*remove_list_redundancies(
             [anim.mobject for anim in animations]))
     self.init_run_time()
     Animation.__init__(self, self.group, **kwargs)
Example #16
0
 def __init__(self, clock, **kwargs):
     if not hasattr(self, "args"):
         self.args = serialize_args([clock])
     if not hasattr(self, "config"):
         self.config = serialize_config({
             **kwargs,
         })
     digest_config(self, kwargs)
     assert (isinstance(clock, Clock))
     rot_kwargs = {"axis": OUT, "about_point": clock.get_center()}
     hour_radians = -self.hours_passed * 2 * np.pi / 12
     self.hour_rotation = Rotating(clock.hour_hand,
                                   radians=hour_radians,
                                   **rot_kwargs)
     self.hour_rotation.begin()
     self.minute_rotation = Rotating(clock.minute_hand,
                                     radians=12 * hour_radians,
                                     **rot_kwargs)
     self.minute_rotation.begin()
     Animation.__init__(self, clock, **kwargs)
Example #17
0
 def __init__(self, clock, **kwargs):
     digest_config(self, kwargs)
     assert(isinstance(clock, Clock))
     rot_kwargs = {
         "axis": OUT,
         "about_point": clock.get_center()
     }
     hour_radians = -self.hours_passed * 2 * np.pi / 12
     self.hour_rotation = Rotating(
         clock.hour_hand,
         radians=hour_radians,
         **rot_kwargs
     )
     self.hour_rotation.begin()
     self.minute_rotation = Rotating(
         clock.minute_hand,
         radians=12 * hour_radians,
         **rot_kwargs
     )
     self.minute_rotation.begin()
     Animation.__init__(self, clock, **kwargs)
Example #18
0
 def __init__(self, mobject, update_function, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Example #19
0
 def __init__(self, tex_list, **kwargs):
     mobject = TexMobject(self.curr_tex).shift(start_center)
     Animation.__init__(self, mobject, **kwargs)
Example #20
0
    def __init__(self, *args, **kwargs):
        """
        Each arg will either be an animation, or an animation class
        followed by its arguments (and potentially a dict for
        configuration).
        """
        animations = []
        state = {
            "animations": animations,
            "curr_class": None,
            "curr_class_args": [],
            "curr_class_config": {},
        }

        def invoke_curr_class(state):
            if state["curr_class"] is None:
                return
            anim = state["curr_class"](
                *state["curr_class_args"],
                **state["curr_class_config"]
            )
            state["animations"].append(anim)
            anim.update(1)
            state["curr_class"] = None
            state["curr_class_args"] = []
            state["curr_class_config"] = {}

        for arg in args:
            if isinstance(arg, Animation):
                animations.append(arg)
                arg.update(1)
                invoke_curr_class(state)
            elif isinstance(arg, type) and issubclass(arg, Animation):
                invoke_curr_class(state)
                state["curr_class"] = arg
            elif isinstance(arg, dict):
                state["curr_class_config"] = arg
            else:
                state["curr_class_args"].append(arg)
        invoke_curr_class(state)
        for anim in animations:
            anim.update(0)

        animations = [x for x in animations if not(x.empty)]

        self.run_times = [anim.run_time for anim in animations]
        if "run_time" in kwargs:
            run_time = kwargs.pop("run_time")
            warnings.warn(
                "Succession doesn't currently support explicit run_time.")
        run_time = sum(self.run_times)
        self.num_anims = len(animations)
        if self.num_anims == 0:
            self.empty = True
        self.animations = animations
        # Have to keep track of this run_time, because Scene.play
        # might very well mess with it.
        self.original_run_time = run_time

        # critical_alphas[i] is the start alpha of self.animations[i]
        # critical_alphas[i + 1] is the end alpha of self.animations[i]
        critical_times = np.concatenate(([0], np.cumsum(self.run_times)))
        self.critical_alphas = [np.true_divide(
            x, run_time) for x in critical_times] if self.num_anims > 0 else [0.0]

        # self.scene_mobjects_at_time[i] is the scene's mobjects at start of self.animations[i]
        # self.scene_mobjects_at_time[i + 1] is the scene mobjects at end of self.animations[i]
        self.scene_mobjects_at_time = [None for i in range(self.num_anims + 1)]
        self.scene_mobjects_at_time[0] = Group()
        for i in range(self.num_anims):
            self.scene_mobjects_at_time[i + 1] = self.scene_mobjects_at_time[i].copy()
            self.animations[i].clean_up(self.scene_mobjects_at_time[i + 1])

        self.current_alpha = 0
        # If self.num_anims == 0, this is an invalid index, but so it goes
        self.current_anim_index = 0
        if self.num_anims > 0:
            self.mobject = self.scene_mobjects_at_time[0]
            self.mobject.add(self.animations[0].mobject)
        else:
            self.mobject = Group()

        Animation.__init__(self, self.mobject, run_time=run_time, **kwargs)
Example #21
0
 def __init__(self, *args, **kwargs):
     return Animation.__init__(self, Group(), *args, **kwargs)
Example #22
0
 def __init__(self, tex_list, **kwargs):
     mobject = TexMobject(self.curr_tex).shift(start_center)
     Animation.__init__(self, mobject, **kwargs)
Example #23
0
 def __init__(self, mobject=None, **kwargs):
     if mobject is None:
         mobject = Line(3 * LEFT, 3 * RIGHT)
     Animation.__init__(self, mobject, **kwargs)
Example #24
0
 def __init__(self, word, **kwargs):
     assert (isinstance(word, SingleStringTexMobject))
     digest_config(self, kwargs)
     run_time = kwargs.pop("run_time", self.time_per_char * len(word))
     Animation.__init__(self, word, run_time=run_time, **kwargs)
Example #25
0
 def __init__(self, vmobject, **kwargs):
     if not isinstance(vmobject, VMobject):
         raise Exception("DrawBorderThenFill only works for VMobjects")
     self.reached_halfway_point_before = False
     Animation.__init__(self, vmobject, **kwargs)
Example #26
0
 def __init__(self, group, **kwargs):
     self.all_submobs = group.submobjects
     Animation.__init__(self, group, **kwargs)
 def __init__(self, run_time=1, **kwargs):
     Animation.__init__(self, Mobject(), run_time=run_time, **kwargs)
Example #28
0
 def __init__(self, mobject, path, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Example #29
0
 def __init__(self, mobject, tracked_mobject, **kwargs):
     digest_config(self, kwargs, locals())
     tcp = self.tracked_critical_point
     self.diff = mobject.get_critical_point(tcp) - \
         tracked_mobject.get_critical_point(tcp)
     Animation.__init__(self, mobject, **kwargs)