def apply_function(self, function): factor = self.pre_function_handle_to_anchor_scale_factor self.scale_handle_to_anchor_distances(factor) Mobject.apply_function(self, function) self.scale_handle_to_anchor_distances(1. / factor) if self.make_smooth_after_applying_functions: self.make_smooth() return self
def get_mobjects_to_display(self, mobjects, include_submobjects=True, excluded_mobjects=None): if include_submobjects: mobjects = Mobject.extract_mobject_family_members( mobjects, only_those_with_points=True, ) if excluded_mobjects: all_excluded = Mobject.extract_mobject_family_members( excluded_mobjects) mobjects = list_difference_update(mobjects, all_excluded) return mobjects
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(consts.ASSETS_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: self.flip() self.direction_was_specified = ("direction" in kwargs) self.content = Mobject()
def get_moving_mobjects(self, *animations): moving_mobjects = Scene.get_moving_mobjects(self, *animations) all_moving_mobjects = Mobject.extract_mobject_family_members( moving_mobjects) movement_indicators = self.camera.get_mobjects_indicating_movement() for movement_indicator in movement_indicators: if movement_indicator in all_moving_mobjects: # When one of these is moving, the camera should # consider all mobjects to be moving return list_update(self.submobjects, moving_mobjects) return moving_mobjects
def get_state(self): # Want to return a mobject that maintains the most # structure. The way to do that is to extract only # those that aren't inside another. return Mobject(*self.get_top_level_mobjects())
def __init__(self, value=0, **kwargs): Mobject.__init__(self, **kwargs) self.points = np.zeros((1, 3)) self.set_value(value)
def match_colors(self, mobject): Mobject.align_data(self, mobject) self.rgbas = np.array(mobject.rgbas) return self
def get_array_attrs(self): return Mobject.get_array_attrs(self) + ["rgbas"]
def __init__(self, **kwargs): digest_config(self, kwargs) self.epsilon = 1.0 / self.density Mobject.__init__(self, **kwargs)
def remove_fixed_in_frame_mobjects(self, *mobjects): for mobject in Mobject.extract_mobject_family_members(mobjects): if mobject in self.fixed_in_frame_mobjects: self.fixed_in_frame_mobjects.remove(mobject)
def remove_fixed_orientation_mobjects(self, *mobjects): for mobject in Mobject.extract_mobject_family_members(mobjects): if mobject in self.fixed_orientation_mobjects: self.fixed_orientation_mobjects.remove(mobject)
def add_fixed_in_frame_mobjects(self, *mobjects): for mobject in Mobject.extract_mobject_family_members(mobjects): self.fixed_in_frame_mobjects.add(mobject)
def get_mobject_family_members(self): return Mobject.extract_mobject_family_members(self.submobjects)
def flip(self, axis=consts.UP): Mobject.flip(self, axis=axis) if abs(axis[1]) > 0: self.direction = -np.array(self.direction) return self
class Bubble(SVGMobject): CONFIG = { "direction": consts.LEFT, "center_point": consts.ORIGIN, "content_scale_factor": 0.75, "height": 5, "width": 8, "bubble_center_adjustment_factor": 1. / 8, "file_name": None, "fill_color": Color('BLACK'), "fill_opacity": 0.8, "stroke_color": Color('WHITE'), "stroke_width": 3, } 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(consts.ASSETS_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: self.flip() self.direction_was_specified = ("direction" in kwargs) self.content = Mobject() def get_tip(self): # TODO, find a better way return self.get_corner( consts.DOWN + self.direction) - 0.6 * self.direction def get_bubble_center(self): factor = self.bubble_center_adjustment_factor return self.get_center() + factor * self.get_height() * consts.UP def move_tip_to(self, point): mover = VGroup(self) if self.content is not None: mover.add(self.content) mover.shift(point - self.get_tip()) return self def flip(self, axis=consts.UP): Mobject.flip(self, axis=axis) if abs(axis[1]) > 0: self.direction = -np.array(self.direction) return self def pin_to(self, mobject): mob_center = mobject.get_center() want_to_flip = np.sign(mob_center[0]) != np.sign(self.direction[0]) can_flip = not self.direction_was_specified if want_to_flip and can_flip: self.flip() boundary_point = mobject.get_critical_point(consts.UP - self.direction) vector_from_center = 1.0 * (boundary_point - mob_center) self.move_tip_to(mob_center + vector_from_center) return self def position_mobject_inside(self, mobject): scaled_width = self.content_scale_factor * self.get_width() if mobject.get_width() > scaled_width: mobject.set_width(scaled_width) mobject.shift( self.get_bubble_center() - mobject.get_center() ) return mobject def add_content(self, mobject): self.position_mobject_inside(mobject) self.content = mobject return self.content def write(self, *text): self.add_content(TextMobject(*text)) return self def resize_to_content(self): target_width = self.content.get_width() target_width += max(consts.MED_LARGE_BUFF, 2) target_height = self.content.get_height() target_height += 2.5 * consts.LARGE_BUFF tip_point = self.get_tip() self.stretch_to_fit_width(target_width) self.stretch_to_fit_height(target_height) self.move_tip_to(tip_point) self.position_mobject_inside(self.content) def clear(self): self.add_content(VMobject()) return self