Skip to content

Commit

Permalink
Add get_highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Apr 14, 2022
1 parent 95f56f5 commit 29816fa
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions manimlib/mobject/mobject.py
Expand Up @@ -421,21 +421,6 @@ def arrange_in_grid(
self.center()
return self

def replicate(self, n: int) -> Group:
return self.get_group_class()(
*(self.copy() for x in range(n))
)

def get_grid(self, n_rows: int, n_cols: int, height: float | None = None, **kwargs):
"""
Returns a new mobject containing multiple copies of this one
arranged in a grid
"""
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)
return grid

def sort(
self,
Expand All @@ -457,6 +442,33 @@ def shuffle(self, recurse: bool = False):
self.assemble_family()
return self

# Creating new Mobjects from this one

def replicate(self, n: int) -> Group:
return self.get_group_class()(
*(self.copy() for x in range(n))
)

def get_grid(self, n_rows: int, n_cols: int, height: float | None = None, **kwargs):
"""
Returns a new mobject containing multiple copies of this one
arranged in a grid
"""
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)
return grid

def get_highlight(self):
from manimlib.mobject.types.dot_cloud import GlowDot
highlight = Group(*(
GlowDot(self.get_corner(v), color=WHITE)
for v in [UR, UL, DL, DR]
))
highlight.add_updater(lambda m: m.move_to(self))
return highlight

# Copying

def copy(self):
Expand Down

0 comments on commit 29816fa

Please sign in to comment.