Skip to content

Commit

Permalink
Release 0.1.5 (#2)
Browse files Browse the repository at this point in the history
* feat: updated MArray & MArrayElement + added MVariable

* Added remove element function in MArray
* Added label support in MArrayElement
* Added generic mob fetch function in MArrayElement coupled with MArrayElementComp enum
* Changed array.py to m_array.py because of conflict with native array module
* Added variables documentation in references
* Updated module name of m_array in references

* feat: MArray label added

* Label with four different direcitons added.
* Label shifts on append and remove element appropriately.
* Update label text doesn't remove previous label, therefore not added in this commit.
* Method to fetch array label.

* add: updated docs for new features

* release: 0.1.5
  • Loading branch information
drageelr authored Dec 10, 2022
1 parent 81e1387 commit fc4c4cb
Show file tree
Hide file tree
Showing 12 changed files with 948 additions and 29 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ 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.5] - 2022-12-10

### PRs

- [#1](https://github.com/drageelr/manim-data-structures/pull/1):
- `MVariable` added.
- `MArray.remove_elem()` added.
- `MArray.append_elem()` changed.
- `MArray` label and fetch method added.
- Generic `MArrayElement` sub-mobjects fetch method added.
- `MArrayElementComp` enum added.
- Changed `array.py` to `m_array.py`.
- Documentation updated.

## [0.1.4] - 2022-11-27

### Added
Expand Down
184 changes: 177 additions & 7 deletions docs/source/guides/arrays.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Animating Arrays
================

.. currentmodule:: manim_data_structures.array
.. currentmodule:: manim_data_structures.m_array

Manim Array - MArray
--------------------
Expand Down Expand Up @@ -39,6 +39,7 @@ Animating MArray
To animate the :py:class:`MArray`, simply invoke the ``animate`` property as shown below:

.. code-block:: python
:linenos:
self.play(arr.animate.shift(UP * 2 + LEFT * 5))
Expand All @@ -62,6 +63,7 @@ To animate the :py:class:`MArray`, simply invoke the ``animate`` property as sho
Moreover, you can also use the :py:func:`MArray.animate_elem` method to animate a single element of the :py:class:`MArray` as well:

.. code-block:: python
:linenos:
self.play(arr.animate_elem(1).shift(DOWN))
Expand All @@ -85,6 +87,7 @@ Moreover, you can also use the :py:func:`MArray.animate_elem` method to animate
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.

.. code-block:: python
:linenos:
self.play(
arr.animate_elem_square(1).set_fill(BLACK),
Expand Down Expand Up @@ -119,6 +122,7 @@ 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.

.. code-block:: python
:linenos:
arr = MArray(
[1, 2, 3],
Expand Down Expand Up @@ -206,7 +210,71 @@ To do this, simply pass your preferred direction enum from :py:class:`MArrayDire

self.wait(1)

.. currentmodule:: manim_data_structures.array
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.

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

.. code-block:: python
:linenos:
class MyScene(Scene):
def construct(self):
arr_label_left = MArray([1, 2, 3], label='Arr')
arr_label_right = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.RIGHT)
arr_label_down = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.DOWN)
arr_label_up = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.UP, arr_label_gap=0.75)
self.play(Create(arr_label_left))
self.play(arr_label_left.animate.shift(UP * 2 + LEFT * 4))
self.play(Create(arr_label_right))
self.play(arr_label_right.animate.shift(DOWN * 2 + LEFT * 4))
self.play(Create(arr_label_down))
self.play(arr_label_down.animate.shift(UP * 2 + RIGHT))
self.play(Create(arr_label_up))
self.play(arr_label_up.animate.shift(DOWN * 2 + RIGHT))
self.wait(1)
.. raw:: html

<div>

.. manim:: MyScene
:hide_source:
:quality: low

from manim_data_structures import *

class MyScene(Scene):
def construct(self):
arr_label_left = MArray([1, 2, 3], label='Arr')
arr_label_right = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.RIGHT)
arr_label_down = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.DOWN)
arr_label_up = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.UP, arr_label_gap=0.75)

self.play(Create(arr_label_left))
self.play(arr_label_left.animate.shift(UP * 2 + LEFT * 4))
self.play(Create(arr_label_right))
self.play(arr_label_right.animate.shift(DOWN * 2 + LEFT * 4))
self.play(Create(arr_label_down))
self.play(arr_label_down.animate.shift(UP * 2 + RIGHT))
self.play(Create(arr_label_up))
self.play(arr_label_up.animate.shift(DOWN * 2 + RIGHT))

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.

Hex Indices
^^^^^^^^^^^
Expand Down Expand Up @@ -247,7 +315,7 @@ Lets say you want to show a 4-byte integer array with its addresses. You can sim
self.wait(1)

Hide Indices
^^^^^^^^^^^^^^^
^^^^^^^^^^^^

Or if you don't want to show the indices at all, simply pass ``True`` as the ``hide_index`` argument to the constructor

Expand Down Expand Up @@ -297,10 +365,10 @@ For an existing array, you can also append an element simply by invoking the :py
class MyScene(Scene):
def construct(self):
arr = MArray([1, 2, 3])
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
self.add(arr)
self.wait(1)
self.play(Write(arr.append_elem(4)))
self.play(*arr.append_elem(4))
self.wait(1)
.. raw:: html
Expand All @@ -315,16 +383,118 @@ For an existing array, you can also append an element simply by invoking the :py

class MyScene(Scene):
def construct(self):
arr = MArray([1, 2, 3])
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
self.add(arr)
self.wait(1)
self.play(Write(arr.append_elem(4)))
self.play(*arr.append_elem(4))
self.wait(1)
.. note::

You can also pass ``mob_*_args`` to this method to customize the inserted element.

Did you notice the the ``*`` before we invoked the :py:func:`MArray.append_elem` method? Since the method returns a list of :py:class:`manim.Animation` therefore, we unpack it while feeding it to the ``self.play`` method of the ``Scene``.

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:class:`MArray.append_elem` method:

.. code-block:: python
:linenos:
self.play(*arr.append_elem(4, append_anim=GrowFromCenter))
.. raw:: html

<div>

.. manim:: MyScene
:hide_source:
:quality: low

from manim_data_structures import *

class MyScene(Scene):
def construct(self):
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
self.add(arr)
self.wait(1)
self.play(*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.

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. The method returns two the removal animation and a function that udpates the indices of the remaining elements.

.. code-block:: python
:linenos:
(remove_anim, update_indices) = arr.remove_elem(1)
self.play(remove_anim)
self.play(*update_indices())
.. raw:: html

<div>

.. manim:: MyScene
:hide_source:
:quality: low

from manim_data_structures import *

class MyScene(Scene):
def construct(self):
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
self.add(arr)
self.wait(1)
(remove_anim, update_indices) = arr.remove_elem(1)
self.play(remove_anim)
self.play(*update_indices())
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:
1. Element removal animation via the ``removal_anim`` parameter.
2. Indices update animation via the ``update_anim`` parameter.

The code snippet below provides an example:

.. code-block:: python
:linenos:
(remove_anim, update_indices) = arr.remove_elem(1, removal_anim=ShowPassingFlash , update_anim=Indicate)
.. raw:: html

<div>

.. manim:: MyScene
:hide_source:
:quality: low

from manim_data_structures import *

class MyScene(Scene):
def construct(self):
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
self.add(arr)
self.wait(1)
(remove_anim, update_indices) = arr.remove_elem(1, removal_anim=ShowPassingFlash , update_anim=Indicate)
self.play(remove_anim)
self.play(*update_indices())
self.wait(1)
.. note::

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.

Update Element
^^^^^^^^^^^^^^

Expand Down
26 changes: 26 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ To import the package in your script, add the following import statement:
from manim_data_structures import *
Variables
~~~~~~~~~

.. manim:: VarScene
:save_last_frame:

from manim_data_structures import *

class VarScene(Scene):
def construct(self):
var = MVariable(10, 0, 'Var')
self.add(var)

Arrays
~~~~~~

.. manim:: ArrayScene
:save_last_frame:

from manim_data_structures import *

class ArrayScene(Scene):
def construct(self):
arr = MArray([1, 2, 3], label='Arr')
self.add(arr)

Next Steps
----------

Expand Down
4 changes: 2 additions & 2 deletions docs/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Arrays
.. autosummary::
:toctree: generated

~array.MArrayElement
~array.MArray
~m_array.MArrayElement
~m_array.MArray
1 change: 1 addition & 0 deletions docs/source/reference/enums.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Enums
:toctree: generated

~m_enum.MArrayDirection
~m_enum.MArrayElementComp
1 change: 1 addition & 0 deletions docs/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Module Index
.. toctree::
:maxdepth: 2

variables
arrays
enums
9 changes: 9 additions & 0 deletions docs/source/reference/variables.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Variables
=========

.. currentmodule:: manim_data_structures

.. autosummary::
:toctree: generated

~m_variable.MVariable
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "manim-data-structures"
version = "0.1.4"
version = "0.1.5"
description = "A Manim implementation for data structures"
authors = ["Hammad Nasir <[email protected]>"]
readme = "README.md"
Expand Down
13 changes: 10 additions & 3 deletions src/manim_data_structures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
__version__ = "0.1.4"
__version__ = "0.1.5"

from .array import *
from .m_array import *
from .m_enum import *
from .m_variable import *

__all__ = ["MArrayElement", "MArray", "MArrayDirection"]
__all__ = [
"MArrayElement",
"MArray",
"MArrayDirection",
"MArrayElementComp",
"MVariable",
]
Loading

0 comments on commit fc4c4cb

Please sign in to comment.