mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Allow group_by_rows and group_bg_cols option for creating grids
This commit is contained in:
parent
b6dd640fe7
commit
a4ffe9b4e5
1 changed files with 22 additions and 3 deletions
|
@ -681,16 +681,35 @@ class Mobject(object):
|
|||
group_class = self.get_group_class()
|
||||
return group_class(*(self.copy() for _ in range(n)))
|
||||
|
||||
def get_grid(self, n_rows: int, n_cols: int, height: float | None = None, **kwargs) -> Group:
|
||||
def get_grid(self,
|
||||
n_rows: int,
|
||||
n_cols: int,
|
||||
height: float | None = None,
|
||||
width: float | None = None,
|
||||
group_by_rows: bool = False,
|
||||
group_by_cols: bool = False,
|
||||
**kwargs) -> Group:
|
||||
"""
|
||||
Returns a new mobject containing multiple copies of this one
|
||||
arranged in a grid
|
||||
"""
|
||||
grid = self.replicate(n_rows * n_cols)
|
||||
total = n_rows * n_cols
|
||||
grid = self.replicate(total)
|
||||
if group_by_cols:
|
||||
kwargs["fill_rows_first"] = False
|
||||
grid.arrange_in_grid(n_rows, n_cols, **kwargs)
|
||||
if height is not None:
|
||||
grid.set_height(height)
|
||||
return grid
|
||||
if width is not None:
|
||||
grid.set_height(width)
|
||||
|
||||
group_class = self.get_group_class()
|
||||
if group_by_rows:
|
||||
return group_class(*(grid[n:n + n_cols] for n in range(0, total, n_cols)))
|
||||
elif group_by_cols:
|
||||
return group_class(*(grid[n:n + n_rows] for n in range(0, total, n_rows)))
|
||||
else:
|
||||
return grid
|
||||
|
||||
# Updating
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue