mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 20:43:56 +08:00
Add Mobject.replicate
This commit is contained in:
@ -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)
|
||||||
|
Reference in New Issue
Block a user