mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Updated arrange_in_grid
This commit is contained in:
parent
72472c5836
commit
e7a60c6c85
1 changed files with 19 additions and 13 deletions
|
@ -1013,23 +1013,29 @@ class Mobject(Container):
|
||||||
self.center()
|
self.center()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def arrange_in_grid(self, n_rows=None, n_cols=None, **kwargs):
|
def arrange_in_grid(self, n_rows=None, n_cols=None,
|
||||||
|
buff=MED_LARGE_BUFF,
|
||||||
|
aligned_edge=ORIGIN,
|
||||||
|
fill_rows_first=True):
|
||||||
submobs = self.submobjects
|
submobs = self.submobjects
|
||||||
if n_rows is None and n_cols is None:
|
if n_rows is None and n_cols is None:
|
||||||
n_rows = int(np.sqrt(len(submobs)))
|
n_rows = int(np.sqrt(len(submobs)))
|
||||||
|
if n_rows is None:
|
||||||
|
n_rows = len(submobs) // n_cols
|
||||||
|
if n_cols is None:
|
||||||
|
n_cols = len(submobs) // n_rows
|
||||||
|
|
||||||
if n_rows is not None:
|
x_unit = buff + max([sm.get_width() for sm in submobs])
|
||||||
v1 = RIGHT
|
y_unit = buff + max([sm.get_height() for sm in submobs])
|
||||||
v2 = DOWN
|
|
||||||
n = len(submobs) // n_rows
|
for index, sm in enumerate(submobs):
|
||||||
elif n_cols is not None:
|
if rows_first:
|
||||||
v1 = DOWN
|
x, y = index % n_cols, index // n_cols
|
||||||
v2 = RIGHT
|
else:
|
||||||
n = len(submobs) // n_cols
|
x, y = index // n_rows, index % n_rows
|
||||||
Group(*[
|
sm.move_to(ORIGIN, aligned_edge)
|
||||||
Group(*submobs[i:i + n]).arrange(v1, **kwargs)
|
sm.shift(x * x_unit * RIGHT + y * y_unit * DOWN)
|
||||||
for i in range(0, len(submobs), n)
|
self.center()
|
||||||
]).arrange(v2, **kwargs)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def sort(self, point_to_num_func=lambda p: p[0], submob_func=None):
|
def sort(self, point_to_num_func=lambda p: p[0], submob_func=None):
|
||||||
|
|
Loading…
Add table
Reference in a new issue