Added some example animations hacked together in python.

This commit is contained in:
Sebastian 2015-09-17 02:27:11 +02:00
parent 3d78da51b2
commit 621741b046
5 changed files with 201 additions and 0 deletions

View File

@ -34,3 +34,24 @@ being able to override it you have to set it to 0 in every packet you send.
It is also a good Idea to send an empty packet (newline directly followed by a EOF)
before killing the client, as it will clear any leftover reserved channels
for your priority level.
Example Animations
------------------
Some example animations can be found in the animation folder.
They can be connected to a twinkle-client process using a pipe.
* `randomvalues.py` Sets all channels to a random value and quits
* `fullwhite.py` Set the lightwall to full white (use *lightwall.lan* as host) and quits
* `gradient.py` Displays a red/green gradient on the lightwall and quits
* `matrix.py` Matrix animation for the lightwall (use *lightwall.lan* as host)
**Examples:**
```
python2 fullwithe.py | ../bin/twinkl-client lightwall.lan 7
python2 gradient.py | ../bin/twinkl-client lightwall.lan 7
python2 matrix.py | ../bin/twinkl-client lightwall.lan 7
python2 random.py | ../bin/twinkl-client ampel.lan 7
```

46
animations/fullwhite.py Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python2
from random import randint
from time import sleep
from subprocess import Popen, PIPE
HEIGHT = 8
WIDTH = 6
# As viewn from the inside
BOX_MAP = [
[357, 18, 369, 186, 249, 228, 51],
[279, 10, 57, 159, 300, 108, 204],
[261, 42, 183, 201, 273, 246, 15],
[306, 168, 24, 138, 309, 165, 39],
[258, 222, 87, 363, 291, 231, 243],
[252, 114, 180, 75, 282, 141, 033],
[264, 288, 120, 135, 255, 99, 105],
[285, 207, 102, 45, 297, 216, 63],
]
channels = {}
def set_box(x,y,r,g,b):
if x >= 0 and y >= 0 and x < WIDTH and y < HEIGHT:
base_address = BOX_MAP[y][x]
channels[base_address] = r
channels[base_address + 1] = g
channels[base_address + 2] = b
def output_channels():
for channel, value in channels.items():
print "%d : %d" % (channel, value)
print ""
for x in range(0, WIDTH):
for y in range(0, HEIGHT):
set_box(x,y, 255, 255, 255)
output_channels()

44
animations/gradient.py Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python2
from random import randint
from time import sleep
from subprocess import Popen, PIPE
HEIGHT = 8
WIDTH = 6
# As viewn from the inside
BOX_MAP = [
[357, 18, 369, 186, 249, 228, 51],
[279, 9, 57, 159, 300, 108, 204],
[261, 42, 183, 201, 273, 246, 15],
[306, 168, 24, 138, 309, 165, 39],
[258, 222, 87, 363, 291, 231, 243],
[252, 114, 180, 75, 282, 141, 033],
[264, 288, 120, 135, 255, 99, 105],
[285, 207, 102, 45, 297, 216, 63],
]
channels = {}
def set_box(x,y,r,g,b):
if x >= 0 and y >= 0 and x < WIDTH and y < HEIGHT:
base_address = BOX_MAP[y][x]
channels[base_address] = r
channels[base_address + 1] = g
channels[base_address + 2] = b
def output_channels():
for channel, value in channels.items():
print "%d : %d" % (channel, value)
print ""
for x in range(0, WIDTH):
for y in range(0, HEIGHT):
set_box(x,y, 100 + (155 / WIDTH) * (x + 1), 100 + (155 / HEIGHT) * (y + 1), 0)
output_channels()

85
animations/matrix.py Normal file
View File

@ -0,0 +1,85 @@
#!/usr/bin/env python2
from random import randint
from time import sleep
from subprocess import Popen, PIPE
WIDTH = 6
HEIGHT = 8
# As viewn from the inside
BOX_MAP = [
[357, 18, 369, 186, 249, 228, 51],
[279, 9, 57, 159, 300, 108, 204],
[261, 42, 183, 201, 273, 246, 15],
[306, 168, 24, 138, 309, 165, 39],
[258, 222, 87, 363, 291, 231, 243],
[252, 114, 180, 75, 282, 141, 33],
[264, 288, 120, 135, 255, 99, 105],
[285, 207, 102, 45, 297, 216, 63],
]
channels = {}
def set_box(x,y,r,g,b):
if x >= 0 and y >= 0 and x < WIDTH and y < HEIGHT:
base_address = BOX_MAP[y][x]
channels[base_address] = r
channels[base_address + 1] = g
channels[base_address + 2] = b
def output_channels():
for channel, value in channels.items():
print "%d : %d" % (channel, value)
print ""
def clear():
for x in range(0, WIDTH):
for y in range(0, HEIGHT):
set_box(x, y, 0, 0, 0)
class Collumn(object):
def __init__(self):
self.x = randint(0, WIDTH)
self.y = randint(-HEIGHT/2, -1)
self.speed = randint(1, 10)
self.length = randint(4, HEIGHT)
self.count = 0
def render(self):
for y in range(self.y - self.length, self.y):
green = 255 - (255.0 / self.length) * (self.y - y)
set_box(self.x, y, 0, green, 0)
set_box(self.x, self.y, 64, 255, 64)
def update(self):
self.count = (self.count + 1) % self.speed
if(self.count == 0):
self.y += 1
collumns = []
# Add some initial collums
for i in range(0, 16):
collumns.append(Collumn())
while(True):
clear();
collumns = sorted(collumns, key = lambda c: -c.y)
for i in range(0,len(collumns)):
if collumns[i].y - collumns[i].length > HEIGHT:
collumns[i] = Collumn()
collumns[i].update()
collumns[i].render()
output_channels()
sleep(0.050)

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python2
import random
for chan in range(0,512):
print "%d : %d" % (chan, random.randint(0,255))