Created
September 30, 2019 23:02
-
-
Save PFython/77950bc4bb8af1d3d41ee6ef7797b813 to your computer and use it in GitHub Desktop.
Simple visual effects for python-elgato-streamdeck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def slideshow(cycles=3, interval=5): | |
#TODO: Make non blocking so that effect continues to cycle in parallel | |
for cycle in range(cycles): | |
for source in IMAGES: | |
image = create_full_deck_sized_image(deck, source) | |
for k in range(deck.key_count()): | |
key_image = crop_key_image_from_deck_sized_image(deck, image, k) | |
deck.set_key_image(k, key_image) | |
time.sleep(interval) | |
def shuffle(cycles=1000, interval=3): | |
#TODO: Make non blocking so that effect continues to cycle in parallel | |
#TODO: This runs slowly and is inefficient because images are recomputed | |
# each time. Improve using cache (e.g. @functools.lru_cache decorator) | |
# or write a separate initialiser to convert images to button images once only. | |
for cycle in range(cycles): | |
k= randint(0,deck.key_count()) | |
image = create_full_deck_sized_image(deck, IMAGES[randint(0,len(IMAGES)-1)]) | |
key_image = crop_key_image_from_deck_sized_image(deck, image, k) | |
deck.set_key_image(k, key_image) | |
time.sleep(randint(0,interval)) | |
def pulse(cycles=3,interval=0.02): | |
#TODO: Make non blocking so that effect continues to cycle in parallel | |
for centisecond in range(cycles * 100 * 2): | |
brightness = (1 - (math.cos((centisecond / 200) *2 * math.pi))) * 100/2 | |
deck.set_brightness(int(brightness)) | |
time.sleep(interval) | |
# for cycle in range(cycles): | |
# for a in numpy.arange(0, math.pi, math.pi / 200.0): | |
# brightness = int(math.sin(a)*100) | |
# deck.set_brightness(brightness) | |
# time.sleep(interval) | |
def flicker(cycles=200,interval=0.1): | |
#TODO: Make non blocking so that effect continues to cycle in parallel | |
for cycle in range(cycles): | |
deck.set_brightness(randint(0,100)) | |
time.sleep(randint(0,100)*interval/100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment