def __init__(self, background=None, **kwargs): digest_config(self, kwargs, locals()) self.rgb_max_val = np.iinfo(self.pixel_array_dtype).max self.pixel_array_to_cairo_context = {} self.init_background() self.resize_frame_shape() self.reset()
def __init__(self, **kwargs): digest_config(self, kwargs) videos = [VideoIcon() for x in range(self.num_videos)] VGroup.__init__(self, *videos, **kwargs) self.arrange_submobjects() self.scale_to_fit_width(FRAME_WIDTH-MED_LARGE_BUFF) self.set_color_by_gradient(*self.gradient_colors)
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, **kwargs): digest_config(self, kwargs) videos = [VideoIcon() for x in range(self.num_videos)] VGroup.__init__(self, *videos, **kwargs) self.arrange_submobjects() self.scale_to_fit_width(FRAME_WIDTH - MED_LARGE_BUFF) self.set_color_by_gradient(*self.gradient_colors)
def __init__(self, mobject, **kwargs): mobject = instantiate(mobject) assert(isinstance(mobject, Mobject)) digest_config(self, kwargs, locals()) self.internal_time = 0 self.external_time = 0 self.setup() self.update(0)
def __init__(self, **kwargs): digest_config(self, kwargs) if self.leftmost_tick is None: tf = self.tick_frequency self.leftmost_tick = tf * np.ceil(self.x_min / tf) VMobject.__init__(self, **kwargs) if self.include_tip: self.add_tip()
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, mobject, direction=None, **kwargs): digest_config(self, kwargs) target = mobject.copy() if direction is None: direction = self.direction mobject.shift(direction) mobject.fade(1) Transform.__init__(self, mobject, target, **kwargs)
def __init__(self, **kwargs): digest_config(self, kwargs) Rectangle.__init__( self, height=self.side_length, width=self.side_length, **kwargs )
def __init__(self, mobject, point, **kwargs): digest_config(self, kwargs) target = mobject.copy() point_mob = VectorizedPoint(point) if self.point_color: point_mob.set_color(self.point_color) mobject.replace(point_mob) mobject.set_color(point_mob.get_color()) Transform.__init__(self, mobject, target, **kwargs)
def __init__(self, function, **kwargs): digest_config(self, kwargs) parametric_function = lambda t: t * RIGHT + function(t) * UP ParametricFunction.__init__(self, parametric_function, t_min=self.x_min, t_max=self.x_max, **kwargs) self.function = function
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, function, **kwargs): digest_config(self, kwargs) self.x_scale = (self.x_max - self.x_min) / (self.t_max - self.t_min) def parametric_function(t): return t * self.x_scale * RIGHT + self.y_scale * function(t) * UP ParametricFunction.__init__(self, parametric_function, **kwargs) self.function = function
def __init__(self, **kwargs): digest_config(self, kwargs) height = self.height if "height" in kwargs: kwargs.pop("height") Rectangle.__init__(self, width=self.aspect_ratio[0], height=self.aspect_ratio[1], **kwargs) self.scale_to_fit_height(height)
def __init__(self, **kwargs): digest_config(self, kwargs) kwargs.update({ "x_unit_size": self.unit_size, "y_unit_size": self.unit_size, "x_line_frequency": self.line_frequency, "x_faded_line_frequency": self.faded_line_frequency, "y_line_frequency": self.line_frequency, "y_faded_line_frequency": self.faded_line_frequency, }) NumberPlane.__init__(self, **kwargs)
def __init__(self, tex_string, **kwargs): digest_config(self, kwargs) assert (isinstance(tex_string, str)) self.tex_string = tex_string file_name = tex_to_svg_file(self.get_modified_expression(tex_string), self.template_tex_file_body) SVGMobject.__init__(self, file_name=file_name, **kwargs) if self.height is None: self.scale(TEX_MOB_SCALE_FACTOR) if self.organize_left_to_right: self.organize_submobjects_left_to_right()
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 )
def __init__(self, mobject, **kwargs): mobject = instantiate(mobject) assert(isinstance(mobject, Mobject)) digest_config(self, kwargs, locals()) self.starting_mobject = self.mobject.copy() if self.rate_func is None: self.rate_func = (lambda x: x) if self.name is None: self.name = self.__class__.__name__ + str(self.mobject) self.all_families_zipped = self.get_all_families_zipped() self.update(0)
def __init__(self, mobject, **kwargs): mobject = instantiate(mobject) assert (isinstance(mobject, Mobject)) digest_config(self, kwargs, locals()) self.starting_mobject = self.mobject.copy() if self.rate_func is None: self.rate_func = (lambda x: x) if self.name is None: self.name = self.__class__.__name__ + str(self.mobject) self.all_families_zipped = self.get_all_families_zipped() self.update(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)
def __init__(self, pi_creature=None, **kwargs): digest_config(self, kwargs) SVGMobject.__init__(self, file_name=self.file_name, **kwargs) self.stretch(self.y_stretch_factor, 1) self.scale_to_fit_height(self.height) self.set_stroke(width=0) self.set_fill(color=self.color) if pi_creature is not None: eyes = pi_creature.eyes self.scale_to_fit_height(3 * eyes.get_height()) self.move_to(eyes, DOWN) self.shift(DOWN * eyes.get_height() / 4)
def __init__(self, *tex_strings, **kwargs): digest_config(self, kwargs) tex_strings = self.break_up_tex_strings(tex_strings) self.tex_strings = tex_strings SingleStringTexMobject.__init__( self, self.arg_separator.join(tex_strings), **kwargs ) self.break_up_by_substrings() self.set_color_by_tex_to_color_map(self.tex_to_color_map) if self.organize_left_to_right: self.organize_submobjects_left_to_right()
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, **kwargs): digest_config(self, kwargs) height = self.height if "height" in kwargs: kwargs.pop("height") Rectangle.__init__( self, width=self.aspect_ratio[0], height=self.aspect_ratio[1], **kwargs ) self.scale_to_fit_height(height)
def __init__(self, filename_or_array, **kwargs): digest_config(self, kwargs) if isinstance(filename_or_array, str): path = get_full_raster_image_path(filename_or_array) image = Image.open(path).convert(self.image_mode) self.pixel_array = np.array(image) else: self.pixel_array = np.array(filename_or_array) self.change_to_rgba_array() if self.invert: self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3] AbstractImageMobject.__init__(self, **kwargs)
def __init__(self, filename_or_array, **kwargs): digest_config(self, kwargs) if isinstance(filename_or_array, str): path = get_full_raster_image_path(filename_or_array) image = Image.open(path).convert(self.image_mode) self.pixel_array = np.array(image) else: self.pixel_array = np.array(filename_or_array) self.change_to_rgba_array() if self.invert: self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3] Mobject.__init__(self, **kwargs)
def __init__(self, *tex_strings, **kwargs): digest_config(self, kwargs) tex_strings = self.break_up_tex_strings(tex_strings) self.tex_strings = tex_strings SingleStringTexMobject.__init__(self, self.arg_separator.join(tex_strings), **kwargs) self.break_up_by_substrings() self.set_color_by_tex_to_color_map(self.tex_to_color_map) if self.organize_left_to_right: self.organize_submobjects_left_to_right()
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, pi_creature = None, **kwargs): digest_config(self, kwargs) SVGMobject.__init__(self, file_name = self.file_name, **kwargs) self.stretch(self.y_stretch_factor, 1) self.scale_to_fit_height(self.height) self.set_stroke(width = 0) self.set_fill(color = self.color) if pi_creature is not None: eyes = pi_creature.eyes self.scale_to_fit_height(3*eyes.get_height()) self.move_to(eyes, DOWN) self.shift(DOWN*eyes.get_height()/4)
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, mobject_or_point, **kwargs): digest_config(self, kwargs) big_dot = Dot( radius = FRAME_X_RADIUS+FRAME_Y_RADIUS, stroke_width = 0, fill_color = self.color, fill_opacity = 0, ) little_dot = Dot(radius = 0) little_dot.set_fill(self.color, opacity = self.opacity) little_dot.move_to(mobject_or_point) Transform.__init__(self, big_dot, little_dot, **kwargs)
def __init__(self, left_camera, right_camera, **kwargs): digest_config(self, kwargs) self.left_camera = left_camera self.right_camera = right_camera half_width = self.pixel_shape[1] / 2 for camera in [self.left_camera, self.right_camera]: camera.pixel_shape = (self.pixel_shape[0], half_width) # TODO: Round up on one if width is odd camera.init_background() camera.resize_frame_shape() camera.reset() MultiCamera.__init__(self, (left_camera, (0, 0)), (right_camera, (0, half_width)))
def __init__(self, mobject_or_point, **kwargs): digest_config(self, kwargs) big_dot = Dot( radius=FRAME_X_RADIUS + FRAME_Y_RADIUS, stroke_width=0, fill_color=self.color, fill_opacity=0, ) little_dot = Dot(radius=0) little_dot.set_fill(self.color, opacity=self.opacity) little_dot.move_to(mobject_or_point) Transform.__init__(self, big_dot, little_dot, **kwargs)
def __init__(self, mobject, **kwargs): digest_config(self, kwargs, locals()) left_x = mobject.get_left()[0] right_x = mobject.get_right()[0] vect = self.amplitude * self.direction def homotopy(x, y, z, t): start_point = np.array([x, y, z]) alpha = (x - left_x) / (right_x - left_x) power = np.exp(2 * (alpha - 0.5)) nudge = there_and_back(t**power) return np.array([x, y, z]) + nudge * vect Homotopy.__init__(self, homotopy, mobject, **kwargs)
def __init__(self, mobject, **kwargs): digest_config(self, kwargs, locals()) left_x = mobject.get_left()[0] right_x = mobject.get_right()[0] vect = self.amplitude * self.direction def homotopy(x, y, z, t): alpha = (x - left_x) / (right_x - left_x) # lf = self.lag_factor power = np.exp(2.0 * (alpha - 0.5)) nudge = there_and_back(t**power) return np.array([x, y, z]) + nudge * vect Homotopy.__init__(self, homotopy, mobject, **kwargs)
def __init__(self, tex_string, **kwargs): digest_config(self, kwargs) assert(isinstance(tex_string, str)) self.tex_string = tex_string file_name = tex_to_svg_file( self.get_modified_expression(tex_string), self.template_tex_file ) SVGMobject.__init__(self, file_name=file_name, **kwargs) if self.height is None: self.scale(TEX_MOB_SCALE_FACTOR) if self.organize_left_to_right: self.organize_submobjects_left_to_right()
def __init__(self, frame=None, **kwargs): """ frame is a Mobject, (should almost certainly be a rectangle) determining which region of space the camera displys """ digest_config(self, kwargs) if frame is None: frame = ScreenRectangle(height=FRAME_HEIGHT) frame.set_stroke( self.default_frame_stroke_color, self.default_frame_stroke_width, ) self.frame = frame Camera.__init__(self, **kwargs)
def __init__(self, mob_or_text, **kwargs): digest_config(self, kwargs) if isinstance(mob_or_text, str): mobject = TextMobject(mob_or_text) else: mobject = mob_or_text if "run_time" not in kwargs: self.establish_run_time(mobject) if "lag_factor" not in kwargs: if len(mobject.family_members_with_points()) < 4: min_lag_factor = 1 else: min_lag_factor = 2 self.lag_factor = max(self.run_time - 1, min_lag_factor) ShowCreation.__init__(self, mobject, **kwargs)
def __init__(self, mobject, angle=np.pi, axis=OUT, **kwargs): if "path_arc" not in kwargs: kwargs["path_arc"] = angle if "path_arc_axis" not in kwargs: kwargs["path_arc_axis"] = axis digest_config(self, kwargs, locals()) target = mobject.copy() if self.in_place: self.about_point = mobject.get_center() target.rotate( angle, axis=axis, about_point=self.about_point, ) Transform.__init__(self, mobject, target, **kwargs)
def __init__(self, left_camera, right_camera, **kwargs): digest_config(self, kwargs) self.left_camera = left_camera self.right_camera = right_camera half_width = self.get_pixel_width() / 2 for camera in [self.left_camera, self.right_camera]: # TODO: Round up on one if width is odd camera.reset_pixel_shape(camera.get_pixel_height(), half_width) OldMultiCamera.__init__( self, (left_camera, (0, 0)), (right_camera, (0, half_width)), )
def __init__(self, mobject, angle = np.pi, axis = OUT, **kwargs): if "path_arc" not in kwargs: kwargs["path_arc"] = angle if "path_arc_axis" not in kwargs: kwargs["path_arc_axis"] = axis digest_config(self, kwargs, locals()) target = mobject.copy() if self.in_place: self.about_point = mobject.get_center() target.rotate( angle, axis = axis, about_point = self.about_point, ) Transform.__init__(self, mobject, target, **kwargs)
def __init__(self, suit_name, **kwargs): digest_config(self, kwargs) suits_to_colors = { "hearts": self.red, "diamonds": self.red, "spades": self.black, "clubs": self.black, } if suit_name not in suits_to_colors: raise Exception("Invalid suit name") SVGMobject.__init__(self, file_name=suit_name, **kwargs) color = suits_to_colors[suit_name] self.set_stroke(width=0) self.set_fill(color, 1) self.scale_to_fit_height(self.height)
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, **kwargs): digest_config(self, kwargs, locals()) if self.file_name is None: raise Exception("Must invoke Bubble subclass") try: SVGMobject.__init__(self, **kwargs) except IOError as err: self.file_name = os.path.join(FILE_DIR, self.file_name) SVGMobject.__init__(self, **kwargs) self.center() self.stretch_to_fit_height(self.height) self.stretch_to_fit_width(self.width) if self.direction[0] > 0: Mobject.flip(self) self.direction_was_specified = ("direction" in kwargs) self.content = Mobject()
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, focal_point, **kwargs): digest_config(self, kwargs) circles = VGroup() for x in range(self.n_circles): circle = Circle( radius=self.big_radius, stroke_color=BLACK, stroke_width=0, ) circle.move_to(focal_point) circle.save_state() circle.scale_to_fit_width(self.small_radius * 2) circle.set_stroke(self.color, self.start_stroke_width) circles.add(circle) LaggedStart.__init__( self, ApplyMethod, circles, lambda c: (c.restore,), **kwargs )
def __init__(self, mobject, direction=DOWN, **kwargs): digest_config(self, kwargs, locals()) angle = -np.arctan2(*direction[:2]) + np.pi mobject.rotate(-angle, about_point=ORIGIN) left = mobject.get_corner(DOWN + LEFT) right = mobject.get_corner(DOWN + RIGHT) target_width = right[0] - left[0] # Adding int(target_width) qquads gives approximately the right width num_quads = np.clip( int(self.width_multiplier * target_width), self.min_num_quads, self.max_num_quads ) tex_string = "\\underbrace{%s}" % (num_quads * "\\qquad") TexMobject.__init__(self, tex_string, **kwargs) self.tip_point_index = np.argmin(self.get_all_points()[:, 1]) self.stretch_to_fit_width(target_width) self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN) for mob in mobject, self: mob.rotate(angle, about_point=ORIGIN)
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, mode="plain", **kwargs): digest_config(self, kwargs) self.mode = mode self.parts_named = False try: svg_file = os.path.join( PI_CREATURE_DIR, "%s_%s.svg" % (self.file_name_prefix, mode) ) SVGMobject.__init__(self, file_name=svg_file, **kwargs) except: warnings.warn("No %s design with mode %s" % (self.file_name_prefix, mode)) svg_file = os.path.join( FILE_DIR, "PiCreatures_plain.svg", ) SVGMobject.__init__(self, file_name=svg_file, **kwargs) if self.flip_at_start: self.flip() if self.start_corner is not None: self.to_corner(self.start_corner)
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) rect = SurroundingRectangle( mobject, **self.surrounding_rectangle_config ) AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) target = mobject.copy() target.scale_in_place(self.scale_factor) target.set_color(self.color) Transform.__init__(self, mobject, target, **kwargs)
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) circle = Circle(color=self.color, **kwargs) circle.surround(mobject) Indicate.__init__(self, circle, **kwargs)