Commit 5c2886f8 authored by Christian Wander's avatar Christian Wander
Browse files

move the function into a class an use them

parent 55ad95d1
def pretty_print(thing, w, h):
PINK = (255, 0, 255)
n = 0
class Thing:
def __init__(self, matrix):
self.matrix = matrix
for i in thing:
def console_print(self):
for line in self.matrix:
for item in line:
print("{0:3d}".format(sum(item)), end='')
print()
def snake_tuple(self):
"""Returns a tuple, where where the pixels in every 2nd line are in reverse order.
n += 1
print(i, end='')
"""
tmp = self.snakify()
return self.tuplify(tmp)
if n == w * 3:
print()
n = 0
def console_print(thing):
def snakify(self):
"""Returns the snakified strip
Expects a 2dim array of tuples!!1
"""
result = []
line_no = 0
for line in self.matrix:
for line in thing:
for item in line:
print("{0:3d}".format(sum(item)), end='')
print()
if line_no % 2 == 0:
# even line number? append normally
result.append(line)
else:
# odd line number? append the line reversed!
result.append(line[::-1])
line_no += 1
def snakify(thing):
"""Returns the snakified strip
return result
Expects a 2dim array of tuples!!1
"""
result = []
line_no = 0
@staticmethod
def tuplify(matrix):
"""Returns one tuple with rgb values
for line in thing:
Expects a 2dim array of tuples!
"""
if line_no % 2 == 0:
# even line number? append normally
result.append(line)
else:
# odd line number? append the line reversed!
result.append(line[::-1])
line_no += 1
return result
result = []
for line in matrix:
for i in line:
for v in i:
result.append(v)
return tuple(result)
def from_heart(color = PINK):
return Thing(heart_tuple(color))
def heart_tuple(color):
......@@ -60,6 +82,7 @@ def heart_tuple(color):
[o, o, o, o, x, x, x, x, o, o, o, o], \
[o, o, o, o, o, x, x, o, o, o, o, o]]
def eck_tuple(color):
o = (0, 0, 0)
......@@ -79,49 +102,16 @@ def eck_tuple(color):
[x, x, x, x, x, x, x, x, x, x, x, x]]
def heart(color):
o = (0, 0, 0)
x = color
return o + x + x + x + x + o + o + x + x + x + x + o + \
x + x + x + x + x + x + x + x + x + x + x + x + \
x + x + x + x + x + x + x + x + x + x + x + x + \
x + x + x + x + x + x + x + x + x + x + x + x + \
x + x + x + x + x + x + x + x + x + x + x + x + \
x + x + x + x + x + x + x + x + x + x + x + x + \
o + x + x + x + x + x + x + x + x + x + x + o + \
o + x + x + x + x + x + x + x + x + x + x + o + \
o + o + x + x + x + x + x + x + x + x + o + o + \
o + o + o + x + x + x + x + x + x + o + o + o + \
o + o + o + o + x + x + x + x + o + o + o + o + \
o + o + o + o + o + x + x + o + o + o + o + o
def eck(color):
o = (0, 0, 0)
x = color
return x + o + o + o + o + o + o + o + o + o + o + o + \
x + x + o + o + o + o + o + o + o + o + o + o + \
x + x + x + o + o + o + o + o + o + o + o + o + \
x + x + x + x + o + o + o + o + o + o + o + o + \
x + x + x + x + x + o + o + o + o + o + o + o + \
x + x + x + x + x + x + o + o + o + o + o + o + \
x + x + x + x + x + x + x + o + o + o + o + o + \
x + x + x + x + x + x + x + x + o + o + o + o + \
x + x + x + x + x + x + x + x + x + o + o + o + \
x + x + x + x + x + x + x + x + x + x + o + o + \
x + x + x + x + x + x + x + x + x + x + x + o + \
x + x + x + x + x + x + x + x + x + x + x + x
if __name__ == "__main__":
print(">> blinktest")
color = (127, 127, 127)
print(">>")
console_print(snakify(eck_tuple(color)))
# print(">>")
# console_print(snakify(eck_tuple(color)))
# print(tuplify(eck_tuple(color)))
\ No newline at end of file
t = from_heart();
print(t.console_print())
print(t.snake_tuple())
......@@ -2,7 +2,7 @@ import sacn
import time
import json
from blink import eck, heart
import blink
count = 144
pink = (255, 0, 255)
......@@ -19,29 +19,24 @@ def main():
sender = sacn.sACNsender()
sender.start()
sender.activate_output(universe)
# sender[1].multicast = True
sender[universe].destination = "192.168.178.37"
# mode 4 Multiple RGB ('led0 red', 'led0 green', 'led0 blue', 'led1 red', ...)
# sender[universe].dmx_data = (255, 0, 255, 0, 255, 255, 0, 0, 255) ## some test DMX data
# sender[universe].dmx_data = gimme(pink)
# pink = (128, 128, 0, 128)
# sender[universe].dmx_data = (200, 0, 200)
colors = (pink, lightblue, blue)
while True:
for c in colors:
sender[universe].dmx_data = eck(c)
## sender[universe].dmx_data = blink.eck(c)
# eck = blink.tuplify(blink.snakify(blink.eck_tuple(c)))
t = blink.from_heart(c);
sender[universe].dmx_data = t.snake_tuple()
time.sleep(5)
# sender[universe].dmx_data = (5, 6, 7, 8)
## combining two tuples into one: (2, 4) + (5, 4) --> (2, 4, 5)
## stopping the sender?!
sender.stop()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment