Add Mobject.replicate

This commit is contained in:
Grant Sanderson
2021-08-28 06:21:51 -07:00
parent 0d2d1b5c03
commit 17c2772b84

View File

@ -365,14 +365,17 @@ class Mobject(object):
self.center() self.center()
return self return self
def replicate(self, n):
return self.get_group_class()(
*(self.copy() for x in range(n))
)
def get_grid(self, n_rows, n_cols, height=None, **kwargs): def get_grid(self, n_rows, n_cols, height=None, **kwargs):
""" """
Returns a new mobject containing multiple copies of this one Returns a new mobject containing multiple copies of this one
arranged in a grid arranged in a grid
""" """
grid = self.get_group_class()( grid = self.replicate(n_rows * n_cols)
*(self.copy() for n in range(n_rows * n_cols))
)
grid.arrange_in_grid(n_rows, n_cols, **kwargs) grid.arrange_in_grid(n_rows, n_cols, **kwargs)
if height is not None: if height is not None:
grid.set_height(height) grid.set_height(height)