Animation Queue Example

Tom Ritchford edited this page May 13, 2017 · 4 revisions

Most situations call for more than one animation and the ability to control what order the animations run in, for how long, how fast, etc. While you can certainly just add one animation after another in your code, sometimes it's better to have a single point of control. This is where AnimationQueue comes in. Below is a basic example of controlling three animations in a queue:

#import base classes and driver
from bibliopixel import *
from bibliopixel.drivers.visualizer import Visualizer

#import AnimationQueue
from bibliopixel.animation import AnimationQueue

#import animations
from BiblioPixelAnimations.matrix.bloom import Bloom
from BiblioPixelAnimations.matrix.GameOfLife import GameOfLife
from BiblioPixelAnimations.matrix.pinwheel import Pinwheel

#load driver and controller and animation queue
driver = Visualizer(width=10, height=10, stayTop=True)
led = Matrix(driver)
anim = AnimationQueue(led)

#Load animations into Queue
bloom = Bloom(led)
#run at 15fps, for 10 seconds
anim.addAnim(bloom, amt=6, fps=15, max_steps=150)

gol = GameOfLife(led)
#run at queue default framerate, until simulation completes twice
anim.addAnim(gol, fps=None, untilComplete=True, max_cycles=2)

pin = Pinwheel(led)
#run at queue default framerate for 300 steps
anim.addAnim(pin, amt=4, fps=None, max_steps=300)

#run animations at default 30fps

Download Example

Queued animations can either be given an explicit framerate or use a global framerate set on the queue by leaving the fps parameter as None. When the AnimationQueue is run, it will loop unless untilComplete is set to True. If it is stopped and restarted later, it will always start at the beginning of the queue, not where it left off.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.