Compare commits

..

25 Commits

Author SHA1 Message Date
informaniac 77cb3516ca gamemenu: fixed direction evaluation 7 years ago
informaniac 16e895e390 gamemenu now uses balance_util 7 years ago
informaniac b778375165 tetris: fixed socket connection 7 years ago
informaniac 90e1c5c9b8 tetris: fixed player event DOWN to DROP 7 years ago
informaniac b904fcc449 whitespace fix 7 years ago
informaniac c805f6c71b fixed string formatting arguments 7 years ago
informaniac 278f080e23 balancepong now calls the new get_player_ready function. also fixed function call for player 2 7 years ago
informaniac 397e4c323a renamed BalanceUtil._get_raw_data to _get_raw_player_data 7 years ago
informaniac 81de8409f2 balance_util is created and used to create the BalanceTtrsPlayer 7 years ago
informaniac 9bce3e7916 player information is now retrieved via balance_util 7 years ago
informaniac 8cb7470d22 added direction to event evaluation 7 years ago
informaniac ca848e9ba1 removed old balance to event evaluation 7 years ago
informaniac 5cad7825f3 removed old data retrival via socket 7 years ago
informaniac 1e974a74d6 moved creation of the socket into main function 7 years ago
informaniac a5ae8985ce added balance_util import 7 years ago
informaniac 29d0cfcb31 BalanceTtrsPlayer now is being created with a BalanceUtil instead of socket address and player id 7 years ago
informaniac 038f33df2c create BalanceBoardPlayer(s) with the respective balance_utils 7 years ago
informaniac 026f05c958 use the balance_util functions to determine if the player(s) are ready 7 years ago
informaniac 16c4dcc8d6 added balance_utils for player 1 and 2 7 years ago
informaniac 075e8c5c03 player information is now retrieved from the balance_util 7 years ago
informaniac e34f76b22d BalanceBoardPlayer now uses the balance_util for the y-axis data 7 years ago
informaniac 6da1b8cf13 BalanceBoardPlayer now needs a balance_util instead of the wiimote_socket and player_id 7 years ago
informaniac 9c2d3cb33a removed socket retrieval function 7 years ago
informaniac 2b0bde627f imported balance_util 7 years ago
informaniac 02cb0e8348 added blup balance util 7 years ago
  1. 16
      blup/output.py
  2. 87
      games/balancep0ng.py
  3. 2
      games/gamemenu.py
  4. 9
      games/pong.py
  5. 126
      generators/blobs.py
  6. 140
      generators/checkerboard.py
  7. 2
      generators/colormarq.py
  8. 2
      generators/colorwischer.py
  9. 107
      generators/curves.py
  10. 114
      generators/discs.py
  11. 141
      generators/dlines.py
  12. 150
      generators/faces.py
  13. 2
      generators/fire.py
  14. 30
      generators/fireworks.py
  15. 147
      generators/gameOfLife.py
  16. 121
      generators/lines.py
  17. 222
      generators/movingshapes.py
  18. 122
      generators/orbs.py
  19. 2
      generators/scroll.py
  20. 232
      generators/thimblerig.py
  21. 124
      generators/twister.py
  22. 133
      generators/unrath.py
  23. 2
      utils/blmplay.py
  24. 6
      utils/blphub.py
  25. 151
      utils/blpserver.py
  26. 31
      utils/miniplayer.py
  27. 26
      wii-pair/daemon.py

16
blup/output.py

@ -331,18 +331,17 @@ class BLPOutput(Output): @@ -331,18 +331,17 @@ class BLPOutput(Output):
#
class BlinkenbuntHDOutput(Output):
moduleRegexDesc = 'bbunthd:BRIGHTNESS[:GAMMA]'
moduleRegex = '^bbunthd:(?P<brightness>\d+)(:(?P<gamma>\d+(\.\d+)?))?$'
moduleRegexDesc = 'bbunthd[:BRIGHTNESS]'
moduleRegex = '^bbunthd(:(?P<brightness>\d+))?$'
def __init__(self, brightness, gamma=1):
def __init__(self, brightness):
import neopixel
self.w = 22
self.h = 16
self.gamma = gamma
LED_COUNT = self.w * self.h
LED_PIN = 13
LED_FREQ_HZ = 800000
LED_DMA = 10
LED_DMA = 5
LED_INVERT = False
LED_PWM = 1
@ -355,9 +354,8 @@ class BlinkenbuntHDOutput(Output): @@ -355,9 +354,8 @@ class BlinkenbuntHDOutput(Output):
@classmethod
def fromRegexMatch(cls, regexMatch):
b = int(regexMatch.group('brightness'))
g = float(regexMatch.group('gamma') or 1)
return cls(brightness=b, gamma=g)
b = int(regexMatch.groupdict().get('brightness', 50))
return cls(brightness=b)
def sendFrame(self, frame):
for y in range(self.h):
@ -367,7 +365,7 @@ class BlinkenbuntHDOutput(Output): @@ -367,7 +365,7 @@ class BlinkenbuntHDOutput(Output):
else:
lednum = x*self.h - y + 15
pix = frame.getPixel(self.w - x - 1, self.h - y - 1)
r, g, b = map(lambda c: round(((c/255)**self.gamma)*255), pix)
r, g, b = pix
self.strip.setPixelColor(lednum, self._color_cls(g, r, b))
self.strip.show()

