Python library to generate seamlesslylooping animated images and closed curves, and seamlessytileable images. Based on 4D OpenSimplex noise.
Project description
OpenSimplex Loops
This library provides higherlevel functions that can generate seamlesslylooping animated images and closed curves, and seamlessytileable images. It relies on 4D OpenSimplex noise, which is a type of gradient noise that features spatial coherence.
This library is an extension to the OpenSimplex Python library by lmas.
Inspiration taken from Coding Challenge #137: 4D OpenSimplex Noise Loop by The Coding Train.
Demos
looping_animated_2D_image()
Seamlesslylooping animated 2D images.
looping_animated_closed_1D_curve()
Seamlesslylooping animated 1D curves, each curve in turn also closing up seamlessly backtofront.
tileable_2D_image()
Seamlesslytileable 2D image.
Installation
pip install opensimplexloops
This will install the following dependencies:
opensimplex
numpy
numba
numbaprogress
Notes:
The OpenSimplex library by lmas does not enforce the use of the numba package, but is left optional instead. Here, I have set it as a requirement due to the heavy computation required by these highlerlevel functions. I have them optimized for numba which enables multicore parallel processing within Python, resulting in major speed improvements compared to as running without. I have gotten computational speedups by a factor of ~200.
Note that the very first call of each of these OpenSimplex functions will take a longer time than later calls. This is because numba needs to compile this Python code to bytecode specific to your platform, once.
The numbaprogress package is actually optional. When present, a progress bar will be shown during the noise generation.
API
looping_animated_2D_image(...)
Generates a stack of seamlesslylooping animated 2D raster images drawn from 4D OpenSimplex noise.
The first two OpenSimplex dimensions are used to describe a plane that gets projected onto a 2D raster image. The last two dimensions are used to describe a circle in time.
 Args:
 N_frames (int, default = 200)
Number of time frames
 N_pixels_x (int, default = 1000)
Number of pixels on the xaxis
 N_pixels_y (int  None, default = None)
Number of pixels on the yaxis. When set to None N_pixels_y will be set equal to N_pixels_x.
 t_step (float, default = 0.1)
Time step
 x_step (float, default = 0.01)
Spatial step in the xdirection
 y_step (float  None, default = None)
Spatial step in the ydirection. When set to None y_step will be set equal to x_step.
 dtype (type, default = numpy.double)
Return type of the noise array elements. To reduce the memory footprint one can change from the default numpy.double to e.g. numpy.float32.
 seed (int, default = 3)
Seed value for the OpenSimplex noise
 verbose (bool, default = True)
Print ‘Generating noise…’ to the terminal? If the numba_progress package is present a progress bar will also be shown.
 Returns:
The 2D image stack as 3D array [time, ypixel, xpixel] containing the OpenSimplex noise values as floating points. The output is garantueed to be in the range [1, 1], but the exact extrema cannot be known apriori and are probably quite smaller than [1, 1].
looping_animated_closed_1D_curve(...)
Generates a stack of seamlesslylooping animated 1D curves, each curve in turn also closing up seamlessly backtofront, drawn from 4D OpenSimplex noise.
The first two OpenSimplex dimensions are used to describe a circle that gets projected onto a 1D curve. The last two dimensions are used to describe a circle in time.
 Args:
 N_frames (int, default = 200)
Number of time frames
 N_pixels_x (int, default = 1000)
Number of pixels of the curve
 t_step (float, default = 0.1)
Time step
 x_step (float, default = 0.01)
Spatial step in the xdirection
 dtype (type, default = numpy.double)
Return type of the noise array elements. To reduce the memory footprint one can change from the default numpy.double to e.g. numpy.float32.
 seed (int, default = 3)
Seed value for the OpenSimplex noise
 verbose (bool, default = True)
Print ‘Generating noise…’ to the terminal? If the numba_progress package is present a progress bar will also be shown.
 Returns:
The 1D curve stack as 2D array [time, xpixel] containing the OpenSimplex noise values as floating points. The output is garantueed to be in the range [1, 1], but the exact extrema cannot be known apriori and are probably quite smaller than [1, 1].
tileable_2D_image(...)
Generates a seamlesslytileable 2D raster image drawn from 4D OpenSimplex noise.
The first two OpenSimplex dimensions are used to describe a circle that gets projected onto the xaxis of the 2D raster image. The last two dimensions are used to describe another circle that gets projected onto the yaxis of the 2D raster image.
 Args:
 N_pixels_x (int, default = 1000)
Number of pixels on the xaxis
 N_pixels_y (int  None, default = None)
Number of pixels on the yaxis. When set to None N_pixels_y will be set equal to N_pixels_x.
 x_step (float, default = 0.01)
Spatial step in the xdirection
 y_step (float  None, default = None)
Spatial step in the ydirection. When set to None y_step will be set equal to x_step.
 dtype (type, default = numpy.double)
Return type of the noise array elements. To reduce the memory footprint one can change from the default numpy.double to e.g. numpy.float32.
 seed (int, default = 3)
Seed value for the OpenSimplex noise
 verbose (bool, default = True)
Print ‘Generating noise…’ to the terminal? If the numba_progress package is present a progress bar will also be shown.
 Returns:
The 2D image as 2D array [ypixel, xpixel] containing the OpenSimplex noise values as floating points. The output is garantueed to be in the range [1, 1], but the exact extrema cannot be known apriori and are probably quite smaller than [1, 1].
Changelog
1.0.1 (20240812)
Obtained a DOI from Zenodo
1.0.0 (20230827)
Stable release
Added looping animated circle demo
0.1.3 (20230127)
Fixed wrong docstr description on the return value of tileable_2D_image()
Generalized the internal functions
0.1.2 (20230126)
Using raw.githubusercontent.com for the images in README to show up in PyPi
0.1.0 (20230126)
First release on PyPI
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
Hashes for opensimplex_loops1.0.1py3noneany.whl
Algorithm  Hash digest  

SHA256  955e23ffde0933ff977b8f41219c97d6b0015dba390c4b970ecf9c011dc7925c 

MD5  d5419bf060ca78df0e3df902c8eb2a05 

BLAKE2b256  104ee8981e0d8bf49ae1f06ba7b5d1611c7e58facb2143b2a658bdce0f9dde87 