Group¶
Qualified name: algan.mobs.group.Group
- class Group(*mobs, link_children=True, **kwargs)[source]¶
Bases:
MobCombine 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:
*mobs – The Mobs to group, as separate arguments or as one iterable –
Group(a, b)andGroup([a, b])are the same call, and nested iterables are flattened. They must all belong to the same Scene.link_children (bool) – Whether the Mobs become real children of the Group, so that they carry it as a parent and follow its transforms. Defaults to True.
Falsemakes an observational view: transforms still recurse over the members, but theirparentsare untouched, which is whatgroup[1:3]returns.**kwargs – Passed to
Mob– notablyscene, which must be the members’ own Scene, andname.
- Raises:
TypeError – If a member is not an
Animatableinstance.
Examples
Arrange 3 mobs horizontally in a line, left to right.
Example: Example1Group ¶
from algan import * group = Group([Square() for _ in range(3)]).arrange_in_line(RIGHT).spawn() group.rotate(90, OUT) Scene.save_video()
Methods
Add Mobs to the Group.
Space the members evenly along the segment between two points.
Lay the members out in a grid, filling row by row.
Lay the members out in a line.
Get the Group's members as a list.
Attributes
animation_managerThis mob's scene-owned animation manager.
basisThe Mob's orientation and scale, as a flattened 3x3 matrix of shape
(*, 9).casts_shadowsWhether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.
childrenThe Mobs attached below this one, in attachment order.
closed_shellWhether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.
draws_descendantsWhether
get_render_primitivesreturns geometry belonging to this Mob's DESCENDANTS as well as its own.forwardGet the direction the Mob is facing.
lifespanThis mob's [spawn, despawn) interval on its Scene timeline (a
Lifespan).locationThe Mob's position in world space, shape
(*, 3).normalized_basisThe Mob's orientation with scale divided out, shape
(*, 9).parentsThe Mobs this one is attached to, in attachment order.
receives_shadowsWhether this Mob's surfaces are darkened by shadows cast onto them.
rightGet the Mob's own rightward direction.
scale_coefficientThe Mob's scale along its own right, up and forward axes, shape
(*, 3).two_sidedWhether this Mob's geometry should be lit from whichever side the ray arrives on.
upGet the Mob's own upward direction.
xThe Mob's x coordinate in world units, shape
(*, 1).xyThe Mob's x and y coordinates in world units, shape
(*, 2).yThe Mob's y coordinate in world units, shape
(*, 1).zThe Mob's z coordinate in world units, shape
(*, 1).- add(*mobs)[source]¶
Add Mobs to the Group.
The added Mobs become children, so the Group’s transforms carry them along, and the Group’s anchor moves to the middle of the enlarged collection. Re-adding an existing member does nothing.
Animation
Not animated: membership and the Group’s re-centering both happen instantly (the re-centering is done inside
Off(), so it costs no video time and does not drag the existing members around).- Parameters:
*mobs – Mobs to add. Nested iterables are flattened, so
group.add([a, b])andgroup.add(a, b)are the same.- Returns:
This Group, so calls can be chained.
- Return type:
- Raises:
.HierarchyError – If a Mob is added twice, belongs to another Scene, or the change would create a cycle.
- arrange_between_points(start, end)[source]¶
Space the members evenly along the segment between two points.
Members are placed at equal fractions of the way from
starttoend, both endpoints excluded, sonmembers divide the segment inton + 1equal steps. Sizes are ignored – it is the centers that are evenly spaced.Animation
Recorded as an animation: every member moves at once inside a
Sync, over the current context’s runtime (1 second by default).- Parameters:
start (Tensor) – Start of the segment, shape
(*, 3).end (Tensor) – End of the segment, shape
(*, 3).
- Returns:
This Group, so calls can be chained.
- Return type:
- arrange_in_grid(num_rows=None, row_direction=tensor([1., 0., 0.]), column_direction=tensor([-0., -1., -0.]), row_buffer=None, column_buffer=None, tight_axis=None)[source]¶
Lay the members out in a grid, filling row by row.
Cells are sized to the largest member so the grid stays regular, and the whole grid is centered on the Group’s location. Members fill along
row_directionfirst, wrapping to the next line alongcolumn_direction.Animation
Recorded as an animation: every member moves at once inside a
Sync, over the current context’s runtime (1 second by default). Call it before spawning to lay a Group out for free.- Parameters:
num_rows (int) – Number of rows; columns follow from the member count. Defaults to
None, meaningceil(sqrt(len(mobs)))– as square a grid as the count allows.row_direction (Tensor) – Non-zero direction along which a row runs; its magnitude is ignored. Defaults to
RIGHT.column_direction (Tensor) – Non-zero direction in which successive rows are stacked; its magnitude is ignored. Defaults to
DOWN.row_buffer – Gap between members within a row, in world units. Defaults to
None, meaningSETTINGS.style.buffer(0.6).column_buffer – Gap between rows, in world units. Defaults to
None, meaning userow_buffer.tight_axis – Which axis sizes its cells per row/column rather than uniformly across the whole grid:
0for columns,1for rows. Defaults toNone, meaning every cell is the same size. Use it to close up the gaps when members vary a lot in size.
- Returns:
This Group, so calls can be chained.
- Return type:
- Raises:
.AlganConfigurationError – If
num_rowsis not a positive integer, a direction is zero or invalid, ortight_axisis not0,1orNone.
Examples
Arrange mobs in a 3x3 grid slanted at a 45 degrees angle.
Example: Example1ArrangeInGrid ¶
from algan import * group = Group([Square() for _ in range(9)]).scale(1/3).arrange_in_grid(3, RIGHT+UP, RIGHT+DOWN).spawn() group.rotate(90, OUT) Scene.save_video()
- arrange_in_line(direction=tensor([1., 0., 0.]), buffer=None, start_at_first=False, equal_widths=False, align_to=None)[source]¶
Lay the members out in a line.
Members are placed edge to edge with
bufferbetween them, so differently sized Mobs still end up evenly gapped rather than evenly centred.Animation
Recorded as an animation: every member moves at once inside a
Sync, over the current context’s runtime (1 second by default). Call it before spawning to lay a Group out for free.- Parameters:
direction (Tensor) – Non-zero direction the line runs in; its magnitude is ignored. Defaults to
RIGHT.buffer (float | None) – Gap between neighbouring members, in world units;
0puts them edge to edge. Defaults toNone, meaningSETTINGS.style.buffer(0.6).start_at_first (bool) – Whether to keep the first member where it is and build the line out from it. Defaults to False, which centers the line on the Group’s location.
equal_widths (bool) – Whether to space members by a constant pitch (that of the largest member) rather than by their own sizes. Defaults to False. True gives evenly spaced centers, which is what you want for a row of labelled cells.
align_to (Tensor | None) – Direction along which to additionally align members, e.g.
DOWNto sit them all on a shared baseline. Defaults toNone, meaning no secondary alignment.
- Returns:
This Group, so calls can be chained.
- Return type:
- Raises:
.AlganConfigurationError – If
directionoralign_tois zero or not a finite 3-D vector.
See also
arrange_in_grid()Lay members out in rows and columns.
arrange_between_points()Space members evenly between two points.
- get_parts_as_mobs()[source]¶
Get the Group’s members as a list.
- Returns:
The members. Unlike
get_parts_as_mobs(), the Group itself is not included – it carries no geometry of its own.- Return type:
list[
Mob]