87
games/balancep0ng.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
import time
import argparse
@ -91,8 +91,7 @@ class BalanceBoardPlayer(object): @@ -91,8 +91,7 @@ class BalanceBoardPlayer(object):
return true
def gametickcb(self):
# TODO: add CLI option to select axis
bal = self.__balance_util.get_raw_2dir_x()
bal = self.__balance_util.get_raw_2dir_y()
if bal == -128:
print("player %d has quit" % self.__balance_util.player_id)
@ -117,7 +116,7 @@ class BalanceBoardPlayer(object): @@ -117,7 +116,7 @@ class BalanceBoardPlayer(object):
class B4lancePong(object):
def __init__(self, out, balanceserver=None, color=True):
def __init__(self, out, balanceserver=None, color=True, numplayers=None):
self.__playground = None
self.__out = out
self.__color = color
@ -125,21 +124,13 @@ class B4lancePong(object): @@ -125,21 +124,13 @@ class B4lancePong(object):
self.__balanceserver = ('localhost', 4711)
else:
self.__balanceserver = balanceserver
self.__numplayers = numplayers
if color:
self.__dimension = blup.frame.FrameDimension(22, 16, 256, 3)
else:
self.__dimension = blup.frame.FrameDimension(18, 8, 2, 1)
def gametickcb(self):
for i, p in enumerate(self.__players):
if isinstance(p, pong.PongBot):
print('bot in game')
if (isinstance(p, pong.PongBot) and \
self.__bplayers[i].get_player_ready()):
print('second player joined, cancelling current game')
self.__playground.cancel()
def runGame(self):
print('starting a game...')
scoreLeft = 0
@ -151,35 +142,28 @@ class B4lancePong(object): @@ -151,35 +142,28 @@ class B4lancePong(object):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(self.__balanceserver)
print('connected!')
self.__bplayers = [
blup.balance_util.BalanceUtil(sock, 0),
blup.balance_util.BalanceUtil(sock, 1)
]
while not (self.__bplayers[0].get_player_ready() or
self.__bplayers[1].get_player_ready()):
time.sleep(0.1)
for i in range(5):
frame = mk_logo_frame(self.__dimension, onePlayer)
self.__out.sendFrame(frame)
print('waiting for second player...')
if (self.__bplayers[0].get_player_ready() and
self.__bplayers[1].get_player_ready()):
break
balance_util_p1 = blup.balance_util.BalanceUtil(sock, 0)
balance_util_p2 = blup.balance_util.BalanceUtil(sock, 1)
while not balance_util_p1.get_player_ready():
print('waiting for player...')
time.sleep(1)
self.__players = []
for i in [0, 1]:
paddle = self.__playground.leftPaddle if i == 0 else \
self.__playground.rightPaddle
if self.__bplayers[i].get_player_ready():
player = BalanceBoardPlayer(self.__playground, paddle,
self.__bplayers[i])
else:
player = pong.PongBot(self.__playground, paddle, 3)
self.__players.append(player)
self.__players.append(BalanceBoardPlayer(self.__playground, self.__playground.leftPaddle, balance_util_p1))
if self.__numplayers == 2:
self.__players.append(BalanceBoardPlayer(self.__playground, self.__playground.rightPaddle, balance_util_p2))
elif self.__numplayers is None:
for i in range(5):
frame = mk_logo_frame(self.__dimension, onePlayer)
self.__out.sendFrame(frame)
print('waiting for second player...')
if balance_util_p2.get_player_ready():
self.__players.append(BalanceBoardPlayer(self.__playground, self.__playground.rightPaddle,
balance_util_p2))
break
time.sleep(1)
frame = mk_logo_frame(self.__dimension, logo)
self.__out.sendFrame(frame)
@ -194,25 +178,25 @@ class B4lancePong(object): @@ -194,25 +178,25 @@ class B4lancePong(object):
self.__out.sendFrame(frame)
time.sleep(1)
self.__playground.addGameTickCallback(self.gametickcb)
if len(self.__players) == 1:
bot = pong.PongBot(self.__playground, self.__playground.rightPaddle, 3)
self.__players.append(bot)
while (max(scoreLeft, scoreRight) < __MAX_SCORE__ and
not self.__playground.cancelled):
while max(scoreLeft, scoreRight) < __MAX_SCORE__:
winner = self.__playground.play()
if winner is self.__playground.leftPaddle:
if winner is self.__players[0].ownPaddle:
scoreLeft += 1
else:
scoreRight += 1
pong.displayScore(self.__out, self.__dimension, scoreLeft, scoreRight, 3000)
if not self.__playground.cancelled:
for i in range(3):
frame = blup.frame.Frame(self.__dimension)
self.__out.sendFrame(frame)
time.sleep(0.5)
pong.displayScore(self.__out, self.__dimension, scoreLeft, scoreRight, 500)
for i in range(3):
frame = blup.frame.Frame(self.__dimension)
self.__out.sendFrame(frame)
time.sleep(0.5)
pong.displayScore(self.__out, self.__dimension, scoreLeft, scoreRight, 500)
frame = blup.frame.Frame(self.__dimension)
self.__out.sendFrame(frame)
self.__playground = None
self.__players = []
@ -221,6 +205,8 @@ class B4lancePong(object): @@ -221,6 +205,8 @@ class B4lancePong(object):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Blinkenbunt Pong!')
parser.add_argument('--players', dest='players', type=int,
help='number of players (autodetect if unspecified)')
parser.add_argument('--balance', dest='balance', type=str,
metavar='HOST:PORT', help='use balance input')
parser.add_argument('--out', dest='out', type=str, metavar='OUTPUT',
@ -230,6 +216,7 @@ if __name__ == '__main__': @@ -230,6 +216,7 @@ if __name__ == '__main__':
out = blup.output.getOutput(args.out)
bhost, bport = args.balance.split(':')
p0ng = B4lancePong(out, balanceserver=(bhost, int(bport)), color=True)
p0ng = B4lancePong(out, balanceserver=(bhost, int(bport)), color=True,
numplayers=args.players)
p0ng.runGame()

2
games/gamemenu.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
import sys
import time

9
games/pong.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python
import time
import random
@ -183,8 +183,6 @@ class Playground(object): @@ -183,8 +183,6 @@ class Playground(object):
paddleRight = Paddle(self, width - 1, (height - paddlesize)//2, paddlesize)
self.__paddles = [paddleLeft, paddleRight]
self.cancelled = False
self.__ball = Ball(self, 0, 0, 1, 1)
self.__gameTickCallbacks = []
self.__newRoundCallbacks = []
@ -229,9 +227,6 @@ class Playground(object): @@ -229,9 +227,6 @@ class Playground(object):
if paddle.containsPoint(x, y):
return paddle
def cancel(self):
self.cancelled = True
def play(self, serve=None):
leftPaddle = self.__paddles[0]
rightPaddle = self.__paddles[1]
@ -255,7 +250,7 @@ class Playground(object): @@ -255,7 +250,7 @@ class Playground(object):
callback()
ticks = 0
while not self.cancelled:
while True:
ticks += 1
time.sleep(0.08)
if ticks %2 == 0:

126
generators/blobs.py

@ -1,126 +0,0 @@ @@ -1,126 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import argparse
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 1, 1)
def get_random_point():
return (random.randint(0, WIDTH-1), random.randint(0, HEIGHT-1))
def cap(x):
return min(1, max(0, x))
def cyc(x):
while x < 0:
x += 1
while x > 1:
x -= 1
return x
class Point:
def __init__(self, pos, color, evolve):
self.pos = pos
self.color = color
self.neighbours = []
h, s, v = colorsys.rgb_to_hsv(*color)
self.evolve = evolve
if 'h' in evolve:
h += (random.random()-.5) * 0.1
if 's' in evolve:
s += (random.random()-.5) * 0.5
if 'v' in evolve:
v += (random.random()-.5) * 0.5
self.ncolor = colorsys.hsv_to_rgb(cyc(h), cap(s), cap(v))
def __eq__(self, other):
return self.pos == other.pos
def __hash__(self):
return self.pos.__hash__()
def get_neighbours(self):
for x in [-1, 0, 1]:
for y in [-1, 0, 1]:
n = (self.pos[0]+x, self.pos[1]+y)
if n[0] >= 0 and n[1] >= 0 and n[0] < WIDTH and \
n[1] < HEIGHT and abs(x+y) < 2:
yield Point(n, self.ncolor, self.evolve)
class Blob:
def __init__(self, pos, color):
e = random.choice('hsv')
if random.random() > 0.8:
e += random.choice('hsv')
p = Point(pos, color, e)
self.points = set([p])
self.candids = set(p.get_neighbours())
self.completed = False
def grow(self):
if len(self.candids) == 0:
self.completed = True
return
newp = random.sample(self.candids, 1)[0]
self.candids.remove(newp)
self.points.add(newp)
self.candids = self.candids.union(set(newp.get_neighbours()) -
self.points - self.candids)
def draw(self, frame):
for p in self.points:
frame.setPixel(p.pos[0], p.pos[1], convert_color(p.color))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate blob animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
t = 0
blobs = [Blob(get_random_point(), get_random_color())]
while t < args.time:
t += args.delay / 1000
frame = blup.animation.AnimationFrame(dim, args.delay)
for b in blobs:
for i in range(4):
b.grow()
b.draw(frame)
if len(blobs[-1].points) > WIDTH*HEIGHT*0.6 and len(blobs) < 3:
blobs.append(Blob(get_random_point(), get_random_color()))
if len(blobs) >=2 and blobs[0].completed and blobs[1].completed:
blobs.remove(blobs[0])
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

140
generators/checkerboard.py

@ -1,140 +0,0 @@ @@ -1,140 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
raise Exception('not implemented')
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
if isinstance(other, Point):
raise ValueError()
else:
return self * (1/other)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
@property
def n(self):
n = Point(self.y, -self.x)
return n / n.len
@property
def intp(self):
return Point(int(round(self.x)), int(round(self.y)))
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 0.5 + random.random() / 2, 1)
class BlinkingCheckerboard:
def __init__(self, size, fieldsize, h, num_fields, rounds):
self.size, self.fieldsize, self.h, self.num_fields, self.rounds = \
size, fieldsize, h, num_fields, rounds
self.roundtime = 0.5
self.fieldpoints = [
Point(random.randint(0, WIDTH-1), random.randint(0, HEIGHT-1))
]
xm = self.fieldpoints[-1].x % (fieldsize * 2)
ym = self.fieldpoints[-1].y % (fieldsize * 2)
while len(self.fieldpoints) < self.num_fields:
p = random.choice(self.fieldpoints)
o = Point(random.randint(-2, 2), random.randint(-2, 2))
if abs(o.x) + abs(o.y) != 2:
continue
p += o * fieldsize
if p.x < 0 or p.y < 0 or p.x >= size.x or p.y > size.y:
continue
if p not in self.fieldpoints:
self.fieldpoints.append(p)
self.done = False
def update(self, t, dt):
r = t / self.roundtime
if r >= self.rounds + 1:
self.done = True
self.fieldvals = [0] * self.num_fields
else:
self.fieldvals = []
for i in range(self.num_fields):
offs = i / (self.num_fields - 1) * 2 * math.pi
pos = 2 * math.pi * r
self.fieldvals.append(max(math.sin(offs + pos), 0))
if r > self.rounds and r < self.rounds + 1:
if self.fieldvals[-1] < 0.01:
self.fieldvals[-1] = 0
def draw(self, frame):
for i, f in enumerate(self.fieldpoints):
color = colorsys.hsv_to_rgb(self.h, 1, self.fieldvals[i])
for x in range(self.fieldsize):
for y in range(self.fieldsize):
try:
p = f + Point(x, y)
frame.setPixel(p.x, p.y, convert_color(color))
except ValueError:
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
t = 0
dt = args.delay / 1000
tt = 0
bc = None
while t < args.time or not bc.done:
t += dt
tt += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
if (bc is None or bc.done) and t < args.time:
tt = 0
bc = BlinkingCheckerboard(
Point(WIDTH, HEIGHT),
2,
random.random(),
random.randint(13, 23),
random.randint(3, 5)
)
bc.update(tt, dt)
bc.draw(frame)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

