From 621741b0469ee3a700031109682dc4a581d54fa2 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Thu, 17 Sep 2015 02:27:11 +0200 Subject: [PATCH] Added some example animations hacked together in python. --- README.md | 21 ++++++++++ animations/fullwhite.py | 46 +++++++++++++++++++++ animations/gradient.py | 44 ++++++++++++++++++++ animations/matrix.py | 85 ++++++++++++++++++++++++++++++++++++++ animations/randomvalues.py | 5 +++ 5 files changed, 201 insertions(+) create mode 100644 animations/fullwhite.py create mode 100644 animations/gradient.py create mode 100644 animations/matrix.py create mode 100644 animations/randomvalues.py diff --git a/README.md b/README.md index e572063..c6b6add 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/animations/fullwhite.py b/animations/fullwhite.py new file mode 100644 index 0000000..1c1a967 --- /dev/null +++ b/animations/fullwhite.py @@ -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() diff --git a/animations/gradient.py b/animations/gradient.py new file mode 100644 index 0000000..225a23b --- /dev/null +++ b/animations/gradient.py @@ -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() diff --git a/animations/matrix.py b/animations/matrix.py new file mode 100644 index 0000000..c81cfc9 --- /dev/null +++ b/animations/matrix.py @@ -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) diff --git a/animations/randomvalues.py b/animations/randomvalues.py new file mode 100644 index 0000000..57ab1c4 --- /dev/null +++ b/animations/randomvalues.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python2 +import random + +for chan in range(0,512): + print "%d : %d" % (chan, random.randint(0,255))