Skip to main content

Lissajou Animation Framework

Description

The Lissajou Animation Framework is a Python module designed for creating diverse animations using matplotlib. It offers a structured approach to building animations, including parametric animations and 3D parametric animations. While the module includes demonstrations of Lissajou curves, its primary focus is on providing a framework for general animation creation.

Installation

You can install the Lissajou Animation Framework using pip:

pip install lissajou

Usage

To create animations using the framework, you can utilize the provided classes and methods. Here's a basic example to get you started:

from lissajou.anim import GenericLissajou

# Create a GenericLissajou object
animation = GenericLissajou()
animation.show()

Classes and Features

The framework includes the following main classes:

  • BaseAnimation: An abstract base class for creating animations with setup steps and frame updates.
  • ImageAnimation: A subclass of BaseAnimation for creating animations with image data.
  • ParametricAnimation: A subclass of BaseAnimation for creating parametric 2D animations.
  • ThreeDimensionalParametricAnimation: A subclass of ParametricAnimation for creating parametric 3D animations.

Showcase

Some Lissajou patterns support have been added to the module. You will find implementations of these animations in the module lissajou.lissajou so you can import them, and use with your custom parameters.

For example

from lissajou.lissajou import SinusoidalAmplitudeLissajou
liss = SinusoidalAmplitudeLissajou(a=6, delta=np.pi / 6, range=18, nb_points=18000)
liss.show()

Here are some examples showcasing different types of Lissajou animations:

  • Generic Lissajou Curve
  • Lissajou Curve with Varying Amplitude
  • Lissajou Curve with Sinusoidal Amplitude
  • Lissajou Curve with Fixed Ratio
  • Lissajou Ellipse Animation
  • Lissajou Circle Animation

Usage examples an be tested in the file examples/lissajou_examples.py

Custom Animation Examples

The framework allows for creating custom animations beyond the included examples. Here are some demonstrations:

Image Animation

This example demonstrates creating an animation with image data.

class ImageAnimationExample(ImageAnimation):
    """
    A subclass of ImageAnimation for creating animations with sinusoidal image data.

    This class generates sinusoidal image data and updates the animation view with
    the computed sine values for each frame.
    """

    def __init__(self, n):
        """
        Initializes the SinusoidalImageAnimation object with sinusoidal image data.
        """
        self.x = np.random.binomial(1, 0.3, size=(n, n))  # Generate random binary image
        super().__init__()  # Call the superclass constructor to set up the animation

    def _set_params(self, **kwargs):
        """
        Sets the parameters for the animation, including the shape of the image.
        """
        kwargs["shape"] = (
            self.x.shape
        )  # Set the shape parameter based on the generated image
        return super()._set_params(
            **kwargs
        )  # Call the superclass method to set parameters

    def _before_each_iteration(self, t):
        """
        Hook method called before each frame iteration.
        """
        pass  # No pre-iteration setup is needed for this subclass

    def _img_fct(self, t):
        """
        Computes the image values for each frame using sine function.
        """
        return np.sin(t * self.x)  # Compute sine values for the current frame


if __name__ == "__main__":
    print("Example 1: ImageAnimationExample")
    liss = ImageAnimationExample(100)
    liss.show()

3D Sinusoidal Parametric Animation

This example demonstrates creating a 2D or 3D animation using parametric equations with sine functions.

class ThreeDsinusoidalParametricAnimation(ThreeDimensionalParametricAnimation):
    """
    A subclass of ThreeDimensionalParametricAnimation for creating 3D sinusoidal parametric animations.

    This class generates parametric data for x, y, and z coordinates using sinusoidal functions.
    """

    def __init__(self, n):
        """
        Initializes the ThreeDsinusoidalParametricAnimation object.
        """
        self.n = n
        super().__init__()  # Call the superclass constructor to set up the animation

    def _before_each_iteration(self, t):
        """
        Hook method called before each frame iteration.
        """
        self.tx = np.linspace(-np.pi, np.pi, self.n)  # Generate x values for each frame

    def _fx(self, t):
        """
        Computes the x-coordinate values for each frame using a sinusoidal function.
        """
        return np.sin(t * self.tx)  # Generate x values based on the sine of tx

    def _fy(self, t):
        """
        Computes the y-coordinate values for each frame using a sinusoidal function.
        """
        return np.cos(t * self.tx)  # Generate y values based on the cosine of tx

    def _fz(self, t):
        """
        Computes the z-coordinate values for each frame using a hyperbolic tangent function.
        """
        return np.tanh(
            t * self.tx
        )  # Generate z values based on the hyperbolic tangent of tx

if __name__ == "__main__":
    print("Example 2: ThreeDsinusoidalParametricAnimation")
    liss = ThreeDsinusoidalParametricAnimation(100)
    liss.show(x_range=(-1, 1), y_range=(-1, 1), z_range=(-1, 1))

You can also implement a 2D animation in a similar fashion, by using the ParametricAnimation abstract class.

These are just a few examples of how to create custom animations using the Lissajou Animation Framework. Feel free to explore the provided classes and experiment with your own animation ideas!

Contributing

If you wish to contribute to the Lissajou Animation Framework, feel free to report issues or submit pull requests on the project's repository.

License

This project is distributed under the MIT License.

This updated README now includes explanations and code examples for custom animation implementations, allowing users to explore the framework's capabilities further.

Metadata

Release files for lissajou 0.2.0

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

Source distribution (sdist)

Source distribution for lissajou 0.2.0
File Size Uploaded Provenance Actions
lissajou-0.2.0.tar.gz 9.9 kB Without provenance Details for lissajou-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.2 kB

Release files / lissajou-0.2.0.tar.gz

Download URL lissajou-0.2.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d272dacc6b69e1bd8814645a99bea3f2fa9e3d766eda29fd7de10fe7c9c73d3f
BLAKE2b-256 checksum
How to use checksums
1f4416b39c4e634a957cfdca5f969c0a80da0f06bd37c89bc2a75163faac949f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.4 Linux/6.5.0-25-generic

Release files / lissajou-0.2.0-py3-none-any.whl

Download URL lissajou-0.2.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fdf46c071ce5936b790fdf5aba3142b8748291608ff4d9a2f4eed175e5fcaa64
BLAKE2b-256 checksum
How to use checksums
b209d9ce33a22fb5c931271d7bed37e336acac4eb966eaf93dcd54066e69d9ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.4 Linux/6.5.0-25-generic

Security for lissajou 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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