Skip to main content
https://img.shields.io/pypi/v/opensimplex-loops https://img.shields.io/pypi/pyversions/opensimplex-loops https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/License-MIT-purple.svg

OpenSimplex Loops

Extension to the OpenSimplex Python library by lmas. This library provides higher-level functions that can generate seamlessly-looping animated images and closed curves, and seamlessy-tileable images. It relies on 4D OpenSimplex noise.

Inspiration taken from Coding Challenge #137: 4D OpenSimplex Noise Loop by The Coding Train.

Demos

looping_animated_2D_image()

looping_animated_2D_image

Seamlessly-looping animated 2D images.

Code: demos/demo_looping_animated_2D_image.py

looping_animated_closed_1D_curve()

looping_animated_closed_1D_curve

Seamlessly-looping animated 1D curves, each curve in turn also closing up seamlessly back-to-front.

Code: demos/demo_looping_animated_closed_1D_curve.py

tileable_2D_image()

tileable_2D_image

Seamlessly-tileable 2D image.

Code: demos/demo_tileable_2D_image.py

Installation

pip install opensimplex-loops

This will install the following dependencies:

  • opensimplex

  • numpy

  • numba

  • numba-progress

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 highler-level functions. I have them optimized for numba which enables multi-core 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 numba-progress 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 seamlessly-looping 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 x-axis

N_pixels_y (int | None, default = None)

Number of pixels on the y-axis. 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 x-direction

y_step (float | None, default = None)

Spatial step in the y-direction. 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, y-pixel, x-pixel] 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 a-priori and are probably quite smaller than [-1, 1].

looping_animated_closed_1D_curve(...)

Generates a stack of seamlessly-looping animated 1D curves, each curve in turn also closing up seamlessly back-to-front, 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 x-direction

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, x-pixel] 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 a-priori and are probably quite smaller than [-1, 1].

tileable_2D_image(...)

Generates a seamlessly-tileable 2D raster image drawn from 4D OpenSimplex noise.

The first two OpenSimplex dimensions are used to describe a circle that gets projected onto the x-axis of the 2D raster image. The last two dimensions are used to describe another circle that gets projected onto the y-axis of the 2D raster image.

Args:
N_pixels_x (int, default = 1000)

Number of pixels on the x-axis

N_pixels_y (int | None, default = None)

Number of pixels on the y-axis. 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 x-direction

y_step (float | None, default = None)

Spatial step in the y-direction. 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 [y-pixel, x-pixel] 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 a-priori and are probably quite smaller than [-1, 1].

Changelog

0.1.3 (2023-01-27)

  • Fixed wrong docstr description on the return value of tileable_2D_image()

  • Generalized the internal functions

0.1.2 (2023-01-26)

  • Using raw.githubusercontent.com for the images in README to show up in PyPi

0.1.0 (2023-01-26)

  • First release on PyPI

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensimplex-loops-0.1.3.tar.gz (2.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opensimplex_loops-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file opensimplex-loops-0.1.3.tar.gz.

File metadata

  • Download URL: opensimplex-loops-0.1.3.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for opensimplex-loops-0.1.3.tar.gz
Algorithm Hash digest
SHA256 52c96d568bbe07c8b731fdd0f879075106060972364567100bc37336d9beb500
MD5 b5b0a5a57cb86d4ddfc3b849bd3dbf7c
BLAKE2b-256 f8c3b5fa618320e3ac901f1c3b273701acb827771242e06c94ec8fef1c7b5c02

See more details on using hashes here.

File details

Details for the file opensimplex_loops-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for opensimplex_loops-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 89fa72236b930fd2cd21bc3285a16f892b9b8bea01942bd3031f520fad970c73
MD5 a2261509c95a59591756f147c10befa1
BLAKE2b-256 d76fd8534e63aac8772e056561da21cc0e0cb7afb7f70abcd7657363d8c65f0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page