Skip to content

Commit

Permalink
Add Mobject.replicate
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Aug 28, 2021
1 parent 0d2d1b5 commit 17c2772
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,17 @@ def arrange_in_grid(self, n_rows=None, n_cols=None,
self.center()
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):
"""
Returns a new mobject containing multiple copies of this one
arranged in a grid
"""
grid = self.get_group_class()(
*(self.copy() for n in range(n_rows * n_cols))
)
grid = self.replicate(n_rows * n_cols)
grid.arrange_in_grid(n_rows, n_cols, **kwargs)
if height is not None:
grid.set_height(height)
Expand Down

0 comments on commit 17c2772

Please sign in to comment.