Skip to content

Instantly share code, notes, and snippets.

@Phyks
Created June 3, 2014 17:43
Show Gist options
  • Save Phyks/80c3e814d818568c1757 to your computer and use it in GitHub Desktop.
Save Phyks/80c3e814d818568c1757 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# -*- coding: utf8 -*-
# -----------------------------------------------------------------------------
# "THE NO-ALCOHOL BEER-WARE LICENSE" (Revision 42):
# Phyks (webmaster@phyks.me) wrote or updated these files for hackEns. As long
# as you retain this notice you can do whatever you want with this stuff
# (and you can also do whatever you want with this stuff without retaining it,
# but that's not cool...).
#
# If we meet some day, and you think this stuff is worth it, you can buy us a
# <del>beer</del> soda in return.
# Phyks for hackEns
# -----------------------------------------------------------------------------
#
# This is a script to test animation and fading
# Usage: Edit the parameters section to fit your needs
import colors
import math
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation
from predefined_colors import *
if __name__ == '__main__':
# Parameters
start_color = rose
end_color = black
nb_leds = 9
duration = 3
end_color_duration = 2
filename = "output.mp4"
# End
iterations = 25 * duration
size = int(math.sqrt(nb_leds) * 10 + (math.sqrt(nb_leds) - 1) * 2)
fading = colors.fading(start_color, end_color, iterations)
images = [np.zeros((size, size, 3), np.uint8) for _ in
range(iterations+end_color_duration * 25)]
fading.extend([end_color for _ in range(end_color_duration * 25)])
count = 0
for img in range(len(images)):
for k in range(int(math.sqrt(nb_leds))):
for l in range(int(math.sqrt(nb_leds))):
for i in range(10):
for j in range(10):
images[img][i + k*12, j + l*12] = (fading[count]['r'],
fading[count]['g'],
fading[count]['b'])
count += 1
fig = plt.figure()
im = plt.imshow(images[0], interpolation='nearest')
def animate(i):
im.set_array(images[i])
return im,
anim = animation.FuncAnimation(fig, animate, frames=(duration+
end_color_duration) * 25,
interval=1000/25,
blit=True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment