Skip to content

Commit fc4c4cb

Browse files
authored
Release 0.1.5 (#2)
* 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
1 parent 81e1387 commit fc4c4cb

File tree

12 files changed

+948
-29
lines changed

12 files changed

+948
-29
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.5] - 2022-12-10
9+
10+
### PRs
11+
12+
- [#1](https://github.com/drageelr/manim-data-structures/pull/1):
13+
- `MVariable` added.
14+
- `MArray.remove_elem()` added.
15+
- `MArray.append_elem()` changed.
16+
- `MArray` label and fetch method added.
17+
- Generic `MArrayElement` sub-mobjects fetch method added.
18+
- `MArrayElementComp` enum added.
19+
- Changed `array.py` to `m_array.py`.
20+
- Documentation updated.
21+
822
## [0.1.4] - 2022-11-27
923

1024
### Added

docs/source/guides/arrays.rst

Lines changed: 177 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Animating Arrays
22
================
33

4-
.. currentmodule:: manim_data_structures.array
4+
.. currentmodule:: manim_data_structures.m_array
55

66
Manim Array - MArray
77
--------------------
@@ -39,6 +39,7 @@ Animating MArray
3939
To animate the :py:class:`MArray`, simply invoke the ``animate`` property as shown below:
4040

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

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

8789
.. code-block:: python
90+
:linenos:
8891
8992
self.play(
9093
arr.animate_elem_square(1).set_fill(BLACK),
@@ -119,6 +122,7 @@ Customizing MArray
119122
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.
120123

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

207211
self.wait(1)
208212

209-
.. currentmodule:: manim_data_structures.array
213+
Array Label
214+
^^^^^^^^^^^
215+
216+
.. currentmodule:: manim_data_structures.m_array
217+
218+
For an :py:class:`MArray`, you can also a label with the array via specifying the ``label`` argument.
219+
220+
.. currentmodule:: manim_data_structures.m_enum
221+
222+
Similar to how we specify the growth direction using :py:class:`MArrayDirection` enum, we can dictate the position of the label.
223+
224+
.. code-block:: python
225+
:linenos:
226+
227+
class MyScene(Scene):
228+
def construct(self):
229+
arr_label_left = MArray([1, 2, 3], label='Arr')
230+
arr_label_right = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.RIGHT)
231+
arr_label_down = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.DOWN)
232+
arr_label_up = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.UP, arr_label_gap=0.75)
233+
234+
self.play(Create(arr_label_left))
235+
self.play(arr_label_left.animate.shift(UP * 2 + LEFT * 4))
236+
self.play(Create(arr_label_right))
237+
self.play(arr_label_right.animate.shift(DOWN * 2 + LEFT * 4))
238+
self.play(Create(arr_label_down))
239+
self.play(arr_label_down.animate.shift(UP * 2 + RIGHT))
240+
self.play(Create(arr_label_up))
241+
self.play(arr_label_up.animate.shift(DOWN * 2 + RIGHT))
242+
243+
self.wait(1)
244+
245+
.. raw:: html
246+
247+
<div>
248+
249+
.. manim:: MyScene
250+
:hide_source:
251+
:quality: low
252+
253+
from manim_data_structures import *
254+
255+
class MyScene(Scene):
256+
def construct(self):
257+
arr_label_left = MArray([1, 2, 3], label='Arr')
258+
arr_label_right = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.RIGHT)
259+
arr_label_down = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.DOWN)
260+
arr_label_up = MArray([1, 2, 3], label='Arr', arr_label_pos=MArrayDirection.UP, arr_label_gap=0.75)
261+
262+
self.play(Create(arr_label_left))
263+
self.play(arr_label_left.animate.shift(UP * 2 + LEFT * 4))
264+
self.play(Create(arr_label_right))
265+
self.play(arr_label_right.animate.shift(DOWN * 2 + LEFT * 4))
266+
self.play(Create(arr_label_down))
267+
self.play(arr_label_down.animate.shift(UP * 2 + RIGHT))
268+
self.play(Create(arr_label_up))
269+
self.play(arr_label_up.animate.shift(DOWN * 2 + RIGHT))
270+
271+
self.wait(1)
272+
273+
.. currentmodule:: manim_data_structures.m_array
274+
275+
.. note::
276+
277+
The ``arr_label_gap`` argument specifies the distance between the :py:class:`MArrayElement` 's :py:class:`manim.Square` and the array label itself.
210278

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

249317
Hide Indices
250-
^^^^^^^^^^^^^^^
318+
^^^^^^^^^^^^
251319

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

@@ -297,10 +365,10 @@ For an existing array, you can also append an element simply by invoking the :py
297365
298366
class MyScene(Scene):
299367
def construct(self):
300-
arr = MArray([1, 2, 3])
368+
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
301369
self.add(arr)
302370
self.wait(1)
303-
self.play(Write(arr.append_elem(4)))
371+
self.play(*arr.append_elem(4))
304372
self.wait(1)
305373
306374
.. raw:: html
@@ -315,16 +383,118 @@ For an existing array, you can also append an element simply by invoking the :py
315383

