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]

Bases: ABC, VGroup, Labelable

An abstract base class representing a collection of MElement objects.

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 is RIGHT.

  • margin (float, optional) – The distance between elements in the collection. Default is 0.

  • style (MCollectionStyle._DefaultStyle, optional) – The style configuration for the elements. Default is MCollectionStyle.DEFAULT.

Methods

add_label

Adds a label to the collection, positioned relative to its elements.

append

Appends a new element to the collection, styled according to the current configuration.

pop

Removes the element at the specified index and shifts all subsequent elements accordingly.

swap

Swaps the positions of two elements in the collection.

Inherited Attributes

animate

Used to animate the application of any method of self.

color

depth

The depth of the mobject.

fill_color

If there are multiple colors (for gradient) this returns the first one

height

The height of the mobject.

n_points_per_curve

sheen_factor

stroke_color

width

The 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 is UP.

  • 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 underlying add_label method.

Returns:

The instance of the MCollection with 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 MCollection with 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 MCollection with the specified element removed.

Return type:

self

swap(i, j)[source]

Swaps the positions of two elements in the collection.

Parameters:
  • i (int) – The index of the first element to be swapped.

  • j (int) – The index of the second element to be swapped.

Returns:

The instance of the MCollection with the swapped elements.

Return type:

self