Skip to main content

An API to animate the Simon fractal

Project description

Attractor Tools

Attractor-tools is a Python module for animating the Simon fractal using efficient rendering. It provides a clean API to generate frames, assinging colormaps, and export visualizations as videos.


✨ Features

  • Animate the Simon fractal with customizable parameters
  • NumPy, Numba and Multiprocessing for performance
  • Automate Parameters using interpolation between a set of points

Example:

alt text

📦 Installation

pip install attractor-tools

Example usage

from attractor import sinspace, Performance_Renderer, ColorMap

def main():
    # array with values from lower to upper using a sinewave (p=1)
    # a, b are the initial values of the system used in the attractor
    # To animate this effectively, at least one of these parameters should change each frame
    a = sinspace(0.32, 0.38, 100)

    # Main rendering class
    # Use this when rendering a video with multiple frames.
    # For single-frame rendering, this class is overkill — use 'render_frame(...)' instead.
    renderer = Performance_Renderer(
        a=a,
        b=1.5,
        colormap=ColorMap("viridis"),
        frames=len(a),
        fps=10
    )

    # Important: 'a' is an array of values, one per frame (a[i] used for frame i)
    # So we need to mark it as non-static to allow per-frame variation
    renderer.set_static("a", False)

    # Set how many processes/threads to use (via multiprocessing.Pool)
    # Use None for unlimited; here we use 4 threads with a chunk size of 4
    renderer.start_render_process("./your_filename.mp4", threads=4, chunksize=4)

if __name__ == "__main__":
    # see all colormaps available
    print(ColorMap.colormaps())
    main()

Automations

def keyframe_example():
    # generic animation option (20 frames)
    opts = Option.from_time(
        seconds=4,
        fps=5
    )

    # KeyframeInterpolator is similar to linspace, sinspace, sqaurespace, ...
    # The difference you can define a set of point: point(value, frame)
    # between this points linspace is used to interpolate between those
    interpolation = KeyframeInterpolator(opts, 0.32, 0.32)
    interpolation.add_keyframe(Point(frame=5, value=0.4))
    interpolation.add_keyframe(Point(frame=10, value=0.4))
    interpolation.add_keyframe(Point(frame=15, value=0.32))

    a = interpolation.to_array()

    renderer = Performance_Renderer(
        opts=opts,
        a=a,
        b=1.5,
        iterations=3_000_000
    )
    renderer.set_static("a", False)
    renderer.show_demo(nth_frame=1)

Generic mp4

def generic_example():
    opts = Option.from_time(
        seconds=4,
        fps=5
    )

    renderer = Performance_Renderer(
        opts=opts,
        a=0.35,
        b=1.5,
        iterations=3_000_000
    )  
    # Set generic flag to save image in grayscale
    renderer.start_render_process("demo.mp4", save_as_generic=True)

    # after rendering you can apply a colormap (still takes some time)
    # make sure to use the same fps and frames as the rendering
    color_generic("demo.mp4", ColorMap("viridis"), opts.fps, frames=opts.frames)

Project details


Download files

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

Source Distribution

attractor_tools-0.2.1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

attractor_tools-0.2.1-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file attractor_tools-0.2.1.tar.gz.

File metadata

  • Download URL: attractor_tools-0.2.1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for attractor_tools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 300e71a0bd44b37c96a58c7a5d3271cf118e4afaa4dbc9bf567edcc066bb5cb2
MD5 66cbd2fd11b7d18006bb3066b26201a7
BLAKE2b-256 b1d89a38626b252708869d50afc519de8a148a8cb72cfe4424a0770dc331f618

See more details on using hashes here.

File details

Details for the file attractor_tools-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for attractor_tools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8925a9796a1b16fee35150f92a9e7ec8a679c346a1407c4758925c0af864c19
MD5 95078fb379265bc933b873689a44fec8
BLAKE2b-256 70db392dc3ec1c38fa3bf61530382b11abcbdf177e7d13eb60040536b2352b33

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 Pingdom Monitoring Sentry Error logging StatusPage Status page