Skip to content

Provides a function to write a NumPy array to a GIF, or a list of arrays to an animated GIF.

License

Notifications You must be signed in to change notification settings

PVirie/array2gif

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Array2GIF: convert NumPy arrays to (animated) GIF

Animation of random pixels converging from two colors to one color. T = 0.7 T_c. T = 0.7 T_c Animation of random pixels converging less slowly to one color. T = 0.88 T_c. T = 0.88 T_c Animation of random pixels staying mostly random. T = 1.06 T_c. T = 1.06 T_c

Array2GIF provides a single top-level function, write_gif(), to write a 3-D NumPy array to a GIF, or a list of these arrays to an animated GIF. It works for me - just small animations of thermodynamics simulations - like the magnetization in the Ising model shown here.

Usage

Here is an example for a 2 pixel by 3 pixel animated GIF with two frames, switching 5 frames per second. All animations from this library will loop indefinitely.

import numpy as np
from array2gif import write_gif

dataset = [
    np.array([
        [[255, 0, 0], [255, 0, 0]],  # red intensities
        [[0, 255, 0], [0, 255, 0]],  # green intensities
        [[0, 0, 255], [0, 0, 255]]   # blue intensities
    ]),
    np.array([
        [[0, 0, 255], [0, 0, 255]],
        [[0, 255, 0], [0, 255, 0]],
        [[255, 0, 0], [255, 0, 0]]
    ])
]
write_gif(dataset, 'rgbbgr.gif', fps=5)

# or for just a still GIF
write_gif(dataset[0], 'rgb.gif')

Installation

Either:

pip install array2gif

or:

sudo pip install git+https://github.com/pvirie/array2gif.git#egg=array2gif

to upgrade:

sudo pip install --upgrade git+https://github.com/pvirie/array2gif.git#egg=array2gif

About

Provides a function to write a NumPy array to a GIF, or a list of arrays to an animated GIF.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%