2
generators/colormarq.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python
import sys

2
generators/colorwischer.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
import sys
import colorsys

107
generators/curves.py

@ -1,107 +0,0 @@ @@ -1,107 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
import functools
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
raise Exception('not implemented')
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
if isinstance(other, Point):
raise ValueError()
else:
return self * (1/other)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
@property
def n(self):
n = Point(self.y, -self.x)
return n / n.len
@property
def intp(self):
return Point(int(round(self.x)), int(round(self.y)))
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 0.5 + random.random() / 2, 1)
class CurveFunction():
def __init__(self, p1, p2):
self.p1, self.p2 = p1, p2
d = p2 - p1
self.pp = p1 + d/2 + d.n * (d.len * 0.8)
def __call__(self, t):
ret = (self.p1 - self.pp*2 + self.p2) * t**2
ret += (self.p1 * -2 + self.pp * 2) * t
ret += self.p1
return ret
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
t = 0
dt = args.delay / 1000
while t < args.time:
t += dt
p1 = p2 = None
while p1 == p2 or (p1 - p2).len < max(WIDTH, HEIGHT) / 2:
p1 = Point(random.randint(0, WIDTH-1), random.randint(0, HEIGHT-1))
p2 = Point(random.randint(0, WIDTH-1), random.randint(0, HEIGHT-1))
cf = CurveFunction(p1, p2)
color = convert_color(get_random_color())
tt = 0
points = []
while tt <= 1:
t += dt
tt += 0.025
p = cf(tt).intp
points.append(p)
frame = blup.animation.AnimationFrame(dim, args.delay)
for p in points:
try:
frame.setPixel(p.x, p.y, color)
except ValueError:
pass
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

114
generators/discs.py

@ -1,114 +0,0 @@ @@ -1,114 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
raise Exception('not implemented')
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
if isinstance(other, Point):
raise ValueError()
else:
return self * (1/other)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
@property
def n(self):
n = Point(self.y, -self.x)
return n / n.len
@property
def intp(self):
return Point(int(round(self.x)), int(round(self.y)))
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 1, 1)
class Disc:
def __init__(self, worldsize, hue):
self.worldsize = worldsize
self.pos = Point(random.randint(0, worldsize.x - 1),
random.randint(0, worldsize.y - 1))
self.hue = hue
self.r = 1
self.speed = min(worldsize.x, worldsize.y) / 2
self.done = False
def update(self, t, dt):
self.r += self.speed * dt
if self.r > max(self.worldsize.x, self.worldsize.y):
self.done = True
def draw(self, frame):
color = colorsys.hsv_to_rgb(self.hue, 1, 1)
for x in range(self.worldsize.x):
for y in range(self.worldsize.y):
p = Point(x, y)
if (p - self.pos).len < self.r:
frame.setPixel(p.x, p.y, convert_color(color))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
discs = []
t = 0
dt = args.delay / 1000
while t < args.time:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
if len(discs) == 0 or discs[-1].r > min(WIDTH, HEIGHT) / 2:
hue = random.random()
if len(discs) > 0:
l = lambda d: hue - d.hue if d.hue < hue else d.hue - hue
while not 0.2 < sorted(map(l, discs))[0] < 0.8:
hue = random.random()
discs.append(Disc(Point(WIDTH, HEIGHT), hue))
for d in discs:
d.update(t, dt)
d.draw(frame)
if len(discs) > 2 and discs[0].done and discs[1].done:
del discs[0]
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

141
generators/dlines.py

@ -1,141 +0,0 @@ @@ -1,141 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
import functools
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
class PointLenOrder:
def __init__(self, value):
self.value = value
def __eq__(self, other):
return other.value.len == self.value.len
def __lt__(self, other):
return other.value.len < self.value.len
DIRECTIONS = [ Point(x, y) for x in [-1, 1] for y in [-1, 1] ]
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 0.5 + random.random() / 2, 1)
class Line:
def __init__(self, worldsize):
self.worldsize = worldsize
self.line = [Point(random.randint(0, worldsize.x),
random.randint(0, worldsize.y))]
self.slen = 1
self.dir = random.choice(DIRECTIONS)
self.color = get_random_color()
diaglen = int(math.sqrt(worldsize.x**2 + worldsize.y**2))
self.maxlen = random.randint(diaglen, diaglen * 3)
self.fadeout_time = 2 + random.random() * 2
self.fadeout_remaining = None
self.finished = False
def check_bounds(self, p):
return p.x < self.worldsize.x and p.x >= 0 \
and p.y < self.worldsize.y and p.y >= 0
def update(self, t, dt):
if len(self.line) < self.maxlen:
if self.slen >= 3 and random.random() < 0.4:
dirs = list(DIRECTIONS)
dirs.remove(self.line[-1] - self.line[-2])
if self.check_bounds(self.line[-1]):
newp = None
while newp is None or newp == self.line[-2]:
self.dir = random.choice(dirs)
newp = self.line[-1] + self.dir
else:
dirs.sort(key=lambda d: ((self.line[-1]+d) - Point(0, 0)).len)
self.dir = dirs[0]
self.slen = 1
else:
self.slen += 1
self.line.append(self.line[-1] + self.dir)
else:
if self.fadeout_remaining is None:
self.fadeout_remaining = self.fadeout_time
elif self.fadeout_remaining <= 0:
self.finished = True
else:
self.fadeout_remaining -= dt
def draw(self, frame):
if self.fadeout_remaining is not None:
if self.fadeout_remaining > 0:
h, s, v = colorsys.rgb_to_hsv(*self.color)
v = v * (self.fadeout_remaining / self.fadeout_time)
color = colorsys.hsv_to_rgb(h, s, v)
else:
color = (0, 0, 0)
else:
color = self.color
for p in self.line:
if self.check_bounds(p):
frame.setPixel(p.x, p.y, convert_color(color))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
lines = [Line(Point(WIDTH, HEIGHT))]
t = 0
dt = args.delay / 1000
while t < args.time:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
for l in lines:
l.update(t, dt)
l.draw(frame)
if lines[-1].fadeout_remaining is not None:
lines.append(Line(Point(WIDTH, HEIGHT)))
for l in lines:
if l.finished:
lines.remove(l)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

150
generators/faces.py

