#!/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 scroll_image(img, delay, color): 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 def create_scrolltext(text, delay, color): img = create_image(text) return scroll_image(img, delay, color) 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('-i', '--image', type=str) parser.add_argument('-t', '--text', type=str) parser.add_argument('output_file') args = parser.parse_args() if args.image is not None and args.text is not None: print('--image and --text are exclusive', file=sys.stderr) sys.exit(1) 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) if args.text: anim = create_scrolltext(args.text, args.delay, col) elif args.image: img = Image.open(args.image) img.convert(mode='RGB') anim = scroll_image(img, args.delay, col) writebml.writeBml(anim, args.output_file) ''' 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') '''