Added various animation scripts

This commit is contained in:
Thomas Kolb 2019-12-01 14:21:01 +01:00
parent 8e72cce8cc
commit 1d25136d95
11 changed files with 570 additions and 25 deletions

36
fader.py Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
import sk6812
import time
import random
s = sk6812.SK6812("zybot", 2703)
s.set_fadestep(10)
colorcycle = [
(255, 0, 0, 0),
(0, 255, 0, 0),
(0, 0, 255, 0),
(0, 0, 0, 255),
(255, 0, 0, 255),
(0, 255, 0, 255),
(0, 0, 255, 255),
(255, 255, 255, 255),
]
k = 0
while True:
r = colorcycle[k][0]
g = colorcycle[k][1]
b = colorcycle[k][2]
w = colorcycle[k][3]
for i in range(300):
s.fade_color(i, r, g, b, w)
s.commit()
time.sleep(0.01)
k = (k + 1) % len(colorcycle)
time.sleep(1)

56
fireworks.py Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env python3
import sk6812
import time
from random import randint
class Rocket:
def __init__(self, sk, color = [0,0,0,255], alt = 100, size = 10):
self.sk = sk
self.color = color
self.alt = alt
self.size = size
self.pos = 0
self.dist = 0
def draw(self):
if self.pos < self.alt:
# launching
self.sk.add_color(self.pos, 64, 32, 0, 0)
self.sk.add_color(self.pos+1, 64, 32, 0, 0)
self.pos += 2
elif self.dist < self.size:
# exploded
self.sk.set_color(self.alt, 0, 0, 0, 255)
self.sk.add_color(self.alt + self.dist, self.color[0], self.color[1], self.color[2], self.color[3])
self.sk.add_color(self.alt - self.dist, self.color[0], self.color[1], self.color[2], self.color[3])
self.dist += 1
num_modules = 300
interval = 0.05
w = sk6812.SK6812("zybot", 2703)
w.set_fadestep(1.00/interval)
w.set_num_modules(num_modules)
rockets = []
frame = 0
while True:
if frame % 30 == 0:
rockets.append(Rocket(w, [randint(0, 255), randint(0, 255), randint(0, 255), randint(0, 255)], randint(50, 249), randint(10, 50)))
for r in rockets:
r.draw()
for i in range(num_modules):
w.fade_color(i, 0, 0, 0, 0)
w.commit()
frame += 1
time.sleep(interval)

