mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 02:35:22 +08:00
Made slicing into mobjects return a Group or VGroup instead of a list
This commit is contained in:
@ -663,8 +663,12 @@ class Mobject(object):
|
|||||||
|
|
||||||
## Family matters
|
## Family matters
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, value):
|
||||||
return self.split()[index]
|
self_list = self.split()
|
||||||
|
if isinstance(value, slice):
|
||||||
|
GroupClass = self.get_group_class()
|
||||||
|
return GroupClass(*self_list.__getitem__(value))
|
||||||
|
return self_list.__getitem__(value)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.split())
|
return iter(self.split())
|
||||||
@ -672,6 +676,9 @@ class Mobject(object):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.split())
|
return len(self.split())
|
||||||
|
|
||||||
|
def get_group_class(self):
|
||||||
|
return Group
|
||||||
|
|
||||||
def split(self):
|
def split(self):
|
||||||
result = [self] if len(self.points) > 0 else []
|
result = [self] if len(self.points) > 0 else []
|
||||||
return result + self.submobjects
|
return result + self.submobjects
|
||||||
|
@ -19,6 +19,9 @@ class VMobject(Mobject):
|
|||||||
"make_smooth_after_applying_functions" : False,
|
"make_smooth_after_applying_functions" : False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_group_class(self):
|
||||||
|
return VGroup
|
||||||
|
|
||||||
## Colors
|
## Colors
|
||||||
def init_colors(self):
|
def init_colors(self):
|
||||||
self.set_style_data(
|
self.set_style_data(
|
||||||
|
Reference in New Issue
Block a user