def test_mobject_copy(): """Test that a copy is a deepcopy.""" orig = Mobject() orig.add(*[Mobject() for _ in range(10)]) copy = orig.copy() assert orig is orig assert orig is not copy assert orig.submobjects is not copy.submobjects for i in range(10): assert orig.submobjects[i] is not copy.submobjects[i]
def add( self, name: str, val_orig: m.Mobject, highlight: m.Mobject = None, extra_animations: List[m.Animation] = None, ) -> None: """Add an name-value association to the context and return animations name -- the name part of the association val_orig -- a Mobject that is the value part of the association highlight -- a Mobject that should be highlighted before other animations are played, defaults to val_orig extra_animations -- animations to be played along the others during the last step This creates a copy of `val_orig` and sets its target to the position of the value in the context, the returned animations will make the copy move to this position. """ self.scene.play(m.Indicate(highlight if highlight else val_orig)) association = m.VDict([ ("name", m.Tex(name, color=m.GRAY)), ("eq", m.Tex("=", color=m.GRAY)), ("val", val_orig.copy()), ]) association["name"].move_to(self.entries[-1], aligned_edge=m.LEFT) association["eq"].next_to(association["name"], m.RIGHT) association["val"].generate_target().next_to(association["eq"], m.RIGHT).set_color(m.GRAY) self.scene.play( m.ApplyMethod(self.entries.shift, m.UP * 0.5), m.FadeInFrom(association["name"], direction=m.DOWN), m.FadeInFrom(association["eq"], direction=m.DOWN), m.MoveToTarget(association["val"]), *(extra_animations if extra_animations else []), ) self.entries.add(association) self.scene.remove(association) # The previous line created a copy