316384
class MyScene(Scene):
317385
def construct(self):
318-
arr = MArray([1, 2, 3])
386+
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
319387
self.add(arr)
320388
self.wait(1)
321-
self.play(Write(arr.append_elem(4)))
389+
self.play(*arr.append_elem(4))
322390
self.wait(1)
323391
324392
.. note::
325393

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

396+
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``.
397+
398+
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:
399+
400+
.. code-block:: python
401+
:linenos:
402+
403+
self.play(*arr.append_elem(4, append_anim=GrowFromCenter))
404+
405+
.. raw:: html
406+
407+
<div>
408+
409+
.. manim:: MyScene
410+
:hide_source:
411+
:quality: low
412+
413+
from manim_data_structures import *
414+
415+
class MyScene(Scene):
416+
def construct(self):
417+
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
418+
self.add(arr)
419+
self.wait(1)
420+
self.play(*arr.append_elem(4, append_anim=GrowFromCenter))
421+
self.wait(1)
422+
423+
.. currentmodule:: manim_data_structures.m_enum
424+
425+
.. note::
426+
427+
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.
428+
429+
Remove Element
430+
^^^^^^^^^^^^^^
431+
432+
.. currentmodule:: manim_data_structures.m_array
433+
434+
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.
435+
436+
.. code-block:: python
437+
:linenos:
438+
439+
(remove_anim, update_indices) = arr.remove_elem(1)
440+
self.play(remove_anim)
441+
self.play(*update_indices())
442+
443+
.. raw:: html
444+
445+
<div>
446+
447+
.. manim:: MyScene
448+
:hide_source:
449+
:quality: low
450+
451+
from manim_data_structures import *
452+
453+
class MyScene(Scene):
454+
def construct(self):
455+
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
456+
self.add(arr)
457+
self.wait(1)
458+
(remove_anim, update_indices) = arr.remove_elem(1)
459+
self.play(remove_anim)
460+
self.play(*update_indices())
461+
self.wait(1)
462+
463+
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:
464+
1. Element removal animation via the ``removal_anim`` parameter.
465+
2. Indices update animation via the ``update_anim`` parameter.
466+
467+
The code snippet below provides an example:
468+
469+
.. code-block:: python
470+
:linenos:
471+
472+
(remove_anim, update_indices) = arr.remove_elem(1, removal_anim=ShowPassingFlash , update_anim=Indicate)
473+
474+
.. raw:: html
475+
476+
<div>
477+
478+
.. manim:: MyScene
479+
:hide_source:
480+
:quality: low
481+
482+
from manim_data_structures import *
483+
484+
class MyScene(Scene):
485+
def construct(self):
486+
arr = MArray([1, 2, 3], label='Array', arr_label_pos=MArrayDirection.DOWN)
487+
self.add(arr)
488+
self.wait(1)
489+
(remove_anim, update_indices) = arr.remove_elem(1, removal_anim=ShowPassingFlash , update_anim=Indicate)
490+
self.play(remove_anim)
491+
self.play(*update_indices())
492+
self.wait(1)
493+
494+
.. note::
495+
496+
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.
497+
328498
Update Element
329499
^^^^^^^^^^^^^^
330500

docs/source/index.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ To import the package in your script, add the following import statement:
2626
2727
from manim_data_structures import *
2828
29+
Variables
30+
~~~~~~~~~
31+
32+
.. manim:: VarScene
33+
:save_last_frame:
34+
35+
from manim_data_structures import *
36+
37+
class VarScene(Scene):
38+
def construct(self):
39+
var = MVariable(10, 0, 'Var')
40+
self.add(var)
41+
42+
Arrays
43+
~~~~~~
44+
45+
.. manim:: ArrayScene
46+
:save_last_frame:
47+
48+
from manim_data_structures import *
49+
50+
class ArrayScene(Scene):
51+
def construct(self):
52+
arr = MArray([1, 2, 3], label='Arr')
53+
self.add(arr)
54+
2955
Next Steps
3056
----------
3157

docs/source/reference/arrays.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Arrays
66
.. autosummary::
77
:toctree: generated
88

9-
~array.MArrayElement
10-
~array.MArray
9+
~m_array.MArrayElement
10+
~m_array.MArray

docs/source/reference/enums.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Enums
77
:toctree: generated
88

99
~m_enum.MArrayDirection
10+
~m_enum.MArrayElementComp

docs/source/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Module Index
99
.. toctree::
1010
:maxdepth: 2
1111

12+
variables
1213
arrays
1314
enums
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Variables
2+
=========
3+
4+
.. currentmodule:: manim_data_structures
5+
6+
.. autosummary::
7+
:toctree: generated
8+
9+
~m_variable.MVariable

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "manim-data-structures"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
description = "A Manim implementation for data structures"
55
authors = ["Hammad Nasir <[email protected]>"]
66
readme = "README.md"
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
__version__ = "0.1.4"
1+
__version__ = "0.1.5"
22

3-
from .array import *
3+
from .m_array import *
44
from .m_enum import *
5+
from .m_variable import *
56

6-
__all__ = ["MArrayElement", "MArray", "MArrayDirection"]
7+
__all__ = [
8+
"MArrayElement",
9+
"MArray",
10+
"MArrayDirection",
11+
"MArrayElementComp",
12+
"MVariable",
13+
]

0 commit comments

Comments
 (0)