@ -1,150 +0,0 @@ @@ -1,150 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
SMILEYSIZE = 5
Point = collections.namedtuple('Point', ['x', 'y'])
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def expand(somepoints, allpoints):
todo = set(somepoints)
ret = set(somepoints)
while len(todo) > 0:
p = todo.pop()
ret.add(p)
adj = { Point(p.x + x, p.y + y) for x in [-1,0,1] for y in [-1,0,1] \
if abs(x) + abs(y) == 1 and p.x + x in range(0, SMILEYSIZE) \
and p.y + y in range(0, SMILEYSIZE) }
adj = (allpoints - ret).intersection(adj)
todo = todo.union(adj)
return ret
def gen_face_shape():
while True:
i = random.randint(0, 2**(SMILEYSIZE * (SMILEYSIZE//2 + 1)))
lpoints = { Point(x, y) for x in range(0, SMILEYSIZE // 2) \
for y in range(SMILEYSIZE) \
if i & 2**(x*SMILEYSIZE + y) > 0 }
mpoints = { Point(SMILEYSIZE//2, y) for y in range(SMILEYSIZE) \
if i & 2**((SMILEYSIZE//2) * SMILEYSIZE + y) > 0 }
rpoints = { Point(SMILEYSIZE - x - 1, y) \
for x in range(0, SMILEYSIZE // 2) \
for y in range(SMILEYSIZE) \
if i & 2**(x*SMILEYSIZE + y) > 0 }
points = set.union(lpoints, mpoints, rpoints)
eyes = { p for p in points if p.y < SMILEYSIZE // 2 and \
p.x != SMILEYSIZE // 2 }
nose = { p for p in points if p.y >= SMILEYSIZE // 3 and \
p.y < SMILEYSIZE // 2 + 1 and p.x == SMILEYSIZE//2 }
mouth = { p for p in points if p.y > SMILEYSIZE // 2 }
nose = expand(nose, points)
mouth = expand(mouth, points)
face = True
if len(eyes.intersection(nose)) > 0:
face = False
if len(eyes.intersection(mouth)) > 0:
face = False
if len(nose.intersection(mouth)) > 0:
face = False
if len(points - eyes - nose - mouth) > 0:
face = False
if len(eyes) == 0:
face = False
if len(mouth) == 0:
face = False
if len(nose) > 0:
nosey = set(map(lambda p: p.y, nose))
if min(nosey) < SMILEYSIZE//3:
face = False
if face:
return points
class Face:
def __init__(self, pos):
self.pos = pos
self.shape = gen_face_shape()
self.lifetime = 0.7
self.fadetime = 0.1 + random.random() / 10
self.age = 0
self.done = False
self.hue = random.random()
def update(self, dt):
self.age += dt
if self.age > self.lifetime:
self.done = True
def draw(self, frame):
if self.done:
return
if self.age < self.fadetime:
v = self.age / self.fadetime
elif self.age > self.lifetime - self.fadetime:
v = (self.lifetime-self.age) / self.fadetime
else:
v = 1
for p in self.shape:
frame.setPixel(
p.x + self.pos.x,
p.y + self.pos.y,
convert_color(colorsys.hsv_to_rgb(self.hue, 1, v))
)
def get_face_pos():
x = random.randint(0, WIDTH - SMILEYSIZE)
y = random.randint(0, HEIGHT - SMILEYSIZE)
return Point(x, y)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate Face animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
f = Face(get_face_pos())
t = 0
dt = args.delay / 1000
while f is not None:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
f.update(dt)
f.draw(frame)
if f.done:
if t < args.time:
f = Face(get_face_pos())
else:
f = None
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

2
generators/fire.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
import colorsys
import random

30
generators/fireworks.py

@ -71,20 +71,9 @@ class Rocket: @@ -71,20 +71,9 @@ class Rocket:
def getRandomColor(maxval):
return list(map(lambda x: int(round(x*maxval)), colorsys.hsv_to_rgb(random.random(), 1, 1)))
def gen_rockets(num, now=0):
for i in range(num):
yield Rocket(
np.array([random.randint(0, dim.width-1), dim.height-1]),
np.array([random.randint(-8, 8), -20 + random.randint(-2, 2)]),
4 + random.randint(-2, 2),
now + random.randint(0, 40) / 10,
np.array([dim.depth-1] * 3)
)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate plasma animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=0)
parser.add_argument('-n', '--num-rockets', type=int, default=3)
parser.add_argument('output_file')
args = parser.parse_args()
@ -93,7 +82,17 @@ if __name__ == '__main__': @@ -93,7 +82,17 @@ if __name__ == '__main__':
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
rockets = list(gen_rockets(args.num_rockets))
rockets = []
for i in range(args.num_rockets):
rockets.append(
Rocket(
np.array([random.randint(0, dim.width-1), dim.height-1]),
np.array([random.randint(-8, 8), -20 + random.randint(-2, 2)]),
4 + random.randint(-2, 2),
random.randint(0, 40) / 10,
np.array([dim.depth-1] * 3)
)
)
fbs = []
t = 0
@ -127,12 +126,7 @@ if __name__ == '__main__': @@ -127,12 +126,7 @@ if __name__ == '__main__':
anim.addFrame(frame)
if len(rockets) == 0 and len(fbs) == 0:
if t < args.time:
frame = blup.animation.AnimationFrame(dim, 700)
anim.addFrame(frame)
rockets = list(gen_rockets(args.num_rockets, t))
else:
break
break
t += args.delay / 1000
blup.writebml.writeBml(anim, args.output_file)

147
generators/gameOfLife.py

@ -1,12 +1,10 @@ @@ -1,12 +1,10 @@
#!/usr/bin/env python3
import sys
import ast
import time as t
import random as r
from blup import frame
from blup import animation
import blup.animation
import blup.frame
import blup.writebml
import argparse
import math
r.seed()
@ -15,95 +13,84 @@ HEIGHT = 16 @@ -15,95 +13,84 @@ HEIGHT = 16
COLOR_DEPTH = 256
COLORS = 3
DELAY = 300
DEAD = 0
DEAD_COLOR = (0, 0, 0)
DEADCOLOR = (0,0,0)
ALIVE = 1
ALIVE_COLOR = (r.randint(0, 255), r.randint(0, 255), r.randint(0, 255))
ALIVECOLOR = (0,0,255)
def generate_rand_game_board():
board = []
for rows in range(HEIGHT):
x_coordinates = []
for cols in range(WIDTH):
x_coordinates.append(r.randint(0, 1))
board.append(x_coordinates)
return board
dimension = blup.frame.FrameDimension(WIDTH, HEIGHT, COLOR_DEPTH, COLORS)
animation = blup.animation.Animation(dimension)
def generateRandomGameBoard():
gameBoard = []
for i in range(HEIGHT):
xCoordinates = []
for j in range(WIDTH):
xCoordinates.append(r.randint(0, 1))
gameBoard.append(xCoordinates)
return gameBoard
def get_neighbors(x, y):
for rowNumber in range(y-1, y+2):
if 0 <= rowNumber < HEIGHT:
for colNumber in range(x-1, x+2):
if 0 <= colNumber < WIDTH:
if not (y == rowNumber and x == colNumber):
yield game_board[rowNumber][colNumber]
if __name__ == "__main__":
argument_parser = argparse.ArgumentParser(description="Game of Life bml generator")
argument_parser.add_argument('-o', dest="output_path", type=str, help="output file (mandatory)")
argument_parser.add_argument('-w', dest="world", type=list, default=None, help="pre-constructed world (optional)")
argument_parser.add_argument('-t', dest="secs", type=int, default=90, help="time in seconds (optional)")
argument_parser.add_argument('-d', dest="delay", type=int, default=300, help="delay between frames (optional)")
args = argument_parser.parse_args()
if not (y==rowNumber and x==colNumber):
yield gameBoard[rowNumber][colNumber]
frames = int(math.floor(args.secs * 1000 / args.delay))
if len(sys.argv) == 1:
gameBoard = generateRandomGameBoard()
gameBoardIsSanitized = True
elif len(sys.argv) != 2:
print("check args. found "+str(len(sys.argv)))
exit()
dimension = frame.FrameDimension(WIDTH, HEIGHT, COLOR_DEPTH, COLORS)
game_of_life_animation = animation.Animation(dimension)
if not gameBoardIsSanitized:
gameBoard = ast.literal_eval(sys.argv[1])
if args.output_path is None:
argument_parser.print_help()
if len(gameBoard) != HEIGHT:
print("len(gameBoard) != "+str(HEIGHT)+". counted "+str(len(gameBoard)))
exit()
if args.world is None:
game_board = generate_rand_game_board()
else:
game_board = ast.literal_eval(args.world)
if len(game_board) != HEIGHT:
print("len(gameBoard) != " + str(HEIGHT) + ". counted " + str(len(game_board)))
for i in gameBoard:
if len(i) != WIDTH:
print("len(rows) != "+str(WIDTH)+". counted "+str(len(i)))
exit()
for i in game_board:
if len(i) != WIDTH:
print("len(rows) != "+str(WIDTH)+". counted "+str(len(i)))
exit()
for frame in range(frames):
# construct frame
new_frame = animation.AnimationFrame(dimension, args.delay)
for row_index in range(HEIGHT):
for col_index in range(WIDTH):
cell_status = game_board[row_index][col_index]
if cell_status == ALIVE:
new_frame.setPixel(col_index, row_index, ALIVE_COLOR)
else:
new_frame.setPixel(col_index, row_index, DEAD_COLOR)
game_of_life_animation.addFrame(new_frame)
# calculate next step
next_game_board_step = []
previous_game_board_step = game_board
for row_index in range(HEIGHT):
new_row = []
for col_index in range(WIDTH):
neighbor_list = list(get_neighbors(col_index, row_index))
alive_neighbors = neighbor_list.count(1)
if alive_neighbors < 2:
new_row.append(DEAD)
elif alive_neighbors == 2:
new_row.append(game_board[row_index][col_index])
elif alive_neighbors == 3:
new_row.append(ALIVE)
elif alive_neighbors >= 4:
new_row.append(DEAD)
next_game_board_step.append(new_row)
game_board = next_game_board_step
if game_board == previous_game_board_step:
for i in range(20):
game_of_life_animation.addFrame(new_frame)
break
blup.writebml.writeBml(game_of_life_animation, args.output_path)
for frame in range(500):
# construct frame
newframe = blup.animation.AnimationFrame(dimension, DELAY)
for rowIndex in range(HEIGHT):
for colIndex in range(WIDTH):
cellStatus = gameBoard[rowIndex][colIndex]
if cellStatus == ALIVE:
newframe.setPixel(colIndex, rowIndex, ALIVECOLOR)
else:
newframe.setPixel(colIndex, rowIndex, DEADCOLOR)
animation.addFrame(newframe)
# calculate next step
gameBoardNextStep = []
lastGameBoard = gameBoard
for rowIndex in range(HEIGHT):
newRow = []
for colIndex in range(WIDTH):
neighborList = list(get_neighbors(colIndex, rowIndex))
aliveNeighbors = neighborList.count(1)
if aliveNeighbors < 2:
newRow.append(DEAD)
elif aliveNeighbors == 2:
newRow.append(gameBoard[rowIndex][colIndex])
elif aliveNeighbors == 3:
newRow.append(ALIVE)
elif aliveNeighbors >= 4:
newRow.append(DEAD)
gameBoardNextStep.append(newRow)
gameBoard = gameBoardNextStep
if(gameBoard == lastGameBoard):
for i in range(20):
animation.addFrame(newframe)
break
blup.writebml.writeBml(animation, '/home/pi/animations/gameOfLife.bml')

121
generators/lines.py

@ -1,121 +0,0 @@ @@ -1,121 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
raise Exception('not implemented')
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
if isinstance(other, Point):
raise ValueError()
else:
return self * (1/other)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
@property
def n(self):
n = Point(self.y, -self.x)
return n / n.len
@property
def intp(self):
return Point(int(round(self.x)), int(round(self.y)))
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 0.5 + random.random() / 2, 1)
class Line:
def __init__(self, size):
self.size = size
r = random.choice([0, 1])
s = random.choice([-1, 1])
if r == 0:
self.pos = Point(size.x if s == -1 else 0,
random.randint(0, size.y - 1))
else:
self.pos = Point(random.randint(0, size.x - 1),
size.y if s == -1 else 0)
self.dir = Point(s if r == 0 else 0, s if r == 1 else 0)
m = max(size.x, size.y)
self.length = random.randint(int(0.4 * m), int(1.1 * m))
self.color = get_random_color()
self.speed = 10
self.done = False
def update(self, t, dt):
self.pos += self.dir * (dt * self.speed)
end = self.pos - self.dir * self.length
if self.dir.x > 0 and end.x > self.size.x \
or self.dir.y > 0 and end.y > self.size.y \
or self.dir.x < 0 and end.x < 0 \
or self.dir.y < 0 and end.y < 0:
self.done = True
def draw(self, frame):
if self.done:
return
for i in range(self.length):
p = self.pos.intp - self.dir * i
try:
frame.setPixel(p.x, p.y, convert_color(self.color))
except ValueError:
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
lines = []
t = 0
dt = args.delay / 1000
while t < args.time or len(lines) > 0:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
if len(lines) < 5 and t < args.time:
lines.append(Line(Point(WIDTH, HEIGHT)))
for l in lines:
l.update(t, dt)
l.draw(frame)
lines = list(filter(lambda l: not l.done, lines))
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

222
generators/movingshapes.py

@ -1,222 +0,0 @@ @@ -1,222 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
import math
WIDTH = 22
HEIGHT = 16
DEPTH = 256
_ALLSHAPES = [
[[0, 1, 0, 1, 0],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0]],
[[1, 0, 0, 0, 1],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[1, 0, 0, 0, 1],
[0, 1, 1, 1, 0]],
[[1, 0, 1, 0, 1],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 0, 1, 0],
[1, 1, 0, 1, 1]],
]
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
ALLSHAPES = []
for s in _ALLSHAPES:
ALLSHAPES.append(set())
y = 0
for l in s:
x = 0
for i in l:
if i == 1:
ALLSHAPES[-1].add(Point(x, y))
x += 1
y += 1
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 1, 1)
class Shape:
def __init__(self, shape, pos, color):
self.shape, self.pos, self.color = shape, pos, color
self.period = 2
self.fadetime = 0.5 + random.random() / 5
self.t = random.random() * self.period
self.t = 0
self.oldv = 1
self.v = 1
self.newshape = None
def update(self, t, dt):
self.t += dt
if self.t > self.period:
t = self.t - self.period
if t >= self.fadetime:
self.v = 1
self.t = random.random() * self.period
else:
self.v = math.cos(t * (math.pi / self.fadetime)) ** 2
if (self.newshape is not None \
and (self.oldv < self.v or self.v == 0)):
self.shape = self.newshape
self.color = self.newcolor
self.newshape = None
self.oldv = self.v
def change_shape_and_color(self, newshape, newcolor):
self.newshape = newshape
self.newcolor = newcolor
self.t = self.period
def draw(self, frame, origin=Point(0, 0)):
h, s, v = colorsys.rgb_to_hsv(*self.color)
for p in self.shape:
try:
pos = self.pos + p - origin
c = colorsys.hsv_to_rgb(h, s, v * self.v)
frame.setPixel(pos.x, pos.y, convert_color(c))
except ValueError:
pass
class World:
def __init__(self, size, allshapes, gap=2):
self.size, self.allshapes, self.gap = size, allshapes, gap
self.shapes = {}
self.pos = Point(0, 0)
self.cycletime = 60
self.curshape = random.choice(allshapes)
self.curcolor = get_random_color()
self.shapesize = Point(0, 0)
for s in allshapes:
assert min(map(lambda p: p.x, s)) >= 0
assert min(map(lambda p: p.y, s)) >= 0
shapesize = Point(
max(map(lambda p: p.x, s)) + 1,
max(map(lambda p: p.y, s)) + 1,
)
if shapesize.x > self.shapesize.x:
self.shapesize = Point(shapesize.x, self.shapesize.y)
if shapesize.y > self.shapesize.y:
self.shapesize = Point(self.shapesize.x, shapesize.y)
print (self.shapesize)
@property
def shape_space(self):
ret = set()
for x in range(self.size.x):
for y in range(self.size.y):
p = self.pos + Point(x, y)
if (p.x % (self.shapesize.x + self.gap) >= self.gap
and p.y % (self.shapesize.y + self.gap) >= self.gap):
ret.add(p)
return ret
def get_shape_coverage(self, shape):
return { shape.pos + Point(x, y) for x in range(self.shapesize.x) \
for y in range(self.shapesize.y) }
def update(self, t, dt):
self.pos = Point(
int(math.sin((t * math.pi/self.cycletime)*4) * self.size.x),
int(math.cos((t * math.pi/self.cycletime)*5) * self.size.y)
)
space = self.shape_space
for s in self.shapes.values():
space -= self.get_shape_coverage(s)
while len(space) > 0: # and len(self.shapes) < 1:
print('...')
p = space.pop()
newpos = Point(
(p.x // (self.shapesize.x + self.gap)) \
* (self.shapesize.x + self.gap) + self.gap,
(p.y // (self.shapesize.y + self.gap)) \
* (self.shapesize.y + self.gap) + self.gap
)
print(p, newpos)
# TODO improve shape and color selection
newshape = Shape(self.curshape, newpos, self.curcolor)
assert newpos in self.get_shape_coverage(newshape)
print('covered', self.get_shape_coverage(newshape))
print('space before', len(space))
space -= self.get_shape_coverage(newshape)
print('space after ', len(space))
assert newpos not in self.shapes
self.shapes[newpos] = newshape
print('new', len(self.shapes))
#print(space)
newshape = None
newcolor = None
if round(t*1000) % 3000 == 0:
newshape = random.choice(self.allshapes)
self.curshape = newshape
newcolor = get_random_color()
self.curcolor = newcolor
for s in self.shapes.values():
if newshape is not None:
s.change_shape_and_color(newshape, newcolor)
s.update(t, dt)
def draw(self, frame):
for s in self.shapes.values():
s.draw(frame, self.pos)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
w = World(Point(WIDTH, HEIGHT), ALLSHAPES)
t = 0
dt = args.delay / 1000
while t < args.time:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
w.update(t, dt)
w.draw(frame)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

122
generators/orbs.py

@ -1,122 +0,0 @@ @@ -1,122 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import numpy as np
import argparse
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
def fill_trace(points):
for i in range(len(points)):
yield points[i]
if i == len(points)-1:
break
v = points[i+1] - points[i]
l = int(np.linalg.norm(v))
for j in range(l):
yield points[i] + v * (j+1)/(l+1)
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 1, 1)
class Orb:
def __init__(self, pos, speed, tracelen, color, tracecolor, boxsize):
self.pos = pos
self.speed = speed
self.tracelen = tracelen
self.color = color
self.tracecolor = tracecolor
self.boxsize = boxsize
self.trace = []
def update(self, dt):
newpos = self.pos + self.speed * dt
#newpos = self.pos
for dim in [0, 1]:
if newpos[dim] >= self.boxsize[dim] or newpos[dim] <= 0:
newpos[dim] = 0 if newpos[dim]<0 else self.boxsize[dim]-1
self.speed[dim] *= -1
self.speed += np.array([random.randint(-5, 6), random.randint(-5, 6)])
self.trace.insert(0, self.pos)
self.trace = self.trace[:self.tracelen]
self.pos = newpos
def draw(self, frame):
for i, p in enumerate(fill_trace([self.pos] + self.trace)):
f = (self.tracelen - i) / self.tracelen
try:
c = colorsys.rgb_to_hsv(*self.tracecolor)
s = 0.1 if random.random()>0.9 else c[1]
c = colorsys.hsv_to_rgb(c[0], s, c[2]*f)
frame.setPixel(int(p[0]), int(p[1]), convert_color(c))
except ValueError:
pass
offs = [ np.array([x,y]) for x in [-1,0,1] for y in [-1,0,1] ]
points = []
for o in offs:
p = self.pos.astype('int') + o
if random.random() > 0.2 and not (p == np.array([0,0])).all():
points.append(p)
for p in points:
try:
c = colorsys.rgb_to_hsv(*self.color)
c = colorsys.hsv_to_rgb(c[0], c[1], c[2]*0.2)
frame.setPixel(p[0], p[1], convert_color(c))
except ValueError:
pass
frame.setPixel(int(self.pos[0]), int(self.pos[1]), convert_color(self.color))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate plasma animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('-n', '--num-orbs', type=int, default=2)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
orbs = []
for i in range(args.num_orbs):
orbs.append(Orb(
np.array([random.randint(0, WIDTH-1),random.randint(0, HEIGHT-1)]),
np.array([8,10]),
20,
get_random_color(),
get_random_color(),
np.array([WIDTH, HEIGHT])
))
t = 0
while t < args.time:
t += args.delay / 1000
frame = blup.animation.AnimationFrame(dim, args.delay)
for orb in orbs:
orb.update(args.delay / 1000)
orb.draw(frame)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

2
generators/scroll.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
import sys
import colorsys

232
generators/thimblerig.py

@ -1,232 +0,0 @@ @@ -1,232 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
import functools
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
raise Exception('not implemented')
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
if isinstance(other, Point):
raise ValueError()
else:
return self * (1/other)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
@property
def n(self):
n = Point(self.y, -self.x)
return n / n.len
@property
def intp(self):
return Point(int(round(self.x)), int(round(self.y)))
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 0.5 + random.random() / 2, 1)
class CurveFunction():
def __init__(self, p1, p2):
self.p1, self.p2 = p1, p2
d = p2 - p1
self.pp = p1 + d/2 + d.n * (d.len * 0.8)
def __call__(self, t):
ret = (self.p1 - self.pp*2 + self.p2) * t**2
ret += (self.p1 * -2 + self.pp * 2) * t
ret += self.p1
return ret
class Box():
def __init__(self, pos, size, hue, swaptime, content=None,
contentcolor=None):
self.pos, self.size, self.hue, self.content, self.contentcolor = \
pos, size, hue, content, contentcolor
self.swaptime = swaptime
self.covered = False
self.swapstart = None
self.newpos = None
self.cf = None
self.colorcycletime = 1
def swap(self, other):
self.newpos = other.pos
other.newpos = self.pos
def update(self, t, dt):
self.hue += 0.05 # dt / self.colorcycletime
if self.hue > 1:
self.hue -= 1
if self.newpos is not None:
if self.cf is None:
self.cf = CurveFunction(self.pos, self.newpos)
self.swapstart = t
elif t - self.swapstart >= self.swaptime:
self.pos = self.newpos
self.newpos = None
self.cf = None
self.swapstart = None
else:
self.pos = (self.cf((t - self.swapstart) / self.swaptime)).intp
def draw(self, frame):
if self.covered:
for x in range(self.size):
for y in range(self.size):
if x == 0 or x == self.size - 1 \
or y == 0 or y == self.size -1:
color = (0.6, 0.6, 0.6)
else:
color = colorsys.hsv_to_rgb(self.hue, 1, 1)
try:
frame.setPixel(self.pos.x + x, self.pos.y + y,
convert_color(color))
except ValueError:
pass
else:
if self.content is not None:
for p in self.content:
try:
frame.setPixel(self.pos.x + p.x + 1,
self.pos.y + p.y + 1,
convert_color(self.contentcolor))
except ValueError:
pass
class Game():
def __init__(self, size, boxsize, gap, content, contentcolor, swaptime):
self.swaptime = swaptime
self.boxes = []
boxbase = Point((size.x - (2*boxsize + gap)) / 2,
(size.y - (2*boxsize + gap)) / 2)
self.n_boxes = 4
for i in range(self.n_boxes):
boxpos = boxbase + Point(
(i % (self.n_boxes/2)) * (boxsize + gap),
(i // (self.n_boxes/2)) * (boxsize + gap)
)
self.boxes.append(Box(
boxpos.intp,
boxsize,
i * (1/self.n_boxes),
swaptime
))
winner = random.randint(0, self.n_boxes - 1)
self.boxes[winner].content = content
self.boxes[winner].contentcolor = contentcolor
self.statetimes = [2, 1, 5, 2, 1, 2]
self.statestarts = [0]
for t in self.statetimes[:-1]:
self.statestarts.append(self.statestarts[-1] + t)
self.done = False
def update(self, t, dt):
state = 0
for i, st in enumerate(self.statestarts):
if st < t:
state = i
else:
break
state_t = t - self.statestarts[state]
if state == 1 or state == 4:
for i, b in enumerate(self.boxes):
if state_t >= i * (self.statetimes[state] / self.n_boxes):
b.covered = (state == 1)
elif state == 2:
if True not in map(lambda b: b.newpos is not None, self.boxes) \
and random.random() > 0.2:
b1 = random.randint(0, self.n_boxes - 1)
b2 = random.randint(0, self.n_boxes - 1)
while b1 == b2:
b2 = random.randint(0, self.n_boxes - 1)
self.boxes[b1].swap(self.boxes[b2])
if state > 0 and state < 5:
for b in self.boxes:
b.update(t, dt)
if state == len(self.statetimes) - 1 and state_t > self.statetimes[-1]:
self.done = True
def draw(self, frame):
for b in self.boxes:
if b.newpos is None:
b.draw(frame)
for b in self.boxes:
if b.newpos is not None:
b.draw(frame)
BOXCONTENT = {
Point(0, 0),
Point(3, 0),
Point(0, 2),
Point(3, 2),
Point(1, 3),
Point(2, 3),
}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
t = 0
dt = args.delay / 1000
gamestart = 0
game = None
while t < args.time or not game.done:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
if (game is None or game.done) and t < args.time:
game = Game(Point(WIDTH, HEIGHT), 6, 2, BOXCONTENT,
get_random_color(), 0.5)
gamestart = t
game.update(t - gamestart, dt)
game.draw(frame)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

124
generators/twister.py

@ -1,124 +0,0 @@ @@ -1,124 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import math
import argparse
import collections
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
class Point(collections.namedtuple('Point', ['x', 'y'])):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, other):
if isinstance(other, Point):
raise Exception('not implemented')
else:
return Point(self.x * other, self.y * other)
def __truediv__(self, other):
if isinstance(other, Point):
raise ValueError()
else:
return self * (1/other)
@property
def len(self):
return math.sqrt(self.x**2 + self.y**2)
@property
def n(self):
n = Point(self.y, -self.x)
return n / n.len
@property
def intp(self):
return Point(int(round(self.x)), int(round(self.y)))
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
return colorsys.hsv_to_rgb(random.random(), 0.5 + random.random() / 2, 1)
class Twister:
def __init__(self, worldsize):
self.worldsize = worldsize
self.cycletime = 1.3
self.sat = 0.5 + random.random() / 2
self.hues = [random.random()]
self.hues += [ self.hues[0] + (i+1) * 0.25 for i in range(3) ]
random.shuffle(self.hues)
self.width = worldsize.x // 2.9
def update(self, t, dt):
# inspired by https://www.lexaloffle.com/bbs/?tid=3050
self.rows = []
a0 = t * math.pi / self.cycletime
while len(self.rows) < self.worldsize.y:
y = len(self.rows)
a = a0 - y * math.pi / self.worldsize.y \
* (math.sin(t * math.pi / 10) * 0.7)
ot1 = t * math.pi / 5
ot2 = y * math.pi / (self.worldsize.y * 2)
offs = self.worldsize.x / 2 + math.sin(ot1 + ot2) * self.width / 2
x1 = int(round(offs + self.width * math.sin(a)))
x2 = int(round(offs + self.width * math.sin(a+0.5*math.pi)))
x3 = int(round(offs + self.width * math.sin(a+math.pi)))
x4 = int(round(offs + self.width * math.sin(a+1.5*math.pi)))
row = []
for i, (start, end) in enumerate([(x1, x2), (x2, x3),
(x3, x4), (x4, x1)]):
if start < end:
row += [(x, i, (x - start) / (end - start - 1))
for x in range(start, end - 1)]
self.rows.append(row)
def draw(self, frame):
for y, line in enumerate(self.rows):
for point in line:
x, i, j = point
val = 1 - math.sin(j * math.pi) / 2.3
color = colorsys.hsv_to_rgb(self.hues[i], self.sat, val)
try:
frame.setPixel(x, y, convert_color(color))
except ValueError:
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
twister = Twister(Point(WIDTH, HEIGHT))
t = 0
dt = args.delay / 1000
while t < args.time:
t += dt
frame = blup.animation.AnimationFrame(dim, args.delay)
twister.update(t, dt)
twister.draw(frame)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

133
generators/unrath.py

@ -1,133 +0,0 @@ @@ -1,133 +0,0 @@
#!/usr/bin/env python3
import sys
import random
import argparse
import blup.frame
import blup.output
import blup.animation
import blup.writebml
import colorsys
WIDTH = 22
HEIGHT = 16
DEPTH = 256
def convert_color(c):
return list(map(lambda x: int(round(x*(DEPTH-1))), c))
def get_random_color():
if random.random() < 0.5:
s = 1
v = random.random()
else:
s = random.random()
v = 1
return colorsys.hsv_to_rgb(random.random(), s, v)
class Unrath:
def __init__(self, world):
self.world = world
self.shape = set([(0, 0)])
shapesize = random.randint(2, 5)
while len(self.shape) < shapesize:
p = random.sample(self.shape, 1)[0]
self.shape.add((p[0]+random.randint(-1, 1),
p[1]+random.randint(-1, 1)))
minx = min(map(lambda p: p[0], self.shape))
miny = min(map(lambda p: p[1], self.shape))
self.shape = {(p[0]+abs(minx), p[1]+abs(miny)) for p in self.shape}
self.shapewidth = max(map(lambda p: p[0], self.shape))
shapeheight = max(map(lambda p: p[1], self.shape))
y = random.randint(0, HEIGHT-shapeheight)
if random.random() > 0.5:
d = 1
x = -self.shapewidth
else:
d = -1
x = WIDTH + self.shapewidth
self.pos = (x, y)
self.finished = False
self.speed = d * random.randint(2, WIDTH/2)
self.color = get_random_color()
def update(self, dt, nocheck=False):
if (self.pos[0] + self.shapewidth < 0 and self.speed < 0) or \
(self.pos[0] > WIDTH and self.speed > 0):
self.finished = True
return
newpos = (self.pos[0] + dt*self.speed, self.pos[1])
newpoints = self.get_points(newpos)
collision = False
for unrath in self.world.unraethe - {self}:
if len(unrath.get_points().intersection(newpoints)) > 0:
collision = True
if abs(unrath.speed) > abs(self.speed):
fast = unrath
slow = self
else:
slow = unrath
fast = self
slow.speed = fast.speed * (1.1 + random.random()/10)
slow.update(dt, True)
if not collision:
self.pos = newpos
def get_points(self, pos=None):
if pos is None:
pos = self.pos
return {(int(pos[0] + s[0]), int(pos[1] + s[1])) for s in self.shape}
def draw(self, frame):
for p in self.get_points():
try:
frame.setPixel(p[0], p[1], convert_color(self.color))
except ValueError:
pass
class World:
def __init__(self, num_unraethe):
self.num_unraethe = num_unraethe
self.unraethe = {}
def update(self, dt):
self.unraethe = set(filter(lambda u: not u.finished, self.unraethe))
if len(self.unraethe) < self.num_unraethe:
self.unraethe.add(Unrath(self))
for u in self.unraethe:
u.update(dt)
def draw(self, frame):
for u in self.unraethe:
u.draw(frame)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate Unrath animations')
parser.add_argument('-d', '--delay', type=int, default=50)
parser.add_argument('-t', '--time', type=int, default=15)
parser.add_argument('-n', '--num-unraethe', type=int, default=5)
parser.add_argument('output_file')
args = parser.parse_args()
dim = blup.frame.FrameDimension(WIDTH, HEIGHT, DEPTH, 3)
anim = blup.animation.Animation(dim)
anim.tags['description'] = ' '.join(sys.argv)
t = 0
w = World(args.num_unraethe)
while t < args.time:
t += args.delay / 1000
frame = blup.animation.AnimationFrame(dim, args.delay)
w.update(args.delay / 1000)
w.draw(frame)
anim.addFrame(frame)
blup.writebml.writeBml(anim, args.output_file)

2
utils/blmplay.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#! /usr/bin/env python3
#!/usr/bin/python
import sys
import getopt

6
utils/blphub.py

@ -69,11 +69,7 @@ class BLPHub(): @@ -69,11 +69,7 @@ class BLPHub():
self.__lastFrameTimeout = (
currentTime + self.__streams[stream]['timeout']
)
try:
self.__output.sendFrame(frame)
except Exception as e:
# TODO better error handling
print('could not send frame: %s' % (repr(e)))
self.__output.sendFrame(frame)
return True
return False

151
utils/blpserver.py

@ -1,4 +1,3 @@ @@ -1,4 +1,3 @@
#! /usr/bin/env python3
import socket
import getopt
@ -6,86 +5,84 @@ import sys @@ -6,86 +5,84 @@ import sys
from blup.BLP import BLPServer
import blup.BLP
import blup.output
import blup.output
def printUsage(errMsg=None):
if errMsg is not None:
print('error: %s\n' % (errMsg))
print('usage: %s [OPTIONS]' % (sys.argv[0]))
print('supported options:')
print(' -a ADDR address to listen for packets',
'(default: 127.0.0.1)')
print(' --address ADDR\n')
print(' -p PORT port to listen for packets (default: 4242)')
print(' --port PORT\n')
print(' -o OUTPUT where to put the recieved frames',
'(default: shell)')
print(' --output OUTPUT\n')
print(' --eblp use EBLP instead of BLP\n')
print(' --e3blp use E3BLP instead of BLP\n')
print(' -h print this text')
print(' --help')
if errMsg is not None:
print 'error: %s\n' % (errMsg)
print 'usage: %s [OPTIONS]' % (sys.argv[0])
print 'supported options:'
print ' -a ADDR address to listen for packets (default: 127.0.0.1)'
print ' --address ADDR\n'
print ' -p PORT port to listen for packets (default: 4242)'
print ' --port PORT\n'
print ' -o OUTPUT where to put the recieved frames (default: shell)'
print ' --output OUTPUT\n'
print ' --eblp use EBLP instead of BLP\n'
print ' --e3blp use E3BLP instead of BLP\n'
print ' -h print this text'
print ' --help'
def main():
try:
(opts, args) = getopt.gnu_getopt(sys.argv, 'ha:p:o:',
['help', 'address=', 'port=',
'output=', 'eblp', 'e3blp'])
opts = dict(opts)
except getopt.GetoptError as e:
printUsage(e.msg)
sys.exit(1)
if '--help' in opts:
printUsage()
sys.exit(0)
if '-a' in opts:
addr = opts['-a']
elif '--address' in opts:
addr = opts['--address']
else:
addr = '127.0.0.1'
if '-p' in opts:
port = opts['-p']
elif '--port' in opts:
port = opts['--port']
else:
port = 4242
if '-o' in opts:
output = opts['-o']
elif '--output' in opts:
output = opts['--output']
else:
output = 'shell'
if '--eblp' in opts:
protocol = blup.BLP.PROTO_EBLP
elif '--e3blp' in opts:
protocol = blup.BLP.PROTO_E3BLP
else:
protocol = blup.BLP.PROTO_BLP
if '--eblp' in opts and '--e3blp' in opts:
printUsage('please only specify one of --eblp or --e3blp')
sys.exit(1)
try:
port = int(port)
except ValueError:
printUsage('invalid port specified')
sys.exit(1)
out = blup.output.getOutput(output)
srv = BLPServer(output=out, addr=addr, port=port, protocol=protocol)
try:
srv.serve()
except KeyboardInterrupt:
pass
try:
(opts, args) = getopt.gnu_getopt(sys.argv, 'ha:p:o:', ['help', 'address=', 'port=', 'output=', 'eblp', 'e3blp'])
opts = dict(opts)
except getopt.GetoptError as e:
printUsage(e.msg)
sys.exit(1)
if opts.has_key('--help'):
printUsage()
sys.exit(0)
if opts.has_key('-a'):
addr = opts['-a']
elif opts.has_key('--address'):
addr = opts['--address']
else:
addr = '127.0.0.1'
if opts.has_key('-p'):
port = opts['-p']
elif opts.has_key('--port'):
port = opts['--port']
else:
port = 4242
if opts.has_key('-o'):
output = opts['-o']
elif opts.has_key('--output'):
output = opts['--output']
else:
output = 'shell'
if opts.has_key('--eblp'):
protocol = blup.BLP.PROTO_EBLP
elif opts.has_key('--e3blp'):
protocol = blup.BLP.PROTO_E3BLP
else:
protocol = blup.BLP.PROTO_BLP
if opts.has_key('--eblp') and opts.has_key('--e3blp'):
printUsage('please only specify one of --eblp or --e3blp')
sys.exit(1)
try:
port = int(port)
except ValueError:
printUsage('invalid port specified')
sys.exit(1)
out = blup.output.getOutput(output)
srv = BLPServer(output=out, addr=addr, port=port, protocol=protocol)
try:
srv.serve()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()
main()

31
utils/miniplayer.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/python3
import threading
import os
@ -47,17 +47,14 @@ class MiniPlayer(object): @@ -47,17 +47,14 @@ class MiniPlayer(object):
"""
def __init__(self, animDir, animExtensions, output):
def __init__(self, animDir, output):
self.__animDir = animDir
self.__animExtensions = animExtensions
self.__output = output
self.loopTime = 10000
self.gap = 800
self.maxPlayNext = 3
self.__playNext = []
self.__running = False
self.__anims = {}
self.__anims_remaining = {}
def terminate(self):
self.__running = False
@ -82,23 +79,10 @@ class MiniPlayer(object): @@ -82,23 +79,10 @@ class MiniPlayer(object):
"""
if len(self.__playNext) > 0 and os.path.isfile(self.__playNext[0]):
anim = self.__playNext.pop(0)
return self.__playNext.pop(0)
else:
anims = set()
for dp, dns, fns in os.walk(self.__animDir, followlinks=True):
for fn in fns:
root, ext = os.path.splitext(fn)
if ext[1:] in self.__animExtensions:
anims.add(os.path.join(dp, fn))
if anims != self.__anims or len(self.__anims_remaining) == 0:
self.__anims = anims
self.__anims_remaining = set(anims)
anim = random.sample(self.__anims_remaining, 1)[0]
self.__anims_remaining.remove(anim)
print(anim)
return anim
files = os.listdir(self.__animDir)
return random.choice(files)
def run(self):
"""
@ -113,7 +97,8 @@ class MiniPlayer(object): @@ -113,7 +97,8 @@ class MiniPlayer(object):
while self.__running:
# begin to load the next animation
loader = AnimationLoaderThread(self.getNextFilename())
filename = os.path.join(self.__animDir, self.getNextFilename())
loader = AnimationLoaderThread(filename)
loader.start()
# play the animation in case it had been successfully loaded before
@ -187,7 +172,7 @@ def main(): @@ -187,7 +172,7 @@ def main():
print('%s is not a directory' % (animDir))
sys.exit(1)
p = MiniPlayer(animDir, ['bml'], out)
p = MiniPlayer(animDir, out)
try:
p.run()
except KeyboardInterrupt:

26
wii-pair/daemon.py

@ -15,9 +15,6 @@ known_boards = {'niklas': '00:26:59:34:C8:69', @@ -15,9 +15,6 @@ known_boards = {'niklas': '00:26:59:34:C8:69',
'fed': '00:23:CC:23:5E:1D',
}
MIN_WEIGHT = 10
PLAYER_TIMEOUT = 3
class StatusThread(Thread):
def __init__(self, t1, t2):
Thread.__init__(self)
@ -91,7 +88,6 @@ class WiiThread(Thread): @@ -91,7 +88,6 @@ class WiiThread(Thread):
self.pos_x = None
self.pos_y = None
self.weight = 0
self.timeout = None
def run(self):
if self.addr != 'dummy':
@ -112,8 +108,7 @@ class WiiThread(Thread): @@ -112,8 +108,7 @@ class WiiThread(Thread):
while not self.stop and self.board.status == 'Connected':
self.weight = self.board.mass.totalWeight
if self.board.mass.totalWeight >= MIN_WEIGHT:
self.timeout = None
if self.board.mass.totalWeight > 15:
m = self.board.mass
x_balance = -(m.topLeft+m.bottomLeft) + (m.topRight+m.bottomRight)
x_balance = x_balance/float(m.totalWeight)
@ -122,12 +117,8 @@ class WiiThread(Thread): @@ -122,12 +117,8 @@ class WiiThread(Thread):
self.pos_x = x_balance
self.pos_y = y_balance
else:
if self.timeout is None:
self.timeout = time.time()+PLAYER_TIMEOUT
else:
if time.time() >= self.timeout:
self.pos_x = None
self.pos_y = None
self.pos_x = None
self.pos_y = None
time.sleep(0.1)
@ -168,11 +159,9 @@ t2.start() @@ -168,11 +159,9 @@ t2.start()
while not t2.connected:
time.sleep(0.1)
tStatus = None
if os.environ.get('DEBUG_STATUS', 0) == '1':
tStatus = StatusThread(t1, t2)
tStatus.daemon = True
tStatus.start()
tStatus = StatusThread(t1, t2)
tStatus.daemon = True
tStatus.start()
wiis = [t1, t2]
@ -240,7 +229,6 @@ try: @@ -240,7 +229,6 @@ try:
except (KeyboardInterrupt, SystemExit):
t1.stop = True
t2.stop = True
if tStatus is not None:
tStatus.stop = True
tStatus.stop = True
sys.exit()

Loading…
Cancel
Save