A Python module for creating animations, including Lissajou curve simulations.
Project description
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 ofBaseAnimation
for creating animations with image data.ParametricAnimation
: A subclass ofBaseAnimation
for creating parametric 2D animations.ThreeDimensionalParametricAnimation
: A subclass ofParametricAnimation
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lissajou-0.2.0.tar.gz
.
File metadata
- Download URL: lissajou-0.2.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.4 Linux/6.5.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d272dacc6b69e1bd8814645a99bea3f2fa9e3d766eda29fd7de10fe7c9c73d3f |
|
MD5 | acdb906132304ac0c3bb464327f29410 |
|
BLAKE2b-256 | 1f4416b39c4e634a957cfdca5f969c0a80da0f06bd37c89bc2a75163faac949f |
File details
Details for the file lissajou-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: lissajou-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.4 Linux/6.5.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdf46c071ce5936b790fdf5aba3142b8748291608ff4d9a2f4eed175e5fcaa64 |
|
MD5 | 5be8eb4a5d135711e8af84081ecde559 |
|
BLAKE2b-256 | b209d9ce33a22fb5c931271d7bed37e336acac4eb966eaf93dcd54066e69d9ba |