MCollection¶
Qualified name: manim\_dsa.m\_collection.m\_collection.MCollection
- class MCollection(arr=[], direction=array([1., 0., 0.]), margin=0, style=<manim_dsa.constants.MCollectionStyle._DefaultStyle object>)[source]¶
-
An abstract base class representing a collection of
MElementobjects.- Parameters:
arr (list, optional) – The initial list of values to populate the collection. Default is an empty list.
direction (
Vector3D, optional) – The direction in which to arrange the elements. Default isRIGHT.margin (float, optional) – The distance between elements in the collection. Default is
0.style (
MCollectionStyle._DefaultStyle, optional) – The style configuration for the elements. Default isMCollectionStyle.DEFAULT.
Methods
Adds a label to the collection, positioned relative to its elements.
Appends a new element to the collection, styled according to the current configuration.
Removes the element at the specified index and shifts all subsequent elements accordingly.
Swaps the positions of two elements in the collection.
Inherited Attributes
animateUsed to animate the application of any method of
self.colordepthThe depth of the mobject.
fill_colorIf there are multiple colors (for gradient) this returns the first one
heightThe height of the mobject.
n_points_per_curvesheen_factorstroke_colorwidthThe width of the mobject.
- add_label(text, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]¶
Adds a label to the collection, positioned relative to its elements.
- Parameters:
text (
Text) – The text label to be added.direction (
Vector3D, optional) – The direction in which to position the label. Default isUP.buff (float, optional) – The buffer distance between the label and the element. Default is 0.5.
**kwargs – Additional keyword arguments that are passed to the
next_to()method of the underlyingadd_labelmethod.
- Returns:
The instance of the
MCollectionwith the added label.- Return type:
self
- append(value)[source]¶
Appends a new element to the collection, styled according to the current configuration.
- Parameters:
value (Any) – The value to append. It will be converted to a string representation.
- Returns:
The instance of the
MCollectionwith the newly appended element.- Return type:
self
- pop(index=-1)[source]¶
Removes the element at the specified index and shifts all subsequent elements accordingly.
- Parameters:
index (int, optional) – The index of the element to be removed. Default is
-1, which removes the last element.- Returns:
The instance of the
MCollectionwith the specified element removed.- Return type:
self
- swap(i, j)[source]¶
Swaps the positions of two elements in the collection.
- Parameters:
- Returns:
The instance of the
MCollectionwith the swapped elements.- Return type:
self