lissajou


Namelissajou JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://hermann-web.github.io/blog/projects/introducing-lissajou-for-animated-plots/
SummaryA Python module for creating animations, including Lissajou curve simulations.
upload_time2024-04-04 12:17:01
maintainerHermann Agossou
docs_urlNone
authorHermann Agossou
requires_python<4.0,>=3.8
licenseMIT
keywords animation matplotlib simulation lissajou parametric visualization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [Lissajou Animation Framework](https://github.com/Hermann-web/lissajou)

## 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](https://en.wikipedia.org/wiki/Lissajous_curve), its primary focus is on providing a framework for general animation creation.

## Installation

You can install the Lissajou Animation Framework using pip:

```bash
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:

```python
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

```python
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](./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.

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

```python

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://hermann-web.github.io/blog/projects/introducing-lissajou-for-animated-plots/",
    "name": "lissajou",
    "maintainer": "Hermann Agossou",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": "agossouhermann7@gmail.com",
    "keywords": "animation, matplotlib, simulation, Lissajou, parametric, visualization",
    "author": "Hermann Agossou",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/1f/44/16b39c4e634a957cfdca5f969c0a80da0f06bd37c89bc2a75163faac949f/lissajou-0.2.0.tar.gz",
    "platform": null,
    "description": "# [Lissajou Animation Framework](https://github.com/Hermann-web/lissajou)\n\n## Description\n\nThe 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](https://en.wikipedia.org/wiki/Lissajous_curve), its primary focus is on providing a framework for general animation creation.\n\n## Installation\n\nYou can install the Lissajou Animation Framework using pip:\n\n```bash\npip install lissajou\n```\n\n## Usage\n\nTo create animations using the framework, you can utilize the provided classes and methods. Here's a basic example to get you started:\n\n```python\nfrom lissajou.anim import GenericLissajou\n\n# Create a GenericLissajou object\nanimation = GenericLissajou()\nanimation.show()\n```\n\n## Classes and Features\n\nThe framework includes the following main classes:\n\n- `BaseAnimation`: An abstract base class for creating animations with setup steps and frame updates.\n- `ImageAnimation`: A subclass of `BaseAnimation` for creating animations with image data.\n- `ParametricAnimation`: A subclass of `BaseAnimation` for creating parametric 2D animations.\n- `ThreeDimensionalParametricAnimation`: A subclass of `ParametricAnimation` for creating parametric 3D animations.\n\n## Showcase\n\nSome 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.\n\nFor example\n\n```python\nfrom lissajou.lissajou import SinusoidalAmplitudeLissajou\nliss = SinusoidalAmplitudeLissajou(a=6, delta=np.pi / 6, range=18, nb_points=18000)\nliss.show()\n```\n\nHere are some examples showcasing different types of Lissajou animations:\n\n- Generic Lissajou Curve\n- Lissajou Curve with Varying Amplitude\n- Lissajou Curve with Sinusoidal Amplitude\n- Lissajou Curve with Fixed Ratio\n- Lissajou Ellipse Animation\n- Lissajou Circle Animation\n\nUsage examples an be tested in the file [examples/lissajou_examples.py](./examples/lissajou_examples.py)\n\n## Custom Animation Examples\n\nThe framework allows for creating custom animations beyond the included examples. Here are some demonstrations:\n\n### Image Animation\n\nThis example demonstrates creating an animation with image data.\n\n```python\nclass ImageAnimationExample(ImageAnimation):\n    \"\"\"\n    A subclass of ImageAnimation for creating animations with sinusoidal image data.\n\n    This class generates sinusoidal image data and updates the animation view with\n    the computed sine values for each frame.\n    \"\"\"\n\n    def __init__(self, n):\n        \"\"\"\n        Initializes the SinusoidalImageAnimation object with sinusoidal image data.\n        \"\"\"\n        self.x = np.random.binomial(1, 0.3, size=(n, n))  # Generate random binary image\n        super().__init__()  # Call the superclass constructor to set up the animation\n\n    def _set_params(self, **kwargs):\n        \"\"\"\n        Sets the parameters for the animation, including the shape of the image.\n        \"\"\"\n        kwargs[\"shape\"] = (\n            self.x.shape\n        )  # Set the shape parameter based on the generated image\n        return super()._set_params(\n            **kwargs\n        )  # Call the superclass method to set parameters\n\n    def _before_each_iteration(self, t):\n        \"\"\"\n        Hook method called before each frame iteration.\n        \"\"\"\n        pass  # No pre-iteration setup is needed for this subclass\n\n    def _img_fct(self, t):\n        \"\"\"\n        Computes the image values for each frame using sine function.\n        \"\"\"\n        return np.sin(t * self.x)  # Compute sine values for the current frame\n\n\nif __name__ == \"__main__\":\n    print(\"Example 1: ImageAnimationExample\")\n    liss = ImageAnimationExample(100)\n    liss.show()\n```\n\n### 3D Sinusoidal Parametric Animation\n\nThis example demonstrates creating a 2D or 3D animation using parametric equations with sine functions.\n\n```python\n\nclass ThreeDsinusoidalParametricAnimation(ThreeDimensionalParametricAnimation):\n    \"\"\"\n    A subclass of ThreeDimensionalParametricAnimation for creating 3D sinusoidal parametric animations.\n\n    This class generates parametric data for x, y, and z coordinates using sinusoidal functions.\n    \"\"\"\n\n    def __init__(self, n):\n        \"\"\"\n        Initializes the ThreeDsinusoidalParametricAnimation object.\n        \"\"\"\n        self.n = n\n        super().__init__()  # Call the superclass constructor to set up the animation\n\n    def _before_each_iteration(self, t):\n        \"\"\"\n        Hook method called before each frame iteration.\n        \"\"\"\n        self.tx = np.linspace(-np.pi, np.pi, self.n)  # Generate x values for each frame\n\n    def _fx(self, t):\n        \"\"\"\n        Computes the x-coordinate values for each frame using a sinusoidal function.\n        \"\"\"\n        return np.sin(t * self.tx)  # Generate x values based on the sine of tx\n\n    def _fy(self, t):\n        \"\"\"\n        Computes the y-coordinate values for each frame using a sinusoidal function.\n        \"\"\"\n        return np.cos(t * self.tx)  # Generate y values based on the cosine of tx\n\n    def _fz(self, t):\n        \"\"\"\n        Computes the z-coordinate values for each frame using a hyperbolic tangent function.\n        \"\"\"\n        return np.tanh(\n            t * self.tx\n        )  # Generate z values based on the hyperbolic tangent of tx\n\nif __name__ == \"__main__\":\n    print(\"Example 2: ThreeDsinusoidalParametricAnimation\")\n    liss = ThreeDsinusoidalParametricAnimation(100)\n    liss.show(x_range=(-1, 1), y_range=(-1, 1), z_range=(-1, 1))\n```\n\nYou can also implement a 2D animation in a similar fashion, by using the `ParametricAnimation` abstract class.\n\nThese 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!\n\n## Contributing\n\nIf you wish to contribute to the Lissajou Animation Framework, feel free to report issues or submit pull requests on the project's repository.\n\n## License\n\nThis project is distributed under the MIT License.\n\nThis updated README now includes explanations and code examples for custom animation implementations, allowing users to explore the framework's capabilities further.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python module for creating animations, including Lissajou curve simulations.",
    "version": "0.2.0",
    "project_urls": {
        "Documentation": "https://github.com/Hermann-web/lissajou/blob/main/docs/index.md",
        "Homepage": "https://hermann-web.github.io/blog/projects/introducing-lissajou-for-animated-plots/",
        "Repository": "https://github.com/Hermann-web/lissajou"
    },
    "split_keywords": [
        "animation",
        " matplotlib",
        " simulation",
        " lissajou",
        " parametric",
        " visualization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b209d9ce33a22fb5c931271d7bed37e336acac4eb966eaf93dcd54066e69d9ba",
                "md5": "5be8eb4a5d135711e8af84081ecde559",
                "sha256": "fdf46c071ce5936b790fdf5aba3142b8748291608ff4d9a2f4eed175e5fcaa64"
            },
            "downloads": -1,
            "filename": "lissajou-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5be8eb4a5d135711e8af84081ecde559",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 9316,
            "upload_time": "2024-04-04T12:16:58",
            "upload_time_iso_8601": "2024-04-04T12:16:58.397479Z",
            "url": "https://files.pythonhosted.org/packages/b2/09/d9ce33a22fb5c931271d7bed37e336acac4eb966eaf93dcd54066e69d9ba/lissajou-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f4416b39c4e634a957cfdca5f969c0a80da0f06bd37c89bc2a75163faac949f",
                "md5": "acdb906132304ac0c3bb464327f29410",
                "sha256": "d272dacc6b69e1bd8814645a99bea3f2fa9e3d766eda29fd7de10fe7c9c73d3f"
            },
            "downloads": -1,
            "filename": "lissajou-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "acdb906132304ac0c3bb464327f29410",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 9908,
            "upload_time": "2024-04-04T12:17:01",
            "upload_time_iso_8601": "2024-04-04T12:17:01.841928Z",
            "url": "https://files.pythonhosted.org/packages/1f/44/16b39c4e634a957cfdca5f969c0a80da0f06bd37c89bc2a75163faac949f/lissajou-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-04 12:17:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Hermann-web",
    "github_project": "lissajou",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "lissajou"
}
        
Elapsed time: 0.45838s