42
hsv_fade.py Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env python
import sk6812_multistrip as sk6812
import time
import math
import sys
import random
from hsv2rgbw import hsv2rgbw
import numpy as np
sk = sk6812.SK6812(sys.argv[1], 2703)
sk.set_fadestep(10)
interval = 1/30
nled = 16
nstrip = 8
h = 0
s = 192
v = 255
loop = 0
while True:
v = (loop // 30) % 255
# update colors
for led in range(nled):
for strip in range(nstrip):
color = hsv2rgbw(h + 360 * strip//nstrip, s, v)
color = color * 50 // 100
sk.set_color(strip, led, color[0], color[1], color[2], color[3])
sk.commit()
loop += 1
time.sleep(interval)

View file

@ -1,41 +1,44 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import ws2801
import sk6812
import time
num_modules = 20
num_modules = 300
interval = 0.1
interval = 0.05
w = ws2801.WS2801("192.168.23.222", 2703)
w.set_fadestep(1.0/interval)
w = sk6812.SK6812("zybot", 2703)
w.set_fadestep(0.05/interval)
w.set_num_modules(num_modules)
# dictionary which maps {module: [r, g, b]}
set_colors = {}
curModule = [0, 0, 0]
speed = [0.49, 0.65, 1]
curModule = [0, 0, 0, 0]
speed = [0.49, 0.65, 1, 0.81]
#countUp = [True, True, False]
while True:
set_colors = {}
set_colors[int(curModule[0])] = [0, 0, 0]
set_colors[int(curModule[1])] = [0, 0, 0]
set_colors[num_modules-1-int(curModule[2])] = [0, 0, 0]
set_colors[int(curModule[0])] = [0, 0, 0, 0]
set_colors[int(curModule[1])] = [0, 0, 0, 0]
set_colors[num_modules-1-int(curModule[2])] = [0, 0, 0, 0]
set_colors[num_modules-1-int(curModule[3])] = [0, 0, 0, 0]
set_colors[int(curModule[0])][0] = 255
set_colors[int(curModule[1])][1] = 255
set_colors[num_modules-1-int(curModule[2])][2] = 255
set_colors[num_modules-1-int(curModule[3])][3] = 255
for k in set_colors.keys():
w.add_color(k, set_colors[k][0], set_colors[k][1], set_colors[k][2])
w.add_color(k, set_colors[k][0], set_colors[k][1], set_colors[k][2], set_colors[k][3])
for i in range(num_modules):
w.fade_color(i, 0, 0, 0)
w.fade_color(i, 0, 0, 0, 0)
w.commit()
for i in range(3):
for i in range(4):
curModule[i] += speed[i]
if curModule[i] >= num_modules:
curModule[i] -= num_modules

52
knightrider_multistrip.py Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env python3
import sk6812_multistrip as sk6812
import time
num_modules = 16
interval = 1/60
w = sk6812.SK6812("192.168.42.1", 2703)
w.set_fadestep(0.20/interval)
#w.set_num_modules(num_modules)
# dictionary which maps {module: [r, g, b]}
set_colors = {}
curModule = [0, 0, 0, 0]
#speed = [0.49, 0.65, 1, 0.81]
speed = [0.24, 0.31, 0.5, 0.41]
#countUp = [True, True, False]
brightness = 32
strip = 0
while True:
set_colors = {}
set_colors[int(curModule[0])] = [0, 0, 0, 0]
set_colors[int(curModule[1])] = [0, 0, 0, 0]
set_colors[num_modules-1-int(curModule[2])] = [0, 0, 0, 0]
set_colors[num_modules-1-int(curModule[3])] = [0, 0, 0, 0]
set_colors[int(curModule[0])][0] = brightness
set_colors[int(curModule[1])][1] = brightness
set_colors[num_modules-1-int(curModule[2])][2] = brightness
set_colors[num_modules-1-int(curModule[3])][3] = brightness
for strip in range(8):
for k in set_colors.keys():
w.add_color(strip, k, set_colors[k][0], set_colors[k][1], set_colors[k][2], set_colors[k][3])
for i in range(num_modules):
w.fade_color(strip, i, 0, 0, 0, 0)
w.commit()
for i in range(4):
curModule[i] += speed[i]
if curModule[i] >= num_modules:
curModule[i] -= num_modules
time.sleep(interval)

View file

@ -1,23 +1,24 @@
#!/usr/bin/env python
import ws2801
import sk6812
import time
import random
w = ws2801.WS2801("192.168.23.222", 2703)
w.set_fadestep(2)
s = sk6812.SK6812("zybot", 2703)
s.set_fadestep(2)
# dictionary which maps {module: [r, g, b]}
set_colors = {}
while True:
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
r = random.randint(0, 254)
g = random.randint(0, 254)
b = random.randint(0, 254)
w = random.randint(0, 254)
for i in range(20):
w.fade_color(i, r, g, b)
w.commit()
time.sleep(0.1)
for i in range(300):
s.fade_color(i, r, g, b, w)
s.commit()
time.sleep(0.01)
time.sleep(120)
#time.sleep(120)

118
rgbw_flame.py Executable file
View file

@ -0,0 +1,118 @@
#!/usr/bin/env python
import sk6812_multistrip as sk6812
import time
import math
import sys
import random
import numpy as np
s = sk6812.SK6812(sys.argv[1], 2703)
s.set_fadestep(10)
phase = 0
nled = 16
nstrip = 8
interval = 1.0/30
scale = 0.15
strip = 0
tiltphase = 0
ENERGY_MULT = 92
ENERGY_DIV = 100
MAXENERGY_ADD = 160
ENERGY_SUB = 7
ENERGY_PULL_MAX_PCT = 100
energy = np.zeros( (nled+1, nstrip), dtype=int )
energy_smooth = np.zeros( energy.shape, dtype=int )
COLORMAP_X = [ 0, 70, 120, 200, 225, 255]
COLORMAP_Y = [(0, 0, 0, 0), (128, 0, 0, 0), (192, 64, 0, 0), (255, 128, 0, 0), (255, 128, 0, 20), (255, 128, 0, 40)]
def colormap(x):
i = 0
while i < len(COLORMAP_X)-1 and COLORMAP_X[i+1] < x:
i += 1
if i >= len(COLORMAP_X)-1:
return np.array(COLORMAP_Y[len(COLORMAP_Y)-1])
start_x = COLORMAP_X[i]
end_x = COLORMAP_X[i+1]
start_col = np.array(COLORMAP_Y[i], dtype=int)
end_col = np.array(COLORMAP_Y[i+1], dtype=int)
col = (x - start_x) * 100 // (end_x - start_x) * (end_col - start_col) // 100 + start_col
return col
loop = 0
intensity = MAXENERGY_ADD
while True:
if loop % 5 == 0:
intensity = random.randint(MAXENERGY_ADD*3//4, MAXENERGY_ADD*5//4)
# inject random energy in bottom row
for i in range(nstrip):
energy[0, i] += random.randint(0, intensity)
# pull energy from the cell below
for led in range(nled, 0, -1):
for strip in range(nstrip):
wanted_energy = random.randint(0, ENERGY_PULL_MAX_PCT) * energy[led-1, strip] // 100
pulled_energy = min(wanted_energy, energy[led-1, strip])
energy[led, strip] += pulled_energy
energy[led-1, strip] -= pulled_energy
# decrease global amount of energy
for led in range(nled+1):
for strip in range(nstrip):
#energy[led, strip] *= ENERGY_MULT
#energy[led, strip] //= ENERGY_DIV
energy[led, strip] -= min(ENERGY_SUB, energy[led, strip])
# smooth the energy distribution
for led in range(nled):
for strip in range(nstrip):
strip_left = (strip + nstrip - 1) % nstrip
strip_right = (strip + nstrip + 1) % nstrip
led_above = led + 1
led_below = led - 1
energy_smooth[led, strip] = 100 * energy[led, strip]
energy_smooth[led, strip] += 30 * energy[led, strip_left]
energy_smooth[led, strip] += 30 * energy[led, strip_right]
gain = 160
if led_above < nled:
energy_smooth[led, strip] += 10 * energy[led_above, strip]
gain += 10
if led_below >= 0:
energy_smooth[led, strip] += 10 * energy[led_below, strip]
gain += 10
energy_smooth[led, strip] //= gain
# update colors
for led in range(nled):
for strip in range(nstrip):
color = colormap(energy_smooth[led, strip])**2//255
s.fade_color(strip, led, color[0], color[1], color[2], color[3])
s.commit()
loop += 1
time.sleep(interval)

131
rgbw_hsv_flame.py Executable file
View file

@ -0,0 +1,131 @@
#!/usr/bin/env python
import sk6812_multistrip as sk6812
import time
import math
import sys
import random
from hsv2rgbw import hsv2rgbw
import numpy as np
s = sk6812.SK6812(sys.argv[1], 2703)
s.set_fadestep(10)
phase = 0
nled = 16
nstrip = 8
interval = 1.0/30
scale = 0.15
strip = 0
tiltphase = 0
ENERGY_MULT = 92
ENERGY_DIV = 100
MAXENERGY_ADD = 160
ENERGY_SUB = 7
ENERGY_PULL_MAX_PCT = 100
HIGHLIGHT_OFFSET = -60
energy = np.zeros( (nled+1, nstrip), dtype=int )
energy_smooth = np.zeros( energy.shape, dtype=int )
COLORMAP_X = [ 0, 70, 120, 200, 225, 255]
COLORMAP_Y = [
(0, 255, 0),
(0, 255, 128),
(0, 255, 192),
(0, 192, 192),
(0, 128, 255),
(0, 128, 300)]
def colormap(x, h):
i = 0
while i < len(COLORMAP_X)-1 and COLORMAP_X[i+1] < x:
i += 1
if i >= len(COLORMAP_X)-1:
return hsv2rgbw(*COLORMAP_Y[len(COLORMAP_Y)-1])
start_x = COLORMAP_X[i]
end_x = COLORMAP_X[i+1]
start_col = np.array(COLORMAP_Y[i], dtype=int)
end_col = np.array(COLORMAP_Y[i+1], dtype=int)
col = (x - start_x) * 100 // (end_x - start_x) * (end_col - start_col) // 100 + start_col
col[0] = (col[0] + h + 360) % 360
return hsv2rgbw(*col)
loop = 0
intensity = MAXENERGY_ADD
while True:
if loop % 5 == 0:
intensity = random.randint(MAXENERGY_ADD*3//4, MAXENERGY_ADD*5//4)
# inject random energy in bottom row
for i in range(nstrip):
energy[0, i] += random.randint(0, intensity)
# pull energy from the cell below
for led in range(nled, 0, -1):
for strip in range(nstrip):
wanted_energy = random.randint(0, ENERGY_PULL_MAX_PCT) * energy[led-1, strip] // 100
pulled_energy = min(wanted_energy, energy[led-1, strip])
energy[led, strip] += pulled_energy
energy[led-1, strip] -= pulled_energy
# decrease global amount of energy
for led in range(nled+1):
for strip in range(nstrip):
#energy[led, strip] *= ENERGY_MULT
#energy[led, strip] //= ENERGY_DIV
energy[led, strip] -= min(ENERGY_SUB, energy[led, strip])
# smooth the energy distribution
for led in range(nled):
for strip in range(nstrip):
strip_left = (strip + nstrip - 1) % nstrip
strip_right = (strip + nstrip + 1) % nstrip
led_above = led + 1
led_below = led - 1
energy_smooth[led, strip] = 100 * energy[led, strip]
energy_smooth[led, strip] += 30 * energy[led, strip_left]
energy_smooth[led, strip] += 30 * energy[led, strip_right]
gain = 160
if led_above < nled:
energy_smooth[led, strip] += 10 * energy[led_above, strip]
gain += 10
if led_below >= 0:
energy_smooth[led, strip] += 10 * energy[led_below, strip]
gain += 10
energy_smooth[led, strip] //= gain
# update colors
for led in range(nled):
for strip in range(nstrip):
color = colormap(energy_smooth[led, strip], (loop // 20) % 360)**2//255
s.fade_color(strip, led, color[0], color[1], color[2], color[3])
s.commit()
loop += 1
time.sleep(interval)

39
rgbw_prime_sinus.py Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
import sk6812_multistrip as sk6812
import time
import math
import sys
s = sk6812.SK6812(sys.argv[1], 2703)
phase = 0
nled = 16
nstrip = 8
interval = 1.0/60
scale = 0.15
strip = 0
tiltphase = 0
while True:
for i in range(nled):
for strip in range(nstrip):
x = 2*math.pi * i / nled
y = 2*math.pi * strip * 2*math.sin(tiltphase) / nstrip
r = scale * (127 + 127 * math.sin(y + x + 13*phase + 0 * math.pi/2))
g = scale * (127 + 127 * math.sin(y + x + 23*phase + 1 * math.pi/2))
b = scale * (127 + 127 * math.sin(y + x + 42*phase + 2 * math.pi/2))
w = scale * 0.6 * (127 + 127 * math.sin(y + x + 5*phase + 3 * math.pi/2))
s.set_color((strip+5)%nstrip, i, r, g, b, w)
s.commit()
phase += 2*math.pi * interval / 41
tiltphase += 2*math.pi * interval / 11
time.sleep(interval)

34
rgbw_sinus.py Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env python
import sk6812_multistrip as sk6812
import time
import math
s = sk6812.SK6812("192.168.42.1", 2703)
phase = 0
nled = 16
nstrip = 8
interval = 1.0/60
scale = 0.1
strip = 0
while True:
for i in range(nled):
x = 2*math.pi * i / nled
r = scale * (127 + 127 * math.sin(x + 8*phase + 0 * math.pi/2))
g = scale * (127 + 127 * math.sin(x + 4*phase + 1 * math.pi/2))
b = scale * (127 + 127 * math.sin(x + 2*phase + 2 * math.pi/2))
w = scale * (127 + 127 * math.sin(x + 1*phase + 3 * math.pi/2))
for strip in range(nstrip):
s.set_color(strip, i, r, g, b, w)
s.commit()
phase += 2*math.pi * interval / 10
time.sleep(interval)

33
rundumleuchte.py Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import sk6812_multistrip as sk6812
import time
import math
num_modules = 16
num_strips = 8
interval = 1/30
w = sk6812.SK6812("10.42.7.145", 2703)
w.set_fadestep(0.80/interval)
color = [255, 0, 255, 0]
cur_strip = 0
while True:
for k in range(num_modules):
f = math.sin(math.pi * k / num_modules)
w.add_color(cur_strip, k, f*color[0], f*color[1], f*color[2], f*color[3])
for strip in range(8):
for i in range(num_modules):
w.fade_color(strip, i, 0, 0, 0, 0)
w.commit()
cur_strip += 1
cur_strip %= num_strips
time.sleep(interval)