group¶
- class janim.items.group.Group(*items: T, **kwargs)¶
Bases:
Points,Generic[T]Item group
Group items together
- class janim.items.group.NamedGroupMixin(*items: T, named: dict[str, T], **kwargs)¶
Bases:
Group,GenericA convenient base class for inheritance, for example by
AxesSee also:
NamedGroup- add(*items: T, prepend=False, **named_items: T) Self¶
Add child items to this item, and set named child items via keyword arguments
- Parameters:
items – Child items to add
named_items – Named child items to add
prepend – Default is
False; ifTrue, insert at the beginning of the child-item list
- insert(index: int, *items: T, **named_items: T) Self¶
Insert child items at the specified index, and set named child items via keyword arguments
- Parameters:
index – Index at which to insert
items – Child items to insert
named_items – Named child items to insert
- remove(*items_or_names: T | str) Self¶
Remove child items from this item
- Parameters:
items_or_names – Child items or names of named child items to remove
- shuffle() Self¶
Randomly shuffle the order of child items
Note
This method uses
random.shuffle()to shuffleFor reproducible randomness, set the seed with
random.seed()before calling this method
- set_name(item: Item, name: str) Self¶
Set the name for an existing child item
- Parameters:
item – An existing child item
name – The name to set
- by_name(key: str) T¶
Get a child item by name
- resolve() dict[str, T]¶
Resolve the internal index mapping of named child items into a name-to-item map
- Returns:
A mapping dictionary from names to child items
- children_with_name() list[tuple[T, str | None]]¶
Returns a list similar to the children list, but each element is a tuple of
(child item, its name). If the child item is not named, the name isNone
- store(**kwargs)¶
- restore(other: NamedGroupMixin) Self¶
- get_named_indices() dict[str, int]¶
- copy(*, root_only: bool = False)¶
Copy the item
- class janim.items.group.NamedGroup(*items: T, **named_items: T)¶
Bases:
NamedGroupMixin,GenericNamed item group; you can access named items with syntax like
group['name']- Parameters:
items – Initial items
named_items – Initial named items
You can also use
add()orinsert()and pass keyword arguments to add named child itemsExample:
group = NamedGroup( text=Text('lorem'), shape=Circle() ) group.points.arrange(DOWN, aligned_edge=LEFT) self.play( group['text'].anim.color.set(GREEN), group['shape'].anim.color.set(YELLOW), lag_ratio=0.5 ) def updater(group: NamedGroup, p: UpdaterParams) -> None: group.points.rotate(TAU * p.alpha) group['text'].color.mix(BLUE, p.alpha) self.play( GroupUpdater(group, updater) )
Note
Cannot use initialization parameters like
Groupgroup = Group(..., color=RED)
To resolve this, you can write:
group = NamedGroup(...) group.set(color=RED)
Note
If you want to subclass
NamedGroup, usingNamedGroupMixinis a better choiceBecause it does not consume all
**kwargs; instead it uses an explicitnamedparameter to specify the named child-item dictionary