def test_vmob_add_to_back(): """Test the Mobject add_to_back method.""" a = VMobject() b = Line() c = "text" with pytest.raises(ValueError): # Mobject cannot contain self a.add_to_back(a) with pytest.raises(TypeError): # All submobjects must be of type Mobject a.add_to_back(c) # No submobject gets added twice a.add_to_back(b) a.add_to_back(b, b) assert len(a.submobjects) == 1 a.submobjects.clear() a.add_to_back(b, b, b) a.add_to_back(b, b) assert len(a.submobjects) == 1 a.submobjects.clear() # Make sure the ordering has not changed o1, o2, o3 = Square(), Line(), Circle() a.add_to_back(o1, o2, o3) assert a.submobjects.pop() == o3 assert a.submobjects.pop() == o2 assert a.submobjects.pop() == o1
def construct(self): data = [20, 0, 0, -5] x = [0, 8, 38, 39] self.setup_axes() dot_collection = VGroup() for time, val in enumerate(data): dot = Dot().move_to(self.coords_to_point(x[time], val)) self.add(dot) dot_collection.add(dot) l1 = Line(dot_collection[0].get_center(), dot_collection[1].get_center()) l2 = Line(dot_collection[1].get_center(), dot_collection[2].get_center()) l3 = Line(dot_collection[2].get_center(), dot_collection[3].get_center()) self.add(l1, l2, l3)
def insert(self, bt_node, side_offset_multiply: float = 2.5, down_offset_multiply: float = 2.5, direction=LEFT, start_from_root=True) -> BinaryTreeNode: if self.is_full(): raise AttributeError("This node %s is completed" % str(self.node_id)) bt_node.parent = self if start_from_root: parents = [self] while parents[-1].parent is not None: parents.append(parents[-1].parent) self.scene.add(bt_node) bt_node.next_to(parents[-1], buff=0, direction=UP) parents.pop() self.scene.play(FadeIn(bt_node.value), run_time=bt_node.animation_duration) while len(parents) > 0: elem = parents[-1] self.scene.play(bt_node.value.animate.next_to(elem, buff=0), run_time=bt_node.animation_duration) parents.pop() else: bt_node.next_to(self.value, buff=0) self.scene.play(Write(bt_node.value), run_time=bt_node.animation_duration) if direction is LEFT and self.has_left(): direction = RIGHT self.right = bt_node else: self.left = bt_node child_location = self.value.get_center() + \ side_offset_multiply * self.radius * direction + \ down_offset_multiply * self.radius * DOWN parent_child_vector = normalize(child_location - self.value.get_center()) edge_start = (self.value.get_center() + parent_child_vector * self.radius) edge_end = child_location - parent_child_vector * self.radius edge = Line(edge_start, edge_end) self.scene.play(bt_node.value.animate.move_to(child_location), FadeIn(edge), run_time=bt_node.animation_duration) return bt_node
def test_vmob_add_to_back(): """Test the Mobject add_to_back method.""" a = VMobject() b = Line() c = "text" with pytest.raises(ValueError): # Mobject cannot contain self a.add_to_back(a) with pytest.raises(TypeError): # All submobjects must be of type Mobject a.add_to_back(c) # No submobject gets added twice a.add_to_back(b) a.add_to_back(b, b) assert len(a.submobjects) == 1