diff --git a/.flake8 b/.flake8
index e517afe..21f3825 100644
--- a/.flake8
+++ b/.flake8
@@ -9,7 +9,7 @@ max-complexity = 15
max-line-length = 88
statistics = True
# Prevents some flake8-rst-docstrings errors
-rst-roles = attr,class,func,meth,mod,obj,ref,doc,exc
+rst-roles = attr,class,func,meth,mod,obj,ref,doc,exc,py:meth,data
rst-directives = manim, SEEALSO, seealso
docstring-convention=numpy
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef51602..a858d11 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [0.1.7] - 2023-01-09
+
+### PRS
+
+- [#9](https://github.com/drageelr/manim-data-structures/pull/9)
+ - `MArraySlidingWindow` added.
+
+- [#8](https://github.com/drageelr/manim-data-structures/pull/8)
+ - Sphinx extensions added (intersphinx, napolean, viewcode, autodoc_typehints).
+ - Substitution reference file added `refsub.rst` and utilized in Animating Arrays guide.
+ - Docstrings of all classes updated.
+
## [0.1.6] - 2022-12-26
### PRS
diff --git a/docs/requirements.txt b/docs/requirements.txt
index de38f71..46a544c 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -1,2 +1,3 @@
manim
furo
+sphinx-autodoc-typehints
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 3eaf8e1..8993522 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -24,12 +24,28 @@
"sphinx.ext.duration",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
+ "sphinx.ext.intersphinx",
+ "sphinx.ext.viewcode",
"manim.utils.docbuild.manim_directive",
+ "sphinx.ext.napoleon",
+ "sphinx_autodoc_typehints",
]
templates_path = ["_templates"]
exclude_patterns = []
+# displays shorter function names that are documented via autodoc - sphinx.ext.autosummary
+add_module_names = False
+
+# displays type hint defaults - sphinx_autodoc_typehints
+typehints_defaults = "comma"
+
+# allows external documentation to be referred - sphinx.ext.intersphinx
+intersphinx_mapping = {
+ "python": ("https://docs.python.org/3", None),
+ "manim": ("https://docs.manim.community/en/stable/", None),
+}
+
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
diff --git a/docs/source/example.rst b/docs/source/example.rst
index e18653a..c751f11 100644
--- a/docs/source/example.rst
+++ b/docs/source/example.rst
@@ -1,19 +1,19 @@
+.. include:: ./refsub.rst
+
Example Gallery
===============
-.. currentmodule:: manim_data_structures.m_array
-
Find Pair Sum In Sorted MArray
------------------------------
The code snippet below uses the famous two pointer technique to find the pair sum ``17`` in the sorted array ``[2, 3, 5, 8, 9, 10, 11]``.
-.. manim:: MainScene
+.. manim:: PairSumExample
:quality: low
from manim_data_structures import *
- class MainScene(Scene):
+ class PairSumExample(Scene):
def isPairSumAnim(self, arr, n, val):
p_i = MArrayPointer(self, arr, 0, 'i', mob_arrow_args={'color': GREEN}, mob_label_args={'color': GREEN})
p_j = MArrayPointer(self, arr, n - 1, 'j', mob_arrow_args={'color': YELLOW}, mob_label_args={'color': YELLOW})
@@ -27,14 +27,14 @@ The code snippet below uses the famous two pointer technique to find the pair su
pair_sum.update_value(arr.fetch_arr()[p_i.fetch_index()] + arr.fetch_arr()[p_j.fetch_index()])
if (pair_sum.fetch_value() == val):
- pair_sum.fetch_mob_square().set(fill_color=GREEN)
+ self.play(pair_sum.fetch_mob_square().animate.set(fill_color=GREEN))
return True
elif(pair_sum.fetch_value() < val):
p_i.shift_to_elem(p_i.fetch_index() + 1)
else:
p_j.shift_to_elem(p_j.fetch_index() - 1)
- pair_sum.fetch_mob_square().set(fill_color=RED)
+ self.play(pair_sum.fetch_mob_square().aniamte.set(fill_color=RED))
return False
def construct(self):
@@ -43,3 +43,44 @@ The code snippet below uses the famous two pointer technique to find the pair su
self.add(arr)
self.isPairSumAnim(arr, 7, 17)
self.wait(1)
+
+Maxmimum Sum of K Consecutive Integers in MArray
+------------------------------------------------
+
+The code snippet below uses the sliding window technique to find the maximum sum of ``k = 4`` consecutive elements in the array ``[1, 4, 2, 10, 2, 3, 1, 0, 20]``
+
+.. manim:: PairSumExample
+ :quality: low
+
+ from manim_data_structures import *
+
+ class PairSumExample(Scene):
+ def maxSumAnim(self, marr: MArray, k):
+ arr = marr.fetch_arr()
+ n = len(arr)
+
+ window = MArraySlidingWindow(self, marr, 0, k, 'Window')
+ var_window_sum = MVariable(self, sum(arr[:k]), label='Window Sum')
+ var_max_sum = MVariable(self, var_window_sum.fetch_value(), label='Max Sum')
+ var_window_sum.shift(DOWN)
+ var_max_sum.shift(DOWN * 2.5)
+
+ self.play(Create(window))
+ self.play(Create(var_window_sum), Create(var_max_sum))
+
+ for i in range(n - k):
+ window.shift_to_elem(i + 1)
+ var_window_sum.update_value(var_window_sum.fetch_value() - arr[i] + arr[i + k])
+ if var_window_sum.fetch_value() > var_max_sum.fetch_value():
+ var_max_sum.update_value(var_window_sum.fetch_value())
+
+
+ self.play(var_max_sum.fetch_mob_square().animate.set(fill_color=GREEN))
+ return var_max_sum.fetch_value()
+
+ def construct(self):
+ arr = MArray(self, [1, 4, 2, 10, 2, 3, 1, 0, 20], label='Array')
+ arr.shift(UP * 1.5 + LEFT * 4)
+ self.add(arr)
+ self.maxSumAnim(arr, 4)
+ self.wait(1)
diff --git a/docs/source/guides/arrays.rst b/docs/source/guides/arrays.rst
index 0b4077e..8c60358 100644
--- a/docs/source/guides/arrays.rst
+++ b/docs/source/guides/arrays.rst
@@ -1,12 +1,12 @@
+.. include:: ../refsub.rst
+
Animating Arrays
================
-.. currentmodule:: manim_data_structures.m_array
-
Manim Array - MArray
--------------------
-The most basic data structure this package provides is the :py:class:`MArray` (short for Manim Array 😄). To create a :py:class:`MArray` simply create an instance by passing a python :py:class:`list`.
+The most basic data structure this package provides is the |MArray| (short for Manim Array 😄). To create a |MArray| simply create an instance by passing a python |list|.
.. code-block:: python
:linenos:
@@ -36,7 +36,7 @@ The most basic data structure this package provides is the :py:class:`MArray` (s
Animating MArray
~~~~~~~~~~~~~~~~
-To animate the :py:class:`MArray`, simply invoke the ``animate`` property as shown below:
+To animate the |MArray|, simply invoke the |Mobject.animate| property as shown below:
.. code-block:: python
:linenos:
@@ -60,7 +60,7 @@ To animate the :py:class:`MArray`, simply invoke the ``animate`` property as sho
self.play(arr.animate.shift(UP * 2 + LEFT * 5))
self.wait(1)
-Moreover, you can also use the :py:func:`MArray.animate_elem` method to animate a single element of the :py:class:`MArray` as well:
+Moreover, you can also use the |MArray.animate_elem| method to animate a single element of the |MArray| as well:
.. code-block:: python
:linenos:
@@ -84,7 +84,7 @@ Moreover, you can also use the :py:func:`MArray.animate_elem` method to animate
self.play(arr.animate_elem(1).shift(DOWN))
self.wait(1)
-Lastly, you can also animate the body, value and the index of any element using the :py:func:`MArray.animate_elem_square`, :py:func:`MArray.animate_elem_value` and :py:func:`MArray.animate_elem_index` respectively.
+Lastly, you can also animate the body, value and the index of any element using the |MArray.animate_elem_square|, |MArray.animate_elem_value| and |MArray.animate_elem_index| respectively.
.. code-block:: python
:linenos:
@@ -119,7 +119,7 @@ Lastly, you can also animate the body, value and the index of any element using
Customizing MArray
~~~~~~~~~~~~~~~~~~
-The :py:class:`MArray` also allows you to alter the way your array looks. While creating your array pass arguments to ``Square`` (used to represent the element body) and ``Text`` (used to represent the element value and index) mobjects.
+The |MArray| also allows you to alter the way your array looks. While creating your array pass arguments to |Square| (used to represent the element body) and |Text| (used to represent the element value and index) mobjects.
.. code-block:: python
:linenos:
@@ -157,11 +157,9 @@ The :py:class:`MArray` also allows you to alter the way your array looks. While
Growth Direction
^^^^^^^^^^^^^^^^
-Furthermore, you can also create :py:class:`MArray` that grows in different directions (e.g. up, down, right and left etc.).
+Furthermore, you can also create |MArray| that grows in different directions (e.g. up, down, right and left etc.).
-.. currentmodule:: manim_data_structures.m_enum
-
-To do this, simply pass your preferred direction enum from :py:class:`MArrayDirection` as the ``arr_dir`` argument to the constructor. The code snippet below generates four different arrays in each direction.
+To do this, simply pass your preferred direction enum from |MArrayDirection| as the ``arr_dir`` argument to the constructor. The code snippet below generates four different arrays in each direction.
.. code-block:: python
:linenos:
@@ -215,13 +213,9 @@ To do this, simply pass your preferred direction enum from :py:class:`MArrayDire
Array Label
^^^^^^^^^^^
-.. currentmodule:: manim_data_structures.m_array
-
-For an :py:class:`MArray`, you can also a label with the array via specifying the ``label`` argument.
+For an |MArray|, you can also a label with the array via specifying the ``label`` argument.
-.. currentmodule:: manim_data_structures.m_enum
-
-Similar to how we specify the growth direction using :py:class:`MArrayDirection` enum, we can dictate the position of the label.
+Similar to how we specify the growth direction using |MArrayDirection| enum, we can dictate the position of the label.
.. code-block:: python
:linenos:
@@ -272,16 +266,14 @@ Similar to how we specify the growth direction using :py:class:`MArrayDirection`
self.wait(1)
-.. currentmodule:: manim_data_structures.m_array
-
.. note::
- The ``arr_label_gap`` argument specifies the distance between the :py:class:`MArrayElement` 's :py:class:`manim.Square` and the array label itself.
+ The ``arr_label_gap`` argument specifies the distance between the |MArrayElement| 's |Square| and the array label itself.
Hex Indices
^^^^^^^^^^^
-Lets say you want to show a 4-byte integer array with its addresses. You can simply achieve this by using ``index_hex_display`` and ``index_offset`` arguments of the :py:class:`MArray` constructor.
+Lets say you want to show a 4-byte integer array with its addresses. You can simply achieve this by using ``index_hex_display`` and ``index_offset`` arguments of the |MArray| constructor.
.. code-block:: python
:linenos:
@@ -359,12 +351,12 @@ Or if you don't want to show the indices at all, simply pass ``True`` as the ``h
Misc Functions
~~~~~~~~~~~~~~
-The :py:class:`MArray` provides some auxiliary methods which this secion will discuss.
+The |MArray| provides some auxiliary methods which this secion will discuss.
Append Element
^^^^^^^^^^^^^^
-For an existing array, you can also append an element simply by invoking the :py:func:`MArray.append_elem` method.
+For an existing array, you can also append an element simply by invoking the |MArray.append_elem| method.
.. code-block:: python
:linenos:
@@ -399,7 +391,7 @@ For an existing array, you can also append an element simply by invoking the :py
You can also pass ``mob_*_args`` to this method to customize the inserted element.
-Moreover, you can also specify the animation that is played for the inserted element via the ``append_anim`` argument. The code snippet below passes the :py:class:`manim.GrowFromCenter` animation to the :py:func:`MArray.append_elem` method:
+Moreover, you can also specify the animation that is played for the inserted element via the ``append_anim`` argument. The code snippet below passes the |GrowFromCenter| animation to the |MArray.append_elem| method:
.. code-block:: python
:linenos:
@@ -424,15 +416,13 @@ Moreover, you can also specify the animation that is played for the inserted ele
arr.append_elem(4, append_anim=GrowFromCenter)
self.wait(1)
-.. currentmodule:: manim_data_structures.m_enum
-
.. note::
- You can also specify arguments to the passed animation via the ``append_anim_args`` parameter and also set the target of the animation using the ``append_anim_target`` parameter that takes in :py:class:`MArrayElementComp` enum.
+ You can also specify arguments to the passed animation via the ``append_anim_args`` parameter and also set the target of the animation using the ``append_anim_target`` parameter that takes in |MArrayElementComp| enum.
-Did you notice that in both snippets, we didn't pass any animation to our :py:class:`manim.Scene` but the append animation still played? This is thanks to the ``self`` that we pass as the first argument to our :py:class:`MArray` constructor, which is basically a reference to the current :py:class:`manim.Scene`.
+Did you notice that in both snippets, we didn't pass any animation to our |Scene| but the append animation still played? This is thanks to the ``self`` that we pass as the first argument to our |MArray| constructor, which is basically a reference to the current |Scene|.
-However, if you'd like to play the animation yourself, we have got you covered! The :py:func:`MArrayElement` method returns a list of :py:class:`manim.Animation` that you can pass to the :py:func:`manim.Scene.play` method as follows:
+However, if you'd like to play the animation yourself, we have got you covered! The |MArrayElement| method returns a list of |Animation| that you can pass to the |Scene.play| method as follows:
.. code-block:: python
:linenos:
@@ -442,9 +432,7 @@ However, if you'd like to play the animation yourself, we have got you covered!
Remove Element
^^^^^^^^^^^^^^
-.. currentmodule:: manim_data_structures.m_array
-
-To remove an element simply invoke the :py:class:`MArray.remove_elem` method with the index of element you wish to remove.
+To remove an element simply invoke the |MArray.remove_elem| method with the index of element you wish to remove.
.. code-block:: python
:linenos:
@@ -469,7 +457,7 @@ To remove an element simply invoke the :py:class:`MArray.remove_elem` method wit
arr.remove_elem(1)
self.wait(1)
-Similar to how you were able to pass the append animation to the :py:class:`MArray.append_elem` function, you can specify two animations for the :py:class:`MArray.remove_elem` method:
+Similar to how you were able to pass the append animation to the |MArray.append_elem| function, you can specify two animations for the |MArray.remove_elem| method:
1. Element removal animation via the ``removal_anim`` parameter.
2. Indices update animation via the ``update_anim`` parameter.
@@ -503,7 +491,7 @@ The code snippet below provides an example:
You can also specify arguments to the passed animation via the ``*_anim_args`` parameter and also set the target of the animation using the ``*_anim_target`` parameter.
-Lastly, as the :py:func:`MArray.append_elem` returns a list of :py:class:`manim.Animation`, the :py:func:`MArray.remove_elem` returns two objects; a removal animation and a function that udpates the indices of the remaining elements and returns their animations. Hence, you can animate this as follows:
+Lastly, as the |MArray.append_elem| returns a list of |Animation|, the |MArray.remove_elem| returns two objects; a removal animation and a function that udpates the indices of the remaining elements and returns their animations. Hence, you can animate this as follows:
.. code-block:: python
:linenos:
@@ -515,7 +503,7 @@ Lastly, as the :py:func:`MArray.append_elem` returns a list of :py:class:`manim.
Update Element
^^^^^^^^^^^^^^
-You can also update the value and the index of an existing array using the :py:class:`MArray.update_elem_value` and :py:class:`MArray.update_elem_index` methods respectively.
+You can also update the value and the index of an existing array using the |MArray.update_elem_value| and |MArray.update_elem_index| methods respectively.
.. code-block:: python
:linenos:
@@ -555,7 +543,7 @@ You can also update the value and the index of an existing array using the :py:c
Using MArrayPointer
~~~~~~~~~~~~~~~~~~~
-Thus far, if you had been hoping for a pointer to associate with your array, then your prayers have been answered. The :class:`MArrayPointer` allows you to attach a pointer with your array. The following snippet demonstrates its capabilities:
+Thus far, if you had been hoping for a pointer to associate with your array, then your prayers have been answered. The |MArrayPointer| allows you to attach a pointer with your array. The following snippet demonstrates its capabilities:
.. code-block:: python
:linenos:
@@ -604,4 +592,64 @@ Thus far, if you had been hoping for a pointer to associate with your array, the
self.wait(1)
+Using MArraySlidingWindow
+~~~~~~~~~~~~~~~~~~~
+
+In addition to the |MArrayPointer|, we also have the |MArraySlidingWindow| that allows you to attach a sliding window with your array. The following snippet demonstrates its capabilities:
+
+.. code-block:: python
+ :linenos:
+
+ class MyScene(Scene):
+ def construct(self):
+ arr = MArray(self, [1, 2, 3, 4, 5], label='Array')
+ arr.shift(UP + LEFT * 2)
+ self.add(arr)
+
+ window = MArraySlidingWindow(self, arr, 1, 1, 'W')
+ self.play(Create(window))
+ self.wait(1)
+ window.shift_to_elem(2)
+ self.wait(1)
+ window.resize_window(3)
+ self.wait(1)
+ window.shift_to_elem(0)
+ self.wait(1)
+ window.resize_window(1)
+ self.wait(1)
+ window.attach_to_elem(2)
+
+ self.wait(1)
+
+.. raw:: html
+
+
+
+.. manim:: MyScene
+ :hide_source:
+ :quality: low
+
+ from manim_data_structures import *
+
+ class MyScene(Scene):
+ def construct(self):
+ arr = MArray(self, [1, 2, 3, 4, 5], label='Array')
+ arr.shift(UP + LEFT * 2)
+ self.add(arr)
+
+ window = MArraySlidingWindow(self, arr, 1, 1, 'W')
+ self.play(Create(window))
+ self.wait(1)
+ window.shift_to_elem(2)
+ self.wait(1)
+ window.resize_window(3)
+ self.wait(1)
+ window.shift_to_elem(0)
+ self.wait(1)
+ window.resize_window(1)
+ self.wait(1)
+ window.attach_to_elem(2)
+
+ self.wait(1)
+
With this we conclude this guide. We hope you found it useful! ✌️
diff --git a/docs/source/reference/arrays.rst b/docs/source/reference/arrays.rst
index b73b308..b7952e2 100644
--- a/docs/source/reference/arrays.rst
+++ b/docs/source/reference/arrays.rst
@@ -9,3 +9,4 @@ Arrays
~m_array.MArrayElement
~m_array.MArray
~m_array.MArrayPointer
+ ~m_array.MArraySlidingWindow
diff --git a/docs/source/refsub.rst b/docs/source/refsub.rst
new file mode 100644
index 0000000..63ee100
--- /dev/null
+++ b/docs/source/refsub.rst
@@ -0,0 +1,29 @@
+.. currentmodule:: manim_data_structures
+
+.. Manim Data Structures substitutions
+.. |MArray| replace:: :py:class:`~m_array.MArray`
+.. |MArray.animate_elem| replace:: :py:meth:`MArray.animate_elem() `
+.. |MArray.animate_elem_square| replace:: :py:meth:`MArray.animate_elem_square() `
+.. |MArray.animate_elem_value| replace:: :py:meth:`MArray.animate_elem_value() `
+.. |MArray.animate_elem_index| replace:: :py:meth:`MArray.animate_elem_index() `
+.. |MArray.append_elem| replace:: :py:meth:`MArray.append_elem() `
+.. |MArray.remove_elem| replace:: :py:meth:`MArray.remove_elem() `
+.. |MArray.update_elem_value| replace:: :py:meth:`MArray.update_elem_value() `
+.. |MArray.update_elem_index| replace:: :py:meth:`MArray.update_elem_index() `
+.. |MArrayElement| replace:: :py:class:`~m_array.MArrayElement`
+.. |MArrayDirection| replace:: :py:class:`~m_enum.MArrayDirection`
+.. |MArrayElementComp| replace:: :py:class:`~m_enum.MArrayElementComp`
+.. |MArrayPointer| replace:: :py:class:`~m_array.MArrayPointer`
+.. |MArraySlidingWindow| replace:: :py:class:`~m_array.MArraySlidingWindow`
+
+.. Manim substitutions
+.. |Mobject.animate| replace:: :py:attr:`~manim.mobject.mobject.Mobject.animate`
+.. |Scene| replace:: :py:class:`~manim.scene.scene.Scene`
+.. |Scene.play| replace:: :py:meth:`Scene.play() `
+.. |Square| replace:: :py:class:`~manim.mobject.geometry.polygram.Square`
+.. |Text| replace:: :py:class:`~manim.mobject.text.text_mobject.Text`
+.. |Animation| replace:: :py:class:`~manim.animation.animation.Animation`
+.. |GrowFromCenter| replace:: :py:class:`~manim.animation.growing.GrowFromCenter`
+
+.. Python substitutions
+.. |list| replace:: :py:class:`list`
diff --git a/pyproject.toml b/pyproject.toml
index 1ef7fe2..0396ba9 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "manim-data-structures"
-version = "0.1.6"
+version = "0.1.7"
description = "A Manim implementation for data structures"
authors = ["Hammad Nasir "]
readme = "README.md"
diff --git a/src/manim_data_structures/__init__.py b/src/manim_data_structures/__init__.py
index 1a72360..11c8d9e 100644
--- a/src/manim_data_structures/__init__.py
+++ b/src/manim_data_structures/__init__.py
@@ -1,4 +1,4 @@
-__version__ = "0.1.6"
+__version__ = "0.1.7"
from .m_array import *
from .m_enum import *
@@ -8,6 +8,7 @@
"MArrayElement",
"MArray",
"MArrayPointer",
+ "MArraySlidingWindow",
"MArrayDirection",
"MArrayElementComp",
"MVariable",
diff --git a/src/manim_data_structures/m_array.py b/src/manim_data_structures/m_array.py
index 0c4bbbb..6abafb5 100644
--- a/src/manim_data_structures/m_array.py
+++ b/src/manim_data_structures/m_array.py
@@ -13,51 +13,57 @@ class MArrayElement(VGroup):
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- index_pos : :class:`np.ndarray`, default: `UP`
- Specifies the position of :attr:`__mob_index`
- index_gap : :class:`float`, default: `0.25`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_index`
- label_pos : :class:`np.ndarray`, default: `LEFT`
- Specifies the position of :attr:`__mob_label`
- label_gap : :class:`float`, default: `0.5`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_label`
- next_to_mob : :class:`MArrayElement`, default: `None`
- Specifies placement for :attr:`__mob_square`
- next_to_dir : :class:`np.ndarray`, default: `RIGHT`
- Specifies direction of placement for :attr:`__mob_square`
+ scene
+ Specifies the scene where the object is to be rendered.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element label.
+ index_pos
+ Specifies the position of :attr:`__mob_index` w.r.t :attr:`__mob_square`
+ index_gap
+ Specifies the distance between :attr:`__mob_index` and :attr:`__mob_square`.
+ label_pos
+ Specifies the position of :attr:`__mob_label` w.r.t :attr:`__mob_square`.
+ label_gap
+ Specifies the distance between :attr:`__mob_label` and :attr:`__mob_square`.
+ next_to_mob
+ Specifies the placement for :attr:`__mob_square` w.r.t another :class:`MArrayElement`.
+ next_to_dir
+ Specifies the direction of placement for :attr:`__mob_square` w.r.t another :class:`MArrayElement`.
Attributes
----------
- __scene : :class:`manim.Scene`
- The scene where the object should exist.
+ __scene : :class:`~manim.scene.scene.Scene`
+ The scene where the object is to be rendered.
__mob_square_props : :class:`dict`
- Default arguments passed to :class:`manim.Square` that represents the element body.
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
__mob_value_props : :class:`dict`
- Default arguments passed to :class:`manim.Text` that represents the element value.
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
__mob_index_props : :class:`dict`
- Default arguments passed to :class:`manim.Text` that represents the element index.
- __mob_square : :class:`manim.Square`
- :class:`manim.Mobject` that represents the element body.
- __mob_value : :class:`manim.Text`
- :class:`manim.Mobject` that represents the element index.
- __mob_index : :class:`manim.Text`
- :class:`manim.Mobject` that represents the element value.
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ __mob_label_props : :class:`dict`
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element label.
__index_pos : :class:`np.ndarray`
- Specifies the position of :attr:`__mob_index`
+ The position of :attr:`__mob_index` w.r.t :attr:`__mob_square`
__index_gap : :class:`float`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_index`
+ The distance between :attr:`__mob_index` and :attr:`__mob_square`.
__label_pos : :class:`np.ndarray`
- Specifies the position of :attr:`__mob_label`
+ The position of :attr:`__mob_label` w.r.t :attr:`__mob_square`.
__label_gap : :class:`float`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_label`
+ The distance between :attr:`__mob_label` and :attr:`__mob_square`.
+ __mob_square : :class:`~manim.mobject.geometry.polygram.Square`
+ Represents the body of the element.
+ __mob_value : :class:`~manim.mobject.text.text_mobject.Text`
+ Represents the value of the element.
+ __mob_index : :class:`~manim.mobject.text.text_mobject.Text`
+ Represents the index of the element.
+ __mob_label : :class:`~manim.mobject.text.text_mobject.Text`
+ Represents the label of the element.
"""
def __init_props(
@@ -72,32 +78,32 @@ def __init_props(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- index_pos : :class:`np.ndarray`
- Specifies the position of :attr:`__mob_index`
- index_gap : :class:`float`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_index`
- label_pos : :class:`np.ndarray`
- Specifies the position of :attr:`__mob_label`
- label_gap : :class:`float`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_label`
- """
-
- self.__mob_square_props = {
+ scene
+ Specifies the scene where the object is to be rendered.
+ index_pos
+ Specifies the position of :attr:`__mob_index` w.r.t :attr:`__mob_square`
+ index_gap
+ Specifies the distance between :attr:`__mob_index` and :attr:`__mob_square`.
+ label_pos
+ Specifies the position of :attr:`__mob_label` w.r.t :attr:`__mob_square`.
+ label_gap
+ Specifies the distance between :attr:`__mob_label` and :attr:`__mob_square`.
+ """
+
+ self.__mob_square_props: dict = {
"color": BLUE_B,
"fill_color": BLUE_D,
"fill_opacity": 1,
"side_length": 1,
}
- self.__mob_value_props = {"text": "", "color": WHITE, "weight": BOLD}
- self.__mob_index_props = {"text": "", "color": BLUE_D, "font_size": 32}
- self.__mob_label_props = {"text": "", "color": BLUE_A, "font_size": 38}
- self.__scene = scene
- self.__index_pos = index_pos
- self.__index_gap = index_gap
- self.__label_pos = label_pos
- self.__label_gap = label_gap
+ self.__mob_value_props: dict = {"text": "", "color": WHITE, "weight": BOLD}
+ self.__mob_index_props: dict = {"text": "", "color": BLUE_D, "font_size": 32}
+ self.__mob_label_props: dict = {"text": "", "color": BLUE_A, "font_size": 38}
+ self.__scene: Scene = scene
+ self.__index_pos: np.ndarray = index_pos
+ self.__index_gap: float = index_gap
+ self.__label_pos: np.ndarray = label_pos
+ self.__label_gap: float = label_gap
def __update_props(
self,
@@ -110,14 +116,14 @@ def __update_props(
Parameters
----------
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element label.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element label.
"""
self.__mob_square_props.update(mob_square_args)
@@ -143,26 +149,26 @@ def __init_mobs(
next_to_mob: "MArrayElement" = None,
next_to_dir: np.ndarray = RIGHT,
) -> None:
- """Initializes the :class:`Mobject`s for the class.
+ """Initializes the mobjects for the class.
Parameters
----------
- init_square : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Sqaure` and adds it to :attr:`__mob_square`.
- init_value : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Text` and adds it to :attr:`__mob_value`.
- init_index : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Text` and adds it to :attr:`__mob_index`.
- init_label : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Text` and adds it to :attr:`__mob_label`.
- next_to_mob : :class:`MArrayElement`, default: `None`
- Specifies placement for :attr:`__mob_square`
- next_to_dir : :class:`np.ndarray`, default: `RIGHT`
- Specifies direction of placement for :attr:`__mob_square`
+ init_square
+ If `True`, instantiates a :class:`~manim.mobject.geometry.polygram.Square` and assigns it to :attr:`__mob_square`.
+ init_value
+ If `True`, instantiates a :class:`~manim.mobject.text.text_mobject.Text` and assigns it to :attr:`__mob_value`.
+ init_index
+ If `True`, instantiates a :class:`~manim.mobject.text.text_mobject.Text` and assigns it to :attr:`__mob_index`.
+ init_label
+ If `True`, instantiates a :class:`~manim.mobject.text.text_mobject.Text` and assigns it to :attr:`__mob_label`.
+ next_to_mob
+ Specifies placement for :attr:`__mob_square` w.r.t another :class:`MArrayElement`.
+ next_to_dir
+ Specifies direction of placement for :attr:`__mob_square` w.r.t another :class:`MArrayElement`.
"""
if init_square:
- self.__mob_square = Square(**self.__mob_square_props)
+ self.__mob_square: Square = Square(**self.__mob_square_props)
if next_to_mob is not None:
self.__mob_square.next_to(
next_to_mob.fetch_mob_square(), next_to_dir, 0
@@ -170,19 +176,19 @@ def __init_mobs(
self.add(self.__mob_square)
if init_value:
- self.__mob_value = Text(**self.__mob_value_props)
+ self.__mob_value: Text = Text(**self.__mob_value_props)
self.__mob_value.next_to(self.__mob_square, np.array([0, 0, 0]), 0)
self.add(self.__mob_value)
if init_index:
- self.__mob_index = Text(**self.__mob_index_props)
+ self.__mob_index: Text = Text(**self.__mob_index_props)
self.__mob_index.next_to(
self.__mob_square, self.__index_pos, self.__index_gap
)
self.add(self.__mob_index)
if init_label:
- self.__mob_label = Text(**self.__mob_label_props)
+ self.__mob_label: Text = Text(**self.__mob_label_props)
self.__mob_label.next_to(
self.__mob_square, self.__label_pos, self.__label_gap
)
@@ -220,28 +226,28 @@ def __init__(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element label.
- index_pos : :class:`np.ndarray`, default: `UP`
- Specifies the position of :attr:`__mob_index`.
- index_gap : :class:`float`, default: `0.25`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_index`.
- label_pos : :class:`np.ndarray`, default: `LEFT`
- Specifies the position of :attr:`__mob_label`.
- label_gap : :class:`float`, default: `0.5`
- Specifies the distance between :attr:`__mob_square` and :attr:`__mob_label`
- next_to_mob : :class:`MArrayElement`, default: `None`
- Specifies placement for :attr:`__mob_square`.
- next_to_dir : :class:`np.ndarray`, default: `RIGHT`
- Specifies direction of placement for :attr:`__mob_square`.
+ scene
+ Specifies the scene where the object is to be rendered.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element label.
+ index_pos
+ Specifies the position of :attr:`__mob_index` w.r.t :attr:`__mob_square`
+ index_gap
+ Specifies the distance between :attr:`__mob_index` and :attr:`__mob_square`.
+ label_pos
+ Specifies the position of :attr:`__mob_label` w.r.t :attr:`__mob_square`.
+ label_gap
+ Specifies the distance between :attr:`__mob_label` and :attr:`__mob_square`.
+ next_to_mob
+ Specifies the placement for :attr:`__mob_square` w.r.t another :class:`MArrayElement`.
+ next_to_dir
+ Specifies the direction of placement for :attr:`__mob_square` w.r.t another :class:`MArrayElement`.
"""
super().__init__(**kwargs)
@@ -258,61 +264,61 @@ def __init__(
self.__init_mobs(True, True, True, True, next_to_mob, next_to_dir)
def fetch_mob_square(self) -> Square:
- """Fetches the :class:`manim.Square` that represents the element body.
+ """Fetches the square mobject.
Returns
-------
- :class:`manim.Square`
- Represents the element body.
+ :class:`~manim.mobject.geometry.polygram.Square`
+ :attr:`__mob_square`.
"""
return self.__mob_square
def fetch_mob_value(self) -> Text:
- """Fetches the :class:`manim.Text` that represents the element value.
+ """Fetches the value mobject.
Returns
-------
- :class:`manim.Text`
- Represents the element value.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ :attr:`__mob_value`.
"""
return self.__mob_value
def fetch_mob_index(self) -> Text:
- """Fetches the :class:`manim.Text` that represents the element index.
+ """Fetches the index mobject.
Returns
-------
- :class:`manim.Text`
- Represents the element index.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ :attr:`__mob_index`.
"""
return self.__mob_index
def fetch_mob_label(self) -> Text:
- """Fetches the :class:`manim.Text` that represents the element label.
+ """Fetches the label mobject.
Returns
-------
- :class:`manim.Text`
- Represents the element label.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ :attr:`__mob_label`.
"""
return self.__mob_label
def fetch_mob(self, mob_target: MArrayElementComp) -> Mobject:
- """Fetches :class:`manim.Mobject` based on enum :class:`m_enum.MArrayElementComp`.
+ """Fetches the mobject based on the specified enum.
Parameters
----------
- mob_target : :class:`m_enum.MArrayElementComp`
- Specifies the component of :class:`MArrayElement` to fetch.
+ mob_target
+ Specifies the :class:`~manim.mobject.mobject.Mobject` to fetch.
Returns
-------
- :class:`manim.Mobject`
- Represents the component of :class:`MArrayElement`.
+ :class:`~manim.mobject.mobject.Mobject`
+ Mobject of the class.
"""
if mob_target == MArrayElementComp.BODY:
@@ -334,25 +340,25 @@ def update_mob_value(
play_anim: bool = True,
play_anim_args: dict = {},
) -> Text:
- """Re-intializes the :class:`manim.Text` that represents the element value.
+ """Re-intializes the value mobject.
Parameters
----------
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ update_anim
+ Animation to be applied to the updated :attr:`__mob_value`.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element value.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__mob_value`.
"""
# Update props of mob_value
@@ -383,25 +389,25 @@ def update_mob_index(
play_anim: bool = True,
play_anim_args: dict = {},
) -> Text:
- """Re-intializes the :class:`manim.Text` that represents the element index.
+ """Re-intializes the index mobject.
Parameters
----------
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ update_anim
+ Animation to be applied to the updated :attr:`__mob_index`.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element index.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__mob_index`.
"""
# Update props of mob_index
@@ -432,25 +438,25 @@ def update_mob_label(
play_anim: bool = True,
play_anim_args: dict = {},
) -> Text:
- """Re-intializes the :class:`manim.Text` that represents the element label.
+ """Re-intializes the label mobject.
Parameters
----------
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element label.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element label.
+ update_anim
+ Animation to be applied to the updated :attr:`__mob_label`.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element label.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__mob_label`.
"""
# Update props of mob_label
@@ -474,45 +480,45 @@ def update_mob_label(
return self.__mob_label
def animate_mob_square(self) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Square.animate` property of :class:`manim.Square` for the element body.
+ """Invokes the animate property over square mobject.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Square.animate` property of :class:`manim.Square`.
+ Animate property of :attr:`__mob_square`.
"""
return self.__mob_square.animate
def animate_mob_value(self) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Text.animate` property of :class:`manim.Text` for the element value.
+ """Invokes the animate property over value mobject.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Text.animate` property of :class:`manim.Text`.
+ Animate property of :attr:`__mob_value`.
"""
return self.__mob_value.animate
def animate_mob_index(self) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Text.animate` property of :class:`manim.Text` for the element index.
+ """Invokes the animate property over index mobject.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Text.animate` property of :class:`manim.Text`.
+ Animate property of :attr:`__mob_index`.
"""
return self.__mob_index.animate
def animate_mob_label(self) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Text.animate` property of :class:`manim.Text` for the element label.
+ """Invokes the animate property over label mobject.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Text.animate` property of :class:`manim.Text`.
+ Animate property of :attr:`__mob_label`.
"""
return self.__mob_label.animate
@@ -523,63 +529,65 @@ class MArray(VGroup):
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- arr : :class:`list`, default: `[]`
- Array to represent. Elements must be convertible to :class:`str`.
- label : :class:`str`, default: `''`
- Specifies the label of the array.
- index_offset : :class:`int`, default: `1`
- Difference between successive indices.
- index_start : :class:`int`, default: `0`
- Starting value of index.
- index_hex_display : :class:`bool`, default: `False`
- Displays indices in hex if `True` otherwise in decimal.
- hide_index : :class:`bool`, default: `False`
- Specifies whether to display indices or not.
- arr_dir : :class:`.m_enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.RIGHT`
- Specifies the growing direction of array.
- arr_label_pos : :class:`.enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.LEFT`
- Specifies the position of :attr:`__mob_arr_label`.
- arr_label_gap : :class:`float`, default: `0.5`
- Specifies the distance between :attr:`__mob_arr` and :attr:`__mob_arr_label`.
- mob_arr_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the label for :class:`MArray`.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body of :class:`MArrayElement`.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value of :class:`MArrayElement`.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index of :class:`MArrayElement`.
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to represent.
+ label
+ Specifies the value of the array label.
+ index_offset
+ Specifies the difference between successive displayable indices.
+ index_start
+ Specifies the starting value of displayable index.
+ index_hex_display
+ If `True`, displays indices in hex.
+ hide_index
+ If `True`, doesn't display indices.
+ arr_dir
+ Specifies the growth direction of the array.
+ arr_label_pos
+ Specifies the position of :attr:`__mob_arr_label` w.r.t :attr:`__mob_arr`.
+ arr_label_gap
+ Specifies the distance between :attr:`__mob_arr_label` and :attr:`__mob_arr`.
+ mob_arr_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the array label.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
**kwargs
Forwarded to constructor of the parent.
Attributes
----------
- __scene : :class:`manim.Scene`
- The scene where the object should exist.
+ __scene : :class:`~manim.scene.scene.Scene`
+ The scene where the object is to be rendered.
__arr : :class:`list`
- Array to represent. Elements must be convertible to :class:`str`.
- __mob_arr : List[:class:`MArrayElement`]
- Array containing the manim objects.
+ The array to represent.
__label : :class:`str`
- Specifies the label of the array.
+ The value of the array label.
__index_offset : :class:`int`
- Difference between successive indices.
+ The difference between successive displayable indices.
__index_start : :class:`int`
- Starting value of index.
+ The starting value of displayable index.
__index_hex_display : :class:`bool`
- Displays indices in hex if `True` otherwise in decimal.
+ If `True`, displays indices in hex.
__hide_index : :class:`bool`
- Specifies whether to display indices or not.
- __arr_dir : :class:`.m_enum.MArrayDirection`
- Specifies the growing direction of array.
- __arr_label_pos : :class:`.enum.MArrayDirection`
- Specifies the position of :attr:`__mob_arr_label`.
- __arr_label_gap : :class:`float`, default: `0.5`
- Specifies the distance between :attr:`__mob_arr` and :attr:`__mob_arr_label`.
+ If `True`, doesn't display indices.
+ __arr_dir : :class:`~.m_enum.MArrayDirection`
+ The growth direction of the array.
+ __arr_label_pos : :class:`~.m_enum.MArrayDirection`
+ The position of :attr:`__mob_arr_label` w.r.t :attr:`__mob_arr`.
+ __arr_label_gap : :class:`float`
+ The distance between :attr:`__mob_arr_label` and :attr:`__mob_arr`.
__mob_arr_label_props : :class:`dict`
- Arguments for :class:`manim.Text` that represents the label for :class:`MArray`.
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the array label.
+ __mob_arr : :class:`~typing.List`\0[:class:`MArrayElement`]
+ Represents the array.
+ __mob_arr_label : :class:`~manim.mobject.text.text_mobject.Text`
+ Represents the array label.
"""
__dir_map = [
@@ -588,22 +596,22 @@ class MArray(VGroup):
{"arr": RIGHT, "index": UP},
{"arr": LEFT, "index": UP},
]
- """Maps :class:`.m_enum.MArrayDirection` to correct :class:`MArrayElement` placement."""
+ """Maps :class:`~.m_enum.MArrayDirection` to :class:`np.ndarray`."""
def __sum_elem_len(self, index_start: int, index_end: int) -> int:
- """Sums the length of :class:`manim.Square` elements between the specified bound.
+ """Sums the side_length of all elements' square mobject present in the array between the specified range.
Parameters
----------
- index_start : :class:`int`
- Starting index of the bound (inclusive).
- index_end : :class:`int`
- Ending index of the bound (inclusive).
+ index_start
+ Starting index of the range (inclusive).
+ index_end
+ Ending index of the range (inclusive).
Returns
-------
:class:`int`
- Total length of the elements.
+ Sum of `side_length`\0s of all :class:`~manim.mobject.geometry.polygram.Square` present inside :attr:`__mob_arr` in the specified range.
"""
if (
@@ -620,14 +628,14 @@ def __sum_elem_len(self, index_start: int, index_end: int) -> int:
return total_len
def __calc_label_pos_and_mob(self) -> typing.Tuple[Square, np.ndarray]:
- """Calculates the position of the label relative to :class:`MArrayElement` 's :class:`manim.Square` and returns them.
+ """Calculates the position of the array label relative to one of the element's square mobjects.
Returns
-------
- :class:`Manim.Square`
- Represents the :class:`manim.Mobject` next to which the label is positioned.
+ :class:`~manim.mobject.geometry.polygram.Square`
+ Square mobject next to which the array label is positioned.
:class:`np.ndarray`
- Represents the relative label's position.
+ The relative position of the array label.
"""
# Label position is parallel to array growth direction
@@ -667,16 +675,16 @@ def __calc_label_pos_and_mob(self) -> typing.Tuple[Square, np.ndarray]:
)
def __calc_index(self, index: int) -> typing.Union[int, str]:
- """Calculates and returns the index based on attributes set at initialization.
+ """Calculates the displayable index of the specified element based on attributes set at initialization.
Parameters
----------
- index : :class:`int`
- Index of the :attr:`__arr` for which to compute the displayable index.
+ index
+ Specifies the index of the element for which to compute the displayable index.
Returns
-------
- Union[:class:`int`, :class:`str`]
+ :data:`~typing.Union`\0[:class:`int`, :class:`str`]
Displayable index.
"""
@@ -691,12 +699,12 @@ def __calc_index(self, index: int) -> typing.Union[int, str]:
)
def __calc_index_pos(self) -> np.ndarray:
- """Calculates and returns the index position based on attributes set at initialization.
+ """Calculates the index position of all elements based on attributes set at initialization.
Returns
-------
:class:`np.ndarray`
- Represents the index position.
+ Index position.
"""
return (
@@ -706,16 +714,16 @@ def __calc_index_pos(self) -> np.ndarray:
)
def __calc_label_shift_factor(self, mob: MArrayElement) -> float:
- """Calculates how much to shift the :attr:`__mob_arr_label` after insertion/removal of an :class:`MArrayElement`.
+ """Calculates how much to shift the array label after insertion/removal of an element.
Parameters
----------
- mob : :class:`MArrayElement`
- The element that has been inserted or removed.
+ mob
+ Specifies the element that is inserted/removed.
Returns
-------
- :class:`int`
+ :class:`float`
Factor by which to shift the :attr:`__mob_arr_label`.
"""
@@ -742,31 +750,31 @@ def __append_elem(
mob_value_args: dict = {},
mob_index_args: dict = {},
) -> typing.List[Animation]:
- """Creates a new :class:`MArrayElement` and appends it to :attr:`__mob_arr`.
+ """Creates and inserts a new element in the array.
Parameters
----------
value
- Value to append.
- shift_label: :class:`bool`, default: `True`
- Specifies whether to shift the :class:`__mob_arr_label` or not.
- append_anim : :class:`manim.Animation`, default: :class:`manim.Write`
- Specifies the :class:`manim.Animation` to be played on the :class:`MArrayElement` being appended.
- append_anim_args : :class:`dict`, default: `{}`
- Arguments for append :class:`manim.Animation`.
- append_anim_target : :class:`.m_enum.MArrayElementComp`, default: `None`
- Specifies the :class:`manim.Mobject` of the :class:`MArrayElement` on which the append :class:`manim.Animation` is to be played.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body of :class:`MArrayElement`.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value of :class:`MArrayElement`.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index of :class:`MArrayElement`.
+ Specifies the value of the new element.
+ shift_label
+ If `True`, shifts the :attr:`__mob_arr_label` to center of the array.
+ append_anim
+ Animation to be applied to the new element.
+ append_anim_args
+ Arguments for append :class:`~manim.animation.animation.Animation`.
+ append_anim_target
+ Specifies the target :class:`~manim.mobject.mobject.Mobject` of the :class:`MArrayElement` on which the append :class:`~manim.animation.animation.Animation` is to be played.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
Returns
-------
- List[:class:`manim.Animation`]
- List of animations for appending.
+ :data:`typing.List`\0[:class:`~manim.animation.animation.Animation`]
+ List of append animations.
"""
mob_value_args["text"] = value
@@ -811,31 +819,31 @@ def __remove_elem(
removal_anim_target: MArrayElementComp = None,
update_anim_target: MArrayElementComp = MArrayElementComp.INDEX,
) -> typing.Tuple[Succession, typing.Callable[[bool], typing.List[Animation]]]:
- """Removes the :class:`MArrayElement` from :attr:`__mob_arr` at the specified index.
+ """Removes the element from the array at the specified index.
Parameters
----------
- index : :class:`int`
- Index of :class:`MArrayElement` to remove.
- removal_anim : :class:`manim.Animation`, default: :class:`manim.FadeOut`
- Specifies the :class:`manim.Animation` to be played on the :class:`MArrayElement` being removed.
- update_anim : :class:`manim.Animation`, default: :class:`manim.Write`
- Specifies the :class:`manim.Animation` to be played on the :class:`MArrayElement`(s) after the removed element.
- removal_anim_args : :class:`dict`, default: `{}`
- Arguments for removal :class:`manim.Animation`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- removal_anim_target : :class:`.m_enum.MArrayElementComp`, default: `None`
- Specifies the :class:`manim.Mobject` of the :class:`MArrayElement` on which the removal :class:`manim.Animation` is to be played.
- update_anim_target : :class:`.m_enum.MArrayElementComp`, default: :attr:`.m_enum.MArrayElementComp.INDEX`
- Specifies the :class:`manim.Mobject` of the :class:`MArrayElement` on which the update :class:`manim.Animation` is to be played.
+ index
+ Specifies the index of the element to remove.
+ removal_anim
+ Animation to be applied to the element being removed.
+ update_anim
+ Animation to be applied on remaining elements.
+ removal_anim_args
+ Arguments for removal :class:`~manim.animation.animation.Animation`.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ removal_anim_target
+ Specifies the target :class:`~manim.mobject.mobject.Mobject` of the :class:`MArrayElement` on which the removal :class:`~manim.animation.animation.Animation` is to be played.
+ update_anim_target
+ Specifies the target :class:`~manim.mobject.mobject.Mobject` of the :class:`MArrayElement` on which the update :class:`~manim.animation.animation.Animation` is to be played.
Returns
-------
- :class:`manim.Succession`
- Contains :class:`manim.Animations` played for removal and shifting of :class:`MArrayElement`.
- Callable[[bool], List[:class:`manim.Animation`]]
- Method that updates the indices of :class:`MArrayElement`(s) that occur after the removal and returns a list of update :class:`manim.Animation`(s).
+ :class:`~manim.animation.composition.Succession`
+ Contains :class:`~manim.animation.animation.Animation` played for removal and shifting of element(s).
+ :data:`~typing.Callable`\0[[:class:`bool`], :class:`~typing.List`\0[:class:`~manim.animation.animation.Animation`]]
+ Method that updates the indices of element(s) after the removed element and returns a list of update :class:`~manim.animation.animation.Animation`\0(s).
"""
if index < 0 or index > len(self.__mob_arr):
@@ -930,26 +938,26 @@ def __init_props(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- arr : :class:`list`
- Array to represent. Elements must be convertible to :class:`str`.
- label : :class:`str`
- Specifies the label of the array.
- index_offset : :class:`int`
- Difference between successive indices.
- index_start : :class:`int`
- Starting value of index.
- index_hex_display : :class:`bool`
- Displays indices in hex if `True` otherwise in decimal.
- hide_index : :class:`bool`
- Specifies whether to display indices or not.
- arr_dir : :class:`.m_enum.MArrayDirection`
- Specifies the growing direction of array.
- arr_label_pos : :class:`.enum.MArrayDirection`
- Specifies the position of :attr:`__mob_arr_label`.
- arr_label_gap : :class:`float`
- Specifies the distance between :attr:`__mob_arr` and :attr:`__mob_arr_label`.
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to represent.
+ label
+ Specifies the value of the array label.
+ index_offset
+ Specifies the difference between successive displayable indices.
+ index_start
+ Specifies the starting value of displayable index.
+ index_hex_display
+ If `True`, displays indices in hex.
+ hide_index
+ If `True`, doesn't display indices.
+ arr_dir
+ Specifies the growth direction of the array.
+ arr_label_pos
+ Specifies the position of :attr:`__mob_arr_label` w.r.t :attr:`__mob_arr`.
+ arr_label_gap
+ Specifies the distance between :attr:`__mob_arr_label` and :attr:`__mob_arr`.
"""
self.__mob_arr_label_props: dict = {
@@ -978,8 +986,8 @@ def __update_props(
Parameters
----------
- mob_arr_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the array label.
+ mob_arr_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the array label.
"""
self.__mob_arr_label_props["text"] = self.__label
@@ -992,12 +1000,12 @@ def __init_mobs(
self,
init_arr_label: bool = False,
) -> None:
- """Initializes the :class:`Mobject`s for the class.
+ """Initializes the mobjects for the class.
Parameters
----------
- init_arr_label : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Text` and adds it to :attr:`__mob_arr_label`.
+ init_arr_label
+ If `True`, instantiates a :class:`~manim.mobject.text.text_mobject.Text` and assigns it to :attr:`__mob_arr_label`.
"""
if init_arr_label:
@@ -1050,34 +1058,34 @@ def __init__(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- arr : :class:`list`, default: `[]`
- Array to represent. Elements must be convertible to :class:`str`.
- label : :class:`str`, default: `''`
- Specifies the label of the array.
- index_offset : :class:`int`, default: `1`
- Difference between successive indices.
- index_start : :class:`int`, default: `0`
- Starting value of index.
- index_hex_display : :class:`bool`, default: `False`
- Displays indices in hex if `True` otherwise in decimal.
- hide_index : :class:`bool`, default: `False`
- Specifies whether to display indices or not.
- arr_dir : :class:`.m_enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.RIGHT`
- Specifies the growing direction of array.
- arr_label_pos : :class:`.enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.LEFT`
- Specifies the position of :attr:`__mob_arr_label`.
- arr_label_gap : :class:`float`, default: `0.5`
- Specifies the distance between :attr:`__mob_arr` and :attr:`__mob_arr_label`.
- mob_arr_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the label for :class:`MArray`.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body of :class:`MArrayElement`.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value of :class:`MArrayElement`.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index of :class:`MArrayElement`.
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to represent.
+ label
+ Specifies the value of the array label.
+ index_offset
+ Specifies the difference between successive displayable indices.
+ index_start
+ Specifies the starting value of displayable index.
+ index_hex_display
+ If `True`, displays indices in hex.
+ hide_index
+ If `True`, doesn't display indices.
+ arr_dir
+ Specifies the growth direction of the array.
+ arr_label_pos
+ Specifies the position of :attr:`__mob_arr_label` w.r.t :attr:`__mob_arr`.
+ arr_label_gap
+ Specifies the distance between :attr:`__mob_arr_label` and :attr:`__mob_arr`.
+ mob_arr_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the array label.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
**kwargs
Forwarded to constructor of the parent.
"""
@@ -1115,6 +1123,50 @@ def __init__(
# Initialize other mobjects (e.g. __arr_label)
self.__init_mobs(True)
+ def fetch_arr(self) -> list:
+ """Fetches the original array.
+
+ Returns
+ -------
+ :class:`list`
+ :attr:`__arr`.
+ """
+
+ return self.__arr
+
+ def fetch_mob_arr(self) -> typing.List[MArrayElement]:
+ """Fetches the mobject array.
+
+ Returns
+ -------
+ :class:`~typing.List`
+ :attr:`__mob_arr`.
+ """
+
+ return self.__mob_arr
+
+ def fetch_mob_arr_label(self) -> Text:
+ """Fetches the label mobject of the array.
+
+ Returns
+ -------
+ :class:`~manim.mobject.text.text_mobject.Text`
+ :attr:`__mob_arr_label`.
+ """
+
+ return self.__mob_arr_label
+
+ def fetch_arr_dir(self) -> MArrayDirection:
+ """Fetches the growth direction enum of the array.
+
+ Returns
+ -------
+ :class:`~.m_enum.MArrayDirection`
+ :attr:`__arr_dir`.
+ """
+
+ return self.__arr_dir
+
def update_elem_value(
self,
index: int,
@@ -1129,25 +1181,25 @@ def update_elem_value(
Parameters
----------
- index : :class:`int`
- Index of :attr:`__mob_arr` to update.
+ index
+ Specifies the index of element whose value to update.
value
- New value to be assigned.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value of :class:`MArrayElement`.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ New value to be assigned to the element.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ update_anim
+ Animation to be applied to the updated element.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element value.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated element's value mobject.
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1173,25 +1225,25 @@ def update_elem_index(
Parameters
----------
- index : :class:`int`
- Index of :attr:`__mob_arr` to update.
+ index
+ Specifies the index of element whose index to update.
value
- New value to be assigned.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index of :class:`MArrayElement`.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ New value to be assigned to the index of the element.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ update_anim
+ Animation to be applied to the updated element.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element index.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated element's index mobject.
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1211,25 +1263,27 @@ def update_mob_arr_label(
play_anim: bool = True,
play_anim_args: dict = {},
) -> Text:
- """Re-intializes the :class:`manim.Text` that represents the array label.
+ """Updates the array label.
Parameters
----------
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the array label.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ label
+ New value to be assigned to the array label.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the array label.
+ update_anim
+ Animation to be applied to the updated array label.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated array label.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__mob_arr_label`.
"""
self.__label = label
@@ -1255,17 +1309,17 @@ def update_mob_arr_label(
return self.__mob_arr_label
def animate_elem(self, index: int) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`MArrayElement.animate` property of :class:`MArrayElement` on specified index of :attr:`__mob_arr`.
+ """Invokes the animate property over element mobject specified.
Parameters
----------
- index : :class:`int`
- Index of :attr:`__mob_arr` to animate.
+ index
+ Specifies the index of the element to animate.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`MArrayElement.animate` property of :class:`MArrayElement`.
+ Animate property of :class:`MArrayElement`.
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1274,17 +1328,17 @@ def animate_elem(self, index: int) -> "_AnimationBuilder": # type: ignore
return self.__mob_arr[index].animate
def animate_elem_square(self, index: int) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Square.animate` property of :class:`manim.Square` on specified index of :attr:`__mob_arr`.
+ """Invokes the animate property over square mobject of the specified element.
Parameters
----------
- index : :class:`int`
- Index of :attr:`__mob_arr` to animate.
+ index
+ Specifies the index of the element who's square mobject to animate.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Square.animate` property of :class:`manim.Square`.
+ Animate property of :class:`~manim.mobject.geometry.polygram.Square`.
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1293,17 +1347,17 @@ def animate_elem_square(self, index: int) -> "_AnimationBuilder": # type: ignor
return self.__mob_arr[index].animate_mob_square()
def animate_elem_value(self, index: int) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Text.animate` property of :class:`manim.Text` on specified index of :attr:`__mob_arr`.
+ """Invokes the animate property over value mobject of the specified element.
Parameters
----------
- index : :class:`int`
- Index of :attr:`__mob_arr` to animate.
+ index
+ Specifies the index of the element who's value mobject animate.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Text.animate` property of :class:`manim.Text`.
+ Animate property of :class:`~manim.mobject.text.text_mobject.Text`.
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1312,17 +1366,17 @@ def animate_elem_value(self, index: int) -> "_AnimationBuilder": # type: ignore
return self.__mob_arr[index].animate_mob_value()
def animate_elem_index(self, index: int) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Text.animate` property of :class:`manim.Text` on specified index of :attr:`__mob_arr`.
+ """Invokes the animate property over index mobject of the specified element.
Parameters
----------
- index : :class:`int`
- Index of :attr:`__mob_arr` to animate.
+ index
+ Specifies the index of the element who's index mobject animate.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Text.animate` property of :class:`manim.Text`.
+ Animate property of :class:`~manim.mobject.text.text_mobject.Text`.
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1332,43 +1386,43 @@ def animate_elem_index(self, index: int) -> "_AnimationBuilder": # type: ignore
def append_elem(
self,
- value,
+ value: Any,
append_anim: Animation = Write,
append_anim_args: dict = {},
append_anim_target: MArrayElementComp = None,
- play_anim: bool = True,
- play_anim_args: dict = {},
mob_square_args: dict = {},
mob_value_args: dict = {},
mob_index_args: dict = {},
+ play_anim: bool = True,
+ play_anim_args: dict = {},
) -> typing.List[Animation]:
- """Appends the `value` to :attr:`__arr` and creates a new :class:`MArrayElement` and appends it to :attr:`__mob_arr`.
+ """Creates and inserts a new element in the array.
Parameters
----------
value
- Value to append.
- append_anim : :class:`manim.Animation`, default: :class:`manim.Write`
- Specifies the :class:`manim.Animation` to be played on the :class:`MArrayElement` being appended.
- append_anim_args : :class:`dict`, default: `{}`
- Arguments for append :class:`manim.Animation`.
- append_anim_target : :class:`.m_enum.MArrayElementComp`, default: `None`
- Specifies the :class:`manim.Mobject` of the :class:`MArrayElement` on which the append :class:`manim.Animation` is to be played.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body of :class:`MArrayElement`.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value of :class:`MArrayElement`.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index of :class:`MArrayElement`.
+ Specifies the value of the new element.
+ append_anim
+ Animation to be applied to the new element.
+ append_anim_args
+ Arguments for append :class:`~manim.animation.animation.Animation`.
+ append_anim_target
+ Specifies the target :class:`~manim.mobject.mobject.Mobject` of the :class:`MArrayElement` on which the append :class:`~manim.animation.animation.Animation` is to be played.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the element body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the element index.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- List[:class:`manim.Animation`]
- List of animations for appending.
+ :class:`typing.List`\0[:class:`~manim.animation.animation.Animation`]
+ List of append animations.
"""
self.__arr.append(value)
@@ -1390,7 +1444,7 @@ def append_elem(
def remove_elem(
self,
- index,
+ index: int,
removal_anim: Animation = FadeOut,
update_anim: Animation = Indicate,
removal_anim_args: dict = {},
@@ -1400,35 +1454,35 @@ def remove_elem(
play_anim: bool = True,
play_anim_args: dict = {},
) -> typing.Tuple[Succession, typing.Callable[[bool], typing.List[Animation]]]:
- """Removes the element from :attr:`__arr` and removes :class:`MArrayElement` from :attr:`__mob_arr` at the specified index.
+ """Removes the element from the array at the specified index.
Parameters
----------
- index : :class:`int`
- Index of :class:`MArrayElement` to remove.
- removal_anim : :class:`manim.Animation`, default: :class:`manim.FadeOut`
- Specifies the :class:`manim.Animation` to be played on the :class:`MArrayElement` being removed.
- update_anim : :class:`manim.Animation`, default: :class:`manim.Indicate`
- Specifies the :class:`manim.Animation` to be played on the :class:`MArrayElement`(s) after the removed element.
- removal_anim_args : :class:`dict`, default: `{}`
- Arguments for removal :class:`manim.Animation`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- removal_anim_target : :class:`.m_enum.MArrayElementComp`, default: `None`
- Specifies the :class:`manim.Mobject` of the :class:`MArrayElement` on which the removal :class:`manim.Animation` is to be played.
- update_anim_target : :class:`.m_enum.MArrayElementComp`, default: :attr:`.m_enum.MArrayElementComp.INDEX`
- Specifies the :class:`manim.Mobject` of the :class:`MArrayElement` on which the update :class:`manim.Animation` is to be played.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ index
+ Specifies the index of the element to remove.
+ removal_anim
+ Animation to be applied to the element being removed.
+ update_anim
+ Animation to be applied on remaining elements.
+ removal_anim_args
+ Arguments for removal :class:`~manim.animation.animation.Animation`.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ removal_anim_target
+ Specifies the target :class:`~manim.mobject.mobject.Mobject` of the :class:`MArrayElement` on which the removal :class:`~manim.animation.animation.Animation` is to be played.
+ update_anim_target
+ Specifies the target :class:`~manim.mobject.mobject.Mobject` of the :class:`MArrayElement` on which the update :class:`~manim.animation.animation.Animation` is to be played.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Succession`
- Contains :class:`manim.Animations` played for removal and shifting of :class:`MArrayElement`.
- Callable[[bool], List[:class:`manim.Animation`]]
- Method that updates the indices of :class:`MArrayElement`(s) that occur after the removal and returns a list of update :class:`manim.Animation`(s).
+ :class:`~manim.animation.composition.Succession`
+ Contains :class:`~manim.animation.animation.Animation` played for removal and shifting of element(s).
+ :data:`~typing.Callable`\0[[:class:`bool`], :class:`~typing.List`\0[:class:`~manim.animation.animation.Animation`]]
+ Method that updates the indices of element(s) after the removed element and returns a list of update :class:`~manim.animation.animation.Animation`\0(s).
"""
if index < 0 or index > len(self.__mob_arr):
@@ -1452,103 +1506,63 @@ def remove_elem(
return (remove_anim, update_indices)
- def fetch_arr(self) -> list:
- """Fetches :attr:`__arr`.
-
- Returns
- -------
- :class:`list`
- Represents the array stored in :attr:`__arr`.
- """
-
- return self.__arr
-
- def fetch_mob_arr(self) -> typing.List[MArrayElement]:
- """Fetches :attr:`__mob_arr`.
-
- Returns
- -------
- List[:class:`MArrayElement`]
- Represents the array stored in :attr:`__mob_arr`.
- """
-
- return self.__mob_arr
-
- def fetch_arr_label(self) -> Text:
- """Fetches the :class:`manim.Text` that represents the array label.
-
- Returns
- -------
- :class:`manim.Text`
- Represents the array label.
- """
-
- return self.__mob_arr_label
-
- def fetch_arr_dir(self) -> MArrayDirection:
- """Fetches the :class:`MArrayDirection` that represents the array's growth direction.
-
- Returns
- -------
- :class:`MArrayDirection`
- Represents the array's growth direction.
- """
-
- return self.__arr_dir
-
class MArrayPointer(VGroup):
"""A class that represents a pointer.
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- arr : typing.List[:class:`MArray`]
- Array to attach the pointer to.
- index : :class:`int`, default = `0`
- Index of the array to attach the pointer to.
- label : :class:`str`, default: `''`
- Specifies the label of the pointer.
- arrow_len : :class:`float`, default: `1`
- Specifies the length of the arrow.
- arrow_gap : :class:`float`, default: `0.25`
- Specifies the distance between the array and the arrow head.
- label_gap : :class:`float`, default: `0.25`
- Specifies the distance betweem the label and the arrow tail.
- pointer_pos : :class:`.m_enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.DOWN`
- Specifies the poistion of the pointer w.r.t the array.
- mob_arrow_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Arrow` that represents the arrow for :class:`MArrayPointer`.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the label for :class:`MArrayPointer`.
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to which the pointer is to be attached.
+ index
+ Specifies the index of the element to which the pointer is to be attached.
+ label
+ Specifies the value of the pointer label.
+ arrow_len
+ Specifies the length of :attr:`__mob_arrow`.
+ arrow_gap
+ Specifies the distance between :attr:`__mob_arrow` and :attr:`__arr`.
+ label_gap
+ Specifies the distance between :attr:`__mob_arrow` and :attr:`__mob_label`.
+ pointer_pos
+ Specifies the position of the pointer w.r.t to :attr:`__arr`.
+ mob_arrow_args
+ Arguments for :class:`~manim.mobject.geometry.line.Arrow` that represents the pointer arrow.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the pointer label.
**kwargs
Forwarded to constructor of the parent.
Attributes
----------
- __scene : :class:`manim.Scene`
- The scene where the object should exist.
- __arr : :class:`list`
- Array to attach the pointer to.
- __index : :class:`int`, default = `0`
- Index of the array to attach the pointer to.
- __label : :class:`str`, default: `''`
- Specifies the label of the pointer.
- __arrow_len : :class:`float`, default: `1`
- Specifies the length of the arrow.
- __arrow_gap : :class:`float`, default: `0.25`
- Specifies the distance between the array and the arrow head.
- __label_gap : :class:`float`, default: `0.25`
- Specifies the distance betweem the label and the arrow tail.
- __pointer_pos : :class:`.m_enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.DOWN`
- Specifies the poistion of the pointer w.r.t the array.
- __mob_arrow_props : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Arrow` that represents the arrow for :class:`MArrayPointer`.
- __mob_label_props : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the label for :class:`MArrayPointer`.
- __updater_pos : typing.Callable[[], None]
- Updater function to keep the pointer intact with the array.
+ __scene : :class:`~manim.scene.scene.Scene`
+ The scene where the object is to be rendered.
+ __arr : :class:`~typing.List`\0[:class:`MArrayElement`]
+ The array to which the pointer is attached to.
+ __index : :class:`int`
+ The index of the element to which the pointer is attached to.
+ __label : :class:`str`
+ The value of the pointer label.
+ __arrow_len : :class:`float`
+ The length of :attr:`__mob_arrow`.
+ __arrow_gap : :class:`float`
+ The distance between :attr:`__mob_arrow` and :attr:`__arr`.
+ __label_gap : :class:`float`
+ The distance between :attr:`__mob_arrow` and :attr:`__mob_label`.
+ __pointer_pos : :class:`.m_enum.MArrayDirection`
+ The position of the pointer w.r.t to :attr:`__arr`.
+ __mob_arrow_props : :class:`dict`
+ Arguments for :class:`~manim.mobject.geometry.line.Arrow` that represents the pointer arrow.
+ __mob_label_props : :class:`dict`
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the pointer label.
+ __mob_arrow : :class:`~manim.mobject.geometry.line.Arrow`
+ Represents the arrow of the element.
+ __mob_label : :class:`~manim.mobject.text.text_mobject.Text`
+ Represents the label of the element.
+ __updater_pos : :data:`typing.Callable`\0[[], None]
+ The updater function that keeps the pointer intact with the array.
"""
__dir_map = [
@@ -1557,14 +1571,15 @@ class MArrayPointer(VGroup):
{"np": RIGHT, "dir": MArrayDirection.RIGHT},
{"np": LEFT, "dir": MArrayDirection.LEFT},
]
+ """Maps :class:`~.m_enum.MArrayDirection` to :class:`np.ndarray`."""
def __calc_arrow_pos(self) -> np.ndarray:
- """Calculates direction vector for :class:`manim.Arrow`.
+ """Calculates direction vector for the arrow mobject.
Returns
-------
:class:`np.ndarray`
- Position vector for the arrow.
+ Position vector for :attr:`__mob_arrow`.
"""
arr_dir_np = self.__dir_map[self.__arr.fetch_arr_dir().value]["np"]
@@ -1582,7 +1597,7 @@ def __calc_arrow_pos(self) -> np.ndarray:
return arrow_pos_np
def __add_updater(self) -> None:
- """Attaches the position updater with the object."""
+ """Attaches the position updater function with the pointer."""
def updater_pos(mob: Mobject) -> None:
self.__init_pos()
@@ -1592,7 +1607,7 @@ def updater_pos(mob: Mobject) -> None:
self.add_updater(self.__updater_pos)
def __remove_updater(self) -> None:
- """Removes the attached updater from the object."""
+ """Removes the attached position updater function from the pointer."""
self.remove_updater(self.__updater_pos)
@@ -1601,8 +1616,8 @@ def __calc_shift_np(self, new_index: int) -> np.ndarray:
Parameters
----------
- :class:`int`
- New index towards which the pointer should point to.
+ new_index
+ Specifies the prospective index of element to which the pointer is to be attached.
Returns
-------
@@ -1645,22 +1660,22 @@ def __init_props(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- arr : :class:`MArray`
- Array to attach the pointer to.
- index : :class:`int`
- Index of the array to which the pointer is attached.
- label : :class:`str`
- Specifies the label of the pointer.
- arrow_len : :class:`.enum.MArrayDirection`
- Specifies the length of :class:`manim.Arrow`.
- arrow_pos_gap : :class:`float`
- Specifies the distance between :attr:`__mob_arr` and :attr:`__mob_arrow`.
- label_gap : :class:`float`
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to which the pointer is to be attached.
+ index
+ Specifies the index of the element to which the pointer is to be attached.
+ label
+ Specifies the value of the pointer label.
+ arrow_len
+ Specifies the length of :attr:`__mob_arrow`.
+ arrow_gap
+ Specifies the distance between :attr:`__mob_arrow` and :attr:`__arr`.
+ label_gap
Specifies the distance between :attr:`__mob_arrow` and :attr:`__mob_label`.
- pointer_pos : :class:`MArrayDirection`
- Specifies the position of the pointer.
+ pointer_pos
+ Specifies the position of the pointer w.r.t to :attr:`__arr`.
"""
self.__mob_arrow_props: dict = {"color": GOLD_D}
@@ -1676,15 +1691,17 @@ def __init_props(
self.__label_gap: float = label_gap
self.__pointer_pos: MArrayDirection = pointer_pos
- def __update_props(self, mob_arrow_args: dict = {}, mob_label_args: dict = {}):
+ def __update_props(
+ self, mob_arrow_args: dict = {}, mob_label_args: dict = {}
+ ) -> None:
"""Updates the attributes of the class.
Parameters
----------
- mob_arrow_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Arrow` that represents the pointer arrow.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the pointer label.
+ mob_arrow_args
+ Arguments for :class:`~manim.mobject.geometry.line.Arrow` that represents the pointer arrow.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the pointer label.
"""
self.__mob_arrow_props.update(mob_arrow_args)
@@ -1694,15 +1711,15 @@ def __update_props(self, mob_arrow_args: dict = {}, mob_label_args: dict = {}):
if type(self.__mob_label_props["text"]) != str:
self.__mob_label_props["text"] = str(self.__mob_label_props["text"])
- def __init_mobs(self, init_arrow: bool = False, init_label: bool = False):
- """Initializes the :class:`Mobject`s for the class.
+ def __init_mobs(self, init_arrow: bool = False, init_label: bool = False) -> None:
+ """Initializes the mobjects for the class.
Parameters
----------
- init_arrow : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Arrow` and adds it to :attr:`__mob_arrpw`.
- init_label : :class:`bool`, default: `False`
- Instantiates a :class:`manim.Text` and adds it to :attr:`__mob_label`.
+ init_arrow
+ If `True`, instantiates a :class:`~manim.mobject.geometry.line.Arrow` and assigns it to :attr:`__mob_arrow`.
+ init_label
+ If `True`, instantiates a :class:`~manim.mobject.text.text_mobject.Text` and assigns it to :attr:`__mob_label`.
"""
if init_arrow:
@@ -1769,26 +1786,26 @@ def __init__(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
- arr : typing.List[:class:`MArray`]
- Array to attach the pointer to.
- index : :class:`int`, default = `0`
- Index of the array to attach the pointer to.
- label : :class:`str`, default: `''`
- Specifies the label of the pointer.
- arrow_len : :class:`float`, default: `1`
- Specifies the length of the arrow.
- arrow_gap : :class:`float`, default: `0.25`
- Specifies the distance between the array and the arrow head.
- label_gap : :class:`float`, default: `0.25`
- Specifies the distance betweem the label and the arrow tail.
- pointer_pos : :class:`.m_enum.MArrayDirection`, default: :attr:`.m_enum.MArrayDirection.DOWN`
- Specifies the poistion of the pointer w.r.t the array.
- mob_arrow_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Arrow` that represents the arrow for :class:`MArrayPointer`.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the label for :class:`MArrayPointer`.
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to which the pointer is to be attached.
+ index
+ Specifies the index of the element to which the pointer is to be attached.
+ label
+ Specifies the value of the pointer label.
+ arrow_len
+ Specifies the length of :attr:`__mob_arrow`.
+ arrow_gap
+ Specifies the distance between :attr:`__mob_arrow` and :attr:`__arr`.
+ label_gap
+ Specifies the distance between :attr:`__mob_arrow` and :attr:`__mob_label`.
+ pointer_pos
+ Specifies the position of the pointer w.r.t to :attr:`__arr`.
+ mob_arrow_args
+ Arguments for :class:`~manim.mobject.geometry.line.Arrow` that represents the pointer arrow.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the pointer label.
**kwargs
Forwarded to constructor of the parent.
"""
@@ -1809,6 +1826,115 @@ def __init__(
# Add updater
self.__add_updater()
+ def fetch_mob_arrow(self) -> Arrow:
+ """Fetches the arrow mobject of the pointer.
+
+ Returns
+ -------
+ :class:`~manim.mobject.geometry.line.Arrow`
+ :attr:`__mob_arrow`.
+ """
+
+ return self.__mob_arrow
+
+ def fetch_mob_label(self) -> Text:
+ """Fetches the label mobject of the pointer.
+
+ Returns
+ -------
+ :class:`~manim.mobject.text.text_mobject.Text`
+ :attr:`__mob_label`.
+ """
+
+ return self.__mob_label
+
+ def fetch_index(self) -> int:
+ """Fetches the index that the pointer is attached to.
+
+ Returns
+ -------
+ :class:`int`
+ :attr:`__index`.
+ """
+
+ return self.__index
+
+ def update_mob_label(
+ self,
+ label: str,
+ mob_label_args: dict = {},
+ update_anim: Animation = Write,
+ update_anim_args: dict = {},
+ play_anim: bool = True,
+ play_anim_args: dict = {},
+ ) -> Text:
+ """Updates the pointer label.
+
+ Parameters
+ ----------
+ label
+ New value to be assigned to the pointer label.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the pointer label.
+ update_anim
+ Animation to be applied to the updated pointer label.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
+
+ Returns
+ -------
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__mob_label`.
+ """
+
+ self.__label = label
+
+ # Update props of mob_label
+ self.__update_props(mob_label_args=mob_label_args)
+
+ # Remove current mob_label
+ self.remove(self.__mob_label)
+
+ # Initialize new mob_label
+ self.__init_mobs(init_label=True)
+
+ # Add new mob_label to group
+ self.add(self.__mob_label)
+
+ # Animate change
+ if play_anim:
+ self.__scene.play(
+ update_anim(self.__mob_label, **update_anim_args), **play_anim_args
+ )
+
+ return self.__mob_label
+
+ def animate_mob_arrow(self) -> "_AnimationBuilder": # type: ignore
+ """Invokes the animate property over arrow mobject.
+
+ Returns
+ -------
+ :class:`_AnimationBuilder`
+ Animate property of :attr:`__mob_arrow`.
+ """
+
+ return self.__mob_arrow.animate
+
+ def animate_mob_label(self) -> "_AnimationBuilder": # type: ignore
+ """Invokes the animate property over label mobject.
+
+ Returns
+ -------
+ :class:`_AnimationBuilder`
+ Animate property of :attr:`__mob_label`.
+ """
+
+ return self.__mob_label.animate
+
def shift_to_elem(
self, index: int, play_anim: bool = True, play_anim_args: dict = {}
) -> ApplyMethod:
@@ -1816,17 +1942,17 @@ def shift_to_elem(
Parameters
----------
- index : :class:`int`
- Index of the array to shift the pointer to.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ index
+ Specifies the index of the element to which the pointer is to be shifted.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.ApplyMethod`
- Represents the shifting animation.
+ :class:`~manim.animation.transform.ApplyMethod`
+ Shift animation.
"""
if index < 0 or index > len(self.__arr.fetch_mob_arr()):
@@ -1847,8 +1973,8 @@ def attach_to_elem(self, index: int) -> None:
Parameters
----------
- index : :class:`int`
- Index of the array to shift the pointer to.
+ index
+ Specifies the index of the element to which the pointer is to be attached.
"""
if index < 0 or index > len(self.__arr.fetch_mob_arr()):
@@ -1857,38 +1983,368 @@ def attach_to_elem(self, index: int) -> None:
self.__index = index
self.__init_pos()
- def fetch_mob_arrow(self) -> Arrow:
- """Fetches :attr:`__mob_arrow`.
+
+class MArraySlidingWindow(VGroup):
+ """A class that represents a sliding window
+
+ Parameters
+ ----------
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to which the sliding window is to be attached.
+ index
+ Specifies the index of the element to which the sliding window is to be attached.
+ size
+ Specifies the number of elements the sliding window should enclose.
+ label
+ Specifies the value of the sliding window label.
+ label_gap
+ Specifies the distance between :attr:`__mob_label` and :attr:`__mob_window`.
+ label_pos
+ Specifies the position of the pointer w.r.t to :attr:`__mob_window`.
+ mob_window_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Rectangle` that represents the window.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the window label.
+ **kwargs
+ Forwarded to constructor of the parent.
+
+ Attributes
+ ----------
+ __scene : :class:`~manim.scene.scene.Scene`
+ The scene where the object is to be rendered.
+ __arr : :class:`~typing.List`\0[:class:`MArrayElement`]
+ The array to which the sliding window is to be attached.
+ __index : :class:`int`
+ The index of the element to which the sliding window is to be attached.
+ __size : :class:`int`
+ The number of elements the sliding window should enclose.
+ __label : :class:`str`
+ The value of the sliding window label.
+ __label_gap : :class:`float`
+ The distance between :attr:`__mob_label` and :attr:`__mob_window`.
+ __label_pos : :class:`.m_enum.MArrayDirection`
+ The position of the pointer w.r.t to :attr:`__mob_window`.
+ __mob_window_props : :class:`dict`
+ Arguments for :class:`~manim.mobject.geometry.polygram.Rectangle` that represents the window.
+ __mob_label_props : :class:`dict`
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the window label.
+ __mob_window : :class:`~manim.mobject.geometry.polygram.Rectangle`
+ Represents the window of the sliding window.
+ __mob_label : :class:`~manim.mobject.text.text_mobject.Text`
+ Represents the label of the sliding window.
+ __updater_pos : :data:`typing.Callable`\0[[], None]
+ The updater function that keeps the sliding window intact with the array.
+ """
+
+ __dir_map = [
+ {"np": UP, "dir": MArrayDirection.UP},
+ {"np": DOWN, "dir": MArrayDirection.DOWN},
+ {"np": RIGHT, "dir": MArrayDirection.RIGHT},
+ {"np": LEFT, "dir": MArrayDirection.LEFT},
+ ]
+ """Maps :class:`~.m_enum.MArrayDirection` to :class:`np.ndarray`."""
+
+ def __calc_window_dim(self) -> typing.Tuple[float, float]:
+ """Calculates dimensions of window mobject.
Returns
-------
- :class:`manim.Arrow`
- Represents the arrow stored in :attr:`__mob_arrow`.
+ :class:`float`
+ Height of :attr:`__mob_window`.
+ :class:`float`
+ Width of :attr:`__mob_window`.
"""
- return self.__mob_arrow
+ height = self.__arr.fetch_mob_arr()[self.__index].fetch_mob_square().side_length
+ width = self.__arr._MArray__sum_elem_len(
+ self.__index, self.__index + self.__size - 1
+ )
- def fetch_mob_label(self) -> Text:
- """Fetches the :class:`manim.Text` that represents the pointer label.
+ if self.__arr.fetch_arr_dir() in (MArrayDirection.UP, MArrayDirection.DOWN):
+ height, width = width, height
+
+ return (height, width)
+
+ def __calc_window_pos_np(self) -> typing.Tuple[np.ndarray, np.ndarray]:
+ """Calculates position vector and align vector for the window mobject.
Returns
-------
- :class:`manim.Text`
- Represents the pointer label.
+ :class:`np.ndarray`
+ Position vector for :attr:`__mob_window`
+ :class:`np.ndarray`
+ Align vector for :attr:`__mob_window`
"""
- return self.__mob_label
+ point_np = (
+ self.__arr.fetch_mob_arr()[self.__index].fetch_mob_square().get_left()
+ )
+ align_np = LEFT
- def fetch_index(self) -> int:
- """Fetches the index that the pointer is attached to.
+ arr_dir = self.__arr.fetch_arr_dir()
+ if arr_dir == MArrayDirection.LEFT:
+ point_np = (
+ self.__arr.fetch_mob_arr()[self.__index].fetch_mob_square().get_right()
+ )
+ align_np = RIGHT
+ elif arr_dir == MArrayDirection.UP:
+ point_np = (
+ self.__arr.fetch_mob_arr()[self.__index].fetch_mob_square().get_bottom()
+ )
+ align_np = DOWN
+ elif arr_dir == MArrayDirection.DOWN:
+ point_np = (
+ self.__arr.fetch_mob_arr()[self.__index].fetch_mob_square().get_top()
+ )
+ align_np = UP
+
+ return (point_np, align_np)
+
+ def __calc_label_pos_np(self) -> np.ndarray:
+ """Calculates position vector for the label mobject.
Returns
-------
- :class:`int`
- Represents the index that the pointer is attached to.
+ :class:`np.ndarray`
+ Position vector for :attr:`__mob_label`
"""
- return self.__index
+ arr_dir = self.__arr.fetch_arr_dir()
+ # Label position is parallel to array growth direction
+ if np.array_equal(
+ self.__dir_map[self.__label_pos.value]["np"],
+ self.__dir_map[arr_dir.value]["np"],
+ ) or np.array_equal(
+ self.__dir_map[self.__label_pos.value]["np"],
+ -self.__dir_map[arr_dir.value]["np"],
+ ):
+ return self.__dir_map[(self.__label_pos.value + 2) % len(self.__dir_map)][
+ "np"
+ ]
+
+ # Label position is perpendicular to array growth direction
+ else:
+ return self.__dir_map[self.__label_pos.value]["np"]
+
+ def __pos_mobs(self, pos_window: bool = False, pos_label: bool = False) -> None:
+ """Positions mobjects of the class.
+
+ Parameters
+ ----------
+ pos_window
+ If `True`, correctly positions :attr:`__mob_window`.
+ pos_label
+ If `True`, correctly positions :attr:`__mob_label`.
+ """
+
+ if pos_window:
+ point_np, align_np = self.__calc_window_pos_np()
+ self.__mob_window.move_to(point_np, align_np)
+
+ if pos_label:
+ self.__mob_label.next_to(
+ self.__mob_window,
+ self.__calc_label_pos_np(),
+ self.__label_gap,
+ )
+
+ def __add_updater(self) -> None:
+ """Attaches the position updater function with the pointer."""
+
+ def updater_pos(mob: Mobject) -> None:
+ self.__init_pos()
+
+ self.__updater_pos = updater_pos
+
+ self.add_updater(self.__updater_pos)
+
+ def __remove_updater(self) -> None:
+ """Removes the attached position updater function from the pointer."""
+
+ self.remove_updater(self.__updater_pos)
+
+ def __init_props(
+ self,
+ scene: Scene,
+ arr: MArray,
+ index: int,
+ size: int,
+ label: str,
+ label_gap: float,
+ label_pos: MArrayDirection,
+ ) -> None:
+ """Initializes the attributes for the class.
+
+ Parameters
+ ----------
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to which the sliding window is to be attached.
+ index
+ Specifies the index of the element to which the sliding window is to be attached.
+ size
+ Specifies the number of elements the sliding window should enclose.
+ label
+ Specifies the value of the sliding window label.
+ label_gap
+ Specifies the distance between :attr:`__mob_label` and :attr:`__mob_window`.
+ label_pos
+ Specifies the position of the pointer w.r.t to :attr:`__mob_window`.
+ """
+
+ self.__mob_window_props: dict = {"color": RED_D, "stroke_width": 10}
+ self.__mob_label_props: dict = {"text": label, "color": RED_A, "font_size": 38}
+ self.__scene: Scene = scene
+ self.__arr: MArray = arr
+ if index >= len(self.__arr.fetch_mob_arr()) or index < 0:
+ raise Exception("Index out of bounds!")
+ self.__index: int = index
+ if size < 1 or index + size > len(self.__arr.fetch_mob_arr()):
+ raise Exception("Invalid window size!")
+ self.__size: int = size
+ self.__label: str = label
+ self.__label_gap: float = label_gap
+ self.__label_pos: MArrayDirection = label_pos
+
+ def __update_props(
+ self, mob_window_args: dict = {}, mob_label_args: dict = {}
+ ) -> None:
+ """Updates the attributes of the class.
+
+ Parameters
+ ----------
+ mob_window_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Rectangle` that represents the window.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the window label.
+ """
+
+ self.__mob_window_props.update(mob_window_args)
+ self.__mob_label_props["text"] = self.__label
+ self.__mob_label_props.update(mob_label_args)
+
+ if type(self.__mob_label_props["text"]) != str:
+ self.__mob_label_props["text"] = str(self.__mob_label_props["text"])
+
+ def __init_mobs(self, init_window: bool = False, init_label: bool = False) -> None:
+ """Initializes the mobjects for the class.
+
+ Parameters
+ ----------
+ init_arrow
+ If `True`, instantiates a :class:`~manim.mobject.geometry.polygram.Rectangle` and assigns it to :attr:`__mob_window`.
+ init_label
+ If `True`, instantiates a :class:`~manim.mobject.text.text_mobject.Text` and assigns it to :attr:`__mob_label`.
+ """
+
+ if init_window:
+ height, width = self.__calc_window_dim()
+ self.__mob_window = Rectangle(
+ height=height, width=width, **self.__mob_window_props
+ )
+ self.__pos_mobs(pos_window=True)
+ self.add(self.__mob_window)
+
+ if init_label:
+ self.__mob_label = Text(**self.__mob_label_props)
+ self.__pos_mobs(pos_label=True)
+ self.add(self.__mob_label)
+
+ def __init_pos(self) -> None:
+ """Initializes the position of the object"""
+
+ self.__pos_mobs(True, True)
+
+ def __deepcopy__(self, memo):
+ """Deepcopy that excludes attributes specified in `exclude_list`."""
+
+ exclude_list = ["_MArraySlidingWindow__scene", "_MArraySlidingWindow__arr"]
+
+ cls = self.__class__
+ result = cls.__new__(cls)
+ memo[id(self)] = result
+ for k, v in self.__dict__.items():
+ if k not in exclude_list:
+ setattr(result, k, deepcopy(v, memo))
+ return result
+
+ def __init__(
+ self,
+ scene: Scene,
+ arr: MArray,
+ index: int = 0,
+ size: int = 1,
+ label: str = "",
+ label_gap: float = 0.5,
+ label_pos: MArrayDirection = MArrayDirection.DOWN,
+ mob_window_args: dict = {},
+ mob_label_args: dict = {},
+ **kwargs
+ ) -> None:
+ """Initializes the class.
+
+ Parameters
+ ----------
+ scene
+ Specifies the scene where the object is to be rendered.
+ arr
+ Specifies the array to which the sliding window is to be attached.
+ index
+ Specifies the index of the element to which the sliding window is to be attached.
+ size
+ Specifies the number of elements the sliding window should enclose.
+ label
+ Specifies the value of the sliding window label.
+ label_gap
+ Specifies the distance between :attr:`__mob_label` and :attr:`__mob_window`.
+ label_pos
+ Specifies the position of the pointer w.r.t to :attr:`__mob_window`.
+ mob_window_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Rectangle` that represents the window.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the window label.
+ **kwargs
+ Forwarded to constructor of the parent.
+ """
+
+ super().__init__(**kwargs)
+
+ # Initialize props
+ self.__init_props(scene, arr, index, size, label, label_gap, label_pos)
+
+ # Update props
+ self.__update_props(mob_window_args, mob_label_args)
+
+ # Initialize mobjects
+ self.__init_mobs(True, True)
+
+ # Add updater
+ self.__add_updater()
+
+ def fetch_mob_window(self) -> Rectangle:
+ """Fetches the window mobject of the sliding window.
+
+ Returns
+ -------
+ :class:`~manim.mobject.geometry.polygram.Rectangle`
+ :attr:`__mob_window`.
+ """
+
+ return self.__mob_window
+
+ def fetch_mob_label(self) -> Text:
+ """Fetches the label mobject of the sliding window.
+
+ Returns
+ -------
+ :class:`~manim.mobject.text.text_mobject.Text`
+ :attr:`__mob_label`.
+ """
+
+ return self.__mob_label
def update_mob_label(
self,
@@ -1899,25 +2355,27 @@ def update_mob_label(
play_anim: bool = True,
play_anim_args: dict = {},
) -> Text:
- """Re-intializes the :class:`manim.Text` that represents the pointer label.
+ """Updates the window label.
Parameters
----------
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the pointer label.
- update_anim : :class:`manim.Animation`, default `manim.Write`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
- play_anim_args : :class:`dict, default: `{}`
- Arguments for :meth:`manim.Scene.play`.
+ label
+ New value to be assigned to the window label.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the window label.
+ update_anim
+ Animation to be applied to the updated window label.
+ update_anim_args
+ Arguments for update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated pointer label.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__mob_label`.
"""
self.__label = label
@@ -1942,24 +2400,128 @@ def update_mob_label(
return self.__mob_label
- def animate_mob_arrow(self) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Arrow.animate` property of :class:`manim.Arrow` for the pointer arrow.
+ def animate_mob_window(self) -> "_AnimationBuilder": # type: ignore
+ """Invokes the animate property over window mobject.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Arrow.animate` property of :class:`manim.Arrow`.
+ Animate property of :attr:`__mob_window`.
"""
- return self.__mob_arrow.animate
+ return self.__mob_window.animate
def animate_mob_label(self) -> "_AnimationBuilder": # type: ignore
- """Invokes the :meth:`manim.Text.animate` property of :class:`manim.Text` for the pointer label.
+ """Invokes the animate property over label mobject.
Returns
-------
:class:`_AnimationBuilder`
- Value returned by :meth:`manim.Text.animate` property of :class:`manim.Text`.
+ Animate property of :attr:`__mob_label`.
"""
return self.__mob_label.animate
+
+ def shift_to_elem(
+ self, index: int, play_anim: bool = True, play_anim_args: dict = {}
+ ) -> ApplyFunction:
+ """Shifts sliding window to the specified element.
+
+ Parameters
+ ----------
+ index
+ Specifies the index of the element to which the sliding window is to be shifted.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
+
+ Returns
+ -------
+ :class:`~manim.animation.transform.ApplyFunction`
+ Shift animation.
+ """
+
+ if index >= len(self.__arr.fetch_mob_arr()) or index < 0:
+ raise Exception("Index out of bounds!")
+
+ if self.__size < 1 or index + self.__size > len(self.__arr.fetch_mob_arr()):
+ raise Exception("Invalid window size!")
+
+ self.__index = index
+ return self.resize_window(self.__size, play_anim, play_anim_args)
+
+ def attach_to_elem(self, index: int) -> None:
+ """Attaches pointer to the specified element.
+
+ Parameters
+ ----------
+ index
+ Specifies the index of the element to which the sliding window is to be attached.
+ """
+
+ if index >= len(self.__arr.fetch_mob_arr()) or index < 0:
+ raise Exception("Index out of bounds!")
+
+ if self.__size < 1 or index + self.__size > len(self.__arr.fetch_mob_arr()):
+ raise Exception("Invalid window size!")
+
+ self.__index = index
+ self.__init_pos()
+
+ def resize_window(
+ self, size: int, play_anim: bool = True, play_anim_args: dict = {}
+ ) -> ApplyFunction:
+ """Expands or shrinks the window according to the specified size.
+
+ Parameters
+ ----------
+ size
+ Specifies the number of elements the sliding window should enclose.
+ play_anim
+ If `True`, plays the animation(s).
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
+
+ Returns
+ -------
+ :class:`~manim.animation.transform.ApplyFunction`
+ Resize animation.
+ """
+
+ if size < 1 or self.__index + size > len(self.__arr.fetch_mob_arr()):
+ raise Exception("Invalid window size!")
+
+ self.__size = size
+
+ # Variables for resize_and_shift method
+ arr_dir = self.__arr.fetch_arr_dir()
+ height, width = self.__calc_window_dim()
+ window_pos_np, window_align_np = self.__calc_window_pos_np()
+ label_pos_np = self.__calc_label_pos_np()
+
+ def resize_and_shift(mob: MArraySlidingWindow) -> MArraySlidingWindow:
+ """Resizes and shifts the sliding window
+
+ Returns
+ -------
+ :class:`MArraySlidingWindow`
+ Represents the modified mobject.
+ """
+
+ if arr_dir in (MArrayDirection.UP, MArrayDirection.DOWN):
+ mob.__mob_window.stretch_to_fit_height(height)
+ else:
+ mob.__mob_window.stretch_to_fit_width(width)
+ mob.__mob_window.move_to(window_pos_np, window_align_np)
+ mob.__mob_label.next_to(mob.__mob_window, label_pos_np, mob.__label_gap)
+ return mob
+
+ resize_anim = ApplyFunction(
+ resize_and_shift, self, suspend_mobject_updating=True
+ )
+
+ if play_anim:
+ self.__scene.play(resize_anim, **play_anim_args)
+
+ return resize_anim
diff --git a/src/manim_data_structures/m_enum.py b/src/manim_data_structures/m_enum.py
index d4b1015..2f99cf4 100644
--- a/src/manim_data_structures/m_enum.py
+++ b/src/manim_data_structures/m_enum.py
@@ -4,23 +4,23 @@
class MArrayElementComp(Enum):
- """Refers to the individual component :class:`manim.Mobject` of :class:`MArrayElement`."""
+ """Refers to individual component :class:`~manim.mobject.mobject.Mobject`\0s of :class:`~.m_array.MArrayElement`."""
BODY = 0
- """Body :class:`manim.Square`"""
+ """:class:`~manim.mobject.geometry.polygram.Square` that represents the body."""
VALUE = 1
- """Value :class:`manim.Text`"""
+ """:class:`~manim.mobject.text.text_mobject.Text` that represents the value."""
INDEX = 2
- """Index :class:`manim.Text`"""
+ """:class:`~manim.mobject.text.text_mobject.Text` that represents the index."""
LABEL = 3
- """Label :class:`manim.Text`"""
+ """:class:`~manim.mobject.text.text_mobject.Text` that represents the label."""
class MArrayDirection(Enum):
- """Specifies the growth direction of the :class:`MArray`."""
+ """Serves as the direction for :class:`~.m_array.MArray`."""
UP = 0
"""Upward direction."""
diff --git a/src/manim_data_structures/m_variable.py b/src/manim_data_structures/m_variable.py
index c151ffb..b3152b5 100644
--- a/src/manim_data_structures/m_variable.py
+++ b/src/manim_data_structures/m_variable.py
@@ -10,39 +10,41 @@ class MVariable(MArrayElement):
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
+ scene
+ Specifies the scene where the object is to be rendered.
value
Specifies the value of the variable.
index
Specifies the index of the variable.
label
Specifies the label of the variable.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element label.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the variable body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable index.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable label.
+ **kwargs
+ Forwarded to constructor of the parent.
Attributes
----------
- __value
- Specifies the value of the variable.
- __index
- Specifies the index of the variable.
- __label
- Specifies the label of the variable.
+ __value : Any
+ The value of the variable.
+ __index : :data:`~typing.Union`\0[:class:`str`, :class:`int`]
+ The value of the index.
+ __label : :class:`str`
+ The value of the label.
"""
def __init__(
self,
scene: Scene,
- value="",
- index="",
- label="",
+ value: Any = "",
+ index: typing.Union[str, int] = "",
+ label: str = "",
mob_square_args: dict = {},
mob_value_args: dict = {},
mob_index_args: dict = {},
@@ -53,27 +55,29 @@ def __init__(
Parameters
----------
- scene : :class:`manim.Scene`
- The scene where the object should exist.
+ scene
+ Specifies the scene where the object is to be rendered.
value
Specifies the value of the variable.
index
Specifies the index of the variable.
label
Specifies the label of the variable.
- mob_square_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Square` that represents the element body.
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element label.
+ mob_square_args
+ Arguments for :class:`~manim.mobject.geometry.polygram.Square` that represents the variable body.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable value.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable index.
+ mob_label_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable label.
+ **kwargs
+ Forwarded to constructor of the parent.
"""
- self.__value = value
- self.__index = index
- self.__label = label
+ self.__value: Any = value
+ self.__index: typing.Union[str, int] = index
+ self.__label: str = label
mob_value_args["text"] = value
mob_index_args["text"] = index
@@ -88,134 +92,149 @@ def __init__(
**kwargs
)
- def fetch_value(self):
- """Fetches :attr:`__value`.
+ def fetch_value(self) -> Any:
+ """Fetches the value of the variable.
Returns
-------
Any
- Value of :class:`MVariable`.
+ :attr:`__value`.
"""
return self.__value
- def fetch_index(self):
- """Fetches :attr:`__index`.
+ def fetch_index(self) -> typing.Union[str, int]:
+ """Fetches the index of the variable.
Returns
-------
- Any
- Index of :class:`MVariable`.
+ :data:`~typing.Union`\0[:class:`str`, :class:`int`]
+ :attr:`__index`.
"""
return self.__index
- def fetch_label(self):
- """Fetches :attr:`__label`.
+ def fetch_label(self) -> str:
+ """Fetches the label of the variable.
Returns
-------
- Any
- Label of :class:`MVariable`.
+ :class:`str`
+ :attr:`__label`.
"""
return self.__label
def update_value(
self,
- value,
+ value: Any,
mob_value_args: dict = {},
update_anim: Animation = Indicate,
update_anim_args: dict = {},
play_anim: bool = True,
+ play_anim_args: dict = {},
) -> Text:
- """Updates :attr:`__value` and the :class:`manim.Text` that represents the element value.
+ """Updates the value of the variable.
Parameters
----------
- mob_value_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element value.
- update_anim : :class:`manim.Animation`, default `{manim.Indicate}`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
+ value
+ New value to be assigned to the variable.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable value.
+ update_anim
+ Animation to be applied to the updated :class:`~manim.mobject.text.text_mobject.Text`.
+ update_anim_args
+ Arguments for the update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ Specifies whether to play the :class:`~manim.animation.animation.Animation`.
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element value.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__value`.
"""
self.__value = value
mob_value_args["text"] = value
return self.update_mob_value(
- mob_value_args, update_anim, update_anim_args, play_anim
+ mob_value_args, update_anim, update_anim_args, play_anim, play_anim_args
)
def update_index(
self,
- index,
+ index: typing.Union[str, int],
mob_index_args: dict = {},
update_anim: Animation = Indicate,
update_anim_args: dict = {},
play_anim: bool = True,
+ play_anim_args: dict = {},
) -> Text:
- """Updates :attr:`__index` and the :class:`manim.Text` that represents the element index.
+ """Updates the index of the variable.
Parameters
----------
- mob_index_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element index.
- update_anim : :class:`manim.Animation`, default `{manim.Indicate}`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
+ index
+ New index to be assigned to the variable.
+ mob_index_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the variable index.
+ update_anim
+ Animation to be applied to the updated :class:`~manim.mobject.text.text_mobject.Text`.
+ update_anim_args
+ Arguments for the update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ Specifies whether to play the :class:`~manim.animation.animation.Animation`.
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element index.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__index`.
"""
self.__index = index
mob_index_args["text"] = index
return self.update_mob_index(
- mob_index_args, update_anim, update_anim_args, play_anim
+ mob_index_args, update_anim, update_anim_args, play_anim, play_anim_args
)
def update_label(
self,
- label,
+ label: str,
mob_label_args: dict = {},
update_anim: Animation = Indicate,
update_anim_args: dict = {},
play_anim: bool = True,
+ play_anim_args: dict = {},
) -> Text:
- """Updates :attr:`__label` and the :class:`manim.Text` that represents the element label.
+ """Updates the label of the variable.
Parameters
----------
- mob_label_args : :class:`dict`, default: `{}`
- Arguments for :class:`manim.Text` that represents the element label.
- update_anim : :class:`manim.Animation`, default `{manim.Indicate}`
- Animation to be applied to the updated :class:`manim.Text`.
- update_anim_args : :class:`dict`, default: `{}`
- Arguments for update :class:`manim.Animation`.
- play_anim : :class:`bool`, default: `True`
- Specifies whether to play the update :class:`manim.Animation`.
+ label
+ New label to be assigned to the variable.
+ mob_value_args
+ Arguments for :class:`~manim.mobject.text.text_mobject.Text` that represents the label value.
+ update_anim
+ Animation to be applied to the updated :class:`~manim.mobject.text.text_mobject.Text`.
+ update_anim_args
+ Arguments for the update :class:`~manim.animation.animation.Animation`.
+ play_anim
+ Specifies whether to play the :class:`~manim.animation.animation.Animation`.
+ play_anim_args
+ Arguments for :py:meth:`Scene.play() `.
Returns
-------
- :class:`manim.Text`
- Represents the updated element label.
+ :class:`~manim.mobject.text.text_mobject.Text`
+ Updated :attr:`__label`.
"""
self.__value = label
mob_label_args["text"] = label
return self.update_mob_label(
- mob_label_args, update_anim, update_anim_args, play_anim
+ mob_label_args, update_anim, update_anim_args, play_anim, play_anim_args
)