Skip to main content

ArrayViz

Meta license
Testing Pylint and Tests Release

This package allows users to pass a function and visualize it as blocks and elements using Manim, a powerful mathematical animation engine. It provides an easy way to animate algorithms step-by-step, helping with educational purposes and debugging.

Note

This project is a work in progress. Package has not been released yet but is planned to be. Only limited functionality is implemented as of now.

Installation

First, install Manim according to the instructions on Manim's official website.

Install the package via PyPI:

python -m pip install --upgrade arrayviz

Usage

ArrayBlockVisualizer Class

The ArrayBlockVisualizer class is designed to animate the execution of a user-provided function. Users can control when the pointers should update in relation to the array frame updates (before, at the same time, or after).

Parameters

  • func: The user-provided function to animate.
  • func_args: Arguments to pass to the user-provided function.
  • delay (float): The delay time between frames in seconds. Default is 1.
  • **kwargs: Additional keyword arguments for the Scene superclass.

Example

merge sorted arrays

The following example demonstrates how to use the ArrayBlockVisualizer class to animate an example merge function for sorted arrays.

examples/merge_sorted_arrays.py

from arrayviz import ArrayBlockVisualizer


def merge(nums1, m, nums2, n, record_frame):
    """
    Merges two sorted arrays nums1 and nums2 into a single sorted array in place.

    Args:
        nums1 (list): The first sorted array with extra space at the end to hold nums2 elements.
        m (int): The number of valid elements in nums1.
        nums2 (list): The second sorted array.
        n (int): The number of elements in nums2.
        record_frame (callable): A callback function to record the state of arrays and pointers.
    """
    merged_index = m + n

    # Record initial array
    record_frame(arrays=[nums1[:], nums2[:]])

    while m > 0 and n > 0:
        # Record pointers
        record_frame(pointers=[{"i": m - 1}, {"j": n - 1}])
        if nums1[m - 1] > nums2[n - 1]:
            nums1[merged_index - 1] = nums1[m - 1]
            m -= 1
        else:
            nums1[merged_index - 1] = nums2[n - 1]
            n -= 1
        merged_index -= 1

        # Record new array
        record_frame(arrays=[nums1[:], nums2[:]])

    # Record final pointers
    record_frame(pointers=[{"i": n - 1}, {"j": n - 1}])

    nums1[:n] = nums2[:n]

    # Record final array
    record_frame(arrays=[nums1[:], nums2[:]])


# Initial arrays for the merge function
nums1 = [4, 5, 7, 0, 0, 0, 0, 0, 0]
nums2 = [1, 2, 2, 3, 5, 6]
m = 3  # Number of initial valid elements in nums1
n = 6  # Number of elements in nums2


class MergeScene(ArrayBlockVisualizer):
    """
    A Manim scene to visualize the merge function using the FunctionAnimation class.
    """

    def __init__(self, **kwargs):
        """
        Initializes the MergeScene with the merge function and its arguments.

        Args:
            **kwargs: Additional keyword arguments for the ArrayBlockVisualizer superclass.
        """
        super().__init__(merge, (nums1, m, nums2, n), **kwargs)


# To render this scene, use the following command in your terminal:
# manim -pql examples/merge_sorted_arrays.py MergeScene

Running the Example

To render the MergeScene, run the following command in your terminal:

manim -pql example.py MergeScene
  • -pql stands for play in low quality. You can adjust this based on the desired rendering quality.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Acknowledgements

Manim Community for developing the Manim library.

Metadata

Release files for arrayviz 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arrayviz 0.0.1
File Size Uploaded
arrayviz-0.0.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for arrayviz 0.0.1
File Interpreter ABI Platform
arrayviz-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / arrayviz-0.0.1.tar.gz

Download URL arrayviz-0.0.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f36e8424916cf099e5fd0208068e86988e87eb87c1e7d48e965880950851f12c
BLAKE2b-256 checksum
How to use checksums
5c86c07e5ccc4692285e24395c8ac66e1822b5d4e04e471f07c869c557689ae7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / arrayviz-0.0.1-py3-none-any.whl

Download URL arrayviz-0.0.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b627d4f0ecb3840d40546b37fecced406f5ecf5627c3ee092d5487371fdb2cfb
BLAKE2b-256 checksum
How to use checksums
3f7e65933b967c7853845031f5389b2fcd51cab0f6f6a28c8bce46addcddb3ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page