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)
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) mobject.next_to(self.x_start * RIGHT + SPACE_HEIGHT * UP, UP) self.total_vert_shift = \ 2*SPACE_HEIGHT + mobject.get_height() + 2*MED_SMALL_BUFF Animation.__init__(self, mobject, **kwargs)
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)
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)
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__
def __init__(self, clock, **kwargs): assert (isinstance(clock, Clock)) rot_kwargs = {"axis": OUT, "in_place": True} self.hour_rotation = Rotating(clock.hour_hand, radians=-2 * np.pi, **rot_kwargs) self.minute_rotation = Rotating(clock.minute_hand, radians=-12 * 2 * np.pi, **rot_kwargs) Animation.__init__(self, clock, **kwargs)
def __init__(self, walk_func, rev_func, coords_to_point, **kwargs): self.walk_func = walk_func self.rev_func = rev_func self.coords_to_point = coords_to_point self.compound_walker = VGroup() self.compound_walker.walker = PiCreature(color=RED) self.compound_walker.walker.scale(0.35) self.compound_walker.arrow = Arrow(ORIGIN, RIGHT) #, buff = 0) self.compound_walker.digest_mobject_attrs() Animation.__init__(self, self.compound_walker, **kwargs)
def __init__(self, walk_func, rev_func, coords_to_point, show_arrows = True, **kwargs): self.walk_func = walk_func self.rev_func = rev_func self.coords_to_point = coords_to_point self.compound_walker = VGroup() base_walker = Dot().scale(5) # PiCreature().scale(0.8) # self.compound_walker.walker = base_walker.scale(0.35).set_stroke(BLACK, 1.5) #PiCreature() if show_arrows: self.compound_walker.arrow = Arrow(ORIGIN, 0.5 * RIGHT, buff = 0).set_stroke(BLACK, 1.5) self.compound_walker.digest_mobject_attrs() Animation.__init__(self, self.compound_walker, **kwargs)
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)
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__
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 = range(mobject.height * mobject.width) if mode == "random": np.random.shuffle(self.indices) Animation.__init__(self, mobject, **kwargs)
def __init__(self, *sub_anims, **kwargs): sub_anims = filter(lambda x: not(x.empty), sub_anims) 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)
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)
def __init__(self, mobject, **kwargs): self.old_angles = [] for (i, sector) in enumerate(mobject.submobjects): self.old_angles.append(sector.angle) self.old_angles = np.array(self.old_angles) self.old_start_angles = np.cumsum( self.old_angles) - self.old_angles + TAU / 4 digest_config(self, kwargs) Animation.__init__(self, mobject, **kwargs)
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)
def __init__(self, **kwargs): digest_config(self, kwargs) x_axis = NumberLine(x_min=-3, x_max=3, color=BLUE_E) y_axis = x_axis.copy().rotate(np.pi / 2) circle = Circle(color=WHITE) self.trig_lines = [ Line(ORIGIN, RIGHT, color=color) for color in self.sin_color, self.cos_color, self.tan_color ] mobject = VMobject(x_axis, y_axis, circle, *self.trig_lines) mobject.to_edge(RIGHT) self.center = mobject.get_center() Animation.__init__(self, mobject, **kwargs)
def __init__(self, decimal_number_mobject, number_update_func, **kwargs): digest_config(self, kwargs, locals()) self.decimal_number_config = dict( decimal_number_mobject.initial_config) for attr in "num_decimal_places", "show_ellipsis": value = getattr(self, attr) if value is not None: self.decimal_number_config[attr] = value if hasattr(self.decimal_number_mobject, "background_rectangle"): self.decimal_number_config["include_background_rectangle"] = True if self.tracked_mobject: dmc = decimal_number_mobject.get_center() tmc = self.tracked_mobject.get_center() self.diff_from_tracked_mobject = dmc - tmc Animation.__init__(self, decimal_number_mobject, **kwargs)
def __init__(self, decimal_number_mobject, number_update_func, **kwargs): digest_config(self, kwargs, locals()) self.decimal_number_config = dict( decimal_number_mobject.initial_config ) for attr in "num_decimal_places", "show_ellipsis": value = getattr(self, attr) if value is not None: self.decimal_number_config[attr] = value if hasattr(self.decimal_number_mobject, "background_rectangle"): self.decimal_number_config["include_background_rectangle"] = True if self.tracked_mobject: dmc = decimal_number_mobject.get_center() tmc = self.tracked_mobject.get_center() self.diff_from_tracked_mobject = dmc - tmc Animation.__init__(self, decimal_number_mobject, **kwargs)
def __init__(self, AnimationClass, mobject, arg_creator=None, **kwargs): 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: arg_creator = lambda mobject: (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)
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)
def __init__(self, **kwargs): digest_config(self, kwargs) x_axis = NumberLine( x_min = -3, x_max = 3, color = BLUE_E ) y_axis = x_axis.copy().rotate(np.pi/2) circle = Circle(color = WHITE) self.trig_lines = [ Line(ORIGIN, RIGHT, color = color) for color in self.sin_color, self.cos_color, self.tan_color ] mobject = VMobject( x_axis, y_axis, circle, *self.trig_lines ) mobject.to_edge(RIGHT) self.center = mobject.get_center() Animation.__init__(self, mobject, **kwargs)
def __init__(self, **kwargs): digest_config(self, kwargs) em_wave = EMWave(**self.EMWave_config) em_wave.update(0) self.em_wave = em_wave self.vects = VGroup() if self.include_E_vects: self.vects.add(*em_wave.E_vects) if self.include_M_vects: self.vects.add(*em_wave.M_vects) for vect in self.vects: vect.save_state() u = em_wave.propogation_direction self.wave_packet_start, self.wave_packet_end = [ em_wave.start_point - u * self.packet_width / 2, em_wave.start_point + u * (em_wave.length + self.packet_width / 2) ] Animation.__init__(self, self.vects, **kwargs)
def __init__(self, AnimationClass, mobject, arg_creator=None, **kwargs): 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)
def __init__(self, mobject, path, **kwargs): digest_config(self, kwargs, locals()) Animation.__init__(self, mobject, **kwargs)
def __init__(self, mobject=None, **kwargs): if mobject is None: mobject = Line(3 * LEFT, 3 * RIGHT) Animation.__init__(self, mobject, **kwargs)
def __init__(self, graph, **kwargs): digest_config(self, kwargs, locals()) line = Line(LEFT, RIGHT, color=self.line_color) line.save_state() Animation.__init__(self, line, **kwargs)
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). For example, Succession( ShowCreation(circle), Transform, circle, square, Transform, circle, triangle, ApplyMethod, circle.shift, 2*UP, {"run_time" : 2}, ) """ 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)
def __init__(self, mobject=None, new_angle=TAU / 3, **kwargs): self.old_angle = mobject.angle self.start_angle = mobject.start_angle self.new_angle = new_angle Animation.__init__(self, mobject, **kwargs)
def __init__(self, mobject, update_function, **kwargs): digest_config(self, kwargs, locals()) Animation.__init__(self, mobject, **kwargs)
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)
def __init__(self, tex_list, **kwargs): mobject = TexMobject(self.curr_tex).shift(start_center) Animation.__init__(self, mobject, **kwargs)
def __init__(self, *args, **kwargs): return Animation.__init__(self, Group(), *args, **kwargs)
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)
def __init__(self, mobject, vector, **kwargs): radius = mobject.get_width()/2 radians = np.linalg.norm(vector)/radius last_alpha = 0 digest_config(self, kwargs, locals()) Animation.__init__(self, mobject, **kwargs)
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). For example, Succession( ShowCreation(circle), Transform, circle, square, Transform, circle, triangle, ApplyMethod, circle.shift, 2*UP, {"run_time" : 2}, ) """ 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 = filter(lambda x: not(x.empty), animations) 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 = map(lambda x: np.true_divide( x, run_time), 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)
def __init__(self, mobject=None, line=None, buff=0.2, **kwargs): self.line = line self.buff = buff Animation.__init__(self, mobject, **kwargs)