def test_set_compat_layer(): m = Mobject() assert isinstance(m.set_test, types.MethodType) m.set_test(0) assert m.test == 0
def __init__(self, mobject: Mobject, tracked_mobject: Mobject, **kwargs) -> None: self.tracked_mobject = tracked_mobject self.diff = op.sub( mobject.get_center(), tracked_mobject.get_center(), ) super().__init__(mobject, **kwargs)
def __init__(self, bubble_mode="speech", direction=LEFT, height=5, width=8, **kwargs): file_name = str(SVG_DIR / f"bubble_{bubble_mode}.svg") SVGMobject.__init__(self, file_name=file_name, **kwargs) self.stretch_to_fit_height(height) self.stretch_to_fit_width(width) self.direction = direction if self.direction[0] < 0: self.flip() self.content = Mobject()
def test_get_compat_layer(): m = Mobject() assert isinstance(m.get_test, types.MethodType) with pytest.raises(AttributeError): m.get_test() m.test = 0 assert m.get_test() == 0
def zoom_out(self, board=Mobject()): def zoom_out(mob): mob.scale(1/3) mob.to_corner(UL) return mob self.play( LaggedStart( ApplyFunction(zoom_out, board), AnimationGroup( *[FadeInFrom(student) for student in self.students], FadeInFrom(self.teacher, RIGHT), ), lag_ratio = 0.1, run_time=2 ), )
def test_generic_set(): m = Mobject() m.set(test=0) assert m.test == 0
def test_nonexistent_attr(): m = Mobject() with pytest.raises(AttributeError): m.test
def test_nonexistent_attr(): m = Mobject() with pytest.raises(AttributeError, match="object has no attribute"): m.test
def flip(self, axis=UP): Mobject.flip(self, axis=axis) if abs(axis[1]) > 0: self.direction = -np.array(self.direction) return self
class Bubble(SVGMobject): def __init__(self, bubble_mode="speech", direction=LEFT, height=5, width=8, **kwargs): file_name = str(SVG_DIR / f"bubble_{bubble_mode}.svg") SVGMobject.__init__(self, file_name=file_name, **kwargs) self.stretch_to_fit_height(height) self.stretch_to_fit_width(width) self.direction = direction if self.direction[0] < 0: self.flip() self.content = Mobject() def init_colors(self, propagate_colors=True): self.set_fill(color=BACKGROUND_COLOR, opacity=BACKGROUND_OPACITY) self.set_stroke(color=STROKE_COLOR, width=STROKE_WIDTH) def get_tip(self): return self.get_boundary_point(DOWN) def get_bubble_center(self): bubble_center_adjustment_factor = 1 / 8 return self.get_center( ) + bubble_center_adjustment_factor * self.get_height() * UP def move_tip_to(self, point): mover = VGroup(self) if self.content: mover.add(self.content) mover.shift(point - self.get_tip()) return self def flip(self, axis=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]) if want_to_flip: self.flip() boundary_point = mobject.get_critical_point(UP - self.direction) self.move_tip_to(boundary_point) return self def write(self, *text): self.add_content(Tex(*text)) return self def add_content(self, mobject): self.position_mobject_inside(mobject) self.content = mobject return self.content def position_mobject_inside(self, mobject): content_scale_factor = 0.75 scaled_width = 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 resize_to_content(self): target_width = self.content.get_width() target_width += max(MED_LARGE_BUFF, 2) target_height = self.content.get_height() target_height += 2.5 * 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
def wait_while_updating(duration=1): return Animation(Mobject(), run_time=duration)