You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.3 KiB
84 lines
2.3 KiB
8 years ago
|
#!/usr/bin/python3
|
||
|
|
||
|
import sys
|
||
|
import colorsys
|
||
|
import blup.animation
|
||
|
import blup.frame
|
||
|
import writebml
|
||
|
import random
|
||
|
import argparse
|
||
|
from PIL import Image, ImageDraw, ImageFont
|
||
|
|
||
|
def create_image(text):
|
||
|
font = ImageFont.load('8x13-ISO8859-1.pil')
|
||
|
w, h = font.getsize(text)
|
||
|
|
||
|
img = Image.new('RGB', (w+2*22, 16))
|
||
|
draw = ImageDraw.Draw(img)
|
||
|
draw.text((22, (16-h)//2), text, font=font)
|
||
|
|
||
|
return img
|
||
|
|
||
|
def create_scrolltext(text, delay, color):
|
||
|
img = create_image(text)
|
||
|
|
||
|
w, h = img.size
|
||
|
|
||
|
dim = blup.frame.FrameDimension(22, 16, 256, 3)
|
||
|
anim = blup.animation.Animation(dim)
|
||
|
for c in range(w-dim.size()[0]):
|
||
|
frame = blup.animation.AnimationFrame(dim, delay)
|
||
|
for x in range(dim.size()[0]):
|
||
|
for y in range(dim.size()[1]):
|
||
|
pixcol = img.getpixel((x+c, y))
|
||
|
pixcol = (pixcol[0]*color[0],
|
||
|
pixcol[1]*color[1],
|
||
|
pixcol[2]*color[2])
|
||
|
frame.setPixel(x, y, pixcol)
|
||
|
anim.addFrame(frame)
|
||
|
|
||
|
return anim
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
parser = argparse.ArgumentParser(description='Generate scrolltext BML files')
|
||
|
parser.add_argument('-d', '--delay', type=int, default=100)
|
||
|
parser.add_argument('-c', '--color', default='#ffffff')
|
||
|
parser.add_argument('output_file')
|
||
|
parser.add_argument('text')
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
if args.color.startswith('#'):
|
||
|
args.color = args.color[1:]
|
||
|
r = int(args.color[0:2], 16)/255
|
||
|
g = int(args.color[2:4], 16)/255
|
||
|
b = int(args.color[4:6], 16)/255
|
||
|
col = (r, g, b)
|
||
|
|
||
|
anim = create_scrolltext(args.text, args.delay, col)
|
||
|
writebml.writeBml(anim, 'scrolltext.bml')
|
||
|
|
||
|
'''
|
||
|
num = 10
|
||
|
horiz = True
|
||
|
delay = 100
|
||
|
for i in range(num):
|
||
|
newcolor = getRandomColor(dim.depth - 1)
|
||
|
horiz = not horiz
|
||
|
if horiz:
|
||
|
for x in range(dim.size()[0]):
|
||
|
newframe = blup.animation.AnimationFrame(dim, delay)
|
||
|
for y in range(dim.size()[1]):
|
||
|
newframe.setPixel(x, y, newcolor)
|
||
|
newanim.addFrame(newframe)
|
||
|
else:
|
||
|
for y in range(dim.size()[1]):
|
||
|
newframe = blup.animation.AnimationFrame(dim, delay)
|
||
|
for x in range(dim.size()[0]):
|
||
|
newframe.setPixel(x, y, newcolor)
|
||
|
newanim.addFrame(newframe)
|
||
|
|
||
|
|
||
|
|
||
|
writebml.writeBml(newanim, '/tmp/colorwischer.bml')
|
||
|
'''
|