Group¶
Qualified name: algan.mobs.group.Group
- class Group(mobs, *args, **kwargs)[source]¶
Bases:
Mob
Combine a collection of Mobs into a single Mob.
Specifically, creates an empty mob at the mid-point of the bounding box of the given mob collection and adds the mobs as children.
- Parameters:
- Returns:
The new mob which parents the provided mob collection.
- Return type:
Examples
Arrange 3 mobs horizontally in a line, left to right.
Example: Example1Group ¶
group = Group([Square() for _ in range(3)]).arrange_in_line(RIGHT).spawn() group.rotate(90, OUT) render_to_file()
group = Group([Square() for _ in range(3)]).arrange_in_line(RIGHT).spawn() group.rotate(90, OUT) render_to_file()
Methods
arrange_between_points
Moves the grouped mobs so that they in a given grid.
Moves the grouped mobs so that they lie along a given line.
get_boundary_edge_point2
Recursively flattens the Mob and its children into a list of individual Mobs.
highlight
highlight_off
Attributes
animation_manager
basis
The flattened 3x3 matrix representing the Mob's orientation and scale.
color
glow
location
The 3-D location of the Mob in world space.
max_opacity
normalized_basis
The Mob's basis matrix with all its row vectors normalized to unit length.
opacity
scale_coefficient
The scaling factor of the Mob along its local axes, derived from the basis.
- arrange_in_grid(num_rows=2, row_direction=tensor([1., 0., 0.]), column_direction=tensor([-0., -1., -0.]), buffer=0.6, column_buffer=None)[source]¶
Moves the grouped mobs so that they in a given grid.
- Parameters:
num_rows (int) – The number of rows in the grid. The number of columns id then derived as len(mobs) // num_rows.
row_direction (Tensor) – Vector in 3-D specifying the direction along which rows are aligned. Defaults to RIGHT.
column_direction (Tensor) – Vector in 3-D specifying the direction along which columns are aligned. Defaults to DOWN.
buffer – The amount of extra space added between the mobs in the row direction.
column_buffer – The amount of extra space added between the mobs in the column direction. If None then it is set to buffer.
- Returns:
The Group instance itself, allowing for method chaining.
- Return type:
Examples
Arrange mobs in a 3x3 grid slanted at a 45 degrees angle.
Example: Example1ArrangeInGrid ¶
group = Group([Square() for _ in range(9)]).scale(1/3).arrange_in_grid(3, RIGHT+UP, RIGHT+DOWN).spawn() group.rotate(90, OUT) render_to_file()
group = Group([Square() for _ in range(9)]).scale(1/3).arrange_in_grid(3, RIGHT+UP, RIGHT+DOWN).spawn() group.rotate(90, OUT) render_to_file()
- arrange_in_line(direction=tensor([1., 0., 0.]), buffer=0.6, start_at_first=False, equal_displacement=False, alignment_direction=None)[source]¶
Moves the grouped mobs so that they lie along a given line.
- Parameters:
direction (Tensor) – Vector in 3-D specifying the direction of the line. Defaults to RIGHT.
buffer (float) – The amount of extra space added between the mobs. If 0, the mobs will be arranged edge-to-edge.
start_at_first (bool) – if True, the first mob’s position will be unchanged, and the subsequent mobs will be arranged starting from the first mob’s position. If False, the mobs will be arranged so that their center is equal to this Group’s location.
equal_displacement (bool) – If True, the mobs will be arranged at evenly spaced intervals.
alignment_direction (Tensor | None) – If not None, the mobs will additionally be aligned on this direction.
- Returns:
The Group instance itself, allowing for method chaining.
- Return type: